Wed Jan 8 2020 09:50:17

Asterisk developer's documentation


privacy.c File Reference

Privacy Routines. More...

#include "asterisk.h"
#include <sys/time.h>
#include <signal.h>
#include <dirent.h>
#include "asterisk/channel.h"
#include "asterisk/file.h"
#include "asterisk/app.h"
#include "asterisk/dsp.h"
#include "asterisk/astdb.h"
#include "asterisk/callerid.h"
#include "asterisk/privacy.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"

Go to the source code of this file.

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

Privacy Routines.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file privacy.c.

Function Documentation

int ast_privacy_check ( char *  dest,
char *  cid 
)

Definition at line 48 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, and ast_shrink_phone_number().

Referenced by setup_privacy_args().

49 {
50  char tmp[256] = "";
51  char *trimcid = "";
52  char *n, *l;
53  int res;
54  char key[256], result[256];
55  if (cid)
56  ast_copy_string(tmp, cid, sizeof(tmp));
57  ast_callerid_parse(tmp, &n, &l);
58  if (l) {
60  trimcid = l;
61  }
62  snprintf(key, sizeof(key), "%s/%s", dest, trimcid);
63  res = ast_db_get("privacy", key, result, sizeof(result));
64  if (!res) {
65  if (!strcasecmp(result, "allow"))
66  return AST_PRIVACY_ALLOW;
67  if (!strcasecmp(result, "deny"))
68  return AST_PRIVACY_DENY;
69  if (!strcasecmp(result, "kill"))
70  return AST_PRIVACY_KILL;
71  if (!strcasecmp(result, "torture"))
72  return AST_PRIVACY_TORTURE;
73  }
74  return AST_PRIVACY_UNKNOWN;
75 }
#define AST_PRIVACY_ALLOW
Definition: privacy.h:31
int ast_db_get(const char *family, const char *key, char *out, int outlen)
Get key value specified by family/key.
Definition: db.c:348
#define AST_PRIVACY_TORTURE
Definition: privacy.h:33
#define AST_PRIVACY_KILL
Definition: privacy.h:32
#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:223
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:948
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1009
int ast_privacy_reset ( char *  dest)

Definition at line 77 of file privacy.c.

References ast_db_deltree().

78 {
79  if (!dest)
80  return -1;
81  return ast_db_deltree("privacy", dest);
82 }
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb If both parameters are NULL, the entire database will be purged...
Definition: db.c:241
int ast_privacy_set ( char *  dest,
char *  cid,
int  status 
)

Definition at line 84 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(), and ast_strlen_zero().

85 {
86  char tmp[256] = "";
87  char *trimcid = "";
88  char *n, *l;
89  int res;
90  char key[256];
91  if (cid)
92  ast_copy_string(tmp, cid, sizeof(tmp));
93  ast_callerid_parse(tmp, &n, &l);
94  if (l) {
96  trimcid = l;
97  }
98  if (ast_strlen_zero(trimcid)) {
99  /* Don't store anything for empty Caller*ID */
100  return 0;
101  }
102  snprintf(key, sizeof(key), "%s/%s", dest, trimcid);
103  if (status == AST_PRIVACY_UNKNOWN)
104  res = ast_db_del("privacy", key);
105  else if (status == AST_PRIVACY_ALLOW)
106  res = ast_db_put("privacy", key, "allow");
107  else if (status == AST_PRIVACY_DENY)
108  res = ast_db_put("privacy", key, "deny");
109  else if (status == AST_PRIVACY_KILL)
110  res = ast_db_put("privacy", key, "kill");
111  else if (status == AST_PRIVACY_TORTURE)
112  res = ast_db_put("privacy", key, "torture");
113  else
114  res = -1;
115  return res;
116 }
#define AST_PRIVACY_ALLOW
Definition: privacy.h:31
#define AST_PRIVACY_TORTURE
Definition: privacy.h:33
#define AST_PRIVACY_KILL
Definition: privacy.h:32
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#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: db.c:365
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition: db.c:260
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:948
jack_status_t status
Definition: app_jack.c:143
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1009