make app_queue 1.2 jump compliant (issue #5580)
authorRussell Bryant <russell@russellbryant.com>
Tue, 8 Nov 2005 04:48:00 +0000 (04:48 +0000)
committerRussell Bryant <russell@russellbryant.com>
Tue, 8 Nov 2005 04:48:00 +0000 (04:48 +0000)
add missing includes of stdio.h
remove some unused and duplicate headers

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7026 65c4cc65-6c06-0410-ace0-fbb531ad65f3

63 files changed:
ChangeLog
apps/app_chanisavail.c
apps/app_chanspy.c
apps/app_controlplayback.c
apps/app_db.c
apps/app_dictate.c
apps/app_directed_pickup.c
apps/app_dumpchan.c
apps/app_echo.c
apps/app_enumlookup.c
apps/app_externalivr.c
apps/app_flash.c
apps/app_forkcdr.c
apps/app_getcpeid.c
apps/app_hasnewvoicemail.c
apps/app_image.c
apps/app_lookupblacklist.c
apps/app_lookupcidname.c
apps/app_macro.c
apps/app_md5.c
apps/app_meetme.c
apps/app_milliwatt.c
apps/app_mixmonitor.c
apps/app_parkandannounce.c
apps/app_playback.c
apps/app_privacy.c
apps/app_queue.c
apps/app_read.c
apps/app_realtime.c
apps/app_record.c
apps/app_senddtmf.c
apps/app_sendtext.c
apps/app_setcallerid.c
apps/app_setcidname.c
apps/app_setcidnum.c
apps/app_setrdnis.c
apps/app_sms.c
apps/app_softhangup.c
apps/app_striplsd.c
apps/app_substring.c
apps/app_system.c
apps/app_talkdetect.c
apps/app_test.c
apps/app_transfer.c
apps/app_url.c
apps/app_userevent.c
apps/app_waitforring.c
apps/app_waitforsilence.c
apps/app_while.c
apps/app_zapateller.c
apps/app_zapbarge.c
apps/app_zapscan.c
funcs/func_callerid.c
funcs/func_enum.c
funcs/func_groupcount.c
funcs/func_math.c
funcs/func_strings.c
funcs/func_timeout.c
funcs/func_uri.c
pbx/pbx_dundi.c
pbx/pbx_loopback.c
pbx/pbx_realtime.c
res/res_indications.c

index b3bb768..7488956 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,10 @@
 
 2005-11-07  Russell Bryant  <russell@digium.com>
 
+       * apps/app_queue.c: upgrade to new arg/option API and implement priority jumping control (issue #5580)
+       * res/res_indications.c: Add missing include of stdio.h
+       * many files: Add missing include of stdio.h, and remove some duplicate and unused header includes
+
        * include/asterisk/app.h: Increment the arg_index in the options structure to fix applicaiton options that have arguments to them
 
 2005-11-07  Kevin P. Fleming  <kpfleming@digium.com>
index 10a377f..acdc4d9 100755 (executable)
  */
 
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 #include <unistd.h>
 #include <errno.h>
-#include <string.h>
-#include <stdlib.h>
 #include <sys/ioctl.h>
 
 #include "asterisk.h"
index 07b8d8d..4e96d8f 100755 (executable)
@@ -23,8 +23,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 #include <ctype.h>
 
 #include "asterisk.h"
index 47b82ac..6cd577d 100755 (executable)
@@ -22,8 +22,9 @@
  * \ingroup applications
  */
  
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index 60d25f0..659f968 100755 (executable)
@@ -26,8 +26,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 #include <sys/types.h>
 
 #include "asterisk.h"
index 0feee10..91a1650 100755 (executable)
@@ -26,8 +26,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 #include <sys/stat.h>  /* for mkdir */
 
 #include "asterisk.h"
index 400ee07..cd9c62e 100755 (executable)
@@ -24,8 +24,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "asterisk.h"
 
index 15fb3ba..4802dfe 100755 (executable)
@@ -26,8 +26,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "asterisk.h"
 
index 1fbfba5..2b7c200 100755 (executable)
@@ -24,6 +24,7 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <unistd.h>
 #include <string.h>
 
index 6ff2141..435ff61 100755 (executable)
@@ -24,9 +24,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
-#include <stdlib.h>
+#include <unistd.h>
 #include <ctype.h>
 
 #include "asterisk.h"
index c3e3c56..ff5147d 100755 (executable)
@@ -27,9 +27,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
-#include <stdlib.h>
+#include <unistd.h>
 #include <errno.h>
 
 #include "asterisk.h"
index 9a53dd3..a9aae22 100755 (executable)
  * \ingroup applications
  */
  
+#include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <errno.h>
-#include <stdlib.h>
 #include <sys/ioctl.h>
 #ifdef __linux__
 #include <linux/zaptel.h>
index ad8eaa0..21073ff 100755 (executable)
@@ -23,9 +23,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
-#include <pthread.h>
+#include <unistd.h>
 
 #include "asterisk.h"
 
index 0eb1691..b2d883b 100755 (executable)
@@ -24,6 +24,7 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <unistd.h>
 #include <string.h>
 
index abb42e0..678d8c6 100755 (executable)
  * \ingroup applications
  */
 
-#include <sys/types.h>
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 #include <dirent.h>
+#include <sys/types.h>
 
 #include "asterisk.h"
 
index 3e0f858..e23b274 100755 (executable)
@@ -23,8 +23,9 @@
  * \ingroup applications
  */
  
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index 93d3c8c..1f7e30f 100755 (executable)
@@ -24,8 +24,9 @@
  * 
  */
 
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index bce2768..52587b0 100755 (executable)
@@ -23,8 +23,9 @@
  * \ingroup applications
  */
 
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index 6d99a79..72b7577 100755 (executable)
  * \ingroup applications
  */
 
-#include <sys/types.h>
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
 
 #include "asterisk.h"
 
index b9d5412..c9f4f0e 100755 (executable)
@@ -24,8 +24,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "asterisk.h"
 
index bca2ad9..e9f52a7 100755 (executable)
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 #include <errno.h>
-#include <stdlib.h>
 #include <sys/ioctl.h>
 #ifdef __linux__
 #include <linux/zaptel.h>
index 446fd15..5ef708c 100755 (executable)
@@ -24,9 +24,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
-#include <stdlib.h>
+#include <unistd.h>
 #include <errno.h>
 
 #include "asterisk.h"
index ddf8f52..6667377 100755 (executable)
@@ -27,8 +27,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "asterisk.h"
 
index a40c2ef..bb7aa38 100755 (executable)
  * \ingroup applications
  */
 
-#include <sys/types.h>
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
 
 #include "asterisk.h"
 
index 89e7266..485e735 100755 (executable)
@@ -25,6 +25,7 @@
  
 #include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
 
 #include "asterisk.h"
 
index fe56694..799f31b 100755 (executable)
@@ -23,8 +23,9 @@
  * \ingroup applications
  */
 
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index ae622f0..5d8b4bc 100755 (executable)
@@ -74,6 +74,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/channel.h"
 #include "asterisk/pbx.h"
 #include "asterisk/options.h"
+#include "asterisk/app.h"
+#include "asterisk/linkedlists.h"
 #include "asterisk/module.h"
 #include "asterisk/translate.h"
 #include "asterisk/say.h"
@@ -151,27 +153,39 @@ static char *descrip =
 static char *app_aqm = "AddQueueMember" ;
 static char *app_aqm_synopsis = "Dynamically adds queue members" ;
 static char *app_aqm_descrip =
-"   AddQueueMember(queuename[|interface[|penalty]]):\n"
+"   AddQueueMember(queuename[|interface[|penalty[|options]]]):\n"
 "Dynamically adds interface to an existing queue.\n"
 "If the interface is already in the queue and there exists an n+101 priority\n"
 "then it will then jump to this priority.  Otherwise it will return an error\n"
+"The option string may contain zero or more of the following characters:\n"
+"       'j' -- jump to +101 priority when appropriate.\n"
+"  This application sets the following channel variable upon completion:\n"
+"     AQMSTATUS    The status of the attempt to add a queue member as a \n"
+"                     text string, one of\n"
+"           ADDED | MEMBERALREADY | NOSUCHQUEUE \n"
 "Example: AddQueueMember(techsupport|SIP/3000)\n"
 "";
 
 static char *app_rqm = "RemoveQueueMember" ;
 static char *app_rqm_synopsis = "Dynamically removes queue members" ;
 static char *app_rqm_descrip =
-"   RemoveQueueMember(queuename[|interface]):\n"
+"   RemoveQueueMember(queuename[|interface[|options]]):\n"
 "Dynamically removes interface to an existing queue\n"
 "If the interface is NOT in the queue and there exists an n+101 priority\n"
 "then it will then jump to this priority.  Otherwise it will return an error\n"
+"The option string may contain zero or more of the following characters:\n"
+"       'j' -- jump to +101 priority when appropriate.\n"
+"  This application sets the following channel variable upon completion:\n"
+"     RQMSTATUS      The status of the attempt to remove a queue member as a\n"
+"                     text string, one of\n"
+"           REMOVED | NOTINQUEUE | NOSUCHQUEUE \n"
 "Example: RemoveQueueMember(techsupport|SIP/3000)\n"
 "";
 
 static char *app_pqm = "PauseQueueMember" ;
 static char *app_pqm_synopsis = "Pauses a queue member" ;
 static char *app_pqm_descrip =
-"   PauseQueueMember([queuename]|interface):\n"
+"   PauseQueueMember([queuename]|interface[|options]):\n"
 "Pauses (blocks calls for) a queue member.\n"
 "The given interface will be paused in the given queue.  This prevents\n"
 "any calls from being sent from the queue to the interface until it is\n"
@@ -179,17 +193,30 @@ static char *app_pqm_descrip =
 "queuename is given, the interface is paused in every queue it is a\n"
 "member of.  If the interface is not in the named queue, or if no queue\n"
 "is given and the interface is not in any queue, it will jump to\n"
-" priority n+101, if it exists.  The application will fail if the interface is not\n"
-"found and no extension to jump to exists.\n"
+"priority n+101, if it exists and the appropriate options are set.\n"
+"The application will fail if the interface is not found and no extension\n"
+"to jump to exists.\n"
+"The option string may contain zero or more of the following characters:\n"
+"       'j' -- jump to +101 priority when appropriate.\n"
+"  This application sets the following channel variable upon completion:\n"
+"     PQMSTATUS      The status of the attempt to pause a queue member as a\n"
+"                     text string, one of\n"
+"           PAUSED | NOTFOUND\n"
 "Example: PauseQueueMember(|SIP/3000)\n";
 
 static char *app_upqm = "UnpauseQueueMember" ;
 static char *app_upqm_synopsis = "Unpauses a queue member" ;
 static char *app_upqm_descrip =
-"   UnpauseQueueMember([queuename]|interface):\n"
+"   UnpauseQueueMember([queuename]|interface[|options]):\n"
 "Unpauses (resumes calls to) a queue member.\n"
 "This is the counterpart to PauseQueueMember and operates exactly the\n"
 "same way, except it unpauses instead of pausing the given interface.\n"
+"The option string may contain zero or more of the following characters:\n"
+"       'j' -- jump to +101 priority when appropriate.\n"
+"  This application sets the following channel variable upon completion:\n"
+"     UPQMSTATUS       The status of the attempt to unpause a queue \n"
+"                      member as a text string, one of\n"
+"            UNPAUSED | NOTFOUND\n"
 "Example: UnpauseQueueMember(|SIP/3000)\n";
 
 /*! \brief Persistent Members astdb family */
@@ -243,6 +270,7 @@ struct localuser {
 
 LOCAL_USER_DECL;
 
+
 struct queue_ent {
        struct ast_call_queue *parent;  /*!< What queue is our parent */
        char moh[80];                   /*!< Name of musiconhold to be used */
@@ -2554,88 +2582,112 @@ static void reload_queue_members(void)
 static int pqm_exec(struct ast_channel *chan, void *data)
 {
        struct localuser *u;
-       char *queuename, *interface;
+       char *parse;
+       int priority_jump = 0;
+       AST_DECLARE_APP_ARGS(args,
+               AST_APP_ARG(queuename);
+               AST_APP_ARG(interface);
+               AST_APP_ARG(options);
+       );
 
        if (ast_strlen_zero(data)) {
-               ast_log(LOG_WARNING, "PauseQueueMember requires an argument ([queuename]|interface])\n");
+               ast_log(LOG_WARNING, "PauseQueueMember requires an argument ([queuename]|interface[|options])\n");
                return -1;
        }
 
        LOCAL_USER_ADD(u);
 
-       queuename = ast_strdupa((char *)data);
-       if (!queuename) {
-               ast_log(LOG_ERROR, "Out of memory\n");
+       if (!(parse = ast_strdupa(data))) {
+               ast_log(LOG_WARNING, "Memory Error!\n");
                LOCAL_USER_REMOVE(u);
                return -1;
        }
 
-       interface = strchr(queuename, '|');
-       if (!interface) {
-               ast_log(LOG_WARNING, "Missing interface argument to PauseQueueMember ([queuename]|interface])\n");
+       AST_STANDARD_APP_ARGS(args, parse);
+
+       if (args.options) {
+               if (strchr(args.options, 'j'))
+                       priority_jump = 1;
+       }
+
+       if (ast_strlen_zero(args.interface)) {
+               ast_log(LOG_WARNING, "Missing interface argument to PauseQueueMember ([queuename]|interface[|options])\n");
                LOCAL_USER_REMOVE(u);
                return -1;
        }
 
-       *interface = '\0';
-       interface++;
-
-       if (set_member_paused(queuename, interface, 1)) {
-               ast_log(LOG_WARNING, "Attempt to pause interface %s, not found\n", interface);
-               if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) {
-                       LOCAL_USER_REMOVE(u);
-                       return 0;
+       if (set_member_paused(args.queuename, args.interface, 1)) {
+               ast_log(LOG_WARNING, "Attempt to pause interface %s, not found\n", args.interface);
+               if (priority_jump || option_priority_jumping) {
+                       if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) {
+                               pbx_builtin_setvar_helper(chan, "PQMSTATUS", "NOTFOUND");
+                               LOCAL_USER_REMOVE(u);
+                               return 0;
+                       }
                }
                LOCAL_USER_REMOVE(u);
+               pbx_builtin_setvar_helper(chan, "PQMSTATUS", "NOTFOUND");
                return -1;
        }
 
        LOCAL_USER_REMOVE(u);
-
+       pbx_builtin_setvar_helper(chan, "PQMSTATUS", "PAUSED");
        return 0;
 }
 
 static int upqm_exec(struct ast_channel *chan, void *data)
 {
        struct localuser *u;
-       char *queuename, *interface;
+       char *parse;
+       int priority_jump = 0;
+       AST_DECLARE_APP_ARGS(args,
+               AST_APP_ARG(queuename);
+               AST_APP_ARG(interface);
+               AST_APP_ARG(options);
+       );
 
        if (ast_strlen_zero(data)) {
-               ast_log(LOG_WARNING, "UnpauseQueueMember requires an argument ([queuename]|interface])\n");
+               ast_log(LOG_WARNING, "UnpauseQueueMember requires an argument ([queuename]|interface[|options])\n");
                return -1;
        }
 
        LOCAL_USER_ADD(u);
 
-       queuename = ast_strdupa((char *)data);
-       if (!queuename) {
-               ast_log(LOG_ERROR, "Out of memory\n");
+       if (!(parse = ast_strdupa(data))) {
+               ast_log(LOG_WARNING, "Memory Error!\n");
                LOCAL_USER_REMOVE(u);
                return -1;
        }
 
-       interface = strchr(queuename, '|');
-       if (!interface) {
-               ast_log(LOG_WARNING, "Missing interface argument to PauseQueueMember ([queuename]|interface])\n");
+       AST_STANDARD_APP_ARGS(args, parse);
+
+       if (args.options) {
+               if (strchr(args.options, 'j'))
+                       priority_jump = 1;
+       }
+
+       if (ast_strlen_zero(args.interface)) {
+               ast_log(LOG_WARNING, "Missing interface argument to PauseQueueMember ([queuename]|interface[|options])\n");
                LOCAL_USER_REMOVE(u);
                return -1;
        }
 
-       *interface = '\0';
-       interface++;
-
-       if (set_member_paused(queuename, interface, 0)) {
-               ast_log(LOG_WARNING, "Attempt to unpause interface %s, not found\n", interface);
-               if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) {
-                       LOCAL_USER_REMOVE(u);
-                       return 0;
+       if (set_member_paused(args.queuename, args.interface, 0)) {
+               ast_log(LOG_WARNING, "Attempt to unpause interface %s, not found\n", args.interface);
+               if (priority_jump || option_priority_jumping) {
+                       if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) {
+                               pbx_builtin_setvar_helper(chan, "UPQMSTATUS", "NOTFOUND");
+                               LOCAL_USER_REMOVE(u);
+                               return 0;
+                       }
                }
                LOCAL_USER_REMOVE(u);
+               pbx_builtin_setvar_helper(chan, "UPQMSTATUS", "NOTFOUND");
                return -1;
        }
 
        LOCAL_USER_REMOVE(u);
-
+       pbx_builtin_setvar_helper(chan, "UPQMSTATUS", "UNPAUSED");
        return 0;
 }
 
@@ -2643,52 +2695,58 @@ static int rqm_exec(struct ast_channel *chan, void *data)
 {
        int res=-1;
        struct localuser *u;
-       char *info, *queuename;
-       char tmpchan[256]="";
-       char *interface = NULL;
+       char *parse, *temppos = NULL;
+       int priority_jump = 0;
+       AST_DECLARE_APP_ARGS(args,
+               AST_APP_ARG(queuename);
+               AST_APP_ARG(interface);
+               AST_APP_ARG(options);
+       );
+
 
        if (ast_strlen_zero(data)) {
-               ast_log(LOG_WARNING, "RemoveQueueMember requires an argument (queuename[|interface])\n");
+               ast_log(LOG_WARNING, "RemoveQueueMember requires an argument (queuename[|interface[|options]])\n");
                return -1;
        }
 
        LOCAL_USER_ADD(u);
 
-       info = ast_strdupa(data);
-       if (!info) {
-               ast_log(LOG_ERROR, "Out of memory\n");
+       if (!(parse = ast_strdupa(data))) {
+               ast_log(LOG_WARNING, "Memory Error!\n");
                LOCAL_USER_REMOVE(u);
                return -1;
        }
 
-       queuename = info;
-       if (queuename) {
-               interface = strchr(queuename, '|');
-               if (interface) {
-                       *interface = '\0';
-                       interface++;
-               }
-               else {
-                       ast_copy_string(tmpchan, chan->name, sizeof(tmpchan));
-                       interface = strrchr(tmpchan, '-');
-                       if (interface)
-                               *interface = '\0';
-                       interface = tmpchan;
-               }
+       AST_STANDARD_APP_ARGS(args, parse);
+
+       if (ast_strlen_zero(args.interface)) {
+               ast_copy_string(args.interface, chan->name, sizeof(args.interface));
+               temppos = strrchr(args.interface, '-');
+               if (temppos)
+                       *temppos = '\0';
        }
 
-       switch (remove_from_queue(queuename, interface)) {
+       if (args.options) {
+               if (strchr(args.options, 'j'))
+                       priority_jump = 1;
+       }
+
+       switch (remove_from_queue(args.queuename, args.interface)) {
        case RES_OKAY:
-               ast_log(LOG_NOTICE, "Removed interface '%s' from queue '%s'\n", interface, queuename);
+               ast_log(LOG_NOTICE, "Removed interface '%s' from queue '%s'\n", args.interface, args.queuename);
+               pbx_builtin_setvar_helper(chan, "RQMSTATUS", "REMOVED");
                res = 0;
                break;
        case RES_EXISTS:
-               ast_log(LOG_WARNING, "Unable to remove interface '%s' from queue '%s': Not there\n", interface, queuename);
-               ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
+               ast_log(LOG_WARNING, "Unable to remove interface '%s' from queue '%s': Not there\n", args.interface, args.queuename);
+               if (priority_jump || option_priority_jumping) 
+                       ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
+               pbx_builtin_setvar_helper(chan, "RQMSTATUS", "NOTINQUEUE");
                res = 0;
                break;
        case RES_NOSUCHQUEUE:
-               ast_log(LOG_WARNING, "Unable to remove interface from queue '%s': No such queue\n", queuename);
+               ast_log(LOG_WARNING, "Unable to remove interface from queue '%s': No such queue\n", args.queuename);
+               pbx_builtin_setvar_helper(chan, "RQMSTATUS", "NOSUCHQUEUE");
                res = 0;
                break;
        case RES_OUTOFMEMORY:
@@ -2704,72 +2762,71 @@ static int aqm_exec(struct ast_channel *chan, void *data)
 {
        int res=-1;
        struct localuser *u;
-       char *queuename;
-       char *info;
-       char tmpchan[512]="";
-       char *interface=NULL;
-       char *penaltys=NULL;
+       char *parse, *temppos = NULL;
+       int priority_jump = 0;
+       AST_DECLARE_APP_ARGS(args,
+               AST_APP_ARG(queuename);
+               AST_APP_ARG(interface);
+               AST_APP_ARG(penalty);
+               AST_APP_ARG(options);
+       );
        int penalty = 0;
 
        if (ast_strlen_zero(data)) {
-               ast_log(LOG_WARNING, "AddQueueMember requires an argument (queuename[|[interface][|penalty]])\n");
+               ast_log(LOG_WARNING, "AddQueueMember requires an argument (queuename[|[interface]|[penalty][|options]])\n");
                return -1;
        }
 
        LOCAL_USER_ADD(u);
 
-       info = ast_strdupa(data);
-       if (!info) {
-               ast_log(LOG_ERROR, "Out of memory\n");
+       if (!(parse = ast_strdupa(data))) {
+               ast_log(LOG_WARNING, "Memory Error!\n");
                LOCAL_USER_REMOVE(u);
                return -1;
        }
 
-       queuename = info;
-       if (queuename) {
-               interface = strchr(queuename, '|');
-               if (interface) {
-                       *interface = '\0';
-                       interface++;
-               }
-               if (interface) {
-                       penaltys = strchr(interface, '|');
-                       if (penaltys) {
-                               *penaltys = '\0';
-                               penaltys++;
-                       }
-               }
-               if (ast_strlen_zero(interface)) {
-                       ast_copy_string(tmpchan, chan->name, sizeof(tmpchan));
-                       interface = strrchr(tmpchan, '-');
-                       if (interface)
-                               *interface = '\0';
-                       interface = tmpchan;
-               }
-               if (!ast_strlen_zero(penaltys)) {
-                       if ((sscanf(penaltys, "%d", &penalty) != 1) || penalty < 0) {
-                               ast_log(LOG_WARNING, "Penalty '%s' is invalid, must be an integer >= 0\n", penaltys);
-                               penalty = 0;
-                       }
+       AST_STANDARD_APP_ARGS(args, parse);
+
+       if (ast_strlen_zero(args.interface)) {
+               ast_copy_string(args.interface, chan->name, sizeof(args.interface));
+               temppos = strrchr(args.interface, '-');
+               if (temppos)
+                       *temppos = '\0';
+       }
+
+       if (!ast_strlen_zero(args.penalty)) {
+               if ((sscanf(args.penalty, "%d", &penalty) != 1) || penalty < 0) {
+                       ast_log(LOG_WARNING, "Penalty '%s' is invalid, must be an integer >= 0\n", args.penalty);
+                       penalty = 0;
                }
        }
+       
+       if (args.options) {
+               if (strchr(args.options, 'j'))
+                       priority_jump = 1;
+       }
 
-       switch (add_to_queue(queuename, interface, penalty, 0, queue_persistent_members)) {
+
+       switch (add_to_queue(args.queuename, args.interface, penalty, 0, queue_persistent_members)) {
        case RES_OKAY:
-               ast_log(LOG_NOTICE, "Added interface '%s' to queue '%s'\n", interface, queuename);
+               ast_log(LOG_NOTICE, "Added interface '%s' to queue '%s'\n", args.interface, args.queuename);
+               pbx_builtin_setvar_helper(chan, "AQMSTATUS", "ADDED");
                res = 0;
                break;
        case RES_EXISTS:
-               ast_log(LOG_WARNING, "Unable to add interface '%s' to queue '%s': Already there\n", interface, queuename);
-               ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
+               ast_log(LOG_WARNING, "Unable to add interface '%s' to queue '%s': Already there\n", args.interface, args.queuename);
+               if (priority_jump || option_priority_jumping) 
+                       ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
+               pbx_builtin_setvar_helper(chan, "AQMSTATUS", "MEMBERALREADY");
                res = 0;
                break;
        case RES_NOSUCHQUEUE:
-               ast_log(LOG_WARNING, "Unable to add interface to queue '%s': No such queue\n", queuename);
+               ast_log(LOG_WARNING, "Unable to add interface to queue '%s': No such queue\n", args.queuename);
+               pbx_builtin_setvar_helper(chan, "AQMSTATUS", "NOSUCHQUEUE");
                res = 0;
                break;
        case RES_OUTOFMEMORY:
-               ast_log(LOG_ERROR, "Out of memory adding member %s to queue %s\n", interface, queuename);
+               ast_log(LOG_ERROR, "Out of memory adding member %s to queue %s\n", args.interface, args.queuename);
                break;
        }
 
index e024a5c..90e180f 100755 (executable)
@@ -23,8 +23,9 @@
  * \ingroup applications
  */
  
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index 80f0925..a731fd7 100755 (executable)
@@ -25,8 +25,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "asterisk.h"
 
index 31905a6..7c50a1d 100755 (executable)
@@ -23,8 +23,9 @@
  * \ingroup applications
  */
  
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index 41ba1bb..c2c3c76 100755 (executable)
@@ -23,8 +23,9 @@
  * \ingroup applications
  */
  
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index 177a6a6..7830ee8 100755 (executable)
@@ -25,8 +25,9 @@
  * \ingroup applications
  */
  
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index 2d01ccf..877efb5 100755 (executable)
@@ -23,8 +23,9 @@
  * \ingroup applications
  */
  
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index 2cb5896..6906c13 100755 (executable)
@@ -23,8 +23,9 @@
  * \ingroup applications
  */
  
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index 95ea2c0..a8a7e07 100755 (executable)
@@ -24,8 +24,9 @@
  * \ingroup applications
  */
  
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index f7f01c2..69c3ed5 100755 (executable)
@@ -24,8 +24,9 @@
  * \ingroup applications
  */
  
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index cf47d6d..c6feb55 100755 (executable)
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 #include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <dirent.h>
 #include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #include "asterisk.h"
 
index e9b0f24..804a392 100755 (executable)
  * \ingroup applications
  */
 
-#include <sys/types.h>
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
 
 #include "asterisk.h"
 
index e905394..29968d4 100755 (executable)
@@ -24,8 +24,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 #include <sys/types.h>
 
 #include "asterisk.h"
index dbaafd8..9771df9 100755 (executable)
  * \todo Deprecate this application in 1.3dev
  */
 
-#include <sys/types.h>
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
-#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
 
 #include "asterisk.h"
 
index 5d52169..63e9baa 100755 (executable)
@@ -24,9 +24,9 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <unistd.h>
 #include <string.h>
-#include <stdlib.h>
 #include <errno.h>
 
 #include "asterisk.h"
index 30e27e3..11efe70 100755 (executable)
@@ -23,8 +23,9 @@
  * \ingroup applications
  */
  
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index 56b5bf2..dba8bca 100755 (executable)
  * \ingroup applications
  */
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #include "asterisk.h"
 
index 4443a78..aaff52b 100755 (executable)
@@ -26,8 +26,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "asterisk.h"
 
index b44fb21..7f274b4 100755 (executable)
@@ -22,8 +22,9 @@
  * \ingroup applications
  */
  
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index 74fa58f..95f5fbc 100755 (executable)
@@ -23,9 +23,9 @@
 
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
-#include <stdlib.h>
+#include <unistd.h>
 
 #include "asterisk.h"
 
index 0de2056..25e651d 100755 (executable)
@@ -24,9 +24,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
-#include <stdlib.h>
+#include <unistd.h>
 #include <sys/types.h>
 
 #include "asterisk.h"
index 79d2b22..cbba6cf 100755 (executable)
@@ -30,9 +30,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
-#include <pthread.h>
+#include <unistd.h>
 
 #include "asterisk.h"
 
index 757171a..7c98afe 100755 (executable)
@@ -24,8 +24,9 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "asterisk.h"
 
index 00fb647..3120a42 100755 (executable)
@@ -23,8 +23,9 @@
  * \ingroup applications
  */
  
-#include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "asterisk.h"
 
index 9511c4f..10c5c49 100755 (executable)
  */
 
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 #include <unistd.h>
 #include <errno.h>
-#include <string.h>
-#include <stdlib.h>
 #include <sys/ioctl.h>
 
 #ifdef __linux__
index a199d4e..ed0c779 100755 (executable)
  */
 
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 #include <unistd.h>
 #include <errno.h>
-#include <string.h>
-#include <stdlib.h>
 #include <sys/ioctl.h>
 
 #ifdef __linux__
index 9ccfbed..264c404 100755 (executable)
@@ -21,6 +21,7 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
 
index 8034be8..6533d78 100755 (executable)
@@ -25,6 +25,7 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 
 #include "asterisk.h"
 
index 2974229..0f07d83 100755 (executable)
@@ -21,6 +21,7 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
 
index e53eb40..e8a49ac 100755 (executable)
@@ -23,6 +23,7 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
 
index ab9474d..91564d9 100755 (executable)
@@ -23,6 +23,7 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
 #include <regex.h>
index d7d5cf4..4e9256e 100755 (executable)
@@ -23,6 +23,7 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
 
index f75023c..f985f38 100755 (executable)
@@ -26,6 +26,7 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
 
index 8155930..15b1584 100755 (executable)
@@ -23,6 +23,7 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <unistd.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
index 2abc117..5522e9b 100755 (executable)
@@ -23,6 +23,7 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
index 6b1c451..4e9aba1 100755 (executable)
@@ -24,6 +24,7 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
index f53ea76..8a5a9ef 100755 (executable)
@@ -28,6 +28,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>