Browse code

parser: refactored a bit sip_msg_t struct for extra fields needed per process

- a new structure to keep cached decoded flow for outbound, previously
was declared inline
- easier to reset it for shm clone and tm faked environment
- new fields that are needed inside the sip_msg_t but not cloned in shm,
must be added in the msg_ldata_t structure, accessible via ldv field

Daniel-Constantin Mierla authored on 19/09/2013 13:45:43
Showing 2 changed files
... ...
@@ -734,6 +734,7 @@ void free_sip_msg(struct sip_msg* const msg)
734 734
 	if (msg->add_rm)      free_lump_list(msg->add_rm);
735 735
 	if (msg->body_lumps)  free_lump_list(msg->body_lumps);
736 736
 	if (msg->reply_lump)   free_reply_lump(msg->reply_lump);
737
+	msg_ldata_reset(msg);
737 738
 	/* don't free anymore -- now a pointer to a static buffer */
738 739
 #	ifdef DYN_BUF
739 740
 	pkg_free(msg->buf);
... ...
@@ -952,6 +953,16 @@ void reset_ua(struct sip_msg* const msg)
952 952
 	msg->location_ua.len = 0;
953 953
 }
954 954
 
955
+/**
956
+ * reset content of msg->ldv (msg_ldata_t structure)
957
+ */
958
+void msg_ldata_reset(sip_msg_t *msg)
959
+{
960
+	if(msg==NULL)
961
+		return;
962
+	memset(&msg->ldv, 0, sizeof(msg_ldata_t));
963
+}
964
+
955 965
 
956 966
 hdr_field_t* get_hdr(const sip_msg_t* const msg, const enum _hdr_types_t ht)
957 967
 {
... ...
@@ -253,6 +253,19 @@ typedef struct msg_body {
253 253
 /* pre-declaration, to include sys/time.h in .c */
254 254
 struct timeval;
255 255
 
256
+/* structure for cached decoded flow for outbound */
257
+typedef struct ocd_flow {
258
+		int decoded;
259
+		struct receive_info rcv;
260
+} ocd_flow_t;
261
+
262
+/* structure holding fields that don't have to be cloned in shm
263
+ * - its content is memset'ed to in shm clone
264
+ * - add to msg_ldata_reset() if a field uses dynamic memory */
265
+typedef struct msg_ldata {
266
+	ocd_flow_t flow;
267
+} msg_ldata_t;
268
+
256 269
 /*! \brief The SIP message */
257 270
 typedef struct sip_msg {
258 271
 	unsigned int id;               /*!< message id, unique/process*/
... ...
@@ -363,10 +376,9 @@ typedef struct sip_msg {
363 363
 	str ruid;
364 364
 	str location_ua;
365 365
 
366
-	struct {
367
-		int decoded;
368
-		struct receive_info rcv;
369
-	} flow;
366
+	/* structure with fields that are needed for local processing
367
+	 * - not cloned to shm, reset to 0 in the clone */
368
+	msg_ldata_t ldv;
370 369
 
371 370
 	/* IMPORTANT: when adding new fields in this structure (sip_msg_t),
372 371
 	 * be sure it is freed in free_sip_msg() and it is cloned or reset
... ...
@@ -514,4 +526,9 @@ int msg_ctx_id_match(const sip_msg_t* const msg, const msg_ctx_id_t* const mid);
514 514
  */
515 515
 int msg_set_time(sip_msg_t* const msg);
516 516
 
517
+/**
518
+ * reset content of msg->ldv (msg_ldata_t structure)
519
+ */
520
+void msg_ldata_reset(sip_msg_t*);
521
+
517 522
 #endif