00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "asterisk.h"
00027
00028 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 40722 $")
00029
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <sys/time.h>
00034 #include <signal.h>
00035 #include <errno.h>
00036 #include <unistd.h>
00037 #include <dirent.h>
00038
00039 #include "asterisk/channel.h"
00040 #include "asterisk/file.h"
00041 #include "asterisk/app.h"
00042 #include "asterisk/dsp.h"
00043 #include "asterisk/logger.h"
00044 #include "asterisk/options.h"
00045 #include "asterisk/astdb.h"
00046 #include "asterisk/callerid.h"
00047 #include "asterisk/privacy.h"
00048 #include "asterisk/utils.h"
00049 #include "asterisk/lock.h"
00050
00051 int ast_privacy_check(char *dest, char *cid)
00052 {
00053 char tmp[256] = "";
00054 char *trimcid = "";
00055 char *n, *l;
00056 int res;
00057 char key[256], result[256];
00058 if (cid)
00059 ast_copy_string(tmp, cid, sizeof(tmp));
00060 ast_callerid_parse(tmp, &n, &l);
00061 if (l) {
00062 ast_shrink_phone_number(l);
00063 trimcid = l;
00064 }
00065 snprintf(key, sizeof(key), "%s/%s", dest, trimcid);
00066 res = ast_db_get("privacy", key, result, sizeof(result));
00067 if (!res) {
00068 if (!strcasecmp(result, "allow"))
00069 return AST_PRIVACY_ALLOW;
00070 if (!strcasecmp(result, "deny"))
00071 return AST_PRIVACY_DENY;
00072 if (!strcasecmp(result, "kill"))
00073 return AST_PRIVACY_KILL;
00074 if (!strcasecmp(result, "torture"))
00075 return AST_PRIVACY_TORTURE;
00076 }
00077 return AST_PRIVACY_UNKNOWN;
00078 }
00079
00080 int ast_privacy_reset(char *dest)
00081 {
00082 if (!dest)
00083 return -1;
00084 return ast_db_deltree("privacy", dest);
00085 }
00086
00087 int ast_privacy_set(char *dest, char *cid, int status)
00088 {
00089 char tmp[256] = "";
00090 char *trimcid = "";
00091 char *n, *l;
00092 int res;
00093 char key[256];
00094 if (cid)
00095 ast_copy_string(tmp, cid, sizeof(tmp));
00096 ast_callerid_parse(tmp, &n, &l);
00097 if (l) {
00098 ast_shrink_phone_number(l);
00099 trimcid = l;
00100 }
00101 if (ast_strlen_zero(trimcid)) {
00102
00103 return 0;
00104 }
00105 snprintf(key, sizeof(key), "%s/%s", dest, trimcid);
00106 if (status == AST_PRIVACY_UNKNOWN)
00107 res = ast_db_del("privacy", key);
00108 else if (status == AST_PRIVACY_ALLOW)
00109 res = ast_db_put("privacy", key, "allow");
00110 else if (status == AST_PRIVACY_DENY)
00111 res = ast_db_put("privacy", key, "deny");
00112 else if (status == AST_PRIVACY_KILL)
00113 res = ast_db_put("privacy", key, "kill");
00114 else if (status == AST_PRIVACY_TORTURE)
00115 res = ast_db_put("privacy", key, "torture");
00116 else
00117 res = -1;
00118 return res;
00119 }