| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 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) { |
| 57 |
ast_shrink_phone_number(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) { |
| 93 |
ast_shrink_phone_number(l); |
| 94 |
trimcid = l; |
| 95 |
} |
| 96 |
if (ast_strlen_zero(trimcid)) { |
| 97 |
|
| 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 |
} |