2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
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.
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.
21 * \brief Privacy Routines
23 * \author Mark Spencer <markster@digium.com>
27 <support_level>core</support_level>
32 ASTERISK_REGISTER_FILE()
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"
48 int ast_privacy_check(char *dest, char *cid)
54 char key[256], result[256];
56 ast_copy_string(tmp, cid, sizeof(tmp));
57 ast_callerid_parse(tmp, &n, &l);
59 ast_shrink_phone_number(l);
62 snprintf(key, sizeof(key), "%s/%s", dest, trimcid);
63 res = ast_db_get("privacy", key, result, sizeof(result));
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;
74 return AST_PRIVACY_UNKNOWN;
77 int ast_privacy_reset(char *dest)
81 return ast_db_deltree("privacy", dest);
84 int ast_privacy_set(char *dest, char *cid, int status)
92 ast_copy_string(tmp, cid, sizeof(tmp));
93 ast_callerid_parse(tmp, &n, &l);
95 ast_shrink_phone_number(l);
98 if (ast_strlen_zero(trimcid)) {
99 /* Don't store anything for empty Caller*ID */
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");