Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions
privacy.h File Reference

Persistant data storage (akin to *doze registry) More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define AST_PRIVACY_ALLOW   (1 << 1) /* Pass directly to me */
 
#define AST_PRIVACY_DENY   (1 << 0) /* Don't bother ringing, send to voicemail */
 
#define AST_PRIVACY_KILL   (1 << 2) /* Play anti-telemarketer message and hangup */
 
#define AST_PRIVACY_TORTURE   (1 << 3) /* Send directly to tele-torture */
 
#define AST_PRIVACY_UNKNOWN   (1 << 16)
 

Functions

int ast_privacy_check (char *dest, char *cid)
 
int ast_privacy_reset (char *dest)
 
int ast_privacy_set (char *dest, char *cid, int status)
 

Detailed Description

Persistant data storage (akin to *doze registry)

Definition in file privacy.h.

Macro Definition Documentation

◆ AST_PRIVACY_ALLOW

#define AST_PRIVACY_ALLOW   (1 << 1) /* Pass directly to me */

Definition at line 31 of file privacy.h.

Referenced by ast_privacy_check(), ast_privacy_set(), setup_privacy_args(), and valid_priv_reply().

◆ AST_PRIVACY_DENY

#define AST_PRIVACY_DENY   (1 << 0) /* Don't bother ringing, send to voicemail */

Definition at line 30 of file privacy.h.

Referenced by ast_privacy_check(), ast_privacy_set(), setup_privacy_args(), and valid_priv_reply().

◆ AST_PRIVACY_KILL

#define AST_PRIVACY_KILL   (1 << 2) /* Play anti-telemarketer message and hangup */

Definition at line 32 of file privacy.h.

Referenced by ast_privacy_check(), ast_privacy_set(), setup_privacy_args(), and valid_priv_reply().

◆ AST_PRIVACY_TORTURE

#define AST_PRIVACY_TORTURE   (1 << 3) /* Send directly to tele-torture */

Definition at line 33 of file privacy.h.

Referenced by ast_privacy_check(), ast_privacy_set(), setup_privacy_args(), and valid_priv_reply().

◆ AST_PRIVACY_UNKNOWN

#define AST_PRIVACY_UNKNOWN   (1 << 16)

Definition at line 34 of file privacy.h.

Referenced by ast_privacy_check(), ast_privacy_set(), dial_exec_full(), and setup_privacy_args().

Function Documentation

◆ ast_privacy_check()

int ast_privacy_check ( char *  dest,
char *  cid 
)

Definition at line 46 of file privacy.c.

References ast_callerid_parse(), ast_copy_string(), ast_db_get(), AST_PRIVACY_ALLOW, AST_PRIVACY_DENY, AST_PRIVACY_KILL, AST_PRIVACY_TORTURE, AST_PRIVACY_UNKNOWN, ast_shrink_phone_number(), result, and tmp().

Referenced by setup_privacy_args().

47 {
48  char tmp[256] = "";
49  char *trimcid = "";
50  char *n, *l;
51  int res;
52  char key[256], result[256];
53  if (cid)
54  ast_copy_string(tmp, cid, sizeof(tmp));
55  ast_callerid_parse(tmp, &n, &l);
56  if (l) {
58  trimcid = l;
59  }
60  snprintf(key, sizeof(key), "%s/%s", dest, trimcid);
61  res = ast_db_get("privacy", key, result, sizeof(result));
62  if (!res) {
63  if (!strcasecmp(result, "allow"))
64  return AST_PRIVACY_ALLOW;
65  if (!strcasecmp(result, "deny"))
66  return AST_PRIVACY_DENY;
67  if (!strcasecmp(result, "kill"))
68  return AST_PRIVACY_KILL;
69  if (!strcasecmp(result, "torture"))
70  return AST_PRIVACY_TORTURE;
71  }
72  return AST_PRIVACY_UNKNOWN;
73 }
#define AST_PRIVACY_ALLOW
Definition: privacy.h:31
#define AST_PRIVACY_TORTURE
Definition: privacy.h:33
static int tmp()
Definition: bt_open.c:389
#define AST_PRIVACY_KILL
Definition: privacy.h:32
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
Definition: main/db.c:412
#define AST_PRIVACY_UNKNOWN
Definition: privacy.h:34
#define AST_PRIVACY_DENY
Definition: privacy.h:30
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
static PGresult * result
Definition: cel_pgsql.c:88
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()&#39;s, .&#39;s, and -&#39;s...
Definition: callerid.c:947
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1008

◆ ast_privacy_reset()

int ast_privacy_reset ( char *  dest)

Definition at line 75 of file privacy.c.

References ast_db_deltree().

76 {
77  if (!dest)
78  return -1;
79  return ast_db_deltree("privacy", dest);
80 }
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb.
Definition: main/db.c:457

◆ ast_privacy_set()

int ast_privacy_set ( char *  dest,
char *  cid,
int  status 
)

Definition at line 82 of file privacy.c.

References ast_callerid_parse(), ast_copy_string(), ast_db_del(), ast_db_put(), AST_PRIVACY_ALLOW, AST_PRIVACY_DENY, AST_PRIVACY_KILL, AST_PRIVACY_TORTURE, AST_PRIVACY_UNKNOWN, ast_shrink_phone_number(), ast_strlen_zero, and tmp().

Referenced by valid_priv_reply().

83 {
84  char tmp[256] = "";
85  char *trimcid = "";
86  char *n, *l;
87  int res;
88  char key[256];
89  if (cid)
90  ast_copy_string(tmp, cid, sizeof(tmp));
91  ast_callerid_parse(tmp, &n, &l);
92  if (l) {
94  trimcid = l;
95  }
96  if (ast_strlen_zero(trimcid)) {
97  /* Don't store anything for empty Caller*ID */
98  return 0;
99  }
100  snprintf(key, sizeof(key), "%s/%s", dest, trimcid);
102  res = ast_db_del("privacy", key);
103  else if (status == AST_PRIVACY_ALLOW)
104  res = ast_db_put("privacy", key, "allow");
105  else if (status == AST_PRIVACY_DENY)
106  res = ast_db_put("privacy", key, "deny");
107  else if (status == AST_PRIVACY_KILL)
108  res = ast_db_put("privacy", key, "kill");
109  else if (status == AST_PRIVACY_TORTURE)
110  res = ast_db_put("privacy", key, "torture");
111  else
112  res = -1;
113  return res;
114 }
#define AST_PRIVACY_ALLOW
Definition: privacy.h:31
#define AST_PRIVACY_TORTURE
Definition: privacy.h:33
static int tmp()
Definition: bt_open.c:389
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define AST_PRIVACY_KILL
Definition: privacy.h:32
#define AST_PRIVACY_UNKNOWN
Definition: privacy.h:34
#define AST_PRIVACY_DENY
Definition: privacy.h:30
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
Definition: main/db.c:429
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition: main/db.c:327
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()&#39;s, .&#39;s, and -&#39;s...
Definition: callerid.c:947
jack_status_t status
Definition: app_jack.c:146
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1008