Browse code

- updated to new build_lump_rpl() function interface - updated to new build_res_buf_from_sip_req() function interface - t_reply_with_body() reshaped to use reply_lumps + build_res_buf_from_sip_req() instead of build_res_buf_with_body_from_sip_req()

Bogdan-Andrei Iancu authored on 11/09/2003 19:48:29
Showing 1 changed files
... ...
@@ -45,6 +45,10 @@
45 45
  *  2003-04-14  local acks generated before reply processing to avoid
46 46
  *              delays in length reply processing (like opening TCP
47 47
  *              connection to an unavailable destination) (jiri)
48
+ *  2003-09-11  updates to new build_res_buf_from_sip_req() interface (bogdan)
49
+ *  2003-09-11  t_reply_with_body() reshaped to use reply_lumps +
50
+ *              build_res_buf_from_sip_req() instead of
51
+ *              build_res_buf_with_body_from_sip_req() (bogdan)
48 52
  */
49 53
 
50 54
 
... ...
@@ -66,6 +70,7 @@
66 70
 #include "../../dset.h"
67 71
 #include "../../tags.h"
68 72
 #include "../../data_lump.h"
73
+#include "../../data_lump_rpl.h"
69 74
 
70 75
 #include "t_hooks.h"
71 76
 #include "t_funcs.h"
... ...
@@ -83,6 +88,9 @@ enum route_mode rmode=MODE_REQUEST;
83 88
 /* private place where we create to-tags for replies */
84 89
 /* janakj: made public, I need to access this value to store it in dialogs */
85 90
 char tm_tags[TOTAG_VALUE_LEN];
91
+/* bogdan: pack tm_tag buffer and len into a str to pass them to
92
+ * build_res_buf_from_sip_req() */
93
+static str  tm_tag = {tm_tags,TOTAG_VALUE_LEN};
86 94
 char *tm_tag_suffix;
87 95
 
88 96
 /* where to go if there is no positive reply */
... ...
@@ -356,20 +364,15 @@ static int _reply( struct cell *trans, struct sip_msg* p_msg,
356 364
 				&& (get_to(p_msg)->tag_value.s==0 
357 365
 			    || get_to(p_msg)->tag_value.len==0)) {
358 366
 		calc_crc_suffix( p_msg, tm_tag_suffix );
359
-		buf = build_res_buf_from_sip_req(code,text, 
360
-				tm_tags, TOTAG_VALUE_LEN, 
361
-				p_msg,&len, &bm);
362
-
363
-		return _reply_light(trans,buf,len,code,text,
364
-				    tm_tags, TOTAG_VALUE_LEN,
365
-				    lock, &bm);
367
+		buf = build_res_buf_from_sip_req(code,text, &tm_tag, p_msg, &len, &bm);
368
+		return _reply_light( trans, buf, len, code, text,
369
+			tm_tag.s, TOTAG_VALUE_LEN, lock, &bm);
366 370
 	} else {
367
-		buf = build_res_buf_from_sip_req(code,text, 0,0, /* no to-tag */
368
-			p_msg,&len, &bm);
371
+		buf = build_res_buf_from_sip_req(code,text, 0 /*no to-tag*/,
372
+			p_msg, &len, &bm);
369 373
 
370 374
 		return _reply_light(trans,buf,len,code,text,
371
-				    0,0, /* no to-tag */
372
-				    lock, &bm);
375
+			0, 0, /* no to-tag */lock, &bm);
373 376
 	}
374 377
 }
375 378
 
... ...
@@ -867,11 +870,11 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch,
867 870
 				buf = build_res_buf_from_sip_req(
868 871
 						relayed_code,
869 872
 						error_text(relayed_code),
870
-						tm_tags, TOTAG_VALUE_LEN, 
873
+						&tm_tag,
871 874
 						t->uas.request, &res_len, &bm );
872 875
 			} else {
873 876
 				buf = build_res_buf_from_sip_req( relayed_code,
874
-					error_text(relayed_code), 0,0, /* no to-tag */
877
+					error_text(relayed_code), 0/* no to-tag */,
875 878
 					t->uas.request, &res_len, &bm );
876 879
 			}
877 880
 
... ...
@@ -1159,42 +1162,71 @@ done:
1159 1162
 int t_reply_with_body( struct cell *trans, unsigned int code, 
1160 1163
 		char * text, char * body, char * new_header, char * to_tag )
