diff -Nru a/apps/app_setcallerid.c b/apps/app_setcallerid.c --- a/apps/app_setcallerid.c 2005-02-22 18:34:38 -07:00 +++ b/apps/app_setcallerid.c 2005-02-22 18:34:38 -07:00 @@ -31,25 +31,9 @@ LOCAL_USER_DECL; -static struct { - int val; - char *name; -} preses[] = { - { AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, "allowed_not_screened" }, - { AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, "allowed_passed_screen" }, - { AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN, "allowed_failed_screen" }, - { AST_PRES_ALLOWED_NETWORK_NUMBER, "allowed" }, - { AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED , "prohib_not_screened" }, - { AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN, "prohib_passed_screen" }, - { AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN, "prohib_failed_screen" }, - { AST_PRES_PROHIB_NETWORK_NUMBER, "prohib" }, - { AST_PRES_NUMBER_NOT_AVAILABLE, "unavailable" }, -}; - static char *descrip2 = -" SetCallerPres(presentation): Set Caller*ID presentation on\n" -"a call to a new value. Sets ANI as well if a flag is used.\n" -"Always returns 0. Valid presentations are:\n" +" SetCallerPres(presentation): Set Caller*ID presentation on a call.\n" +" Always returns 0. Valid presentations are:\n" "\n" " allowed_not_screened : Presentation Allowed, Not Screened\n" " allowed_passed_screen : Presentation Allowed, Passed Screen\n" @@ -65,33 +49,21 @@ static int setcallerid_pres_exec(struct ast_channel *chan, void *data) { - int res = 0; - char tmp[256] = ""; struct localuser *u; - int x; - char *opts; int pres = -1; - if (data) - strncpy(tmp, (char *)data, sizeof(tmp) - 1); - opts = strchr(tmp, '|'); - if (opts) { - *opts = '\0'; - opts++; - } - for (x=0;xcid.cid_pres = pres; LOCAL_USER_REMOVE(u); - return res; + return 0; } diff -Nru a/callerid.c b/callerid.c --- a/callerid.c 2005-02-22 18:34:38 -07:00 +++ b/callerid.c 2005-02-22 18:34:38 -07:00 @@ -715,3 +715,43 @@ num[0] = '\0'; return 0; } + +static struct { + int val; + char *name; + char *description; +} pres_types[] = { + { AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, "allowed_not_screened", "Presentation Allowed, Not Screened"}, + { AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, "allowed_passed_screen", "Presentation Allowed, Passed Screen"}, + { AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN, "allowed_failed_screen", "Presentation Allowed, Failed Screen"}, + { AST_PRES_ALLOWED_NETWORK_NUMBER, "allowed", "Presentation Allowed, Network Number"}, + { AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED, "prohib_not_screened", "Presentation Prohibited, Not Screened"}, + { AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN, "prohib_passed_screen", "Presentation Prohibited, Passed Screen"}, + { AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN, "prohib_failed_screen", "Presentation Prohibited, Failed Screen"}, + { AST_PRES_PROHIB_NETWORK_NUMBER, "prohib", "Presentation Prohibited, Network Number"}, + { AST_PRES_NUMBER_NOT_AVAILABLE, "unavailable", "Number Unavailable"}, +}; + +int ast_parse_caller_presentation(const char *data) +{ + int i; + + for (i = 0; i < ((sizeof(pres_types) / sizeof(pres_types[0]))); i++) { + if (!strcasecmp(pres_types[i].name, data)) + return pres_types[i].val; + } + + return -1; +} + +const char *ast_describe_caller_presentation(int data) +{ + int i; + + for (i = 0; i < ((sizeof(pres_types) / sizeof(pres_types[0]))); i++) { + if (pres_types[i].val == data) + return pres_types[i].description; + } + + return "unknown"; +} diff -Nru a/channels/chan_sip.c b/channels/chan_sip.c --- a/channels/chan_sip.c 2005-02-22 18:34:38 -07:00 +++ b/channels/chan_sip.c 2005-02-22 18:34:38 -07:00 @@ -3861,7 +3861,7 @@ if (!l || (!ast_isphonenumber(l) && default_callerid[0])) l = default_callerid; /* if user want's his callerid restricted */ - if (p->callingpres & AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED) { + if ((p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) { l = CALLERID_UNKNOWN; n = l; } @@ -6253,7 +6253,8 @@ ast_cli(fd, " Language : %s\n", peer->language); if (!ast_strlen_zero(peer->accountcode)) ast_cli(fd, " Accountcode : %s\n", peer->accountcode); - ast_cli(fd, " AMA flag : %s\n", ast_cdr_flags2str(peer->amaflags)); + ast_cli(fd, " AMA flags : %s\n", ast_cdr_flags2str(peer->amaflags)); + ast_cli(fd, " CallingPres : %s\n", ast_describe_caller_presentation(peer->callingpres)); if (!ast_strlen_zero(peer->fromuser)) ast_cli(fd, " FromUser : %s\n", peer->fromuser); if (!ast_strlen_zero(peer->fromdomain)) @@ -6354,7 +6355,8 @@ ast_cli(fd, " Language : %s\n", user->language); if (!ast_strlen_zero(user->accountcode)) ast_cli(fd, " Accountcode : %s\n", user->accountcode); - ast_cli(fd, " AMA flag : %s\n", ast_cdr_flags2str(user->amaflags)); + ast_cli(fd, " AMA flags : %s\n", ast_cdr_flags2str(user->amaflags)); + ast_cli(fd, " CallingPres : %s\n", ast_describe_caller_presentation(user->callingpres)); ast_cli(fd, " Inc. limit : %d\n", user->incominglimit); ast_cli(fd, " Outg. limit : %d\n", user->outgoinglimit); ast_cli(fd, " Callgroup : "); @@ -9092,7 +9094,9 @@ } else if (!strcasecmp(v->name, "disallow")) { ast_parse_allow_disallow(&user->prefs, &user->capability, v->value, 0); } else if (!strcasecmp(v->name, "callingpres")) { - user->callingpres = atoi(v->value); + user->callingpres = ast_parse_caller_presentation(v->value); + if (user->callingpres == -1) + user->callingpres = atoi(v->value); } /*else if (strcasecmp(v->name,"type")) * ast_log(LOG_WARNING, "Ignoring %s\n", v->name); @@ -9295,7 +9299,9 @@ else peer->addr.sin_port = htons(atoi(v->value)); } else if (!strcasecmp(v->name, "callingpres")) { - peer->callingpres = atoi(v->value); + peer->callingpres = ast_parse_caller_presentation(v->value); + if (peer->callingpres == -1) + peer->callingpres = atoi(v->value); } else if (!strcasecmp(v->name, "username")) { strncpy(peer->username, v->value, sizeof(peer->username)-1); } else if (!strcasecmp(v->name, "language")) { diff -Nru a/include/asterisk/callerid.h b/include/asterisk/callerid.h --- a/include/asterisk/callerid.h 2005-02-22 18:34:38 -07:00 +++ b/include/asterisk/callerid.h 2005-02-22 18:34:38 -07:00 @@ -190,16 +190,6 @@ return *cr; } -#define AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED 0x00 -#define AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN 0x01 -#define AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN 0x02 -#define AST_PRES_ALLOWED_NETWORK_NUMBER 0x03 -#define AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED 0x20 -#define AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN 0x21 -#define AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN 0x22 -#define AST_PRES_PROHIB_NETWORK_NUMBER 0x23 -#define AST_PRES_NUMBER_NOT_AVAILABLE 0x43 - #define PUT_BYTE(a) do { \ *(buf++) = (a); \ bytes++; \ @@ -237,5 +227,48 @@ PUT_CLID_BAUD(1); /* Stop bit */ \ } while(0); +/* Various defines and bits for handling PRI- and SS7-type restriction */ + +#define AST_PRES_NUMBER_TYPE 0x03 +#define AST_PRES_USER_NUMBER_UNSCREENED 0x00 +#define AST_PRES_USER_NUMBER_PASSED_SCREEN 0x01 +#define AST_PRES_USER_NUMBER_FAILED_SCREEN 0x02 +#define AST_PRES_NETWORK_NUMBER 0x03 + +#define AST_PRES_RESTRICTION 0x60 +#define AST_PRES_ALLOWED 0x00 +#define AST_PRES_RESTRICTED 0x20 +#define AST_PRES_UNAVAILABLE 0x40 +#define AST_PRES_RESERVED 0x60 + +#define AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED \ + AST_PRES_USER_NUMBER_UNSCREENED + AST_PRES_ALLOWED + +#define AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN \ + AST_PRES_USER_NUMBER_PASSED_SCREEN + AST_PRES_ALLOWED + +#define AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN \ + AST_PRES_USER_NUMBER_FAILED_SCREEN + AST_PRES_ALLOWED + +#define AST_PRES_ALLOWED_NETWORK_NUMBER \ + AST_PRES_NETWORK_NUMBER + AST_PRES_ALLOWED + +#define AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED \ + AST_PRES_USER_NUMBER_UNSCREENED + AST_PRES_RESTRICTED + +#define AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN \ + AST_PRES_USER_NUMBER_PASSED_SCREEN + AST_PRES_RESTRICTED + +#define AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN \ + AST_PRES_USER_NUMBER_FAILED_SCREEN + AST_PRES_RESTRICTED + +#define AST_PRES_PROHIB_NETWORK_NUMBER \ + AST_PRES_NETWORK_NUMBER + AST_PRES_RESTRICTED + +#define AST_PRES_NUMBER_NOT_AVAILABLE \ + AST_PRES_NETWORK_NUMBER + AST_PRES_UNAVAILABLE + +int ast_parse_caller_presentation(const char *data); +const char *ast_describe_caller_presentation(int data); #endif