Sat Aug 6 00:39:31 2011

Asterisk developer's documentation


privacy.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief Privacy Routines
00022  *
00023  * \author Mark Spencer <markster@digium.com> 
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       /* Don't store anything for empty Caller*ID */
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 }

Generated on Sat Aug 6 00:39:31 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7