1161 1164
 {
1162
-
1163
-    str  s_to_tag,sb,snh;
1164
-    char* res_buf;
1165
-    unsigned int res_len;
1166
-	int ret;
1165
+	struct lump_rpl *hdr_lump;
1166
+	struct lump_rpl *body_lump;
1167
+	str  s_to_tag;
1168
+	str  rpl;
1169
+	int  ret;
1167 1170
 	struct bookmark bm;
1168 1171
 
1169
-    s_to_tag.s = to_tag;
1170
-    if(to_tag)
1172
+	s_to_tag.s = to_tag;
1173
+	if(to_tag)
1171 1174
 		s_to_tag.len = strlen(to_tag);
1172 1175
 
1173
-    /* mark the transaction as replied */
1174
-    if (code>=200) set_kr(REQ_RPLD);
1175
-
1176
-    /* compute the response */
1177
-    sb.s = body;
1178
-    sb.len = strlen(body);
1179
-    snh.s = new_header;
1180
-    snh.len = strlen(new_header);
1181
-
1182
-    res_buf = build_res_buf_with_body_from_sip_req(
1183
-					code,text, s_to_tag.s, s_to_tag.len,
1184
-		   			sb.s,sb.len,
1185
-					snh.s,snh.len,
1186
-					trans->uas.request,&res_len, &bm);
1187
-    
1188
-    DBG("t_reply_with_body: buffer computed\n");
1189
-    // frees 'res_buf' ... no panic !
1190
-    ret=_reply_light( trans, res_buf, res_len, code, text, 
1176
+	/* mark the transaction as replied */
1177
+	if (code>=200) set_kr(REQ_RPLD);
1178
+
1179
+	/* build the lumps for new_header and for body (by bogdan) */
1180
+	hdr_lump = build_lump_rpl( new_header , strlen(new_header) , LUMP_RPL_HDR );
1181
+	if (hdr_lump==0) {
1182
+		LOG(L_ERR,"ERROR:tm:t_reply_with_body: cannot create hdr lump\n");
1183
+		goto error;
1184
+	}
1185
+	add_lump_rpl( trans->uas.request, hdr_lump);
1186
+	/* body lump */
1187
+	body_lump = build_lump_rpl( body , strlen(body) , LUMP_RPL_BODY );
1188
+	if (body_lump==0) {
1189
+		LOG(L_ERR,"ERROR:tm:t_reply_with_body: cannot create body lump\n");
1190
+		goto error_1;
1191
+	}
1192
+	if (add_lump_rpl( trans->uas.request, body_lump)==-1) {
1193
+		LOG(L_ERR,"ERROR:tm:t_reply_with_body: cannot add body lump\n");
1194
+		goto error_1;
1195
+	}
1196
+
1197
+	rpl.s = build_res_buf_from_sip_req(
1198
+			code, text, &s_to_tag,
1199
+			trans->uas.request, &rpl.len, &bm);
1200
+
1201
+	/* since the msg (trans->uas.request) is a clone into shm memory, to avoid
1202
+	 * memory leak or crashing (lumps are create in private memory) I will
1203
+	 * remove the lumps by myself here (bogdan) */
1204
+	unlink_lump_rpl( trans->uas.request, hdr_lump);
1205
+	unlink_lump_rpl( trans->uas.request, body_lump);
1206
+	pkg_free( hdr_lump );
1207
+	pkg_free( body_lump );
1208
+
1209
+	if (rpl.s==0) {
1210
+		LOG(L_ERR,"ERROR:tm:t_reply_with_body: failed in doing "
1211
+			"build_res_buf_from_sip_req()\n");
1212
+		goto error;
1213
+	}
1214
+
1215
+	DBG("t_reply_with_body: buffer computed\n");
1216
+	// frees 'res.s' ... no panic !
1217
+	ret=_reply_light( trans, rpl.s, rpl.len, code, text, 
1191 1218
 		s_to_tag.s, s_to_tag.len, 1 /* lock replies */, &bm );
1192 1219
 	/* this is ugly hack -- the function caller may wish to continue with
1193 1220
 	 * transction and I unref; however, there is now only one use from
1194 1221
 	 * vm/fifo_vm_reply and I'm currently to lazy to export UNREF; -jiri
1195 1222
 	 */
1196 1223
 	UNREF(trans);
1197
-	return ret;
1198 1224
 
1225
+	return ret;
1226
+error_1:
1227
+	unlink_lump_rpl( trans->uas.request, hdr_lump);
1228
+	pkg_free( hdr_lump );
1229
+error:
1230
+	return -1;
1199 1231
 }
1200 1232