Browse code

data_lump_rpk changes: - build_lump_rpl merged into add_lump_rpl - type parameter -> flags - added LUMP_RPL_NODUP and LUMP_RPL_NOFREE flags when adding lump_rpl

Bogdan-Andrei Iancu authored on 11/11/2003 19:34:34
Showing 3 changed files
... ...
@@ -24,6 +24,12 @@
24 24
  * You should have received a copy of the GNU General Public License 
25 25
  * along with this program; if not, write to the Free Software 
26 26
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27
+ *
28
+ * History:
29
+ * 2002-02-14 : created by bogdan
30
+ * 2003-09-11 : lump_rpl type added - LUMP_RPL_BODY & LUMP_RPL_HDR (bogdan)
31
+ * 2003-11-11 : build_lump_rpl merged into add_lump_rpl; types -> flags ;
32
+ *              flags LUMP_RPL_NODUP and LUMP_RPL_NOFREE added (bogdan)
27 33
  */
28 34
 
29 35
 
... ...
@@ -33,62 +39,60 @@
33 33
 #include "data_lump_rpl.h"
34 34
 
35 35
 
36
-struct lump_rpl* build_lump_rpl( char* text, int len , int type)
36
+
37
+struct lump_rpl* add_lump_rpl(struct sip_msg *msg, char *s, int len, int flags)
37 38
 {
38 39
 	struct lump_rpl *lump = 0;
40
+	struct lump_rpl *foo;
39 41
 
40
-	lump = (struct lump_rpl*) pkg_malloc(sizeof(struct lump_rpl));
41
-	if (!lump)
42
-	{
43
-		LOG(L_ERR,"ERROR:build_lump_rpl : no free memory (struct)!\n");
42
+	/* some checkings */
43
+	if ( (flags&(LUMP_RPL_HDR|LUMP_RPL_BODY))==(LUMP_RPL_HDR|LUMP_RPL_BODY)
44
+	|| (flags&(LUMP_RPL_HDR|LUMP_RPL_BODY))==0) {
45
+		LOG(L_ERR,"ERROR:add_lump_rpl: bad type flags (none or both)!\n");
46
+		goto error;
47
+	}
48
+	if (len<=0 || s==0) {
49
+		LOG(L_ERR,"ERROR:add_lump_rpl: I won't add an empty lump!\n");
44 50
 		goto error;
45 51
 	}
46 52
 
47
-	lump->text.s = pkg_malloc( len );
48
-	if (!lump->text.s)
49
-	{
50
-		LOG(L_ERR,"ERROR:build_lump_rpl : no free memory (%d)!\n", len );
53
+	/* build the lump */
54
+	lump = (struct lump_rpl*) pkg_malloc
55
+		( sizeof(struct lump_rpl) + ((flags&LUMP_RPL_NODUP)?0:len) );
56
+	if (!lump) {
57
+		LOG(L_ERR,"ERROR:add_lump_rpl : no free pkg memory !\n");
51 58
 		goto error;
52 59
 	}
53 60
 
54
-	memcpy(lump->text.s,text,len);
61
+	if (flags&LUMP_RPL_NODUP) {
62
+		lump->text.s = s;
63
+	} else {
64
+		lump->text.s = ((char*)lump)+sizeof(struct lump_rpl);
65
+		memcpy( lump->text.s, s, len);
66
+	}
55 67
 	lump->text.len = len;
56
-	lump->type = type;
68
+	lump->flags = flags;
57 69
 	lump->next = 0;
58 70
 
59
-	return lump;
60
-
61
-error:
62
-	if (lump) pkg_free(lump);
63
-	return 0;
64
-}
65
-
66
-
67
-
68
-int add_lump_rpl(struct sip_msg * msg, struct lump_rpl* lump)
69
-{
70
-	struct lump_rpl *foo;
71
-
72
-	if (lump==0 || lump->text.s==0 || lump->text.len==0) {
73
-		LOG(L_ERR,"ERROR:add_lump_rpl: I won't add an empty lump!\n");
74
-		return -1;
75
-	}
76
-
77
-	if (!msg->reply_lump)
78
-	{
71
+	/* add the lump to the msg */
72
+	if (!msg->reply_lump) {
79 73
 		msg->reply_lump = lump;
80 74
 	}else{
81
-		if (lump->type!=LUMP_RPL_BODY)
75
+		if (!(flags&LUMP_RPL_BODY))
82 76
 			for(foo=msg->reply_lump;foo->next;foo=foo->next);
83 77
 		else
84 78
 			for(foo=msg->reply_lump;foo->next;foo=foo->next)
85
-				if (lump->type==LUMP_RPL_BODY) {
79
+				if (lump->flags&LUMP_RPL_BODY) {
86 80
 					LOG(L_ERR,"ERROR:add_lump_rpl: LUMP_RPL_BODY "
87 81
 						"already added!\n");
88
-					return -1;
82
+					pkg_free(lump);
83
+					goto error;
89 84
 				}
90 85
 		foo->next = lump;
91 86
 	}
87
+
88
+	return lump;
89
+error:
92 90
 	return 0;
93 91
 }
94 92
 
... ...
@@ -96,8 +100,12 @@ int add_lump_rpl(struct sip_msg * msg, struct lump_rpl* lump)
96 96
 
97 97
 void free_lump_rpl(struct lump_rpl* lump)
98 98
 {
99
-	if (lump && lump->text.s)  pkg_free(lump->text.s);
100
-	if (lump) pkg_free(lump);
99
+	if (lump) {
100
+		if (!((lump->flags)&LUMP_RPL_NOFREE) && ((lump->flags)&LUMP_RPL_NODUP)
101
+		&& lump->text.s)
102
+			pkg_free(lump->text.s);
103
+		pkg_free(lump);
104
+	}
101 105
 }
102 106
 
103 107
 
... ...
@@ -24,6 +24,13 @@
24 24
  * You should have received a copy of the GNU General Public License 
25 25
  * along with this program; if not, write to the Free Software 
26 26
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27
+ *
28
+ * History:
29
+ * 2002-02-14 : created by bogdan
30
+ * 2003-09-11 : lump_rpl type added - LUMP_RPL_BODY & LUMP_RPL_HDR (bogdan)
31
+ * 2003-11-11 : build_lump_rpl merged into add_lump_rpl; type removed;
32
+ *              flags LUMP_RPL_BODY, LUMP_RPL_NODUP and LUMP_RPL_NOFREE
33
+ *              added (bogdan)
27 34
  */
28 35
 
29 36
 
... ...
@@ -33,19 +40,19 @@
33 33
 #include "parser/msg_parser.h"
34 34
 
35 35
 
36
-#define LUMP_RPL_HDR   1
37
-#define LUMP_RPL_BODY  2
36
+#define LUMP_RPL_HDR     (1<<1)
37
+#define LUMP_RPL_BODY    (1<<2)
38
+#define LUMP_RPL_NODUP   (1<<3)
39
+#define LUMP_RPL_NOFREE  (1<<4)
38 40
 
39 41
 struct lump_rpl
40 42
 {
41 43
 	str text;
42
-	int type;
44
+	int flags;
43 45
 	struct lump_rpl* next;
44 46
 };
45 47
 
46
-struct lump_rpl* build_lump_rpl( char* , int , int );
47
-
48
-int add_lump_rpl(struct sip_msg * , struct lump_rpl* );
48
+struct lump_rpl* add_lump_rpl(struct sip_msg *, char *, int , int );
49 49
 
50 50
 void free_lump_rpl(struct lump_rpl* );
51 51
 
... ...
@@ -55,6 +55,7 @@
55 55
  * 2003-10-02  via+lump dst address/port can be set to preset values (andrei)
56 56
  * 2003-10-08  receive_test function-alized (jiri)
57 57
  * 2003-10-20  added body_lump list (sip_msg), adjust_clen (andrei & jan)
58
+ * 2003-11-11  type of rpl_lumps replaced by flags (bogdan)
58 59
  *
59 60
  */
60 61
 /* Via special params:
... ...
@@ -1667,7 +1668,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text ,str *new_tag,
1667 1667
 	/* lumps length */
1668 1668
 	for(lump=msg->reply_lump;lump;lump=lump->next) {
1669 1669
 		len += lump->text.len;
1670
-		if (lump->type==LUMP_RPL_BODY)
1670
+		if (lump->flags&LUMP_RPL_BODY)
1671 1671
 			body = lump;
1672 1672
 	}
1673 1673
 	/* server header */
... ...
@@ -1795,7 +1796,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text ,str *new_tag,
1795 1795
 	} /* end for */
1796 1796
 	/* lumps */
1797 1797
 	for(lump=msg->reply_lump;lump;lump=lump->next)
1798
-		if (lump->type==LUMP_RPL_HDR){
1798
+		if (lump->flags&LUMP_RPL_HDR){
1799 1799
 			memcpy(p,lump->text.s,lump->text.len);
1800 1800
 			p += lump->text.len;
1801 1801
 		}