Browse code

- the macro XJ_ADJUST_SIPADDR is replaced with fuction 'xj_extract_aor'

Daniel-Constantin Mierla authored on 05/06/2003 17:13:26
Showing 3 changed files
... ...
@@ -408,12 +408,11 @@ static int xj_go_offline(struct sip_msg *msg, char* foo1, char * foo2)
408 408
  */
409 409
 int xjab_manage_sipmsg(struct sip_msg *msg, int type)
410 410
 {
411
-	str body, dst;
411
+	str body, dst, from_uri;
412 412
 	xj_sipmsg jsmsg;
413
-	struct to_body to, *from;
413
+	struct to_body to;
414 414
 	struct sip_uri _uri;
415 415
 	int pipe, fl;
416
-	char   *pc=0;
417 416
 	t_xj_jkey jkey, *p;
418 417
 
419 418
 	// extract message body - after that whole SIP MESSAGE is parsed
... ...
@@ -463,15 +462,21 @@ int xjab_manage_sipmsg(struct sip_msg *msg, int type)
463 462
 	}
464 463
 	
465 464
 	/* parsing from header */
466
-	if ( parse_from_header( msg )==-1 ) 
465
+	if ( parse_from_header( msg )==-1 || msg->from->parsed==NULL) 
467 466
 	{
468 467
 		DBG("ERROR:xjab_manage_sipmsg: cannot get FROM header\n");
469 468
 		goto error;
470 469
 	}
471
-	from = (struct to_body*)msg->from->parsed;
470
+	from_uri.s = ((struct to_body*)msg->from->parsed)->uri.s;
471
+	from_uri.len = ((struct to_body*)msg->from->parsed)->uri.len;
472
+	if(xj_extract_aor(&from_uri, 0))
473
+	{
474
+		DBG("ERROR:xjab_manage_sipmsg: cannot get AoR from FROM header\n");
475
+		goto error;
476
+	}
472 477
 
473
-	jkey.hash = xj_get_hash(&from->uri, NULL);
474
-	jkey.id = &from->uri;
478
+	jkey.hash = xj_get_hash(&from_uri, NULL);
479
+	jkey.id = &from_uri;
475 480
 	// get the communication pipe with the worker
476 481
 	switch(type)
477 482
 	{
... ...
@@ -489,7 +494,7 @@ int xjab_manage_sipmsg(struct sip_msg *msg, int type)
489 494
 			if((pipe = xj_wlist_check(jwl, &jkey, &p)) < 0)
490 495
 			{
491 496
 				DBG("XJAB:xjab_manage_sipmsg: no open Jabber session for"
492
-						" <%.*s>!\n", from->uri.len, from->uri.s);
497
+						" <%.*s>!\n", from_uri.len, from_uri.s);
493 498
 				goto error;
494 499
 			}
495 500
 		break;
... ...
@@ -595,7 +600,11 @@ int xjab_manage_sipmsg(struct sip_msg *msg, int type)
595 600
 	}
596 601
 	
597 602
 	/** skip 'sip:' and parameters in destination address */
598
-	_XJ_ADJUST_SIPADDR(dst.s,dst.len,pc, fl);
603
+	if(xj_extract_aor(&dst, 1))
604
+	{
605
+		DBG("ERROR:xjab_manage_sipmsg: cannot get AoR for destination\n");
606
+		goto error;
607
+	}
599 608
 #ifdef XJ_EXTRA_DEBUG
600 609
 	DBG("XJAB:xjab_manage_sipmsg: DESTINATION after correction [%.*s].\n",
601 610
 				dst.len, dst.s);
