Browse Source

shm duplication functions

Jan Janak 22 years ago
parent
commit
91804f9bd1
4 changed files with 124 additions and 11 deletions
  1. 48 6
      parser/parse_param.c
  2. 14 0
      parser/parse_param.h
  3. 49 5
      parser/parse_rr.c
  4. 13 0
      parser/parse_rr.h

+ 48 - 6
parser/parse_param.c

@@ -38,6 +38,7 @@
 #include "../dprint.h"
 #include "../trim.h"
 #include "../mem/mem.h"
+#include "../mem/shm_mem.h"
 #include "parse_param.h"
 
 
@@ -369,15 +370,34 @@ int parse_params(str* _s, pclass_t _c, param_hooks_t* _h, param_t** _p)
 /*
  * Free linked list of parameters
  */
-void free_params(param_t* _p)
+static inline void do_free_params(param_t* _p, int _shm)
 {
 	param_t* ptr;
 	
 	while(_p) {
 		ptr = _p;
 		_p = _p->next;
-		pkg_free(ptr);
-	}
+		if (_shm) shm_free(ptr);
+		else pkg_free(ptr);
+	}	
+}
+
+
+/*
+ * Free linked list of parameters
+ */
+void free_params(param_t* _p)
+{
+	do_free_params(_p, 0);
+}
+
+
+/*
+ * Free linked list of parameters
+ */
+void shm_free_params(param_t* _p)
+{
+	do_free_params(_p, 1);
 }
 
 
@@ -426,7 +446,7 @@ void print_params(param_t* _p)
 /*
  * Duplicate linked list of parameters
  */
-int duplicate_params(param_t** _n, param_t* _p)
+static inline int do_duplicate_params(param_t** _n, param_t* _p, int _shm)
 {
 	param_t* last, *ptr, *t;
 
@@ -439,7 +459,11 @@ int duplicate_params(param_t** _n, param_t* _p)
 	*_n = 0;
 	ptr = _p;
 	while(ptr) {
-		t = (param_t*)pkg_malloc(sizeof(param_t));
+		if (_shm) {
+			t = (param_t*)shm_malloc(sizeof(param_t));
+		} else {
+			t = (param_t*)pkg_malloc(sizeof(param_t));
+		}
 		if (!t) {
 			LOG(L_ERR, "duplicate_params(): Invalid parameter value\n");
 			goto err;
@@ -455,6 +479,24 @@ int duplicate_params(param_t** _n, param_t* _p)
 	}
 
  err:
-	free_params(*_n);
+	do_free_params(*_n, _shm);
 	return 0;
 }
+
+
+/*
+ * Duplicate linked list of parameters
+ */
+int duplicate_params(param_t** _n, param_t* _p)
+{
+	return do_duplicate_params(_n, _p, 0);
+}
+
+
+/*
+ * Duplicate linked list of parameters
+ */
+int shm_duplicate_params(param_t** _n, param_t* _p)
+{
+	return do_duplicate_params(_n, _p, 1);
+}

+ 14 - 0
parser/parse_param.h

@@ -117,6 +117,14 @@ int parse_params(str* _s, pclass_t _c, param_hooks_t* _h, param_t** _p);
 void free_params(param_t* _p);
 
 
+/*
+ * Free linked list of parameters from shared memory
+ */
+void shm_free_params(param_t* _p);
+
+
+
+
 /*
  * Print linked list of parameters, just for debugging
  */
@@ -129,4 +137,10 @@ void print_params(param_t* _p);
 int duplicate_params(param_t** _n, param_t* _p);
 
 
+/*
+ * Duplicate linked list of parameters
+ */
+int shm_duplicate_params(param_t** _n, param_t* _p);
+
+
 #endif /* PARSE_PARAM_H */

+ 49 - 5
parser/parse_rr.c

@@ -31,6 +31,7 @@
 #include <string.h>
 #include "parse_rr.h"
 #include "../mem/mem.h"
+#include "../mem/shm_mem.h"
 #include "../dprint.h"
 #include "../trim.h"
 #include "../ut.h"
@@ -139,7 +140,7 @@ int parse_rr(struct hdr_field* _h)
  * Free list of rrs
  * _r is head of the list
  */
-void free_rr(rr_t** _r)
+static inline void do_free_rr(rr_t** _r, int _shm)
 {
 	rr_t* ptr;
 
@@ -149,11 +150,34 @@ void free_rr(rr_t** _r)
 		if (ptr->params) {
 			free_params(ptr->params);
 		}
-		pkg_free(ptr);
+		if (_shm) shm_free(ptr);
+		else pkg_free(ptr);
 	}
 }
 
 
+/*
+ * Free list of rrs
+ * _r is head of the list
+ */
+
+void free_rr(rr_t** _r)
+{
+	do_free_rr(_r, 0);
+}
+
+
+/*
+ * Free list of rrs
+ * _r is head of the list
+ */
+
+void shm_free_rr(rr_t** _r)
+{
+	do_free_rr(_r, 1);
+}
+
+
 /*
  * Print list of RRs, just for debugging
  */
@@ -198,7 +222,7 @@ static inline void xlate_pointers(struct sip_msg* _m, rr_t* _r)
 /*
  * Duplicate a single rr_t structure using pkg_malloc
  */
-int duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r)
+static inline int do_duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r, int _shm)
 {
 	int len;
 	rr_t* res;
@@ -214,7 +238,8 @@ int duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r)
 		len = _r->nameaddr.len;
 	}
 
-	res = pkg_malloc(sizeof(rr_t) + len);
+	if (_shm) res = shm_malloc(sizeof(rr_t) + len);
+	else res = pkg_malloc(sizeof(rr_t) + len);
 	if (!res) {
 		LOG(L_ERR, "duplicate_rr(): No memory left\n");
 		return -2;
@@ -225,7 +250,8 @@ int duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r)
 
 	if (duplicate_params(&res->params, _r->params) < 0) {
 		LOG(L_ERR, "Error while duplicating parameters\n");
-		pkg_free(res);
+		if (_shm) shm_free(res);
+		else pkg_free(res);
 		return -3;
 	}
 
@@ -233,3 +259,21 @@ int duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r)
 	*_new = res;
 	return 0;
 }
+
+
+/*
+ * Duplicate a single rr_t structure using pkg_malloc
+ */
+int duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r)
+{
+	return do_duplicate_rr(_m, _new, _r, 0);
+}
+
+
+/*
+ * Duplicate a single rr_t structure using pkg_malloc
+ */
+int shm_duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r)
+{
+	return do_duplicate_rr(_m, _new, _r, 1);
+}

+ 13 - 0
parser/parse_rr.h

@@ -62,6 +62,13 @@ int parse_rr(struct hdr_field* _r);
 void free_rr(rr_t** _r);
 
 
+/*
+ * Free list of rr
+ * _c is head of the list
+ */
+void shm_free_rr(rr_t** _r);
+
+
 /*
  * Print list of rrs, just for debugging
  */
@@ -74,4 +81,10 @@ void print_rr(rr_t* _r);
 int duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r);
 
 
+/*
+ * Duplicate a single rr_t structure using pkg_malloc
+ */
+int shm_duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r);
+
+
 #endif /* PARSE_RR_H */