Browse code

core: added ruid to msg and branch structures

Peter Dunkley authored on 14/03/2013 22:42:16
Showing 5 changed files
... ...
@@ -75,6 +75,8 @@
75 75
 
76 76
 #define MAX_INSTANCE_SIZE 256 		/*!< Maximum length of +sip.instance contact header param value buffer */
77 77
 
78
+#define MAX_RUID_SIZE 65		/*!< Maximum length of ruid for location records */
79
+
78 80
 #define MY_VIA "Via: SIP/2.0/UDP "
79 81
 #define MY_VIA_LEN (sizeof(MY_VIA) - 1)
80 82
 
... ...
@@ -297,7 +297,8 @@ void clear_branches(void)
297 297
 int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path,
298 298
 		  qvalue_t q, unsigned int flags,
299 299
 		  struct socket_info* force_socket,
300
-		  str* instance, unsigned int reg_id)
300
+		  str* instance, unsigned int reg_id,
301
+		  str* ruid)
301 302
 {
302 303
 	str luri;
303 304
 
... ...
@@ -381,6 +382,22 @@ int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path,
381 381
 	/* copy reg_id */
382 382
 	branches[nr_branches].reg_id = reg_id;
383 383
 
384
+	/* copy ruid string */
385
+	if (unlikely(ruid && ruid->len && ruid->s)) {
386
+		if (unlikely(ruid->len > MAX_RUID_SIZE - 1)) {
387
+			LOG(L_ERR, "too long ruid: %.*s\n",
388
+			    ruid->len, ruid->s);
389
+			return -1;
390
+		}
391
+		memcpy(branches[nr_branches].ruid, ruid->s,
392
+		       ruid->len);
393
+		branches[nr_branches].ruid[ruid->len] = 0;
394
+		branches[nr_branches].ruid_len = ruid->len;
395
+	} else {
396
+		branches[nr_branches].ruid[0] = '\0';
397
+		branches[nr_branches].ruid_len = 0;
398
+	}
399
+
384 400
 	nr_branches++;
385 401
 	return 1;
386 402
 }
... ...
@@ -66,6 +66,10 @@ struct branch
66 66
     /* reg-id contact header param value */
67 67
     unsigned int reg_id;
68 68
 
69
+    /* ruid value from usrloc */
70
+    char ruid[MAX_RUID_SIZE];
71
+    unsigned int ruid_len;
72
+
69 73
     /* Branch flags */
70 74
     flag_t flags;
71 75
 };
... ...
@@ -88,11 +92,12 @@ int drop_sip_branch(int idx);
88 88
 int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path,
89 89
 		  qvalue_t q, unsigned int flags,
90 90
 		  struct socket_info* force_socket,
91
-		  str* instance, unsigned int reg_id);
91
+		  str* instance, unsigned int reg_id,
92
+		  str* ruid);
92 93
 
93 94
 /*! \brief kamailio compatible version */
94 95
 #define km_append_branch(msg, uri, dst_uri, path, q, flags, force_socket) \
95
-    append_branch(msg, uri, dst_uri, path, q, flags, force_socket, 0, 0)
96
+    append_branch(msg, uri, dst_uri, path, q, flags, force_socket, 0, 0, 0)
96 97
 
97 98
 /*! \brief ser compatible append_branch version.
98 99
  *  append_branch version compatible with ser: no path or branch flags support
... ...
@@ -109,7 +114,7 @@ static inline int ser_append_branch(struct sip_msg* msg,
109 109
     s_uri.len=uri_len;
110 110
     s_dst_uri.s=dst_uri;
111 111
     s_dst_uri.len=dst_uri_len;
112
-    return append_branch(msg, &s_uri, &s_dst_uri, 0, q, 0, force_socket, 0, 0);
112
+    return append_branch(msg, &s_uri, &s_dst_uri, 0, q, 0, force_socket, 0, 0, 0);
113 113
 }
114 114
 
115 115
 
... ...
@@ -859,6 +859,45 @@ void reset_instance(struct sip_msg* const msg)
859 859
 }
860 860
 
861 861
 
862
+int set_ruid(struct sip_msg* msg, str* ruid)
863
+{
864
+	char* ptr;
865
+
866
+	if (unlikely(!msg || !ruid)) {
867
+		LM_ERR("invalid ruid parameter value\n");
868
+		return -1;
869
+	}
870
+
871
+	if (unlikely(ruid->len == 0)) {
872
+		reset_ruid(msg);
873
+	} else if (msg->ruid.s && (msg->ruid.len >= ruid->len)) {
874
+		memcpy(msg->ruid.s, ruid->s, ruid->len);
875
+		msg->ruid.len = ruid->len;
876
+	} else {
877
+		ptr = (char*)pkg_malloc(ruid->len);
878
+		if (!ptr) {
879
+			LM_ERR("not enough pkg memory for ruid\n");
880
+			return -1;
881
+		}
882
+		memcpy(ptr, ruid->s, ruid->len);
883
+		if (msg->ruid.s) pkg_free(msg->ruid.s);
884
+		msg->ruid.s = ptr;
885
+		msg->ruid.len = ruid->len;
886
+	}
887
+	return 0;
888
+}
889
+
890
+
891
+void reset_ruid(struct sip_msg* const msg)
892
+{
893
+	if(msg->ruid.s != 0) {
894
+		pkg_free(msg->ruid.s);
895
+	}
896
+	msg->ruid.s = 0;
897
+	msg->ruid.len = 0;
898
+}
899
+
900
+
862 901
 hdr_field_t* get_hdr(const sip_msg_t* const msg, const enum _hdr_types_t ht)
863 902
 {
864 903
 	hdr_field_t *hdr;
... ...
@@ -365,6 +365,7 @@ typedef struct sip_msg {
365 365
 	str path_vec;
366 366
         str instance;
367 367
         unsigned int reg_id;
368
+	str ruid;
368 369
 } sip_msg_t;
369 370
 
370 371
 /*! \brief pointer to a fakes message which was never received ;
... ...
@@ -453,6 +454,10 @@ int set_instance(struct sip_msg* msg, str* instance);
453 453
 
454 454
 void reset_instance(struct sip_msg* const msg);
455 455
 
456
+int set_ruid(struct sip_msg* msg, str* ruid);
457
+
458
+void reset_ruid(struct sip_msg* const msg);
459
+
456 460
 /** force a specific send socket for forwarding a request.
457 461
  * @param msg - sip msg.
458 462
  * @param fsocket - forced socket, pointer to struct socket_info, can be 0 (in