privacy.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <dirent.h>
#include <asterisk/channel.h>
#include <asterisk/file.h>
#include <asterisk/app.h>
#include <asterisk/dsp.h>
#include <asterisk/logger.h>
#include <asterisk/options.h>
#include <asterisk/astdb.h>
#include <asterisk/callerid.h>
#include <asterisk/privacy.h>
#include <asterisk/utils.h>
#include <asterisk/lock.h>
#include "asterisk.h"

Include dependency graph for privacy.c:

Go to the source code of this file.

Functions

int ast_privacy_check (char *dest, char *cid)
int ast_privacy_reset (char *dest)
int ast_privacy_set (char *dest, char *cid, int status)


Function Documentation

int ast_privacy_check ( char *  dest,
char *  cid 
)

Definition at line 35 of file privacy.c.

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 }

int ast_privacy_reset ( char *  dest  ) 

Definition at line 64 of file privacy.c.

00065 {
00066    if (!dest)
00067       return -1;
00068    return ast_db_deltree("privacy", dest);
00069 }

int ast_privacy_set ( char *  dest,
char *  cid,
int  status 
)

Definition at line 71 of file privacy.c.

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 Wed Oct 28 17:01:00 2009 for Asterisk by  doxygen 1.5.6