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$")
34 #include "asterisk/channel.h"
35 #include "asterisk/file.h"
36 #include "asterisk/app.h"
37 #include "asterisk/dsp.h"
38 #include "asterisk/astdb.h"
39 #include "asterisk/callerid.h"
40 #include "asterisk/privacy.h"
41 #include "asterisk/utils.h"
42 #include "asterisk/lock.h"
44 int ast_privacy_check(char *dest
, char *cid
)
50 char key
[256], result
[256];
52 ast_copy_string(tmp
, cid
, sizeof(tmp
));
53 ast_callerid_parse(tmp
, &n
, &l
);
55 ast_shrink_phone_number(l
);
58 snprintf(key
, sizeof(key
), "%s/%s", dest
, trimcid
);
59 res
= ast_db_get("privacy", key
, result
, sizeof(result
));
61 if (!strcasecmp(result
, "allow"))
62 return AST_PRIVACY_ALLOW
;
63 if (!strcasecmp(result
, "deny"))
64 return AST_PRIVACY_DENY
;
65 if (!strcasecmp(result
, "kill"))
66 return AST_PRIVACY_KILL
;
67 if (!strcasecmp(result
, "torture"))
68 return AST_PRIVACY_TORTURE
;
70 return AST_PRIVACY_UNKNOWN
;
73 int ast_privacy_reset(char *dest
)
77 return ast_db_deltree("privacy", dest
);
80 int ast_privacy_set(char *dest
, char *cid
, int status
)
88 ast_copy_string(tmp
, cid
, sizeof(tmp
));
89 ast_callerid_parse(tmp
, &n
, &l
);
91 ast_shrink_phone_number(l
);
94 if (ast_strlen_zero(trimcid
)) {
95 /* Don't store anything for empty Caller*ID */
98 snprintf(key
, sizeof(key
), "%s/%s", dest
, trimcid
);
99 if (status
== AST_PRIVACY_UNKNOWN
)
100 res
= ast_db_del("privacy", key
);
101 else if (status
== AST_PRIVACY_ALLOW
)
102 res
= ast_db_put("privacy", key
, "allow");
103 else if (status
== AST_PRIVACY_DENY
)
104 res
= ast_db_put("privacy", key
, "deny");
105 else if (status
== AST_PRIVACY_KILL
)
106 res
= ast_db_put("privacy", key
, "kill");
107 else if (status
== AST_PRIVACY_TORTURE
)
108 res
= ast_db_put("privacy", key
, "torture");