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 39
 #include "data_lump_rpl.h"
34 40
 
35 41
 
36
-struct lump_rpl* build_lump_rpl( char* text, int len , int type)
42
+
43
+struct lump_rpl* add_lump_rpl(struct sip_msg *msg, char *s, int len, int flags)
37 44
 {
38 45
 	struct lump_rpl *lump = 0;
46
+	struct lump_rpl *foo;
39 47
 
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");
48
+	/* some checkings */
49
+	if ( (flags&(LUMP_RPL_HDR|LUMP_RPL_BODY))==(LUMP_RPL_HDR|LUMP_RPL_BODY)
50
+	|| (flags&(LUMP_RPL_HDR|LUMP_RPL_BODY))==0) {
51
+		LOG(L_ERR,"ERROR:add_lump_rpl: bad type flags (none or both)!\n");
52
+		goto error;
53
+	}
54
+	if (len<=0 || s==0) {
55
+		LOG(L_ERR,"ERROR:add_lump_rpl: I won't add an empty lump!\n");
44 56
 		goto error;
45 57
 	}
46 58
 
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 );
59
+	/* build the lump */
60
+	lump = (struct lump_rpl*) pkg_malloc
61
+		( sizeof(struct lump_rpl) + ((flags&LUMP_RPL_NODUP)?0:len) );
62
+	if (!lump) {
63
+		LOG(L_ERR,"ERROR:add_lump_rpl : no free pkg memory !\n");
51 64
 		goto error;
52 65
 	}
53 66
 
54
-	memcpy(lump->text.s,text,len);
67
+	if (flags&LUMP_RPL_NODUP) {
68
+		lump->text.s = s;
69
+	} else {
70
+		lump->text.s = ((char*)lump)+sizeof(struct lump_rpl);
71
+		memcpy( lump->text.s, s, len);
72
+	}
55 73
 	lump->text.len = len;
56
-	lump->type = type;
74
+	lump->flags = flags;
57 75
 	lump->next = 0;
58 76
 
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
-	{
77
+	/* add the lump to the msg */
78
+	if (!msg->reply_lump) {
79 79
 		msg->reply_lump = lump;
80 80
 	}else{
81
-		if (lump->type!=LUMP_RPL_BODY)
81
+		if (!(flags&LUMP_RPL_BODY))
82 82
 			for(foo=msg->reply_lump;foo->next;foo=foo->next);
83 83
 		else
84 84
 			for(foo=msg->reply_lump;foo->next;foo=foo->next)
85
-				if (lump->type==LUMP_RPL_BODY) {
85
+				if (lump->flags&LUMP_RPL_BODY) {
86 86
 					LOG(L_ERR,"ERROR:add_lump_rpl: LUMP_RPL_BODY "
87 87
 						"already added!\n");
88
-					return -1;
88
+					pkg_free(lump);
89
+					goto error;
89 90
 				}
90 91
 		foo->next = lump;
91 92
 	}
93
+
94
+	return lump;
95
+error:
92 96
 	return 0;
93 97
 }
94 98
 
... ...
@@ -96,8 +100,12 @@ int add_lump_rpl(struct sip_msg * msg, struct lump_rpl* lump)
96 100
 
97 101
 void free_lump_rpl(struct lump_rpl* lump)
98 102
 {
99
-	if (lump && lump->text.s)  pkg_free(lump->text.s);
100
-	if (lump) pkg_free(lump);
103
+	if (lump) {
104
+		if (!((lump->flags)&LUMP_RPL_NOFREE) && ((lump->flags)&LUMP_RPL_NODUP)
105
+		&& lump->text.s)
106
+			pkg_free(lump->text.s);
107
+		pkg_free(lump);
108
+	}
101 109
 }
102 110
 
103 111
 
... ...
@@ -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 40
 #include "parser/msg_parser.h"
34 41
 
35 42
 
36
-#define LUMP_RPL_HDR   1
37
-#define LUMP_RPL_BODY  2
43
+#define LUMP_RPL_HDR     (1<<1)
44
+#define LUMP_RPL_BODY    (1<<2)
45
+#define LUMP_RPL_NODUP   (1<<3)
46
+#define LUMP_RPL_NOFREE  (1<<4)
38 47
 
39 48
 struct lump_rpl
40 49
 {
41 50
 	str text;
42
-	int type;
51
+	int flags;
43 52
 	struct lump_rpl* next;
44 53
 };
45 54
 
46
-struct lump_rpl* build_lump_rpl( char* , int , int );
47
-
48
-int add_lump_rpl(struct sip_msg * , struct lump_rpl* );
55
+struct lump_rpl* add_lump_rpl(struct sip_msg *, char *, int , int );
49 56
 
50 57
 void free_lump_rpl(struct lump_rpl* );
51 58
 
... ...
@@ -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 1668
 	/* lumps length */
1668 1669
 	for(lump=msg->reply_lump;lump;lump=lump->next) {
1669 1670
 		len += lump->text.len;
1670
-		if (lump->type==LUMP_RPL_BODY)
1671
+		if (lump->flags&LUMP_RPL_BODY)
1671 1672
 			body = lump;
1672 1673
 	}
1673 1674
 	/* server header */
... ...
@@ -1795,7 +1796,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text ,str *new_tag,
1795 1796
 	} /* end for */
1796 1797
 	/* lumps */
1797 1798
 	for(lump=msg->reply_lump;lump;lump=lump->next)
1798
-		if (lump->type==LUMP_RPL_HDR){
1799
+		if (lump->flags&LUMP_RPL_HDR){
1799 1800
 			memcpy(p,lump->text.s,lump->text.len);
1800 1801
 			p += lump->text.len;
1801 1802
 		}