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>
28 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
39 #include "asterisk/channel.h"
40 #include "asterisk/file.h"
41 #include "asterisk/app.h"
42 #include "asterisk/dsp.h"
43 #include "asterisk/logger.h"
44 #include "asterisk/options.h"
45 #include "asterisk/astdb.h"
46 #include "asterisk/callerid.h"
47 #include "asterisk/privacy.h"
48 #include "asterisk/utils.h"
49 #include "asterisk/lock.h"
51 int ast_privacy_check(char *dest
, char *cid
)
57 char key
[256], result
[256];
59 ast_copy_string(tmp
, cid
, sizeof(tmp
));
60 ast_callerid_parse(tmp
, &n
, &l
);
62 ast_shrink_phone_number(l
);
65 snprintf(key
, sizeof(key
), "%s/%s", dest
, trimcid
);
66 res
= ast_db_get("privacy", key
, result
, sizeof(result
));
68 if (!strcasecmp(result
, "allow"))
69 return AST_PRIVACY_ALLOW
;
70 if (!strcasecmp(result
, "deny"))
71 return AST_PRIVACY_DENY
;
72 if (!strcasecmp(result
, "kill"))
73 return AST_PRIVACY_KILL
;
74 if (!strcasecmp(result
, "torture"))
75 return AST_PRIVACY_TORTURE
;
77 return AST_PRIVACY_UNKNOWN
;
80 int ast_privacy_reset(char *dest
)
84 return ast_db_deltree("privacy", dest
);
87 int ast_privacy_set(char *dest
, char *cid
, int status
)
95 ast_copy_string(tmp
, cid
, sizeof(tmp
));
96 ast_callerid_parse(tmp
, &n
, &l
);
98 ast_shrink_phone_number(l
);
101 if (ast_strlen_zero(trimcid
)) {
102 /* Don't store anything for empty Caller*ID */
105 snprintf(key
, sizeof(key
), "%s/%s", dest
, trimcid
);
106 if (status
== AST_PRIVACY_UNKNOWN
)
107 res
= ast_db_del("privacy", key
);
108 else if (status
== AST_PRIVACY_ALLOW
)
109 res
= ast_db_put("privacy", key
, "allow");
110 else if (status
== AST_PRIVACY_DENY
)
111 res
= ast_db_put("privacy", key
, "deny");
112 else if (status
== AST_PRIVACY_KILL
)
113 res
= ast_db_put("privacy", key
, "kill");
114 else if (status
== AST_PRIVACY_TORTURE
)
115 res
= ast_db_put("privacy", key
, "torture");