Asterisk - The Open Source Telephony Project  18.5.0
privacy.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  *
21  * \brief Privacy Routines
22  *
23  * \author Mark Spencer <[email protected]>
24  */
25 
26 /*** MODULEINFO
27  <support_level>core</support_level>
28  ***/
29 
30 #include "asterisk.h"
31 
32 #include <sys/time.h>
33 #include <signal.h>
34 #include <dirent.h>
35 
36 #include "asterisk/channel.h"
37 #include "asterisk/file.h"
38 #include "asterisk/app.h"
39 #include "asterisk/dsp.h"
40 #include "asterisk/astdb.h"
41 #include "asterisk/callerid.h"
42 #include "asterisk/privacy.h"
43 #include "asterisk/utils.h"
44 #include "asterisk/lock.h"
45 
46 int ast_privacy_check(char *dest, char *cid)
47 {
48  char tmp[256] = "";
49  char *trimcid = "";
50  char *n, *l;
51  int res;
52  char key[256], result[256];
53  if (cid)
54  ast_copy_string(tmp, cid, sizeof(tmp));
55  ast_callerid_parse(tmp, &n, &l);
56  if (l) {
58  trimcid = l;
59  }
60  snprintf(key, sizeof(key), "%s/%s", dest, trimcid);
61  res = ast_db_get("privacy", key, result, sizeof(result));
62  if (!res) {
63  if (!strcasecmp(result, "allow"))
64  return AST_PRIVACY_ALLOW;
65  if (!strcasecmp(result, "deny"))
66  return AST_PRIVACY_DENY;
67  if (!strcasecmp(result, "kill"))
68  return AST_PRIVACY_KILL;
69  if (!strcasecmp(result, "torture"))
70  return AST_PRIVACY_TORTURE;
71  }
72  return AST_PRIVACY_UNKNOWN;
73 }
74 
75 int ast_privacy_reset(char *dest)
76 {
77  if (!dest)
78  return -1;
79  return ast_db_deltree("privacy", dest);
80 }
81 
82 int ast_privacy_set(char *dest, char *cid, int status)
83 {
84  char tmp[256] = "";
85  char *trimcid = "";
86  char *n, *l;
87  int res;
88  char key[256];
89  if (cid)
90  ast_copy_string(tmp, cid, sizeof(tmp));
91  ast_callerid_parse(tmp, &n, &l);
92  if (l) {
94  trimcid = l;
95  }
96  if (ast_strlen_zero(trimcid)) {
97  /* Don't store anything for empty Caller*ID */
98  return 0;
99  }
100  snprintf(key, sizeof(key), "%s/%s", dest, trimcid);
101  if (status == AST_PRIVACY_UNKNOWN)
102  res = ast_db_del("privacy", key);
103  else if (status == AST_PRIVACY_ALLOW)
104  res = ast_db_put("privacy", key, "allow");
105  else if (status == AST_PRIVACY_DENY)
106  res = ast_db_put("privacy", key, "deny");
107  else if (status == AST_PRIVACY_KILL)
108  res = ast_db_put("privacy", key, "kill");
109  else if (status == AST_PRIVACY_TORTURE)
110  res = ast_db_put("privacy", key, "torture");
111  else
112  res = -1;
113  return res;
114 }
#define AST_PRIVACY_ALLOW
Definition: privacy.h:31
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
Convenient Signal Processing routines.
#define AST_PRIVACY_TORTURE
Definition: privacy.h:33
static int tmp()
Definition: bt_open.c:389
Persistant data storage (akin to *doze registry)
int ast_privacy_reset(char *dest)
Definition: privacy.c:75
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
Utility functions.
#define ast_strlen_zero(foo)
Definition: strings.h:52
General Asterisk PBX channel definitions.
#define AST_PRIVACY_KILL
Definition: privacy.h:32
int ast_privacy_check(char *dest, char *cid)
Definition: privacy.c:46
int ast_privacy_set(char *dest, char *cid, int status)
Definition: privacy.c:82
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
Definition: main/db.c:412
#define AST_PRIVACY_UNKNOWN
Definition: privacy.h:34
#define AST_PRIVACY_DENY
Definition: privacy.h:30
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
Definition: main/db.c:429
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
static PGresult * result
Definition: cel_pgsql.c:88
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition: main/db.c:327
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()&#39;s, .&#39;s, and -&#39;s...
Definition: callerid.c:947
Persistant data storage (akin to *doze registry)
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb.
Definition: main/db.c:457
jack_status_t status
Definition: app_jack.c:146
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1008