Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

privacy.c

Go to the documentation of this file.
00001 /* 00002 * Asterisk -- A telephony toolkit for Linux. 00003 * 00004 * Channel Management 00005 * 00006 * Copyright (C) 1999, Mark Spencer 00007 * 00008 * Mark Spencer <markster@linux-support.net> 00009 * 00010 * This program is free software, distributed under the terms of 00011 * the GNU General Public License 00012 */ 00013 00014 #include <stdio.h> 00015 #include <stdlib.h> 00016 #include <pthread.h> 00017 #include <string.h> 00018 #include <sys/time.h> 00019 #include <signal.h> 00020 #include <errno.h> 00021 #include <unistd.h> 00022 #include <dirent.h> 00023 #include <asterisk/channel.h> 00024 #include <asterisk/file.h> 00025 #include <asterisk/app.h> 00026 #include <asterisk/dsp.h> 00027 #include <asterisk/logger.h> 00028 #include <asterisk/options.h> 00029 #include <asterisk/astdb.h> 00030 #include <asterisk/callerid.h> 00031 #include <asterisk/privacy.h> 00032 #include <asterisk/utils.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 /* Don't store anything for empty Caller*ID */ 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 }

Generated on Sat Jun 12 16:40:59 2004 for Asterisk by doxygen 1.3.7