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