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.h"
00033 
00034 int ast_privacy_check(char *dest, char *cid)
00035 {
00036    char tmp[256] = "";
00037    char *trimcid = "";
00038    char *n, *l;
00039    int res;
00040    char key[256], result[256];
00041    if (cid)
00042       strncpy(tmp, cid, sizeof(tmp) - 1);
00043    ast_callerid_parse(tmp, &n, &l);
00044    if (l) {
00045       ast_shrink_phone_number(l);
00046       trimcid = l;
00047    }
00048    snprintf(key, sizeof(key), "%s/%s", dest, trimcid);
00049    res = ast_db_get("privacy", key, result, sizeof(result));
00050    if (!res) {
00051       if (!strcasecmp(result, "allow"))
00052          return AST_PRIVACY_ALLOW;
00053       if (!strcasecmp(result, "deny"))
00054          return AST_PRIVACY_DENY;
00055       if (!strcasecmp(result, "kill"))
00056          return AST_PRIVACY_KILL;
00057       if (!strcasecmp(result, "torture"))
00058          return AST_PRIVACY_TORTURE;
00059    }
00060    return AST_PRIVACY_UNKNOWN;
00061 }
00062 
00063 int ast_privacy_reset(char *dest)
00064 {
00065    if (!dest)
00066       return -1;
00067    return ast_db_deltree("privacy", dest);
00068 }
00069 
00070 int ast_privacy_set(char *dest, char *cid, int status)
00071 {
00072    char tmp[256] = "";
00073    char *trimcid = "";
00074    char *n, *l;
00075    int res;
00076    char key[256];
00077    if (cid)
00078       strncpy(tmp, cid, sizeof(tmp) - 1);
00079    ast_callerid_parse(tmp, &n, &l);
00080    if (l) {
00081       ast_shrink_phone_number(l);
00082       trimcid = l;
00083    }
00084    if (!strlen(trimcid)) {
00085       /* Don't store anything for empty Caller*ID */
00086       return 0;
00087    }
00088    snprintf(key, sizeof(key), "%s/%s", dest, trimcid);
00089    if (status == AST_PRIVACY_UNKNOWN) 
00090       res = ast_db_del("privacy", key);
00091    else if (status == AST_PRIVACY_ALLOW)
00092       res = ast_db_put("privacy", key, "allow");
00093    else if (status == AST_PRIVACY_DENY)
00094       res = ast_db_put("privacy", key, "deny");
00095    else if (status == AST_PRIVACY_KILL)
00096       res = ast_db_put("privacy", key, "kill");
00097    else if (status == AST_PRIVACY_TORTURE)
00098       res = ast_db_put("privacy", key, "torture");
00099    else
00100       res = -1;
00101    return res;
00102 }

Generated on Sun Apr 18 23:33:54 2004 for Asterisk by doxygen 1.3.6-20040222