Index: apps/app_queue.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_queue.c,v retrieving revision 1.51 diff -u -r1.51 app_queue.c --- apps/app_queue.c 13 Mar 2004 06:00:41 -0000 1.51 +++ apps/app_queue.c 22 Mar 2004 01:10:44 -0000 @@ -1095,6 +1095,68 @@ return( cur ) ; } +/* Determine the extension a caller is coming from for dynamic + * queue addition */ +static int qm_determine_extension(struct ast_channel *chan, char **interface) { + char tmpchan[512]; + char *start, *end; + + *interface = NULL; + + // Copy it so we can mangle it + strncpy(tmpchan, chan->name, sizeof(tmpchan) - 1); + + /* SIP/exten-XXXX */ + if(!strncmp(tmpchan, "SIP", 3)) { + end = strrchr(tmpchan, '-'); + + if (end) + *end = '\0'; + + *interface = strdup(tmpchan); + } + + /* IAX2[user@peer]/N or IAX[user@peer]/N */ + if(!strncmp(tmpchan, "IAX", 3)) { + char *start, *end; + + start = strchr(tmpchan, '['); + end = strrchr(tmpchan, ']'); + + if(start && end) { + *start = '/'; + *end = '\0'; + *interface = strdup(tmpchan); + } + } + + /* H323/ip$AAA.BBB.CCC.DDD/NNNN or OH323/ip$AAA.BBB.CCC.DDD/NNNN */ + /* FIXME: This is a truly ugly hack, and may not even work right in all cases */ + if(!strncmp(tmpchan, "H323", 4) || !strncmp(tmpchan, "OH323", 5)) { + char callerid[512], *start, *end; + + strncpy(callerid, chan->callerid, 512); + start = strrchr(callerid, '<'); + end = strrchr(callerid, '>'); + + if(start && end) { + *start = '/'; + *end = '\0'; + strcpy(tmpchan, "H323"); + if(start) + strcat(tmpchan, start); + *interface = strdup(tmpchan); + } + } + + /* If there is no interface determined, log it and return -1 */ + if(!*interface) { + ast_log(LOG_WARNING, "Could not determine extension for channel: %s\n", tmpchan); + return -1; + } + + return 0; +} static int rqm_exec(struct ast_channel *chan, void *data) { @@ -1108,6 +1170,7 @@ char *interface=NULL; struct ast_call_queue *q; int found=0 ; + int free_interface = 0; if (!data) { ast_log(LOG_WARNING, "RemoveQueueMember requires an argument (queuename|optional interface)\n"); @@ -1126,15 +1189,12 @@ interface++; } else { - strncpy(tmpchan, chan->name, sizeof(tmpchan) - 1); - interface = strrchr(tmpchan, '-'); - if (interface) - *interface = '\0'; - interface = tmpchan; + qm_determine_extension(chan, &interface); + free_interface = 1; } } - if( ( q = queues) != NULL ) + if( ( q = queues) != NULL && interface ) { while( q && ( res != 0 ) && (!found) ) { @@ -1165,7 +1225,7 @@ free( node ) ; - ast_log(LOG_NOTICE, "Removed interface '%s' to queue '%s'\n", + ast_log(LOG_NOTICE, "Removed interface '%s' from queue '%s'\n", interface, queuename); res = 0 ; } @@ -1179,15 +1239,19 @@ } } - if( ! found ) + if( ! found && interface ) ast_log(LOG_WARNING, "Unable to remove interface from queue '%s': No such queue\n", queuename); + if( ! interface ) + ast_log(LOG_WARNING, "Nobody was removed from queue '%s' since no extension could be determined\n", queuename); + else + if(free_interface) + free(interface); + LOCAL_USER_REMOVE(u); return res; } - - static int aqm_exec(struct ast_channel *chan, void *data) { int res=-1; @@ -1199,6 +1263,7 @@ struct ast_call_queue *q; struct member *save; int found=0 ; + int free_interface = 0; if (!data) { ast_log(LOG_WARNING, "AddQueueMember requires an argument (queuename|optional interface)\n"); @@ -1217,15 +1282,12 @@ interface++; } else { - strncpy(tmpchan, chan->name, sizeof(tmpchan) - 1); - interface = strrchr(tmpchan, '-'); - if (interface) - *interface = '\0'; - interface = tmpchan; + qm_determine_extension(chan, &interface); + free_interface = 1; } } - if( ( q = queues) != NULL ) + if( ( q = queues) != NULL && interface ) { while( q && ( res != 0 ) && (!found) ) { @@ -1259,9 +1321,15 @@ } } - if( ! found ) + if( ! found && interface ) ast_log(LOG_WARNING, "Unable to add interface to queue '%s': No such queue\n", queuename); + if( ! interface ) + ast_log(LOG_WARNING, "Nobody was added to queue '%s' since no extension could be determined\n", queuename); + else + if(free_interface) + free(interface); + LOCAL_USER_REMOVE(u); return res; }