Wed Jan 8 2020 09:49:49

Asterisk developer's documentation


privacy.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  *
21  * \brief Privacy Routines
22  *
23  * \author Mark Spencer <markster@digium.com>
24  */
25 
26 /*** MODULEINFO
27  <support_level>core</support_level>
28  ***/
29 
30 #include "asterisk.h"
31 
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 369001 $")
33 
34 #include <sys/time.h>
35 #include <signal.h>
36 #include <dirent.h>
37 
38 #include "asterisk/channel.h"
39 #include "asterisk/file.h"
40 #include "asterisk/app.h"
41 #include "asterisk/dsp.h"
42 #include "asterisk/astdb.h"
43 #include "asterisk/callerid.h"
44 #include "asterisk/privacy.h"
45 #include "asterisk/utils.h"
46 #include "asterisk/lock.h"
47 
48 int ast_privacy_check(char *dest, char *cid)
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 }
76 
77 int ast_privacy_reset(char *dest)
78 {
79  if (!dest)
80  return -1;
81  return ast_db_deltree("privacy", dest);
82 }
83 
84 int ast_privacy_set(char *dest, char *cid, int status)
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
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
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
Convenient Signal Processing routines.
int ast_privacy_check(char *dest, char *cid)
Definition: privacy.c:48
#define AST_PRIVACY_TORTURE
Definition: privacy.h:33
Persistant data storage (akin to *doze registry)
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
Utility functions.
General Asterisk PBX channel definitions.
#define AST_PRIVACY_KILL
Definition: privacy.h:32
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
int ast_privacy_set(char *dest, char *cid, int status)
Definition: privacy.c:84
#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
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
int ast_privacy_reset(char *dest)
Definition: privacy.c:77
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
Persistant data storage (akin to *doze registry)
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
jack_status_t status
Definition: app_jack.c:143
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1009