Cleanup formatting in bug 2741 patch
[asterisk/asterisk.git] / res / res_features.c
index d8fcbf2..f79d2b4 100755 (executable)
@@ -181,11 +181,11 @@ int ast_park_call(struct ast_channel *chan, struct ast_channel *peer, int timeou
                                *extout = x;
                        /* Remember what had been dialed, so that if the parking
                           expires, we try to come back to the same place */
-                       if (strlen(chan->macrocontext))
+                       if (!ast_strlen_zero(chan->macrocontext))
                                strncpy(pu->context, chan->macrocontext, sizeof(pu->context)-1);
                        else
                                strncpy(pu->context, chan->context, sizeof(pu->context)-1);
-                       if (strlen(chan->macroexten))
+                       if (!ast_strlen_zero(chan->macroexten))
                                strncpy(pu->exten, chan->macroexten, sizeof(pu->exten)-1);
                        else
                                strncpy(pu->exten, chan->exten, sizeof(pu->exten)-1);
@@ -210,9 +210,11 @@ int ast_park_call(struct ast_channel *chan, struct ast_channel *peer, int timeou
                                 "From: %s\r\n"
                                 "Timeout: %ld\r\n"
                                 "CallerID: %s\r\n"
+                                "CallerIDName: %s\r\n\r\n"
                                 ,pu->parkingnum, pu->chan->name, peer->name
                                 ,(long)pu->start.tv_sec + (long)(pu->parkingtime/1000) - (long)time(NULL)
-                                ,(pu->chan->callerid ? pu->chan->callerid : "")
+                                ,(pu->chan->cid.cid_num ? pu->chan->cid.cid_num : "")
+                                ,(pu->chan->cid.cid_name ? pu->chan->cid.cid_name : "")
                                 );
 
                        if (peer) {
@@ -239,7 +241,7 @@ int ast_park_call(struct ast_channel *chan, struct ast_channel *peer, int timeou
                        }
                        if (con) {
                                snprintf(exten, sizeof(exten), "%d", x);
-                               ast_add_extension2(con, 1, exten, 1, NULL, parkedcall, strdup(exten), free, registrar);
+                               ast_add_extension2(con, 1, exten, 1, NULL, NULL, parkedcall, strdup(exten), free, registrar);
                        }
                        return 0;
                } else {
@@ -302,13 +304,20 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
        int allowdisconnect_in,allowdisconnect_out,allowredirect_in,allowredirect_out;
        char *monitor_exec;
 
-       if(monitor_ok) {
-               if(!monitor_app) 
-                       if(!(monitor_app = pbx_findapp("Monitor")))
+       if (chan && peer) {
+               pbx_builtin_setvar_helper(chan, "BRIDGEPEER", peer->name);
+               pbx_builtin_setvar_helper(peer, "BRIDGEPEER", chan->name);
+       } else if (chan)
+               pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", NULL);
+
+       if (monitor_ok) {
+               if (!monitor_app) { 
+                       if (!(monitor_app = pbx_findapp("Monitor")))
                                monitor_ok=0;
-               if((monitor_exec = pbx_builtin_getvar_helper(chan,"AUTO_MONITOR"))) 
+               }
+               if ((monitor_exec = pbx_builtin_getvar_helper(chan, "AUTO_MONITOR"))) 
                        pbx_exec(chan, monitor_app, monitor_exec, 1);
-               else if((monitor_exec = pbx_builtin_getvar_helper(peer,"AUTO_MONITOR")))
+               else if ((monitor_exec = pbx_builtin_getvar_helper(peer, "AUTO_MONITOR")))
                        pbx_exec(peer, monitor_app, monitor_exec, 1);
        }
        
@@ -324,9 +333,9 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
        peer->appl = "Bridged Call";
        peer->data = chan->name;
        /* copy the userfield from the B-leg to A-leg if applicable */
-       if (chan->cdr && peer->cdr && strlen(peer->cdr->userfield)) {
+       if (chan->cdr && peer->cdr && !ast_strlen_zero(peer->cdr->userfield)) {
                char tmp[256];
-               if (strlen(chan->cdr->userfield)) {
+               if (!ast_strlen_zero(chan->cdr->userfield)) {
                        snprintf(tmp, sizeof(tmp), "%s;%s",chan->cdr->userfield, peer->cdr->userfield);
                        ast_cdr_appenduserfield(chan, tmp);
                } else
@@ -399,21 +408,20 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
                if ((f->frametype == AST_FRAME_DTMF) &&
                        ((allowredirect_in && who == peer) || (allowredirect_out && who == chan)) &&
                        (f->subclass == '#')) {
-                               if(allowredirect_in &&  who == peer) {
+                               if (allowredirect_in &&  who == peer) {
                                        transferer = peer;
                                        transferee = chan;
-                               }
-                               else {
+                               } else {
                                        transferer = chan;
                                        transferee = peer;
                                }
-                               if(!(transferer_real_context=pbx_builtin_getvar_helper(transferee, "TRANSFER_CONTEXT")) &&
+                               if (!(transferer_real_context=pbx_builtin_getvar_helper(transferee, "TRANSFER_CONTEXT")) &&
                                   !(transferer_real_context=pbx_builtin_getvar_helper(transferer, "TRANSFER_CONTEXT"))) {
                                        /* Use the non-macro context to transfer the call */
-                                       if(strlen(transferer->macrocontext))
-                                               transferer_real_context=transferer->macrocontext;
+                                       if (!ast_strlen_zero(transferer->macrocontext))
+                                               transferer_real_context = transferer->macrocontext;
                                        else
-                                               transferer_real_context=transferer->context;
+                                               transferer_real_context = transferer->context;
                                }
                                /* Start autoservice on chan while we talk
                                   to the originator */
@@ -442,7 +450,7 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
                                        len --;
                                }
                                res = 0;
-                               while(strlen(newext) < sizeof(newext) - 1) {
+                               while (strlen(newext) < sizeof(newext) - 1) {
                                        res = ast_waitfordigit(transferer, transferdigittimeout);
                                        if (res < 1) 
                                                break;
@@ -450,7 +458,7 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
                                                break;
                                        *(ptr++) = res;
                                        if (!ast_matchmore_extension(transferer, transferer_real_context
-                                                               , newext, 1, transferer->callerid)) {
+                                                               , newext, 1, transferer->cid.cid_num)) {
                                                break;
                                        }
                                }
@@ -470,7 +478,7 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
                                                   the thread dies -- We have to be careful now though.  We are responsible for 
                                                   hanging up the channel, else it will never be hung up! */
 
-                                               if(transferer==peer)
+                                               if (transferer==peer)
                                                        res=AST_PBX_KEEPALIVE;
                                                else
                                                        res=AST_PBX_NO_HANGUP_PEER;
@@ -479,7 +487,9 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
                                                ast_log(LOG_WARNING, "Unable to park call %s\n", transferee->name);
                                        }
                                        /* XXX Maybe we should have another message here instead of invalid extension XXX */
-                               } else if (ast_exists_extension(transferee, transferer_real_context, newext, 1, transferer->callerid)) {
+                               } else if (ast_exists_extension(transferee, transferer_real_context, newext, 1, transferer->cid.cid_num)) {
+                                       pbx_builtin_setvar_helper(peer, "BLINDTRANSFER", chan->name);
+                                       pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", peer->name);
                                        ast_moh_stop(transferee);
                                        res=ast_autoservice_stop(transferee);
                                        if (!transferee->pbx) {
@@ -842,11 +852,13 @@ static int manager_parking_status( struct mansession *s, struct message *m )
                        "Channel: %s\r\n"
                        "Timeout: %ld\r\n"
                        "CallerID: %s\r\n"
+                       "CallerIDName: %s\r\n"
                        "%s"
                        "\r\n"
                         ,cur->parkingnum, cur->chan->name
                         ,(long)cur->start.tv_sec + (long)(cur->parkingtime/1000) - (long)time(NULL)
-                       ,(cur->chan->callerid ? cur->chan->callerid : "")
+                       ,(cur->chan->cid.cid_num ? cur->chan->cid.cid_num : "")
+                       ,(cur->chan->cid.cid_name ? cur->chan->cid.cid_name : "")
                        ,idText);
                        ast_mutex_unlock(&s->lock);
 
@@ -903,14 +915,16 @@ int load_module(void)
                                }
                        } else if (!strcasecmp(var->name, "adsipark")) {
                                adsipark = ast_true(var->value);
-                       } else if(!strcasecmp(var->name, "transferdigittimeout")) {
+                       } else if (!strcasecmp(var->name, "transferdigittimeout")) {
                                if ((sscanf(var->value, "%d", &transferdigittimeout) != 1) || (transferdigittimeout < 1)) {
                                        ast_log(LOG_WARNING, "%s is not a valid transferdigittimeout\n", var->value);
                                        transferdigittimeout = DEFAULT_TRANSFER_DIGIT_TIMEOUT;
                                } else
                                        transferdigittimeout = transferdigittimeout * 1000;
-                       } else if  (!strcasecmp(var->name, "courtesytone")) {
+                       } else if (!strcasecmp(var->name, "courtesytone")) {
                                strncpy(courtesytone, var->value, sizeof(courtesytone) - 1);
+                       } else if (!strcasecmp(var->name, "pickupexten")) {
+                               strncpy(pickup_ext, var->value, sizeof(pickup_ext) - 1);
                        }
                        var = var->next;
                }
@@ -924,7 +938,7 @@ int load_module(void)
                        return -1;
                }
        }
-       ast_add_extension2(con, 1, ast_parking_ext(), 1, NULL, parkcall, strdup(""),free, registrar);
+       ast_add_extension2(con, 1, ast_parking_ext(), 1, NULL, NULL, parkcall, strdup(""),free, registrar);
        ast_pthread_create(&parking_thread, NULL, do_parking_thread, NULL);
        res = ast_register_application(parkedcall, park_exec, synopsis, descrip);
        if (!res)