]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
chan_sip: Fix order of variables specified in SIPNotify action
authorJonathan Rose <jrose@digium.com>
Fri, 6 Jun 2014 21:44:16 +0000 (21:44 +0000)
committerJonathan Rose <jrose@digium.com>
Fri, 6 Jun 2014 21:44:16 +0000 (21:44 +0000)
Prior to this patch, sequential variables would be ordered in reverse
from the order specified in the manager action.

Review: https://reviewboard.asterisk.org/r/3588/
........

Merged revisions 415359 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 415390 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 415410 from http://svn.asterisk.org/svn/asterisk/branches/12

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

channels/chan_sip.c
include/asterisk/config.h
include/asterisk/manager.h
main/config.c
main/manager.c

index 2d3786256825792a0d6701b125177b426a3248fd..3d9d80b2057d4975f7f627d90e26deec2f0382c8 100644 (file)
@@ -15073,7 +15073,7 @@ static int transmit_notify_with_sipfrag(struct sip_pvt *p, int cseq, char *messa
 static int manager_sipnotify(struct mansession *s, const struct message *m)
 {
        const char *channame = astman_get_header(m, "Channel");
-       struct ast_variable *vars = astman_get_variables(m);
+       struct ast_variable *vars = astman_get_variables_order(m, ORDER_NATURAL);
        struct sip_pvt *p;
        struct ast_variable *header, *var;
 
index 1c10d176bcdf3041780fb452fc8a40814235358f..2579ef2795f72a03538db262b2e7b2b37fc6c1dd 100644 (file)
@@ -559,6 +559,16 @@ int ast_realtime_enabled(void);
  */
 struct ast_variable *ast_variables_dup(struct ast_variable *var);
 
+/*!
+ * \brief Reverse a variable list
+ * \param var the linked list of variables to reverse
+ * \return The head of the reversed variable list
+ *
+ * \note The variable list var is not preserved in this function and should
+ * not be used after reversing it.
+ */
+struct ast_variable *ast_variables_reverse(struct ast_variable *var);
+
 /*!
  * \brief Free variable list
  * \param var the linked list of variables to free
index 42ff31a45670d29a32e45d33eea3ddc7384a8b55..978151ab1b62d3f91a00f4545872363a1001cdfa 100644 (file)
@@ -260,9 +260,21 @@ int __ast_manager_event_multichan(int category, const char *event, int chancount
 /*! \brief Get header from mananger transaction */
 const char *astman_get_header(const struct message *m, char *var);
 
-/*! \brief Get a linked list of the Variable: headers */
+/*! \brief Get a linked list of the Variable: headers
+ *
+ *  \note Order of variables is reversed from the order they are specified in
+ *        the manager message
+ */
 struct ast_variable *astman_get_variables(const struct message *m);
 
+enum variable_orders {
+       ORDER_NATURAL,
+       ORDER_REVERSE
+};
+
+/*! \brief Get a linked list of the Variable: headers with order specified */
+struct ast_variable *astman_get_variables_order(const struct message *m, enum variable_orders order);
+
 /*! \brief Send error in manager transaction */
 void astman_send_error(struct mansession *s, const struct message *m, char *error);
 
index aee81e3ff7dec1ee936605df23bb9484d8f0d762..d9bef2e1b3421065f3854374704f7f14bc6648eb 100644 (file)
@@ -562,6 +562,30 @@ struct ast_variable *ast_variables_dup(struct ast_variable *var)
        return cloned;
 }
 
+struct ast_variable *ast_variables_reverse(struct ast_variable *var)
+{
+       struct ast_variable *var1, *var2;
+
+       var1 = var;
+
+       if (!var1 || !var1->next) {
+               return var1;
+       }
+
+       var2 = var1->next;
+       var1->next = NULL;
+
+       while (var2) {
+               struct ast_variable *next = var2->next;
+
+               var2->next = var1;
+               var1 = var2;
+               var2 = next;
+       }
+
+       return var1;
+}
+
 void ast_variables_destroy(struct ast_variable *v)
 {
        struct ast_variable *vn;
index cb2b0bbe25b61505f50d9fd71933b7100d328b23..09d49f002d2e852322d169243c08eeac3a2e4133 100644 (file)
@@ -2389,6 +2389,12 @@ static struct ast_variable *man_do_variable_value(struct ast_variable *head, con
 }
 
 struct ast_variable *astman_get_variables(const struct message *m)
+{
+       return astman_get_variables_order(m, ORDER_REVERSE);
+}
+
+struct ast_variable *astman_get_variables_order(const struct message *m,
+       enum variable_orders order)
 {
        int varlen;
        int x;
@@ -2405,6 +2411,10 @@ struct ast_variable *astman_get_variables(const struct message *m)
                head = man_do_variable_value(head, m->headers[x] + varlen);
        }
 
+       if (order == ORDER_NATURAL) {
+               head = ast_variables_reverse(head);
+       }
+
        return head;
 }