rendered paste bodyIndex: channels/chan_h323.c===================================================================RCS file: /usr/cvsroot/asterisk/channels/chan_h323.c,vretrieving revision 1.35diff -u -r1.35 chan_h323.c--- channels/chan_h323.c 15 Mar 2004 09:14:16 -0000 1.35+++ channels/chan_h323.c 15 Mar 2004 10:17:28 -0000@@ -191,10 +191,25 @@ ast_mutex_unlock(&iflock); }+static void alias_add_e164(struct oh323_alias *alias, char *val) {+ struct e164_number *tmp = alias->e164;+ alias->e164 = (struct e164_number *)calloc(1, sizeof(struct e164_number));+ alias->e164->next = tmp;+ strncpy(alias->e164->number, val, E164_MAX_LENGTH-1);+}++static void alias_add_prefix(struct oh323_alias *alias, char *val) {+ struct e164_number *tmp = alias->prefix;+ alias->prefix = (struct e164_number *)calloc(1, sizeof(struct e164_number));+ alias->prefix->next = tmp;+ strncpy(alias->prefix->number, val, E164_MAX_LENGTH-1);+}+ static struct oh323_alias *build_alias(char *name, struct ast_variable *v) { struct oh323_alias *alias;-+ char *p, *n;+ alias = (struct oh323_alias *)malloc(sizeof(struct oh323_alias)); if (alias) {@@ -203,9 +218,19 @@ while (v) { if (!strcasecmp(v->name, "e164")) {- strncpy(alias->e164, v->value, sizeof(alias->e164)-1);+ p = v->value;+ n = strsep(&p, ",");+ while(n) {+ alias_add_e164(alias, n);+ n = strsep(&p, ",");+ } } else if (!strcasecmp(v->name, "prefix")) {- strncpy(alias->prefix, v->value, sizeof(alias->prefix)-1);+ p = v->value;+ n = strsep(&p, ",");+ while(n) {+ alias_add_prefix(alias, n);+ n = strsep(&p, ",");+ } } else if (!strcasecmp(v->name, "context")) { strncpy(alias->context, v->value, sizeof(alias->context)-1); } else if (!strcasecmp(v->name, "secret")) {@@ -218,6 +243,7 @@ v = v->next; } }+ return alias; }@@ -841,6 +867,7 @@ { struct oh323_alias *a;+ ast_mutex_lock(&aliasl.lock); a = aliasl.aliases; while(a) {@@ -850,9 +877,68 @@ } a = a->next; }+ ast_mutex_unlock(&aliasl.lock); return a; }+struct oh323_alias *find_e164(const char *source_aliases)+{+ struct oh323_alias *a;+ struct e164_number *num;+ int found = 0;++ ast_mutex_lock(&aliasl.lock);+ a = aliasl.aliases;++ while(a && !found) {+ if(a->e164) {+ num = a->e164;+ while(num) {+ if(!strncmp(num->number, source_aliases, E164_MAX_LENGTH)) {+ found = 1;+ break;+ }+ num = num->next;+ }+ }+ if(!found)+ a = a->next;+ }+ ast_mutex_unlock(&aliasl.lock);++ return a;+}++struct oh323_alias *find_prefix(const char *source_aliases)+{+ struct oh323_alias *a;+ struct e164_number *num;+ int found = 0;++ ast_mutex_lock(&aliasl.lock);++ a = aliasl.aliases;++ while(a && !found) {+ if(a->prefix) {+ num = a->prefix;+ while(num) {+ if(strlen(source_aliases) >= strlen(num->number) &&+ !strncmp(num->number, source_aliases, strlen(num->number))) {+ found = 1;+ break;+ }+ num = num->next;+ }+ }+ if(!found)+ a = a->next;+ }+ ast_mutex_unlock(&aliasl.lock);++ return a;+}+ struct oh323_user *find_user(const call_details_t cd) { struct oh323_user *u;@@ -1000,8 +1086,17 @@ if ((!strcasecmp(cd.sourceIp, gatekeeper)) && (gkroute == -1) && (usingGk == 1)) { if (strlen(cd.call_dest_e164)) {+ alias = find_e164(cd.call_dest_e164);+ if(!alias)+ alias = find_prefix(cd.call_dest_e164);++ if(!alias)+ ast_log(LOG_WARNING, "Call for '%s' could not be routed to a context, sending to default.\n", cd.call_dest_e164);+ else+ ast_log(LOG_NOTICE, "Call for '%s' found and routed to alias '%s' (context '%s')\n", cd.call_dest_e164, alias->name, alias->context);+ strncpy(p->exten, cd.call_dest_e164, sizeof(p->exten)-1);- strncpy(p->context, default_context, sizeof(p->context)-1);+ strncpy(p->context, (alias?alias->context:default_context), sizeof(p->context)-1); } else { alias = find_alias(cd.call_dest_alias);@@ -1372,6 +1467,46 @@ return RESULT_SUCCESS; }+static int h323_show_aliases(int fd, int argc, char *argv[])+{+ struct oh323_alias *alias;+ struct e164_number *num;++ if (argc != 3) {+ return RESULT_SHOWUSAGE;+ }+ ast_cli(fd, "H323 Configured Aliases/E164/Prefixes:\n");++ ast_mutex_lock(&aliasl.lock);+ alias = aliasl.aliases;++ if(!alias) {+ ast_cli(fd, " Nothing configured!\n");+ ast_mutex_unlock(&aliasl.lock);+ return RESULT_SUCCESS;+ }++ ast_cli(fd, "%-20s %-5s %-20s %-20s\n", "Alias", "Type", "E164", "Context");++ while(alias) {+ ast_cli(fd, "%-20s %-5s %-20s %-20s\n", alias->name, "id", "", alias->context);+ num = alias->e164;+ while(num) {+ ast_cli(fd, "%-20s %-5s %-20s %-20s\n", alias->name, "e164", num->number, alias->context);+ num = num->next;+ }+ num = alias->prefix;+ while(num) {+ ast_cli(fd, "%-20s %-5s %-20s %-20s\n", alias->name, "pfx", num->number, alias->context);+ num = num->next;+ }++ alias = alias->next;+ }++ ast_mutex_unlock(&aliasl.lock);+ return RESULT_SUCCESS;+} static char trace_usage[] = "Usage: h.323 trace <level num>\n"@@ -1405,6 +1540,10 @@ "Usage: h.323 show tokens\n" " Print out all active call tokens\n";+static char show_aliases_usage[] =+"Usage: h.323 show aliases\n"+" Print out all configured aliases\n";+ static struct ast_cli_entry cli_trace = { { "h.323", "trace", NULL }, h323_do_trace, "Enable H.323 Stack Tracing", trace_usage }; static struct ast_cli_entry cli_no_trace =@@ -1421,7 +1560,8 @@ { { "h.323", "hangup", NULL }, h323_ep_hangup, "Manually try to hang up a call", show_hangup_usage }; static struct ast_cli_entry cli_show_tokens = { { "h.323", "show", "tokens", NULL }, h323_tokens_show, "Manually try to hang up a call", show_tokens_usage };-+static struct ast_cli_entry cli_show_aliases =+ { { "h.323", "show", "aliases", NULL }, h323_show_aliases, "Show configured aliases", show_aliases_usage }; int reload_config(void)@@ -1612,12 +1752,26 @@ void delete_aliases(void) { struct oh323_alias *alias, *aliaslast;-+ struct e164_number *num, *numlast;+ /* Delete all users */ ast_mutex_lock(&aliasl.lock); for (alias=aliasl.aliases;alias;) { aliaslast = alias; alias=alias->next;++ for(num=aliaslast->e164;num;) {+ numlast = num;+ num = num->next;+ free(num);+ }++ for(num=aliaslast->prefix;num;) {+ numlast = num;+ num = num->next;+ free(num);+ }+ free(aliaslast); } aliasl.aliases=NULL;@@ -1775,7 +1929,8 @@ ast_cli_register(&cli_gk_cycle); ast_cli_register(&cli_hangup_call); ast_cli_register(&cli_show_tokens);-+ ast_cli_register(&cli_show_aliases);+ oh323_rtp.type = type; ast_rtp_proto_register(&oh323_rtp);@@ -1907,7 +2062,3 @@ { return ASTERISK_GPL_KEY; }----Index: channels/h323/chan_h323.h===================================================================RCS file: /usr/cvsroot/asterisk/channels/h323/chan_h323.h,vretrieving revision 1.19diff -u -r1.19 chan_h323.h--- channels/h323/chan_h323.h 4 Mar 2004 01:57:32 -0000 1.19+++ channels/h323/chan_h323.h 15 Mar 2004 10:17:28 -0000@@ -70,12 +70,18 @@ struct oh323_peer *next; };+#define E164_MAX_LENGTH 40+struct e164_number {+ char number[E164_MAX_LENGTH]; /* the E.164 number */+ struct e164_number *next;+};+ /* structure to hold the H.323 aliases which get registered to the H.323 endpoint and gatekeeper */ struct oh323_alias { char name[80];- char e164[20]; /* tells a GK to route this E.164 to this alias */- char prefix[500]; /* tells a GK this alias supports these prefixes */+ struct e164_number *e164;+ struct e164_number *prefix; char secret[20]; /* the H.235 password to send to the GK for authentication */ char context[80]; struct oh323_alias *next;Index: channels/h323/ast_h323.cpp===================================================================RCS file: /usr/cvsroot/asterisk/channels/h323/ast_h323.cpp,vretrieving revision 1.35diff -u -r1.35 ast_h323.cpp--- channels/h323/ast_h323.cpp 4 Mar 2004 06:11:23 -0000 1.35+++ channels/h323/ast_h323.cpp 15 Mar 2004 10:17:28 -0000@@ -886,10 +886,7 @@ int h323_set_alias(struct oh323_alias *alias) {- char *p;- char *num; PString h323id(alias->name);- PString e164(alias->e164); if (!h323_end_point_exist()) { cout << "ERROR: [h323_set_alias] No Endpoint, this is bad!" << endl;@@ -900,21 +897,27 @@ endPoint->AddAliasName(h323id); endPoint->RemoveAliasName(localProcess->GetUserName());- if (!e164.IsEmpty()) {- cout << " == Adding E.164 \"" << e164 << "\" to endpoint" << endl;- endPoint->AddAliasName(e164);- }- if (strlen(alias->prefix)) {- p = alias->prefix;- num = strsep(&p, ",");- while(num) {- cout << " == Adding Prefix \"" << num << "\" to endpoint" << endl;- endPoint->SupportedPrefixes += PString(num);- endPoint->SetGateway();- num = strsep(&p, ",");- }- }-+ if(alias->e164) {+ struct e164_number *num = alias->e164;+ while(num) {+ if(strlen(num->number)) {+ cout << " == Adding E.164 \"" << num->number << "\" to endpoint" << endl;+ endPoint->AddAliasName(num->number);+ }+ num = num->next;+ }+ }+ if(alias->prefix) {+ struct e164_number *num = alias->prefix;+ while(num) {+ if(strlen(num->number)) {+ cout << " == Adding Prefix \"" << num->number << "\" to endpoint" << endl;+ endPoint->SupportedPrefixes += PString(num->number);+ endPoint->SetGateway();+ }+ num = num->next;+ }+ } return 0; }