... ...
@@ -715,8 +724,9 @@ void xj_register_watcher(str *from, str *to, void *cbf, void *pp)
715 724
 {
716 725
 	xj_sipmsg jsmsg = NULL;
717 726
 	t_xj_jkey jkey, *jp;
718
-	int pipe, fl, f;
719
-	char *p, *p0;
727
+	int pipe, fl;
728
+	str from_uri, to_uri;
729
+
720 730
 	if(!to || !from || !cbf)
721 731
 		return;
722 732
 
... ...
@@ -724,8 +734,16 @@ void xj_register_watcher(str *from, str *to, void *cbf, void *pp)
724 734
 	DBG("XJAB:xj_register_watcher: from=[%.*s] to=[%.*s]\n", from->len,
725 735
 			from->s, to->len, to->s);
726 736
 #endif
727
-	jkey.hash = xj_get_hash(from, NULL);
728
-	jkey.id = from;
737
+	from_uri.s = from->s;
738
+	from_uri.len = from->len;
739
+	if(xj_extract_aor(&from_uri, 0))
740
+	{
741
+		DBG("ERROR:xjab_manage_sipmsg: cannot get AoR from FROM header\n");
742
+		goto error;
743
+	}
744
+
745
+	jkey.hash = xj_get_hash(&from_uri, NULL);
746
+	jkey.id = &from_uri;
729 747
 
730 748
 	if((pipe = xj_wlist_get(jwl, &jkey, &jp)) < 0)
731 749
 	{
... ...
@@ -742,16 +760,20 @@ void xj_register_watcher(str *from, str *to, void *cbf, void *pp)
742 760
 	jsmsg->msg.len = 0;
743 761
 	jsmsg->msg.s = NULL;
744 762
 	
745
-	p = to->s;
746
-	fl = to->len;
763
+	to_uri.s = to->s;
764
+	to_uri.len = to->len;
747 765
 	/** skip 'sip:' and parameters in destination address */
748
-	_XJ_ADJUST_SIPADDR(p, fl, p0, f);
766
+	if(xj_extract_aor(&to_uri, 1))
767
+	{
768
+		DBG("ERROR:xjab_manage_sipmsg: cannot get AoR for destination\n");
769
+		goto error;
770
+	}
749 771
 #ifdef XJ_EXTRA_DEBUG
750 772
 	DBG("XJAB:xj_register_watcher: DESTINATION after correction [%.*s].\n",
751
-				fl, p);
773
+				to_uri.len, to_uri.s);
752 774
 #endif
753 775
 
754
-	jsmsg->to.len = fl;
776
+	jsmsg->to.len = to_uri.len;
755 777
 	if((jsmsg->to.s = (char*)shm_malloc(jsmsg->to.len+1)) == NULL)
756 778
 	{
757 779
 		if(jsmsg->msg.s)
... ...
@@ -759,7 +781,8 @@ void xj_register_watcher(str *from, str *to, void *cbf, void *pp)
759 781
 		shm_free(jsmsg);
760 782
 		goto error;
761 783
 	}
762
-	strncpy(jsmsg->to.s, p, jsmsg->to.len);
784
+	strncpy(jsmsg->to.s, to_uri.s, jsmsg->to.len);
785
+	jsmsg->to.s[jsmsg->to.len] = '\0';
763 786
 
764 787
 	jsmsg->jkey = jp;
765 788
 	jsmsg->type = XJ_REG_WATCHER;
... ...
@@ -38,6 +38,7 @@
38 38
 
39 39
 #include "../../mem/mem.h"
40 40
 #include "../../mem/shm_mem.h"
41
+#include "../../parser/parse_uri.h"
41 42
 
42 43
 #include "xjab_base.h"
43 44
 #include "mdefines.h"
... ...
@@ -153,3 +154,22 @@ void xj_sipmsg_free(xj_sipmsg jsmsg)
153 154
 	_M_SHM_FREE(jsmsg);
154 155
 }
155 156
 
157
+int xj_extract_aor(str* u, int t)
158
+{
159
+	struct sip_uri puri;
160
+
161
+	if(!u)
162
+		return -1;
163
+	if (parse_uri(u->s, u->len, &puri) < 0)
164
+	{
165
+		LOG(L_ERR, "XJAB:extract_aor: Error while parsing URI\n");
166
+		return -1;
167
+	}
168
+	
169
+	if(t == 1)
170
+		u->s = puri.user.s;
171
+	u->len = puri.host.s + puri.host.len - u->s;
172
+	return 0;
173
+}
174
+
175
+
... ...
@@ -54,31 +54,6 @@
54 54
 #define XJ_FLAG_OPEN		0
55 55
 #define XJ_FLAG_CLOSE		1
56 56
 
57
-/** skip 'sip:' and parameters in a SIP address */
58
-#define _XJ_ADJUST_SIPADDR(_s, _l, _p, _f) \
59
-	if((_s)[0]=='s' && (_s)[1]=='i' && (_s)[2]=='p') \
60
-	{ \
61
-		(_s) += 3; \
62
-		(_l) -= 3; \
63
-		(_f) = 1; \
64
-		while(*(_s)==' ' || *(_s)=='\t' || *(_s)==':') \
65
-		{ \
66
-			(_s)++; \
67
-			(_l)--; \
68
-			(_f)=0; \
69
-		} \
70
-		if((_f)) \
71
-		{ \
72
-			(_s) -= 3; \
73
-			(_l) += 3; \
74
-		} \
75
-	} \
76
-	(_p) = (_s); \
77
-	while((_p)<(_s)+(_l) && *(_p)!=';' && *(_p)!=' ') \
78
-		(_p)++; \
79
-	if((_p) < (_s)+(_l)) \
80
-		(_l) = (_p) - (_s);
81
-
82 57
 typedef void (*pa_callback_f)(str* _user, int _state, void *p);
83 58
 
84 59
 /**********             ***/
... ...
@@ -117,5 +92,7 @@ void xj_jkey_free(xj_jkey);
117 92
 int xj_get_hash(str*, str*);
118 93
 char *shahash(const char *);
119 94
 
95
+int xj_extract_aor(str*, int);
96
+
120 97
 #endif
121 98