remove lots of useless checks of the result of ast_strdupa
[asterisk/asterisk.git] / apps / app_page.c
old mode 100755 (executable)
new mode 100644 (file)
index d2a65f4..b4eb1a5
@@ -20,6 +20,9 @@
  *
  * \brief page() - Paging application
  *
+ * \author Mark Spencer <markster@digium.com>
+ *
+ * \ingroup applications
  */
 
 #include <stdio.h>
@@ -39,7 +42,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/module.h"
 #include "asterisk/file.h"
 #include "asterisk/app.h"
-
+#include "asterisk/chanvars.h"
+#include "asterisk/utils.h"
 
 static const char *tdesc = "Page Multiple Phones";
 
@@ -53,9 +57,8 @@ static const char *page_descrip =
 "them into a conference bridge as muted participants.  The original\n"
 "caller is dumped into the conference as a speaker and the room is\n"
 "destroyed when the original caller leaves.  Valid options are:\n"
-"      d - full duplex audio\n"
-"      q - quiet, do not play beep to caller\n"
-"Always returns -1.\n";
+"        d - full duplex audio\n"
+"       q - quiet, do not play beep to caller\n";
 
 STANDARD_LOCAL_USER;
 
@@ -77,13 +80,14 @@ struct calloutdata {
        char tech[64];
        char resource[256];
        char meetmeopts[64];
+       struct ast_variable *variables;
 };
 
 static void *page_thread(void *data)
 {
        struct calloutdata *cd = data;
        ast_pbx_outgoing_app(cd->tech, AST_FORMAT_SLINEAR, cd->resource, 30000,
-               "MeetMe", cd->meetmeopts, NULL, 0, cd->cidnum, cd->cidname, NULL, NULL);
+               "MeetMe", cd->meetmeopts, NULL, 0, cd->cidnum, cd->cidname, cd->variables, NULL);
        free(cd);
        return NULL;
 }
@@ -91,16 +95,40 @@ static void *page_thread(void *data)
 static void launch_page(struct ast_channel *chan, const char *meetmeopts, const char *tech, const char *resource)
 {
        struct calloutdata *cd;
+       const char *varname;
+       struct ast_variable *lastvar = NULL;
+       struct ast_var_t *varptr;
        pthread_t t;
        pthread_attr_t attr;
-       cd = malloc(sizeof(struct calloutdata));
-       if (cd) {
-               memset(cd, 0, sizeof(struct calloutdata));
+       if ((cd = ast_calloc(1, sizeof(*cd)))) {
                ast_copy_string(cd->cidnum, chan->cid.cid_num ? chan->cid.cid_num : "", sizeof(cd->cidnum));
                ast_copy_string(cd->cidname, chan->cid.cid_name ? chan->cid.cid_name : "", sizeof(cd->cidname));
                ast_copy_string(cd->tech, tech, sizeof(cd->tech));
                ast_copy_string(cd->resource, resource, sizeof(cd->resource));
                ast_copy_string(cd->meetmeopts, meetmeopts, sizeof(cd->meetmeopts));
+
+               AST_LIST_TRAVERSE(&chan->varshead, varptr, entries) {
+                       if (!(varname = ast_var_full_name(varptr)))
+                               continue;
+                       if (varname[0] == '_') {
+                               struct ast_variable *newvar = NULL;
+
+                               if (varname[1] == '_') {
+                                       newvar = ast_variable_new(varname, ast_var_value(varptr));
+                               } else {
+                                       newvar = ast_variable_new(&varname[1], ast_var_value(varptr));
+                               }
+
+                               if (newvar) {
+                                       if (lastvar)
+                                               lastvar->next = newvar;
+                                       else
+                                               cd->variables = newvar;
+                                       lastvar = newvar;
+                               }
+                       }
+               }
+
                pthread_attr_init(&attr);
                pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
                if (ast_pthread_create(&t, &attr, page_thread, cd)) {
@@ -136,11 +164,6 @@ static int page_exec(struct ast_channel *chan, void *data)
        };
 
        options = ast_strdupa(data);
-       if (!options) {
-               ast_log(LOG_ERROR, "Out of memory\n");
-               LOCAL_USER_REMOVE(u);
-               return -1;
-       }
 
        tmp = strsep(&options, "|");
        if (options)