Mon Jun 27 16:50:55 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: 89511 $")
00029 
00030 #include <sys/time.h>
00031 #include <signal.h>
00032 #include <dirent.h>
00033 
00034 #include "asterisk/channel.h"
00035 #include "asterisk/file.h"
00036 #include "asterisk/app.h"
00037 #include "asterisk/dsp.h"
00038 #include "asterisk/astdb.h"
00039 #include "asterisk/callerid.h"
00040 #include "asterisk/privacy.h"
00041 #include "asterisk/utils.h"
00042 #include "asterisk/lock.h"
00043 
00044 int ast_privacy_check(char *dest, char *cid)
00045 {
00046    char tmp[256] = "";
00047    char *trimcid = "";
00048    char *n, *l;
00049    int res;
00050    char key[256], result[256];
00051    if (cid)
00052       ast_copy_string(tmp, cid, sizeof(tmp));
00053    ast_callerid_parse(tmp, &n, &l);
00054    if (l) {
00055       ast_shrink_phone_number(l);
00056       trimcid = l;
00057    }
00058    snprintf(key, sizeof(key), "%s/%s", dest, trimcid);
00059    res = ast_db_get("privacy", key, result, sizeof(result));
00060    if (!res) {
00061       if (!strcasecmp(result, "allow"))
00062          return AST_PRIVACY_ALLOW;
00063       if (!strcasecmp(result, "deny"))
00064          return AST_PRIVACY_DENY;
00065       if (!strcasecmp(result, "kill"))
00066          return AST_PRIVACY_KILL;
00067       if (!strcasecmp(result, "torture"))
00068          return AST_PRIVACY_TORTURE;
00069    }
00070    return AST_PRIVACY_UNKNOWN;
00071 }
00072 
00073 int ast_privacy_reset(char *dest)
00074 {
00075    if (!dest)
00076       return -1;
00077    return ast_db_deltree("privacy", dest);
00078 }
00079 
00080 int ast_privacy_set(char *dest, char *cid, int status)
00081 {
00082    char tmp[256] = "";
00083    char *trimcid = "";
00084    char *n, *l;
00085    int res;
00086    char key[256];
00087    if (cid)
00088       ast_copy_string(tmp, cid, sizeof(tmp));
00089    ast_callerid_parse(tmp, &n, &l);
00090    if (l) {
00091       ast_shrink_phone_number(l);
00092       trimcid = l;
00093    }
00094    if (ast_strlen_zero(trimcid)) {
00095       /* Don't store anything for empty Caller*ID */
00096       return 0;
00097    }
00098    snprintf(key, sizeof(key), "%s/%s", dest, trimcid);
00099    if (status == AST_PRIVACY_UNKNOWN) 
00100       res = ast_db_del("privacy", key);
00101    else if (status == AST_PRIVACY_ALLOW)
00102       res = ast_db_put("privacy", key, "allow");
00103    else if (status == AST_PRIVACY_DENY)
00104       res = ast_db_put("privacy", key, "deny");
00105    else if (status == AST_PRIVACY_KILL)
00106       res = ast_db_put("privacy", key, "kill");
00107    else if (status == AST_PRIVACY_TORTURE)
00108       res = ast_db_put("privacy", key, "torture");
00109    else
00110       res = -1;
00111    return res;
00112 }

Generated on Mon Jun 27 16:50:55 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7