Index: asterisk/app.c =================================================================== RCS file: /usr/cvsroot/asterisk/app.c,v retrieving revision 1.43 diff -u -r1.43 app.c --- asterisk/app.c 10 Jan 2005 14:46:59 -0000 1.43 +++ asterisk/app.c 16 Jan 2005 21:26:05 -0000 @@ -36,6 +36,81 @@ #define MAX_OTHER_FORMATS 10 +char *ast_getparamvalue(struct ast_params *params,char name) { + struct ast_params *tmp; + ast_log(LOG_NOTICE, "asked for VALUE OF NAME %c\n",name); + tmp = params; + while(tmp){ + if (tmp->name == name) + return tmp->value; + tmp = tmp->next; + } + return NULL; +} +int ast_getparam(struct ast_params *params,char name) { + struct ast_params *tmp; + tmp = params; + ast_log(LOG_NOTICE, "asked for NAME %c\n",name); + while(tmp){ + if (tmp->name == name) + return 1; + tmp = tmp->next; + } + return 0; +} +struct ast_params *ast_parseoptsadd(struct ast_params *params,char name,char *value) { + struct ast_params *tmp; + + tmp = malloc(sizeof(struct ast_params*)); + if (params == NULL) { + tmp->next = NULL; + } else { + tmp->next = params; + } + tmp->name = name; + tmp->value = value; + + return tmp; +} +struct ast_params *ast_parseopts(char *data) { + struct ast_params *params=NULL; + char *tmp; + char c='\0'; + char *at; + char *cur=NULL; + int open=0; + int cnt=0; + + + at = data; + + while (*at) { + if (open == 0 && *(at+1) && *(at+1) == '(') { + c = *at; + *(at++); + open = 1; + cnt=0; + cur = at+1; + + } + if (open == 0) { + c = *at; + params = ast_parseoptsadd(params,c,NULL); + } + if (open == 1 && *at == ')' && *(at-1) != '\\') { + tmp = malloc(cnt - 1 + sizeof(char *)); + memset(tmp,0,sizeof(tmp)); + strncpy(tmp, cur, cnt-1); + params = ast_parseoptsadd(params,c,tmp); + open = 0; + } + if (open == 1) + cnt++; + + *(at++); + } + return params; +} int ast_app_dtget(struct ast_channel *chan, const char *context, char *collect, size_t size, int maxlen, int timeout) { Index: asterisk/apps/app_dial.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_dial.c,v retrieving revision 1.126 diff -u -r1.126 app_dial.c --- asterisk/apps/app_dial.c 16 Jan 2005 07:58:51 -0000 1.126 +++ asterisk/apps/app_dial.c 16 Jan 2005 21:26:05 -0000 @@ -471,16 +471,10 @@ int res=-1; struct localuser *u; char *info, *peers, *timeout, *tech, *number, *rest, *cur; - char privdb[256] = "", *s; - char announcemsg[256] = "", *ann; struct localuser *outgoing=NULL, *tmp; struct ast_channel *peer; int to; struct ast_flags peerflags={0}; - int hasmacro = 0; - int privacy=0; - int announce=0; - int resetcdr=0; int numbusy = 0; int numcongestion = 0; int numnochan = 0; @@ -492,7 +486,6 @@ char *l; char *url=NULL; /* JDG */ unsigned int calldurationlimit=0; - char *cdl; time_t now; struct ast_bridge_config config; long timelimit = 0; @@ -501,19 +494,14 @@ char *warning_sound=NULL; char *end_sound=NULL; char *start_sound=NULL; - char *limitptr; - char limitdata[256]; - char *sdtmfptr; - char sdtmfdata[256] = ""; char *stack,*var; - char *mac = NULL, *macroname = NULL; char status[256]=""; char toast[80]; int play_to_caller=0,play_to_callee=0; int playargs=0, sentringing=0, moh=0; - char *mohclass = NULL; char *outbound_group = NULL; char *macro_result = NULL, *macro_transfer_dest = NULL; + struct ast_params *params=NULL; int digit = 0; time_t start_time, answer_time, end_time; struct ast_app *app = NULL; @@ -564,44 +552,17 @@ if (transfer) { + params = ast_parseopts(transfer); + /* Extract call duration limit */ - if ((cdl = strstr(transfer, "S("))) { - calldurationlimit=atoi(cdl+2); + if (ast_getparam(params,'S')) { + calldurationlimit=atoi(ast_getparamvalue(params,'M')); if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "Setting call duration limit to %i seconds.\n",calldurationlimit); } - /* DTMF SCRIPT*/ - if ((sdtmfptr = strstr(transfer, "D("))) { - strncpy(sdtmfdata, sdtmfptr + 2, sizeof(sdtmfdata) - 1); - /* Overwrite with X's what was the sdtmf info */ - while (*sdtmfptr && (*sdtmfptr != ')')) - *(sdtmfptr++) = 'X'; - if (*sdtmfptr) - *sdtmfptr = 'X'; - /* Now find the end */ - sdtmfptr = strchr(sdtmfdata, ')'); - if (sdtmfptr) - *sdtmfptr = '\0'; - else - ast_log(LOG_WARNING, "D( Data lacking trailing ')'\n"); - } - /* XXX LIMIT SUPPORT */ - if ((limitptr = strstr(transfer, "L("))) { - strncpy(limitdata, limitptr + 2, sizeof(limitdata) - 1); - /* Overwrite with X's what was the limit info */ - while(*limitptr && (*limitptr != ')')) - *(limitptr++) = 'X'; - if (*limitptr) - *limitptr = 'X'; - /* Now find the end */ - limitptr = strchr(limitdata, ')'); - if (limitptr) - *limitptr = '\0'; - else - ast_log(LOG_WARNING, "Limit Data lacking trailing ')'\n"); - + if (ast_getparam(params,'L')) { var = pbx_builtin_getvar_helper(chan,"LIMIT_PLAYAUDIO_CALLER"); play_to_caller = var ? ast_true(var) : 1; @@ -620,7 +581,7 @@ var = pbx_builtin_getvar_helper(chan,"LIMIT_CONNECT_FILE"); start_sound = var ? var : NULL; - var=stack=limitdata; + var=stack=ast_getparamvalue(params,'L'); var = strsep(&stack, ":"); if (var) { @@ -660,101 +621,20 @@ ast_verbose(VERBOSE_PREFIX_3"end_sound=%s\n",end_sound ? end_sound : "UNDEF"); } } - - /* XXX ANNOUNCE SUPPORT */ - if ((ann = strstr(transfer, "A("))) { - announce = 1; - strncpy(announcemsg, ann + 2, sizeof(announcemsg) - 1); - /* Overwrite with X's what was the announce info */ - while(*ann && (*ann != ')')) - *(ann++) = 'X'; - if (*ann) - *ann = 'X'; - /* Now find the end of the privdb */ - ann = strchr(announcemsg, ')'); - if (ann) - *ann = '\0'; - else { - ast_log(LOG_WARNING, "Transfer with Announce spec lacking trailing ')'\n"); - announce = 0; - } - } - - /* Get the macroname from the dial option string */ - if ((mac = strstr(transfer, "M("))) { - hasmacro = 1; - macroname = ast_strdupa(mac + 2); - while (*mac && (*mac != ')')) - *(mac++) = 'X'; - if (*mac) - *mac = 'X'; - else { - ast_log(LOG_WARNING, "Could not find macro to which we should jump.\n"); - hasmacro = 0; - } - mac = strchr(macroname, ')'); - if (mac) - *mac = '\0'; - else { - ast_log(LOG_WARNING, "Macro flag set without trailing ')'\n"); - hasmacro = 0; - } - } - /* Get music on hold class */ - if ((mac = strstr(transfer, "m("))) { - mohclass = ast_strdupa(mac + 2); - mac++; /* Leave the "m" in the string */ - while (*mac && (*mac != ')')) - *(mac++) = 'X'; - if (*mac) - *mac = 'X'; - else { - ast_log(LOG_WARNING, "Could not find music on hold class to use, assuming default.\n"); - mohclass=NULL; - } - mac = strchr(macroname, ')'); - if (mac) - *mac = '\0'; - else { - ast_log(LOG_WARNING, "Music on hold class specified without trailing ')'\n"); - mohclass = NULL; - } - } /* Extract privacy info from transfer */ - if ((s = strstr(transfer, "P("))) { - privacy = 1; - strncpy(privdb, s + 2, sizeof(privdb) - 1); - /* Overwrite with X's what was the privacy info */ - while(*s && (*s != ')')) - *(s++) = 'X'; - if (*s) - *s = 'X'; - /* Now find the end of the privdb */ - s = strchr(privdb, ')'); - if (s) - *s = '\0'; - else { - ast_log(LOG_WARNING, "Transfer with privacy lacking trailing ')'\n"); - privacy = 0; - } - } else if (strchr(transfer, 'P')) { - /* No specified privdb */ - privacy = 1; - } else if (strchr(transfer, 'C')) { - resetcdr = 1; - } } - if (resetcdr && chan->cdr) + if (ast_getparam(params,'C') && chan->cdr) ast_cdr_reset(chan->cdr, 0); - if (ast_strlen_zero(privdb) && privacy) { +// TO FIX + if (ast_getparam(params,'P') && ast_strlen_zero(ast_getparamvalue(params,'P'))) { /* If privdb is not specified and we are using privacy, copy from extension */ - strncpy(privdb, chan->exten, sizeof(privdb) - 1); +// strncpy(ast_getparamvalue(params,'P'), chan->exten, sizeof(ast_getparamvalue(params,'P')) - 1); } - if (privacy) { + if (ast_getparam(params,'P')) { l = chan->cid.cid_num; if (!l) l = ""; - ast_log(LOG_NOTICE, "Privacy DB is '%s', privacy is %d, clid is '%s'\n", privdb, privacy, l); + ast_log(LOG_NOTICE, "Privacy DB is '%s', privacy is %d, clid is '%s'\n", ast_getparamvalue(params,'P'), ast_getparam(params,'P'), l); } /* If a channel group has been specified, get it for use when we create peer channels */ @@ -784,18 +664,18 @@ } memset(tmp, 0, sizeof(struct localuser)); if (transfer) { - ast_set2_flag(tmp, strchr(transfer, 't'), DIAL_ALLOWREDIRECT_IN); - ast_set2_flag(tmp, strchr(transfer, 'T'), DIAL_ALLOWREDIRECT_OUT); - ast_set2_flag(tmp, strchr(transfer, 'r'), DIAL_RINGBACKONLY); - ast_set2_flag(tmp, strchr(transfer, 'm'), DIAL_MUSICONHOLD); - ast_set2_flag(tmp, strchr(transfer, 'H'), DIAL_ALLOWDISCONNECT_OUT); - ast_set2_flag(&peerflags, strchr(transfer, 'H'), DIAL_ALLOWDISCONNECT_OUT); - ast_set2_flag(tmp, strchr(transfer, 'h'), DIAL_ALLOWDISCONNECT_IN); - ast_set2_flag(&peerflags, strchr(transfer, 'h'), DIAL_ALLOWDISCONNECT_IN); - ast_set2_flag(tmp, strchr(transfer, 'f'), DIAL_FORCECALLERID); - ast_set2_flag(&peerflags, strchr(transfer, 'w'), DIAL_MONITOR_IN); - ast_set2_flag(&peerflags, strchr(transfer, 'W'), DIAL_MONITOR_OUT); - ast_set2_flag(tmp, strchr(transfer, 'g'), DIAL_GO_ON); + ast_set2_flag(tmp, ast_getparam(params,'t'), DIAL_ALLOWREDIRECT_IN); + ast_set2_flag(tmp, ast_getparam(params,'T'), DIAL_ALLOWREDIRECT_OUT); + ast_set2_flag(tmp, ast_getparam(params,'r'), DIAL_RINGBACKONLY); + ast_set2_flag(tmp, ast_getparam(params,'m'), DIAL_MUSICONHOLD); + ast_set2_flag(tmp, ast_getparam(params,'H'), DIAL_ALLOWDISCONNECT_OUT); + ast_set2_flag(&peerflags, ast_getparam(params,'H'), DIAL_ALLOWDISCONNECT_OUT); + ast_set2_flag(tmp, ast_getparam(params,'h'), DIAL_ALLOWDISCONNECT_IN); + ast_set2_flag(&peerflags, ast_getparam(params,'h'), DIAL_ALLOWDISCONNECT_IN); + ast_set2_flag(tmp, ast_getparam(params,'f'), DIAL_FORCECALLERID); + ast_set2_flag(&peerflags, ast_getparam(params,'w'), DIAL_MONITOR_IN); + ast_set2_flag(&peerflags, ast_getparam(params,'W'), DIAL_MONITOR_OUT); + ast_set2_flag(tmp, ast_getparam(params,'g'), DIAL_GO_ON); } strncpy(numsubst, number, sizeof(numsubst)-1); /* If we're dialing by extension, look at the extension to know what to dial */ @@ -946,7 +826,7 @@ strncpy(status, "NOANSWER", sizeof(status) - 1); if (ast_test_flag(outgoing, DIAL_MUSICONHOLD)) { moh=1; - ast_moh_start(chan, mohclass); + ast_moh_start(chan, ast_getparamvalue(params,'m')); } else if (ast_test_flag(outgoing, DIAL_RINGBACKONLY)) { ast_indicate(chan, AST_CONTROL_RINGING); sentringing++; @@ -991,12 +871,12 @@ ast_log(LOG_DEBUG, "app_dial: sendurl=%s.\n", url); ast_channel_sendurl( peer, url ); } /* /JDG */ - if (announce && announcemsg) { + if (ast_getparam(params,'A') && ast_getparamvalue(params,'A')) { /* Start autoservice on the other chan */ res = ast_autoservice_start(chan); /* Now Stream the File */ if (!res) - res = ast_streamfile(peer,announcemsg,peer->language); + res = ast_streamfile(peer,ast_getparamvalue(params,'A'),peer->language); if (!res) { digit = ast_waitstream(peer, AST_DIGIT_ANY); } @@ -1010,7 +890,7 @@ } else res = 0; - if (hasmacro && macroname) { + if (ast_getparam(params,'M') && ast_getparamvalue(params,'M')) { res = ast_autoservice_start(chan); if (res) { ast_log(LOG_ERROR, "Unable to start autoservice on calling channel\n"); @@ -1020,10 +900,12 @@ app = pbx_findapp("Macro"); if (app && !res) { - for(res=0;reswhentohangup = now + calldurationlimit; } - if (!ast_strlen_zero(sdtmfdata)) - res = ast_dtmf_stream(peer,chan,sdtmfdata,250); + if (ast_getparam(params,'D') && ast_strlen_zero(ast_getparamvalue(params,'D'))) + res = ast_dtmf_stream(peer,chan,ast_getparamvalue(params,'D'),250); } if (!res) { Index: asterisk/include/asterisk/app.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/app.h,v retrieving revision 1.25 diff -u -r1.25 app.h --- asterisk/include/asterisk/app.h 15 Jan 2005 23:48:12 -0000 1.25 +++ asterisk/include/asterisk/app.h 16 Jan 2005 21:26:05 -0000 @@ -96,6 +96,19 @@ /*! Allow to record message and have a review option */ int ast_record_review(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration); +struct ast_params *ast_parseopts(char *data); +struct ast_params *ast_parseoptsadd(struct ast_params *params,char name,char *value); +char *ast_getparamvalue(struct ast_params *params,char name); +int ast_getparam(struct ast_params *params,char name); + +struct ast_params { + char name; + char *value; + struct ast_params *next; + +}; + + #if defined(__cplusplus) || defined(c_plusplus) } #endif