[sr-dev] git:master: perl: use C append_branch() in Perl function

Daniel-Constantin Mierla miconda at gmail.com
Wed Aug 26 20:26:06 CEST 2009


Module: sip-router
Branch: master
Commit: b3368c5296efeba88b4823fa50903e2d4f9a975d
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b3368c5296efeba88b4823fa50903e2d4f9a975d

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Wed Aug 26 20:23:03 2009 +0200

perl: use C append_branch() in Perl function

- perviously mk_action() was used resulting in lot of pkg operations at
  runtime
- fixes the memory leak reported by James Pucket

---

 modules_k/perl/openserxs.xs |   44 +++++++-----------------------------------
 1 files changed, 8 insertions(+), 36 deletions(-)

diff --git a/modules_k/perl/openserxs.xs b/modules_k/perl/openserxs.xs
index 7791e63..418f1e3 100644
--- a/modules_k/perl/openserxs.xs
+++ b/modules_k/perl/openserxs.xs
@@ -42,6 +42,7 @@
 #include "../../action.h"
 #include "../../flags.h"
 #include "../../pvar.h"
+#include "../../dset.h"
 #include "../../mem/mem.h"
 #include "../../route_struct.h"
 #include "../../qvalue.h"
@@ -1185,11 +1186,8 @@ append_branch(self, branch = NULL, qval = NULL)
 	char *qval;
   PREINIT:
 	struct sip_msg *msg = sv2msg(self);
-	action_u_t elems[MAX_ACTIONS];
-	qvalue_t q;
-	int err = 0;
-	struct action *act = NULL;
-	struct run_act_ctx ra_ctx;
+	qvalue_t q = Q_UNSPECIFIED;
+	str b = {0, 0};
   INIT:
   CODE:
   	if (!msg) {
@@ -1200,43 +1198,17 @@ append_branch(self, branch = NULL, qval = NULL)
 			if (str2q(&q, qval, strlen(qval)) < 0) {
 				LM_ERR("append_branch: Bad q value.");
 			} else { /* branch and qval set */
-				elems[0].type = STRING_ST;
-				elems[0].u.data = branch;
-				elems[1].type = NUMBER_ST;
-				elems[1].u.data = (void *)(long)q;
-				act = mk_action(APPEND_BRANCH_T,
-						2,
-						elems,
-						0);
+				b.s = branch;
+				b.len = strlen(branch);
 			}
 		} else {
 			if (branch) { /* branch set, qval unset */
-				elems[0].type = STRING_ST;
-				elems[0].u.data = branch;
-				elems[1].type = NUMBER_ST;
-				elems[1].u.data = (void *)Q_UNSPECIFIED;
-				act = mk_action(APPEND_BRANCH_T,
-						2,
-						elems,
-						0);
-			} else { /* neither branch nor qval set */
-				elems[0].type = STRING_ST;
-				elems[0].u.data = NULL;
-				elems[1].type = NUMBER_ST;
-				elems[1].u.data = (void *)Q_UNSPECIFIED;
-				act = mk_action(APPEND_BRANCH_T,
-						2,
-						elems,
-						0);
+				b.s = branch;
+				b.len = strlen(branch);
 			}
 		}
 
-		if (act) {
-		    init_run_actions_ctx(&ra_ctx);
-			RETVAL = do_action(&ra_ctx, act, msg);
-		} else {
-			RETVAL = -1;
-		}
+		RETVAL = km_append_branch(msg, (b.s!=0)?&b:0, 0, 0, q, 0, 0);
 	}
   OUTPUT:
 	RETVAL




More information about the sr-dev mailing list