Module: sip-router
Branch: hpw/branch_failure_route
Commit: 76a967f1db16540257fe8a54fe85e3993060b304
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=76a967f1db16540257fe8a54fe85e3993060b304

Author: Hugh Waite <[email protected]>
Committer: Hugh Waite <[email protected]>
Date:   Tue Mar 26 12:10:11 2013 +0000

modules/tm: Update t_next_contact_flows for use in branch_failure event_route

- Rename to t_next_contact_flow as only one flow will be used
- Selects and uses the next flow with the same instance_id as the failed branch

---

 modules/tm/t_serial.c |  261 ++++++++++++++-----------------------------------
 modules/tm/t_serial.h |    2 +-
 modules/tm/tm.c       |    6 +-
 3 files changed, 76 insertions(+), 193 deletions(-)

diff --git a/modules/tm/t_serial.c b/modules/tm/t_serial.c
index 570d02c..3a9e6de 100644
--- a/modules/tm/t_serial.c
+++ b/modules/tm/t_serial.c
@@ -588,7 +588,7 @@ int t_next_contacts(struct sip_msg* msg, char* key, char* 
value)
         vavp = xavp_get(&ruid_name, xavp->val.v.xavp);
         ruid = vavp->val.v.s;
 
-       if (append_branch(msg, &uri, &dst_uri, &path, 0, flags, sock, 0, 0,
+       if (append_branch(msg, &uri, &dst_uri, &path, 0, flags, sock, 
&instance, 0,
                          &ruid) != 1) {
            LM_ERR("appending branch failed\n");
            free_instance_list(il);
@@ -622,15 +622,17 @@ int t_next_contacts(struct sip_msg* msg, char* key, char* 
value)
  * Returns 1, if contact_flows_avp was not empty and a destination set was
  * successfully added.  Returns -2, if contact_flows_avp was empty and thus
  * there was nothing to do. Returns -1 in case of an error. */
-int t_next_contact_flows(struct sip_msg* msg, char* key, char* value)
+int t_next_contact_flow(struct sip_msg* msg, char* key, char* value)
 {
     str uri, dst_uri, path, instance, host, ruid;
+       str this_instance;
+       int this_branch;
     struct socket_info *sock;
     unsigned int flags;
     sr_xavp_t *xavp_list, *xavp, *next_xavp, *vavp;
     char *tmp;
     int port, proto;
-    struct instance_list *il, *ilp;
+       int q_dummy;
 
     /* Check if contact_flows_avp has been defined */
     if (contact_flows_avp.len == 0) {
@@ -640,208 +642,89 @@ int t_next_contact_flows(struct sip_msg* msg, char* key, 
char* value)
     }
 
     /* Load Request-URI and branches */
-
-    /* Find first contact_flows_avp value */
-    xavp_list = xavp_get(&contact_flows_avp, NULL);
-    if (!xavp_list) {
-       LM_DBG("no contacts in contact_flows_avp - we are done!\n");
-       return -2;
-    }
-
-    xavp = xavp_list;
-    next_xavp = xavp_get_next(xavp);
-
-    vavp = xavp_get(&uri_name, xavp->val.v.xavp);
-    uri = vavp->val.v.s;
-
-    vavp = xavp_get(&dst_uri_name, xavp->val.v.xavp);
-    if (vavp != NULL) {
-       dst_uri = vavp->val.v.s;
-    } else {
-       dst_uri.s = 0;
-       dst_uri.len = 0;
-    }
-
-    vavp = xavp_get(&path_name, xavp->val.v.xavp);
-    if (vavp != NULL) {
-       path = vavp->val.v.s;
-    } else {
-       path.s = 0;
-       path.len = 0;
-    }
-
-    vavp = xavp_get(&sock_name, xavp->val.v.xavp);
-    if (vavp != NULL) {
-       tmp = vavp->val.v.s.s;
-       if (parse_phostport(tmp, &host.s, &host.len, &port, &proto) != 0) {
-           LM_ERR("parsing of socket info <%s> failed\n", tmp);
-           xavp_destroy_list(&xavp_list);
-           return -1;
+       this_branch = get_t_branch();
+       uri.s = get_branch(this_branch, &uri.len, &q_dummy, NULL, NULL, NULL, 
NULL, &this_instance);
+
+       /* Find first contact_flows_avp value */
+       xavp_list = xavp_get(&contact_flows_avp, NULL);
+       if (!xavp_list) {
+               LM_DBG("no contacts in contact_flows_avp - we are done!\n");
+               return -2;
        }
-       sock = grep_sock_info(&host, (unsigned short)port,
-                             (unsigned short)proto);
-       if (sock == 0) {
-           xavp_destroy_list(&xavp_list);
-           return -1;
-       }
-    } else {
-       sock = NULL;
-    }
-
-    vavp = xavp_get(&flags_name, xavp->val.v.xavp);
-    flags = vavp->val.v.i;
-
-    vavp = xavp_get(&instance_name, xavp->val.v.xavp);
-    il = (struct instance_list *)0;
-    if ((vavp != NULL) && next_xavp) {
-       instance = vavp->val.v.s;
-       il = (struct instance_list *)pkg_malloc(sizeof(struct instance_list));
-       if (!il) {
-           LM_ERR("no memory for instance list entry\n");
-           return -1;
-       }
-       il->instance.s = pkg_malloc(instance.len);
-       if (!il->instance.s) {
-           pkg_free(il);
-           LM_ERR("no memory for instance list instance\n");
-           return -1;
-       }
-       il->instance.len = instance.len;
-       memcpy(il->instance.s, instance.s, instance.len);
-       il->next = (struct instance_list *)0;
-    }
-
-    vavp = xavp_get(&ruid_name, xavp->val.v.xavp);
-    ruid = vavp->val.v.s;
-
-    /* Rewrite Request-URI */
-    rewrite_uri(msg, &uri);
-
-    if (dst_uri.len) {
-       set_dst_uri(msg, &dst_uri);
-    } else {
-       reset_dst_uri(msg);
-    }
-
-    if (path.len) {
-       set_path_vector(msg, &path);
-    } else {
-       reset_path_vector(msg);
-    }
-
-    set_force_socket(msg, sock);
-
-    set_ruid(msg, &ruid);
-
-    setbflagsval(0, flags);
 
-    /* Append branches until out of branches. */
-    /* Do not include a branch that has same instance value as some */
-    /* previous branch. */
+       xavp = xavp_list;
 
-    xavp_rm(xavp, NULL);
-    xavp = next_xavp;
+       while (xavp) {
+               next_xavp = xavp_get_next(xavp);
 
-    while (xavp) {
-       
-       next_xavp = xavp_get_next(xavp);
-
-       vavp = xavp_get(&instance_name, xavp->val.v.xavp);
-       if (vavp != NULL) {
-           instance = vavp->val.v.s;
-           ilp = il;
-           while (ilp) {
-               if ((instance.len == ilp->instance.len) &&
-                   (strncmp(instance.s, ilp->instance.s, instance.len) == 0))
-                   break;
-               ilp = ilp->next;
-           }
-           if (ilp) {
-               /* skip already appended instance */
-               xavp = next_xavp;
-               continue;
-           }
-           if (next_xavp) {
-               ilp = (struct instance_list *)
-               pkg_malloc(sizeof(struct instance_list));
-               if (!ilp) {
-                   LM_ERR("no memory for new instance list entry\n");
-                   free_instance_list(il);
-                   return -1;
+               vavp = xavp_get(&instance_name, xavp->val.v.xavp);
+               if (vavp == NULL)
+               {
+                       /* Does not match this instance */
+                       goto next_xavp;
                }
-               ilp->instance.s = pkg_malloc(instance.len);
-               if (!ilp->instance.s) {
-                   pkg_free(il);
-                   LM_ERR("no memory for instance list instance\n");
-                   return -1;
+               else
+               {
+                       instance = vavp->val.v.s;
+                       if ((instance.len != this_instance.len) ||
+                           (strncmp(instance.s, this_instance.s, instance.len) 
!= 0))
+                               /* Does not match this instance */
+                               goto next_xavp;
                }
-               ilp->instance.len = instance.len;
-               memcpy(ilp->instance.s, instance.s, instance.len);
-               ilp->next = il;
-               il = ilp;
-           } else {
-               LM_ERR("instance missing from contact_flow_avp contact\n");
-               free_instance_list(il);
-               return -1;
-           }
-       }
 
-       vavp = xavp_get(&uri_name, xavp->val.v.xavp);
-       uri = vavp->val.v.s;
+               vavp = xavp_get(&uri_name, xavp->val.v.xavp);
+               uri = vavp->val.v.s;
 
-       vavp = xavp_get(&dst_uri_name, xavp->val.v.xavp);
-       if (vavp != NULL) {
-           dst_uri = vavp->val.v.s;
-       } else {
-           dst_uri.len = 0;
-       }
+               vavp = xavp_get(&dst_uri_name, xavp->val.v.xavp);
+               if (vavp != NULL) {
+                       dst_uri = vavp->val.v.s;
+               } else {
+                       dst_uri.len = 0;
+               }
 
-       vavp = xavp_get(&path_name, xavp->val.v.xavp);
-       if (vavp != NULL) {
-           path = vavp->val.v.s;
-       } else {
-           path.len = 0;
-       }
+               vavp = xavp_get(&path_name, xavp->val.v.xavp);
+               if (vavp != NULL) {
+                       path = vavp->val.v.s;
+               } else {
+                       path.len = 0;
+               }
 
-       vavp = xavp_get(&sock_name, xavp->val.v.xavp);
-       if (vavp != NULL) {
-           tmp = vavp->val.v.s.s;
-           if (parse_phostport(tmp, &host.s, &host.len, &port, &proto) != 0) {
-               LM_ERR("parsing of socket info <%s> failed\n", tmp);
-               free_instance_list(il);
-               xavp_destroy_list(&xavp_list);
-               return -1;
-           }
-           sock = grep_sock_info(&host, (unsigned short)port,
+               vavp = xavp_get(&sock_name, xavp->val.v.xavp);
+               if (vavp != NULL) {
+                       tmp = vavp->val.v.s.s;
+                       if (parse_phostport(tmp, &host.s, &host.len, &port, 
&proto) != 0) {
+                               LM_ERR("parsing of socket info <%s> failed\n", 
tmp);
+                               xavp_rm(xavp, NULL);
+                               return -1;
+                       }
+                       sock = grep_sock_info(&host, (unsigned short)port,
                                  (unsigned short)proto);
-           if (sock == 0) {
-               free_instance_list(il);
-               xavp_destroy_list(&xavp_list);
-               return -1;
-           }
-       } else {
-           sock = NULL;
-       }
+                       if (sock == 0) {
+                               xavp_rm(xavp, NULL);
+                               return -1;
+                       }
+               } else {
+                       sock = NULL;
+               }
 
-       vavp = xavp_get(&flags_name, xavp->val.v.xavp);
-       flags = vavp->val.v.i;
+               vavp = xavp_get(&flags_name, xavp->val.v.xavp);
+               flags = vavp->val.v.i;
 
-        vavp = xavp_get(&ruid_name, xavp->val.v.xavp);
-        ruid = vavp->val.v.s;
+               vavp = xavp_get(&ruid_name, xavp->val.v.xavp);
+               ruid = vavp->val.v.s;
 
-       if (append_branch(msg, &uri, &dst_uri, &path, 0, flags, sock, 0, 0,
+               if (append_branch(msg, &uri, &dst_uri, &path, 0, flags, sock, 
&instance, 0,
                          &ruid) != 1) {
-           LM_ERR("appending branch failed\n");
-           free_instance_list(il);
-           xavp_destroy_list(&xavp_list);
-           return -1;
-       }
+                       LM_ERR("appending branch failed\n");
+                       xavp_destroy_list(&xavp_list);
+                       return -1;
+               }
 
-       xavp_rm(xavp, NULL);
-       xavp = next_xavp;
-    }
+               xavp_rm(xavp, NULL);
+next_xavp:
+               xavp = next_xavp;
+       }
 
-    free_instance_list(il);
 
-    return 1;
+       return 1;
 }
diff --git a/modules/tm/t_serial.h b/modules/tm/t_serial.h
index b1c8181..0794e31 100644
--- a/modules/tm/t_serial.h
+++ b/modules/tm/t_serial.h
@@ -34,4 +34,4 @@ int t_load_contacts(struct sip_msg* msg, char* key, char* 
value);
 
 int t_next_contacts(struct sip_msg* msg, char* key, char* value);
 
-int t_next_contact_flows(struct sip_msg* msg, char* key, char* value);
+int t_next_contact_flow(struct sip_msg* msg, char* key, char* value);
diff --git a/modules/tm/tm.c b/modules/tm/tm.c
index e2790b3..782ce3f 100644
--- a/modules/tm/tm.c
+++ b/modules/tm/tm.c
@@ -475,8 +475,8 @@ static cmd_export_t cmds[]={
                        REQUEST_ROUTE | FAILURE_ROUTE},
        {"t_next_contacts", t_next_contacts,            0, 0,
                        REQUEST_ROUTE | FAILURE_ROUTE},
-       {"t_next_contact_flows", t_next_contact_flows,            0, 0,
-                       REQUEST_ROUTE | FAILURE_ROUTE},
+       {"t_next_contact_flow", t_next_contact_flow,            0, 0,
+                       REQUEST_ROUTE | BRANCH_FAILURE_ROUTE},
 
        /* not applicable from the script */
        {"load_tm",            (cmd_function)load_tm,           NO_SCRIPT,   0, 
0},
@@ -1444,7 +1444,7 @@ inline static int _w_t_relay_to(struct sip_msg  *p_msg ,
        struct cell *t;
        int res;
 
-       if (is_route_type(FAILURE_ROUTE)) {
+       if (is_route_type(FAILURE_ROUTE|BRANCH_FAILURE_ROUTE)) {
                t=get_t();
                if (!t || t==T_UNDEFINED) {
                        LOG(L_CRIT, "BUG: w_t_relay_to: undefined T\n");


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to