Debian Codegraph @

main/privacy.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2005, Digium, Inc.
5 *
6 * Mark Spencer <[email protected]>
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 <[email protected]>
24 */
25
26 /*** MODULEINFO
27 <support_level>core</support_level>
28 ***/
29
30 #include "asterisk.h"
31
32 #include <sys/time.h>
33 #include <signal.h>
34 #include <dirent.h>
35
36 #include "asterisk/channel.h"
37 #include "asterisk/file.h"
38 #include "asterisk/app.h"
39 #include "asterisk/dsp.h"
40 #include "asterisk/astdb.h"
41 #include "asterisk/callerid.h"
42 #include "asterisk/privacy.h"
43 #include "asterisk/utils.h"
44 #include "asterisk/lock.h"
45
46 int ast_privacy_check(char *dest, char *cid)
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) {
57 ast_shrink_phone_number(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 }
74
75 int ast_privacy_reset(char *dest)
76 {
77 if (!dest)
78 return -1;
79 return ast_db_deltree("privacy", dest);
80 }
81
82 int ast_privacy_set(char *dest, char *cid, int status)
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) {
93 ast_shrink_phone_number(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);
101 if (status == AST_PRIVACY_UNKNOWN)
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 }