Browse code

XJAB module - t_uac replaced with t_uac_dlg - some debug messages wrapped in a define: XJ_EXTRA_DEBUG - contact parameter no longer used - last parse_content_type_hdr method used

Daniel-Constantin Mierla authored on 27/01/2003 15:47:20
Showing 10 changed files
... ...
@@ -75,7 +75,6 @@ char *db_table = "jusers";
75 75
 int nrw = 2;
76 76
 int max_jobs = 10;
77 77
 
78
-char *contact = "-";
79 78
 char *jaddress = "127.0.0.1";
80 79
 int jport = 5222;
81 80
 
... ...
@@ -140,7 +139,6 @@ struct module_exports exports= {
140 139
 	8,
141 140
 
142 141
 	(char*[]) {   /* Module parameter names */
143
-		"contact",
144 142
 		"db_url",
145 143
 		"jaddress",
146 144
 		"aliases",
... ...
@@ -158,7 +156,7 @@ struct module_exports exports= {
158 156
 		STR_PARAM,
159 157
 		STR_PARAM,
160 158
 		STR_PARAM,
161
-		STR_PARAM,
159
+		INT_PARAM,
162 160
 		INT_PARAM,
163 161
 		INT_PARAM,
164 162
 		INT_PARAM,
... ...
@@ -167,7 +165,6 @@ struct module_exports exports= {
167 165
 		INT_PARAM
168 166
 	},
169 167
 	(void*[]) {   /* Module parameter variable pointers */
170
-		&contact,
171 168
 		&db_url,
172 169
 		&jaddress,
173 170
 		&jaliases,
... ...
@@ -180,7 +177,7 @@ struct module_exports exports= {
180 177
 		&sleep_time,
181 178
 		&check_time
182 179
 	},
183
-	12,      /* Number of module paramers */
180
+	11,      /* Number of module paramers */
184 181
 	
185 182
 	mod_init,   /* module initialization function */
186 183
 	(response_function) 0,
... ...
@@ -275,12 +272,6 @@ static int mod_init(void)
275 272
 		return -1;
276 273
 	}
277 274
 	
278
-	if(xj_wlist_init_contact(jwl, contact) < 0)
279
-	{
280
-		DBG("XJAB:mod_init: error initializing workers list properties\n");
281
-		return -1;
282
-	}
283
-
284 275
 	if(xj_wlist_set_aliases(jwl, jaliases, jdomain) < 0)
285 276
 	{
286 277
 		DBG("XJAB:mod_init: error setting aliases\n");
... ...
@@ -410,37 +401,43 @@ int xjab_manage_sipmsg(struct sip_msg *msg, int type)
410 401
 	// extract message body - after that whole SIP MESSAGE is parsed
411 402
 	if (type==XJ_SEND_MESSAGE)
412 403
 	{
413
-		/* get th content-type and content-length headers */
414
-		if (parse_headers( msg, HDR_CONTENTLENGTH|HDR_CONTENTTYPE, 0)==-1
415
-		|| !msg->content_type || !msg->content_length) 
404
+		/* get the message's body */
405
+		body.s = get_body( msg );
406
+		if(body.s==0) 
407
+		{
408
+			LOG(L_ERR,"XJAB:xjab_manage_sipmsg: ERROR cannot extract body from"
409
+				" msg\n");
410
+			goto error;
411
+		}
412
+		
413
+		/* content-length (if present) must be already parsed */
414
+		if(!msg->content_length)
416 415
 		{
417
-			LOG(L_ERR,"XJAB:xjab_manage_sipmsg: ERROR fetching content-lenght"
418
-				" and content_type failed! Parse error or headers missing!\n");
419
-                goto error;
420
-        }
416
+			LOG(L_ERR,"XJAB:xjab_manage_sipmsg: ERROR no Content-Length"
417
+					" header found!\n");
418
+			goto error;
419
+		}
420
+		body.len = get_content_length(msg);
421 421
 
422
-		/* check the content-type value */
423
-		if ( (int)msg->content_type->parsed!=CONTENT_TYPE_TEXT_PLAIN
424
-		&& (int)msg->content_type->parsed!=CONTENT_TYPE_MESSAGE_CPIM ) 
422
+		/* parse the content-type header */
423
+		if(parse_content_type_hdr(msg)==-1)
425 424
 		{
426
-			LOG(L_ERR,"XJAB:xjab_manage_sipmsg: ERROR invalid content-type for"
427
-				" a message request! type found=%d\n",
428
-				(int)msg->content_type->parsed);
425
+			LOG(L_ERR,"XJAB:xjab_manage_sipmsg: ERROR cannot parse"
426
+					" Content-Type header\n");
429 427
 			goto error;
430 428
 		}
431 429
 
432
-		/* get the message's body */
433
-		body.s = get_body( msg );
434
-		if (body.s==0) 
430
+		/* check the content-type value */
431
+		if(get_content_type(msg)!=CONTENT_TYPE_TEXT_PLAIN
432
+			&& get_content_type(msg)!=CONTENT_TYPE_MESSAGE_CPIM)
435 433
 		{
436
-			LOG(L_ERR,"XJAB:xjab_manage_sipmsg: ERROR cannot extract body from"
437
-				" msg\n");
434
+			LOG(L_ERR,"XJAB:xjab_manage_sipmsg: ERROR invalid content-type for"
435
+				" a message request! type found=%d\n", get_content_type(msg));
438 436
 			goto error;
439 437
 		}
440
-		body.len = (int)msg->content_length->parsed;
441 438
 	}
442 439
 	
443
-	// check for TO and FROM headers 
440
+	// check for TO and FROM headers - if is not SIP MESSAGE 
444 441
 	if(parse_headers( msg, HDR_TO|HDR_FROM, 0)==-1 || !msg->to || !msg->from)
445 442
 	{
446 443
 		LOG(L_ERR,"XJAB:xjab_manage_sipmsg: cannot find TO or FROM HEADERS!\n");
... ...
@@ -472,9 +469,6 @@ int xjab_manage_sipmsg(struct sip_msg *msg, int type)
472 469
 		case XJ_EXIT_JCONF:
473 470
 		case XJ_GO_OFFLINE:
474 471
 			if((pipe = xj_wlist_check(jwl, &jkey, &p)) < 0)
475
-/**
476
- *
477
- */
478 472
 			{
479 473
 				DBG("XJAB:xjab_manage_sipmsg: no open Jabber session for"
480 474
 						" <%.*s>!\n", from->uri.len, from->uri.s);
... ...
@@ -495,7 +489,9 @@ int xjab_manage_sipmsg(struct sip_msg *msg, int type)
495 489
 		dst.len = msg->new_uri.len;
496 490
 	} else if ( msg->first_line.u.request.uri.len > 0 )
497 491
 	{
492
+#ifdef XJ_EXTRA_DEBUG
498 493
 		DBG("XJAB:xjab_manage_sipmsg: parsing URI from first line\n");
494
+#endif
499 495
 		if(parse_uri(msg->first_line.u.request.uri.s,
500 496
 					msg->first_line.u.request.uri.len, &_uri) < 0)
501 497
 		{
... ...
@@ -637,7 +633,9 @@ error:
637 633
 void destroy(void)
638 634
 {
639 635
 	int i;
636
+#ifdef XJ_EXTRA_DEBUG
640 637
 	DBG("XJAB: Unloading module ...\n");
638
+#endif
641 639
 	if(pipes)
642 640
 	{ // close the pipes
643 641
 		for(i = 0; i < nrw; i++)
... ...
@@ -660,7 +658,7 @@ void destroy(void)
660 658
 	}
661 659
 			
662 660
 	xj_wlist_free(jwl);
663
-	DBG("XJAB: Unloaded\n");
661
+	DBG("XJAB: Unloaded ...\n");
664 662
 }
665 663
 
666 664
 /**
... ...
@@ -86,7 +86,9 @@ static inline int s_unlock( smart_lock *s )
86 86
 /* lock semaphore s */
87 87
 static inline int s_lock_at(smart_lock *s, int i)
88 88
 {
89
+#ifdef XJ_EXTRA_DEBUG
89 90
 	DBG("XJAB: s_lock_at: <%d>\n", i);
91
+#endif
90 92
 #ifdef FAST_LOCK
91 93
 	get_lock(&s[i]);
92 94
 	return 0;
... ...
@@ -99,7 +101,9 @@ static inline int s_lock_at(smart_lock *s, int i)
99 101
 /* ulock semaphore */
100 102
 static inline int s_unlock_at(smart_lock *s, int i)
101 103
 {
104
+#ifdef XJ_EXTRA_DEBUG
102 105
 	DBG("XJAB: s_unlock_at: <%d>\n", i);
106
+#endif
103 107
 #ifdef FAST_LOCK
104 108
 	release_lock(&s[i]);
105 109
 	return 0;
... ...
@@ -40,10 +40,10 @@
40 40
 #include "xjab_base.h"
41 41
 #include "mdefines.h"
42 42
 
43
-
44
-/** TM bind */
45
-extern struct tm_binds tmb;
46
-
43
+/**
44
+ * get the hash code - based on Andrei's function
45
+ * 
46
+ */
47 47
 int xj_get_hash(str *x, str *y)
48 48
 {
49 49
 	char* p;
... ...
@@ -110,7 +110,9 @@ int xj_jcon_connect(xj_jcon jbc)
110 110
     	DBG("XJAB:xj_jcon_connect: Error to create the socket\n");
111 111
         return -1;
112 112
     }
113
-    DBG("XJAB:xj_jcon_connect: socket [%d]\n", sock);
113
+#ifdef XJ_EXTRA_DEBUG
114
+	DBG("XJAB:xj_jcon_connect: socket [%d]\n", sock);
115
+#endif
114 116
     he=gethostbyname(jbc->hostname);
115 117
     if(he == NULL)
116 118
     {
... ...
@@ -124,7 +126,7 @@ int xj_jcon_connect(xj_jcon jbc)
124 126
     address.sin_family=AF_INET;
125 127
     address.sin_port=htons(jbc->port);
126 128
 
127
-    // try to connect with JCI server
129
+    // try to connect with Jabber server
128 130
     if (connect(sock, (struct sockaddr *)&address, sizeof(address))<0)
129 131
     {
130 132
     	DBG("XJAB:xj_jcon_connect: Error to connect with Jabber server\n");
... ...
@@ -162,15 +164,19 @@ int xj_jcon_disconnect(xj_jcon jbc)
162 164
 {
163 165
 	if(jbc == NULL || jbc->sock < 0)
164 166
 		return -1;
167
+#ifdef XJ_EXTRA_DEBUG
165 168
 	DBG("XJAB:xj_jcon_disconnect: -----START-----\n");
166 169
     DBG("XJAB:xj_jcon_disconnect: socket [%d]\n", jbc->sock);
170
+#endif
167 171
 	xj_jcon_send_presence(jbc, NULL, "unavailable", NULL, NULL);
168 172
 	if(send(jbc->sock, "</stream:stream>", 16, 0) < 16)
169 173
 		DBG("XJAB:xj_jcon_disconnect: error closing stream\n");
170 174
 	if(close(jbc->sock) == -1)
171 175
 		DBG("XJAB:xj_jcon_disconnect: error closing socket\n");
172 176
 	jbc->sock = -1;
177
+#ifdef XJ_EXTRA_DEBUG
173 178
 	DBG("XJAB:xj_jcon_disconnect: -----END-----\n");
179
+#endif
174 180
 	return 0;
175 181
 }
176 182
 
... ...
@@ -266,7 +272,9 @@ int xj_jcon_user_auth(xj_jcon jbc, char *username, char *passwd,
266 272
 	if(xode_get_tag(x, "digest") != NULL)
267 273
 	{ // digest authentication
268 274
 			
269
-		sprintf(msg_buff, "%s%s", jbc->stream_id, passwd);
275
+		//sprintf(msg_buff, "%s%s", jbc->stream_id, passwd);
276
+		strcpy(msg_buff, jbc->stream_id);
277
+		strcat(msg_buff, passwd);
270 278
 		DBG("XJAB:xj_jcon_user_auth: [%s:%s]\n", jbc->stream_id, passwd);
271 279
 		p1 = shahash(msg_buff);
272 280
 
... ...
@@ -343,7 +351,9 @@ error:
343 351
 int xj_jcon_get_roster(xj_jcon jbc)
344 352
 {
345 353
 	int n = strlen(JB_IQ_ROSTER_GET);
354
+#ifdef XJ_EXTRA_DEBUG
346 355
 	DBG("XJAB: xj_jcon_get_roster\n");
356
+#endif
347 357
 	if(send(jbc->sock, JB_IQ_ROSTER_GET, n, 0) != n)
348 358
 		return -1;
349 359
 	return 0;
... ...
@@ -431,8 +441,9 @@ int xj_jcon_send_msg(xj_jcon jbc, char *to, int tol, char *msg,
431 441
 
432 442
 	p = xode_to_str(x);
433 443
 	n = strlen(p);
444
+#ifdef XJ_EXTRA_DEBUG
434 445
 	DBG("XJAB:xj_jcon_send_msg: jabber msg:\n%s\n", p);
435
-	
446
+#endif	
436 447
 	if(send(jbc->sock, p, n, 0) != n)
437 448
 	{
438 449
 		DBG("XJAB:xj_jcon_send_msg: error - message not sent\n");
... ...
@@ -447,6 +458,7 @@ error:
447 458
 
448 459
 /**
449 460
  * receive a message from a JABBER connection
461
+ * NOT USED
450 462
  */
451 463
 int xj_jcon_recv_msg(xj_jcon jbc, char *from, char *msg)
452 464
 {
... ...
@@ -472,8 +484,9 @@ int xj_jcon_send_presence(xj_jcon jbc, char *sto, char *type, char *status,
472 484
 	
473 485
 	if(jbc == NULL)
474 486
 		return -1;
487
+#ifdef XJ_EXTRA_DEBUG
475 488
 	DBG("XJAB:xj_jcon_send_presence: -----START-----\n");
476
-	
489
+#endif	
477 490
 	x = xode_new_tag("presence");
478 491
 	if(!x)
479 492
 		return -1;
... ...
@@ -502,7 +515,9 @@ int xj_jcon_send_presence(xj_jcon jbc, char *sto, char *type, char *status,
502 515
 		goto error;
503 516
 	}
504 517
 	xode_free(x);
518
+#ifdef XJ_EXTRA_DEBUG
505 519
 	DBG("XJAB:xj_jcon_send_presence: presence status was sent\n");
520
+#endif
506 521
 	return 0;
507 522
 error:
508 523
 	xode_free(x);
... ...
@@ -556,7 +571,10 @@ int xj_jcon_free(xj_jcon jbc)
556 571
 	
557 572
 	if(jbc == NULL)
558 573
 		return -1;
574
+
575
+#ifdef XJ_EXTRA_DEBUG
559 576
 	DBG("XJAB:xj_jcon_free: -----START-----\n");
577
+#endif
560 578
 	//if(jbc->sock != -1)
561 579
 	//	jb_disconnect(jbc);
562 580
 
... ...
@@ -567,7 +585,9 @@ int xj_jcon_free(xj_jcon jbc)
567 585
 	
568 586
 	if(jbc->resource != NULL)
569 587
 		_M_FREE(jbc->resource);
588
+#ifdef XJ_EXTRA_DEBUG
570 589
 	DBG("XJAB:xj_jcon_free: %d conferences\n", jbc->nrjconf);
590
+#endif
571 591
 	while(jbc->nrjconf > 0)
572 592
 	{
573 593
 		if((jcf=delpos234(jbc->jconf,0))!=NULL)
... ...
@@ -576,7 +596,9 @@ int xj_jcon_free(xj_jcon jbc)
576 596
 	}
577 597
 	xj_pres_list_free(jbc->plist);
578 598
 	_M_FREE(jbc);
599
+#ifdef XJ_EXTRA_DEBUG
579 600
 	DBG("XJAB:xj_jcon_free: -----END-----\n");
601
+#endif
580 602
 	return 0;
581 603
 }
582 604
 
... ...
@@ -611,8 +633,10 @@ int xj_jcon_update(xj_jcon jbc, int cache_time)
611 633
 {
612 634
 	if(jbc == NULL)
613 635
 		return -1;
636
+#ifdef XJ_EXTRA_DEBUG
614 637
 	DBG("XJAB: xj_jcon_update [%.*s] %d\n", 
615 638
 			jbc->jkey->id->len, jbc->jkey->id->s, cache_time);
639
+#endif
616 640
 	jbc->expire = get_ticks() + cache_time;
617 641
 	return 0;	
618 642
 }
... ...
@@ -629,12 +653,14 @@ int xj_jcon_is_ready(xj_jcon jbc, char *to, int tol, char dl)
629 653
 	sto.len = tol;
630 654
 	if(!xj_jconf_check_addr(&sto, dl))
631 655
 	{
656
+#ifdef XJ_EXTRA_DEBUG
632 657
 		DBG("XJAB: xj_jcon_is_ready: destination=conference\n");
633
-		
658
+#endif		
634 659
 		if((jcf=xj_jcon_get_jconf(jbc, &sto, dl))!=NULL)
635 660
 			return (jcf->status & XJ_JCONF_READY)?0:3;
636
-		
661
+#ifdef XJ_EXTRA_DEBUG
637 662
 		DBG("XJAB: xj_jcon_is_ready: conference does not exist\n");
663
+#endif
638 664
 		return -1;
639 665
 	}
640 666
 	
... ...
@@ -655,8 +681,9 @@ int xj_jcon_is_ready(xj_jcon jbc, char *to, int tol, char dl)
655 681
 
656 682
 	if(!strncasecmp(p, XJ_YAH_NAME, XJ_YAH_LEN))
657 683
 		return (jbc->ready & XJ_NET_YAH)?0:((jbc->allowed & XJ_NET_YAH)?1:2);
658
-
659
-	DBG("XJAB: xj_jcon_is_ready: destination=jabber\n");	
684
+#ifdef XJ_EXTRA_DEBUG
685
+	DBG("XJAB: xj_jcon_is_ready: destination=jabber\n");
686
+#endif
660 687
 	return 0;
661 688
 }
662 689
 
... ...
@@ -666,15 +693,18 @@ xj_jconf  xj_jcon_get_jconf(xj_jcon jbc, str* sid, char dl)
666 693
 
667 694
 	if(!jbc || !sid || !sid->s || sid->len <= 0)
668 695
 		return NULL;
696
+#ifdef XJ_EXTRA_DEBUG
669 697
 	DBG("XJAB: xj_jcon_get_jconf: looking for conference\n");	
670
-	
698
+#endif	
671 699
 	if((jcf = xj_jconf_new(sid))==NULL)
672 700
 		return NULL;
673 701
 	if(xj_jconf_init_sip(jcf, jbc->jkey->id, dl))
674 702
 		goto clean;
675 703
 	if(jbc->nrjconf && (p = find234(jbc->jconf, (void*)jcf, NULL)) != NULL)
676 704
 	{
705
+#ifdef XJ_EXTRA_DEBUG
677 706
 		DBG("XJAB: xj_jcon_get_jconf: conference found\n");
707
+#endif
678 708
 		xj_jconf_free(jcf);
679 709
 		return p;
680 710
 	}
... ...
@@ -689,7 +719,9 @@ xj_jconf  xj_jcon_get_jconf(xj_jcon jbc, str* sid, char dl)
689 719
 
690 720
 	if((p = add234(jbc->jconf, (void*)jcf)) != NULL)
691 721
 	{
722
+#ifdef XJ_EXTRA_DEBUG
692 723
 		DBG("XJAB: xj_jcon_get_jconf: new conference created\n");
724
+#endif
693 725
 		jbc->nrjconf++;
694 726
 		return p;
695 727
 	}
... ...
@@ -707,8 +739,9 @@ xj_jconf xj_jcon_check_jconf(xj_jcon jbc, char* id)
707 739
 
708 740
 	if(!jbc || !id || !jbc->nrjconf)
709 741
 		return NULL;
742
+#ifdef XJ_EXTRA_DEBUG
710 743
 	DBG("XJAB: xj_jcon_get_jconf: looking for conference\n");	
711
-	
744
+#endif	
712 745
 	sid.s = id;
713 746
 	sid.len = strlen(id);
714 747
 	if((jcf = xj_jconf_new(&sid))==NULL)
... ...
@@ -717,12 +750,16 @@ xj_jconf xj_jcon_check_jconf(xj_jcon jbc, char* id)
717 750
 		goto clean;
718 751
 	if((p = find234(jbc->jconf, (void*)jcf, NULL)) != NULL)
719 752
 	{
753
+#ifdef XJ_EXTRA_DEBUG
720 754
 		DBG("XJAB: xj_jcon_get_jconf: conference found\n");
755
+#endif
721 756
 		xj_jconf_free(jcf);
722 757
 		return p;
723 758
 	}
724 759
 clean:
760
+#ifdef XJ_EXTRA_DEBUG
725 761
 	DBG("XJAB: xj_jcon_get_jconf: conference not found\n");
762
+#endif
726 763
 	xj_jconf_free(jcf);
727 764
 	return NULL;	
728 765
 }
... ...
@@ -748,10 +785,10 @@ int  xj_jcon_del_jconf(xj_jcon jbc, str *sid, char dl, int flag)
748 785
 	
749 786
 	if(!jbc || !sid || !sid->s || sid->len <= 0)
750 787
 		return -1;
751
-	
788
+#ifdef XJ_EXTRA_DEBUG
752 789
 	DBG("XJAB: xj_jcon_del_jconf: deleting conference of <%.*s>\n",
753 790
 			sid->len, sid->s);
754
-	
791
+#endif	
755 792
 	if((jcf = xj_jconf_new(sid))==NULL)
756 793
 		return -1;
757 794
 	if(xj_jconf_init_sip(jcf, jbc->jkey->id, dl))
... ...
@@ -768,7 +805,9 @@ int  xj_jcon_del_jconf(xj_jcon jbc, str *sid, char dl, int flag)
768 805
 			xj_jcon_jconf_presence(jbc, jcf, "unavailable", NULL);
769 806
 		jbc->nrjconf--;
770 807
 		xj_jconf_free(p);
808
+#ifdef XJ_EXTRA_DEBUG
771 809
 		DBG("XJAB: xj_jcon_del_jconf: conference deleted\n");
810
+#endif
772 811
 	}
773 812
 
774 813
 	xj_jconf_free(jcf);
... ...
@@ -38,6 +38,9 @@
38 38
 #include "xjab_jconf.h"
39 39
 #include "xjab_base.h"
40 40
 
41
+/**
42
+ *
43
+ */
41 44
 xj_jconf xj_jconf_new(str *u)
42 45
 {
43 46
 	xj_jconf jcf = NULL;
... ...
@@ -76,6 +79,9 @@ xj_jconf xj_jconf_new(str *u)
76 79
 	return jcf;
77 80
 }
78 81
 
82
+/**
83
+ *
84
+ */
79 85
 int xj_jconf_init_sip(xj_jconf jcf, str *sid, char dl)
80 86
 {
81 87
 	char *p, *p0;
... ...
@@ -83,9 +89,9 @@ int xj_jconf_init_sip(xj_jconf jcf, str *sid, char dl)
83 89
 	if(!jcf || !jcf->uri.s || jcf->uri.len <= 0 
84 90
 			|| !sid || !sid->s || sid->len <= 0)
85 91
 		return -1;
86
-
92
+#ifdef XJ_EXTRA_DEBUG
87 93
 	DBG("XJAB:xj_jconf_init_sip: parsing uri\n");
88
-	
94
+#endif	
89 95
 	p = jcf->uri.s;
90 96
 	while(p<(jcf->uri.s + jcf->uri.len)	&& *p != '@') 
91 97
 		p++;
... ...
@@ -138,8 +144,9 @@ int xj_jconf_init_sip(xj_jconf jcf, str *sid, char dl)
138 144
 	}
139 145
 
140 146
 	jcf->jcid = xj_get_hash(&jcf->room, &jcf->server);
147
+#ifdef XJ_EXTRA_DEBUG
141 148
 	DBG("XJAB:xj_jconf_init_sip: conferece id=%d\n", jcf->jcid);
142
-	
149
+#endif	
143 150
 	return 0;
144 151
 	
145 152
 bad_format:
... ...
@@ -147,14 +154,17 @@ bad_format:
147 154
 	return -2;
148 155
 }
149 156
 
157
+/**
158
+ *
159
+ */
150 160
 int xj_jconf_init_jab(xj_jconf jcf)
151 161
 {
152 162
 	char *p, *p0;
153 163
 	if(!jcf || !jcf->uri.s || jcf->uri.len <= 0)
154 164
 		return -1;
155
-
165
+#ifdef XJ_EXTRA_DEBUG
156 166
 	DBG("XJAB:xj_jconf_init_jab: parsing uri\n");
157
-	
167
+#endif	
158 168
 	p = jcf->uri.s;
159 169
 	while(p<(jcf->uri.s + jcf->uri.len)	&& *p != '@') 
160 170
 		p++;
... ...
@@ -176,8 +186,9 @@ int xj_jconf_init_jab(xj_jconf jcf)
176 186
 		jcf->nick.len = jcf->uri.s + jcf->uri.len - jcf->nick.s;
177 187
 	}
178 188
 	jcf->jcid = xj_get_hash(&jcf->room, &jcf->server);
189
+#ifdef XJ_EXTRA_DEBUG
179 190
 	DBG("XJAB:xj_jconf_init_jab: conferece id=%d\n", jcf->jcid);
180
-
191
+#endif
181 192
 	return 0;
182 193
 	
183 194
 bad_format:
... ...
@@ -186,6 +197,9 @@ bad_format:
186 197
 }
187 198
 
188 199
 
200
+/**
201
+ *
202
+ */
189 203
 int xj_jconf_set_status(xj_jconf jcf, int s)
190 204
 {
191 205
 	if(!jcf || !jcf->uri.s || jcf->uri.len <= 0)
... ...
@@ -194,6 +208,9 @@ int xj_jconf_set_status(xj_jconf jcf, int s)
194 208
 	return 0;
195 209
 }
196 210
 
211
+/**
212
+ *
213
+ */
197 214
 int xj_jconf_cmp(void *a, void *b)
198 215
 {
199 216
 	int n;
... ...
@@ -236,6 +253,9 @@ int xj_jconf_cmp(void *a, void *b)
236 253
 	return 0;
237 254
 }
238 255
 
256
+/**
257
+ *
258
+ */
239 259
 int xj_jconf_free(xj_jconf jcf)
240 260
 {
241 261
 	if(!jcf)
... ...
@@ -249,51 +269,9 @@ int xj_jconf_free(xj_jconf jcf)
249 269
 	return 0;
250 270
 }
251 271
 
252
-int xj_jconf_hash(str *x, str *y)
253
-{
254
-	char* p;
255
-	register unsigned v;
256
-	register unsigned h;
257
-
258
-	if(!x && !y)
259
-		return 0;
260
-	h=0;
261
-	if(x)
262
-	{
263
-		for (p=x->s; p<=(x->s+x->len-4); p+=4)
264
-		{
265
-			v=(*p<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
266
-			h+=v^(v>>3);
267
-		}
268
-		v=0;
269
-		for (;p<(x->s+x->len); p++)
270
-		{ 
271
-			v<<=8; 
272
-			v+=*p;
273
-		}
274
-		h+=v^(v>>3);
275
-	}
276
-	if(y)
277
-	{
278
-		for (p=y->s; p<=(y->s+y->len-4); p+=4)
279
-		{
280
-			v=(*p<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
281
-			h+=v^(v>>3);
282
-		}
283
-	
284
-		v=0;
285
-		for (;p<(y->s+y->len); p++)
286
-		{ 
287
-			v<<=8; 
288
-			v+=*p;
289
-		}
290
-		h+=v^(v>>3);
291
-	}
292
-	h=((h)+(h>>11))+((h>>13)+(h>>23));
293
-	
294
-	return (h)?h:1;
295
-}
296
-
272
+/**
273
+ *
274
+ */
297 275
 int xj_jconf_check_addr(str *addr, char dl)
298 276
 {
299 277
 	char *p;
... ...
@@ -38,7 +38,7 @@
38 38
 #include "xjab_presence.h"
39 39
 
40 40
 /**
41
- *
41
+ * create a presence cell
42 42
  */
43 43
 xj_pres_cell xj_pres_cell_new()
44 44
 {
... ...
@@ -60,7 +60,7 @@ xj_pres_cell xj_pres_cell_new()
60 60
 }
61 61
 
62 62
 /**
63
- *
63
+ * free the presence cell
64 64
  */
65 65
 void xj_pres_cell_free(xj_pres_cell prc)
66 66
 {
... ...
@@ -73,7 +73,7 @@ void xj_pres_cell_free(xj_pres_cell prc)
73 73
 }
74 74
 
75 75
 /**
76
- *
76
+ * free all presence cell linked to
77 77
  */
78 78
 void xj_pres_cell_free_all(xj_pres_cell prc)
79 79
 {
... ...
@@ -90,7 +90,7 @@ void xj_pres_cell_free_all(xj_pres_cell prc)
90 90
 }
91 91
 
92 92
 /**
93
- *
93
+ * init a presence cell
94 94
  */
95 95
 int xj_pres_cell_init(xj_pres_cell prc, str* uid, pa_callback_f f, void* p)
96 96
 {
... ...
@@ -108,7 +108,7 @@ int xj_pres_cell_init(xj_pres_cell prc, str* uid, pa_callback_f f, void* p)
108 108
 }
109 109
 
110 110
 /**
111
- *
111
+ * update attributes for a presence cell
112 112
  */
113 113
 int xj_pres_cell_update(xj_pres_cell prc, pa_callback_f f, void *p)
114 114
 {
... ...
@@ -120,7 +120,7 @@ int xj_pres_cell_update(xj_pres_cell prc, pa_callback_f f, void *p)
120 120
 }
121 121
 
122 122
 /**
123
- *
123
+ * init a presence list
124 124
  */
125 125
 xj_pres_list xj_pres_list_init()
126 126
 {
... ...
@@ -136,7 +136,7 @@ xj_pres_list xj_pres_list_init()
136 136
 }
137 137
 
138 138
 /**
139
- *
139
+ * free the presence list
140 140
  */
141 141
 void xj_pres_list_free(xj_pres_list prl)
142 142
 {
... ...
@@ -148,7 +148,7 @@ void xj_pres_list_free(xj_pres_list prl)
148 148
 }
149 149
 
150 150
 /**
151
- *
151
+ * add, if does not exist, an user in present list
152 152
  */
153 153
 xj_pres_cell xj_pres_list_add(xj_pres_list prl, xj_pres_cell prc)
154 154
 {
... ...
@@ -196,7 +196,7 @@ xj_pres_cell xj_pres_list_add(xj_pres_list prl, xj_pres_cell prc)
196 196
 }
197 197
 
198 198
 /**
199
- *
199
+ * delete a user from presence list
200 200
  */
201 201
 int xj_pres_list_del(xj_pres_list prl, str *uid)
202 202
 {
... ...
@@ -232,7 +232,7 @@ int xj_pres_list_del(xj_pres_list prl, str *uid)
232 232
 }
233 233
 
234 234
 /**
235
- *
235
+ * Check if a user is already in presence list
236 236
  */
237 237
 xj_pres_cell xj_pres_list_check(xj_pres_list prl, str* uid)
238 238
 {
... ...
@@ -256,7 +256,7 @@ xj_pres_cell xj_pres_list_check(xj_pres_list prl, str* uid)
256 256
 }
257 257
 
258 258
 /**
259
- *
259
+ * Notify all users from list
260 260
  */
261 261
 void xj_pres_list_notifyall(xj_pres_list prl, int s)
262 262
 {
... ...
@@ -110,8 +110,9 @@ int xj_jcon_pool_add_jmsg(xj_jcon_pool jcp, xj_sipmsg _jsm, xj_jcon _ojc)
110 110
 		return -1;
111 111
 	if(jcp->jmqueue.size == jcp->jmqueue.len)
112 112
 		return -2;
113
-
113
+#ifdef XJ_EXTRA_DEBUG
114 114
 	DBG("XJAB:xj_jcon_pool_add_jmsg: add msg into the pool\n");
115
+#endif
115 116
 	for(i = 0; i<jcp->jmqueue.len; i++)
116 117
 	{
117 118
 		if(jcp->jmqueue.jsm[i] == NULL || jcp->jmqueue.ojc[i] == NULL)
... ...
@@ -155,8 +156,9 @@ int xj_jcon_pool_add(xj_jcon_pool jcp, xj_jcon jc)
155 156
 	
156 157
 	if(jcp == NULL)
157 158
 		return -1;
159
+#ifdef XJ_EXTRA_DEBUG
158 160
 	DBG("XJAB:xj_jcon_pool_add: add connection into the pool\n");
159
-	
161
+#endif	
160 162
 	while(i < jcp->len && jcp->ojc[i] != NULL)
161 163
 		i++;
162 164
 	if(i >= jcp->len)
... ...
@@ -179,9 +181,10 @@ xj_jcon xj_jcon_pool_get(xj_jcon_pool jcp, xj_jkey jkey)
179 181
 	
180 182
 	if(jcp==NULL || jkey==NULL || jkey->id==NULL || jkey->id->s==NULL)
181 183
 		return NULL;
182
-
184
+#ifdef XJ_EXTRA_DEBUG
183 185
 	DBG("XJAB:xj_jcon_pool_get: looking for the connection of <%.*s>"
184 186
 		" into the pool\n", jkey->id->len, jkey->id->s);
187
+#endif
185 188
 	while(i < jcp->len)
186 189
 	{
187 190
 	 	if((jcp->ojc[i]!=NULL) && jcp->ojc[i]->jkey->hash==jkey->hash && 
... ...
@@ -209,9 +212,9 @@ int xj_jcon_pool_del(xj_jcon_pool jcp, xj_jkey jkey)
209 212
 	
210 213
 	if(jcp==NULL || jkey==NULL || jkey->id==NULL || jkey->id->s==NULL)
211 214
 		return -1;
212
-
215
+#ifdef XJ_EXTRA_DEBUG
213 216
 	DBG("XJAB:xj_jcon_pool_del: removing a connection from the pool\n");
214
-
217
+#endif
215 218
 	while(i < jcp->len)
216 219
 	{
217 220
 	 	if((jcp->ojc[i]!=NULL) && jcp->ojc[i]->jkey->hash==jkey->hash && 
... ...
@@ -236,7 +239,9 @@ void xj_jcon_pool_free(xj_jcon_pool jcp)
236 239
 	int i;
237 240
 	if(jcp == NULL)
238 241
 		return;
242
+#ifdef XJ_EXTRA_DEBUG
239 243
 	DBG("XJAB:xj_jcon_pool_free: -----START-----\n");
244
+#endif
240 245
 	if(jcp->ojc != NULL)
241 246
 	{
242 247
 		for(i=0; i<jcp->len; i++)
... ...
@@ -55,9 +55,9 @@ xj_wlist xj_wlist_init(int **pipes, int size, int max, int cache_time,
55 55
 
56 56
 	if(pipes == NULL || size <= 0 || max <= 0)
57 57
 		return NULL;
58
-
58
+#ifdef XJ_EXTRA_DEBUG
59 59
 	DBG("XJAB:xj_wlist_init: -----START-----\n");
60
-	
60
+#endif	
61 61
 	jwl = (xj_wlist)_M_SHM_MALLOC(sizeof(t_xj_wlist));
62 62
 	if(jwl == NULL)
63 63
 		return NULL;
... ...
@@ -68,7 +68,6 @@ xj_wlist xj_wlist_init(int **pipes, int size, int max, int cache_time,
68 68
 	jwl->delayt = delay_time;
69 69
 	jwl->sleept = sleep_time;
70 70
 
71
-	jwl->contact_h = NULL;
72 71
 	jwl->aliases = NULL;
73 72
 	jwl->sems = NULL;
74 73
 	i = 0;
... ...
@@ -109,49 +108,6 @@ clean:
109 108
 
110 109
 }
111 110
 
112
-/**
113
- * init contact address for SIP messages that will be sent by workers
114
- * - jwl - pointer to workers list
115
- * - ch - string representation of the contact, e.g. 'sip:100.100.100.100:5060'
116
- * #return : 0 on success or <0 on error
117
- * info: still has 0 at the end of string
118
- */
119
-int xj_wlist_init_contact(xj_wlist jwl, char *ch)
120
-{
121
-	int f = 0; // correction flag: 1 -> must be converted to <sip: ... > 
122
-	if(ch == NULL)
123
-		return -1;
124
-	if((jwl->contact_h = (str*)_M_SHM_MALLOC(sizeof(str))) == NULL)
125
-		return -1;
126
-	jwl->contact_h->len = strlen(ch);
127
-
128
-	if(jwl->contact_h->len > 2 && strstr(ch, "sip:") == NULL)
129
-	{
130
-		// contact correction
131
-		jwl->contact_h->len += 6;
132
-		f = 1;
133
-	}
134
-
135
-	if((jwl->contact_h->s=(char*)_M_SHM_MALLOC(jwl->contact_h->len+1))==NULL)
136
-	{
137
-		_M_SHM_FREE(jwl->contact_h);
138
-		return -2;
139
-	}
140
-
141
-	if(f)
142
-	{
143
-		strncpy(jwl->contact_h->s, "<sip:", 5);
144
-		strcpy(jwl->contact_h->s+5, ch);
145
-		jwl->contact_h->s[jwl->contact_h->len-1] = '>';
146
-		jwl->contact_h->s[jwl->contact_h->len] = 0;
147
-	}
148
-	else
149
-		strcpy(jwl->contact_h->s, ch);
150
-
151
-	return 0;
152
-}
153
-
154
-
155 111
 /**
156 112
  * set the p.id's of the workers
157 113
  * - jwl : pointer to the workers list
... ...
@@ -176,15 +132,12 @@ int xj_wlist_set_pid(xj_wlist jwl, int pid, int idx)
176 132
 void xj_wlist_free(xj_wlist jwl)
177 133
 {
178 134
 	int i;
135
+#ifdef XJ_EXTRA_DEBUG
179 136
 	DBG("XJAB:xj_wlist_free: freeing 'xj_wlist' memory ...\n");
137
+#endif
180 138
 	if(jwl == NULL)
181 139
 		return;
182 140
 
183
-	if(jwl->contact_h != NULL && jwl->contact_h->s != NULL)
184
-		_M_SHM_FREE(jwl->contact_h->s);
185
-	if(jwl->contact_h != NULL)
186
-		_M_SHM_FREE(jwl->contact_h);
187
-
188 141
 	if(jwl->workers != NULL)
189 142
 	{
190 143
 		for(i=0; i<jwl->len; i++)
... ...
@@ -247,16 +200,20 @@ int xj_wlist_check(xj_wlist jwl, xj_jkey jkey, xj_jkey *p)
247 200
 		if((*p = find234(jwl->workers[i].sip_ids, (void*)jkey, NULL)) != NULL)
248 201
 		{
249 202
 			s_unlock_at(jwl->sems, i);
203
+#ifdef XJ_EXTRA_DEBUG
250 204
 			DBG("XJAB:xj_wlist_check: entry exists for <%.*s> in the"
251 205
 				" pool of <%d> [%d]\n",jkey->id->len, jkey->id->s,
252 206
 				jwl->workers[i].pid,i);
207
+#endif
253 208
 			return jwl->workers[i].wpipe;
254 209
 		}
255 210
 		s_unlock_at(jwl->sems, i);
256 211
 		i++;
257 212
 	}
213
+#ifdef XJ_EXTRA_DEBUG
258 214
 	DBG("XJAB:xj_wlist_check: entry does not exist for <%.*s>\n",
259
-			jkey->id->len, jkey->id->s);	
215
+			jkey->id->len, jkey->id->s);
216
+#endif
260 217
 	return -1;
261 218
 }
262 219
 
... ...
@@ -291,9 +248,11 @@ int xj_wlist_get(xj_wlist jwl, xj_jkey jkey, xj_jkey *p)
291 248
 			if(pos >= 0)
292 249
 				s_unlock_at(jwl->sems, pos);
293 250
 			s_unlock_at(jwl->sems, i);
251
+#ifdef XJ_EXTRA_DEBUG
294 252
 			DBG("XJAB:xj_wlist_get: entry already exists for <%.*s> in the"
295 253
 				" pool of <%d> [%d]\n",jkey->id->len, jkey->id->s,
296 254
 				jwl->workers[i].pid,i);
255
+#endif
297 256
 			return jwl->workers[i].wpipe;
298 257
 		}
299 258
 		if(min > jwl->workers[i].nr)
... ...
@@ -336,9 +295,11 @@ int xj_wlist_get(xj_wlist jwl, xj_jkey jkey, xj_jkey *p)
336 295
 			msid->hash = jkey->hash;
337 296
 			msid->flag = 0;
338 297
 			s_unlock_at(jwl->sems, pos);
298
+#ifdef XJ_EXTRA_DEBUG
339 299
 			DBG("XJAB:xj_wlist_get: new entry for <%.*s> in the pool of"
340 300
 				" <%d> - [%d]\n", jkey->id->len, jkey->id->s,
341 301
 				jwl->workers[pos].pid, pos);
302
+#endif
342 303
 			return jwl->workers[pos].wpipe;
343 304
 		}
344 305
 		_M_SHM_FREE(msid->id->s);
... ...
@@ -349,8 +310,7 @@ int xj_wlist_get(xj_wlist jwl, xj_jkey jkey, xj_jkey *p)
349 310
 error:
350 311
 	if(pos >= 0)
351 312
 		s_unlock_at(jwl->sems, pos);
352
-
353
-	DBG("XJAB:xj_wlist_get: can not create a new entry for <%.*s>\n",
313
+	DBG("XJAB:xj_wlist_get: cannot create a new entry for <%.*s>\n",
354 314
 				jkey->id->len, jkey->id->s);
355 315
 	return -1;
356 316
 }
... ...
@@ -360,12 +320,15 @@ int  xj_wlist_set_aliases(xj_wlist jwl, char *als, char *jd)
360 320
 	char *p, *p0, *p1;
361 321
 	int i, n;
362 322
 	
363
-	DBG("XJAB:xj_wlist_set_aliases\n");
364 323
 	if(jwl == NULL)
365 324
 		return -1;
366 325
 	if(!jd) // || !als || strlen(als)<2)
367 326
 		return 0;
368 327
 	
328
+#ifdef XJ_EXTRA_DEBUG
329
+	DBG("XJAB:xj_wlist_set_aliases\n");
330
+#endif
331
+	
369 332
 	if((jwl->aliases = (xj_jalias)_M_SHM_MALLOC(sizeof(t_xj_jalias)))==NULL)
370 333
 	{
371 334
 		DBG("XJAB:xj_wlist_set_aliases: not enough SHMemory.\n");
... ...
@@ -405,8 +368,10 @@ int  xj_wlist_set_aliases(xj_wlist jwl, char *als, char *jd)
405 368
 			jwl->aliases = NULL;
406 369
 		}
407 370
 		strncpy(jwl->aliases->jdm->s, jd, jwl->aliases->jdm->len);
371
+#ifdef XJ_EXTRA_DEBUG
408 372
 		DBG("XJAB:xj_wlist_set_aliases: jdomain=%.*s delim=%c\n",
409 373
 			jwl->aliases->jdm->len, jwl->aliases->jdm->s, jwl->aliases->dlm);
374
+#endif
410 375
 	}
411 376
 	
412 377
 	if(!als || strlen(als)<2)
... ...
@@ -463,9 +428,11 @@ int  xj_wlist_set_aliases(xj_wlist jwl, char *als, char *jd)
463 428
 		}
464 429
 			
465 430
 		strncpy(jwl->aliases->a[i].s, p, jwl->aliases->a[i].len);
431
+#ifdef XJ_EXTRA_DEBUG
466 432
 		DBG("XJAB:xj_wlist_set_aliases: alias[%d/%d]=%.*s delim=%c\n", 
467 433
 			i+1, jwl->aliases->size, jwl->aliases->a[i].len, 
468 434
 			jwl->aliases->a[i].s, jwl->aliases->d[i]?jwl->aliases->d[i]:'X');
435
+#endif
469 436
 		p = p0 + 1;
470 437
 	}
471 438
 	return 0;
... ...
@@ -515,18 +482,20 @@ void xj_wlist_del(xj_wlist jwl, xj_jkey jkey, int _pid)
515 482
 			_pid, jkey->id->len, jkey->id->s, i);
516 483
 		return;
517 484
 	}
485
+#ifdef XJ_EXTRA_DEBUG
518 486
 	DBG("XJAB:xj_wlist_del:%d: trying to delete entry for <%.*s>...\n",
519 487
 		_pid, jkey->id->len, jkey->id->s);
520
-
488
+#endif
521 489
 	s_lock_at(jwl->sems, i);
522 490
 	p = del234(jwl->workers[i].sip_ids, (void*)jkey);
523 491
 
524 492
 	if(p != NULL)
525 493
 	{
526 494
 		jwl->workers[i].nr--;
527
-
495
+#ifdef XJ_EXTRA_DEBUG
528 496
 		DBG("XJAB:xj_wlist_del:%d: sip id <%.*s> deleted\n", _pid,
529 497
 			jkey->id->len, jkey->id->s);
498
+#endif
530 499
 		xj_jkey_free_p(p);
531 500
 	}
532 501
 
... ...
@@ -91,8 +91,9 @@ int xj_address_translation(str *src, str *dst, xj_jalias als, int flag)
91 91
 		goto done;
92 92
 	
93 93
 	dst->len = 0;
94
-	DBG("XJAB:xj_address_translation:%d: - checking aliases\n", 
95
-			_xj_pid);
94
+#ifdef XJ_EXTRA_DEBUG
95
+	DBG("XJAB:xj_address_translation:%d: - checking aliases\n", _xj_pid);
96
+#endif
96 97
 	p = src->s;
97 98
 
98 99
 	while(p<(src->s + src->len)	&& *p != '@') 
... ...
@@ -139,21 +140,25 @@ int xj_address_translation(str *src, str *dst, xj_jalias als, int flag)
139 140
 			}
140 141
 	}
141 142
 
143
+#ifdef XJ_EXTRA_DEBUG
142 144
 	DBG("XJAB:xj_address_translation:%d: - doing address corection\n", 
143 145
 			_xj_pid);	
144
-
146
+#endif
147
+	
145 148
 	if(flag & XJ_ADDRTR_A2B)
146 149
 	{
147 150
 		if(strncasecmp(p, als->jdm->s, als->jdm->len))
148 151
 		{
149 152
 			DBG("XJA:xj_address_translation:%d: - wrong Jabber"
150
-				" destination!\n", _xj_pid);
153
+				" destination <%.*s>!\n", _xj_pid, src->len, src->s);
151 154
 			return -1;
152 155
 		}
153 156
 		if(flag & XJ_ADDRTR_CON)
154 157
 		{
158
+#ifdef XJ_EXTRA_DEBUG
155 159
 			DBG("XJAB:xj_address_translation:%d: - that is for"
156 160
 				" Jabber conference\n", _xj_pid);
161
+#endif
157 162
 			p0 = p-1;
158 163
 			while(p0 > src->s && *p0 != als->dlm)
159 164
 				p0--;
... ...
@@ -174,9 +179,10 @@ int xj_address_translation(str *src, str *dst, xj_jalias als, int flag)
174 179
 				*p = '@';
175 180
 			return 0;
176 181
 		}
177
-		
182
+#ifdef XJ_EXTRA_DEBUG
178 183
 		DBG("XJAB:xj_address_translation:%d: - that is for"
179 184
 			" Jabber network\n", _xj_pid);
185
+#endif
180 186
 		dst->len = p - src->s - 1;
181 187
 		strncpy(dst->s, src->s, dst->len);
182 188
 		dst->s[dst->len]=0;
... ...
@@ -263,10 +269,8 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
263 269
 	}
264 270
 
265 271
 	pipe = jwl->workers[rank].rpipe;
266
-
267 272
 	DBG("XJAB:xj_worker[%d]:%d: started - pipe=<%d> : 1st message delay"
268 273
 		" <%d>\n", rank, _xj_pid, pipe, jwl->delayt);
269
-
270 274
 	if((jcp=xj_jcon_pool_init(jwl->maxj,XJ_MSG_POOL_SIZE,jwl->delayt))==NULL)
271 275
 	{
272 276
 		DBG("XJAB:xj_worker: cannot allocate the pool\n");
... ...
@@ -306,12 +310,14 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
306 310
 			}
307 311
 			if(jcp->jmqueue.expire[i] < get_ticks())
308 312
 			{
313
+#ifdef XJ_EXTRA_DEBUG
309 314
 				DBG("XJAB:xj_worker:%d: message to %.*s is expired\n",
310 315
 					_xj_pid, jcp->jmqueue.jsm[i]->to.len, 
311 316
 					jcp->jmqueue.jsm[i]->to.s);
317
+#endif
312 318
 				xj_send_sip_msgz(jcp->jmqueue.jsm[i]->jkey->id, 
313
-						&jcp->jmqueue.jsm[i]->to, jwl->contact_h, 
314
-						XJ_DMSG_ERR_SENDIM, &jcp->jmqueue.ojc[i]->jkey->flag);
319
+						&jcp->jmqueue.jsm[i]->to, XJ_DMSG_ERR_SENDIM,
320
+						&jcp->jmqueue.ojc[i]->jkey->flag);
315 321
 				if(jcp->jmqueue.jsm[i]!=NULL)
316 322
 				{
317 323
 					xj_sipmsg_free(jcp->jmqueue.jsm[i]);
... ...
@@ -322,6 +328,7 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
322 328
 				continue;
323 329
 			}
324 330
 
331
+#ifdef XJ_EXTRA_DEBUG
325 332
 			DBG("XJAB:xj_worker:%d:%d: QUEUE: message[%d] from [%.*s]/to [%.*s]/"
326 333
 					"body[%.*s] expires at %d\n",
327 334
 					_xj_pid, get_ticks(), i, 
... ...
@@ -330,6 +337,7 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
330 337
 					jcp->jmqueue.jsm[i]->to.len,jcp->jmqueue.jsm[i]->to.s,
331 338
 					jcp->jmqueue.jsm[i]->msg.len,jcp->jmqueue.jsm[i]->msg.s,
332 339
 					jcp->jmqueue.expire[i]);
340
+#endif
333 341
 			if(xj_jcon_is_ready(jcp->jmqueue.ojc[i], jcp->jmqueue.jsm[i]->to.s,
334 342
 					jcp->jmqueue.jsm[i]->to.len, jwl->aliases->dlm))
335 343
 				continue;
... ...
@@ -344,10 +352,11 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
344 352
 			if(xj_address_translation(&jcp->jmqueue.jsm[i]->to,
345 353
 				&sto, jwl->aliases, flag) == 0)
346 354
 			{
347
-		
348 355
 				/** send message from queue */
349
-				DBG("XJAB:xj_worker:%d: SENDING THE MESSAGE FROM "
350
-					" LOCAL QUEUE TO JABBER NETWORK ...\n", _xj_pid);
356
+#ifdef XJ_EXTRA_DEBUG
357
+				DBG("XJAB:xj_worker:%d: SENDING the message from "
358
+					" local queue to Jabber network ...\n", _xj_pid);
359
+#endif
351 360
 				xj_jcon_send_msg(jcp->jmqueue.ojc[i],
352 361
 					sto.s, sto.len,
353 362
 					jcp->jmqueue.jsm[i]->msg.s,
... ...
@@ -355,8 +364,8 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
355 364
 					(flag&XJ_ADDRTR_CON)?XJ_JMSG_GROUPCHAT:XJ_JMSG_CHAT);
356 365
 			}
357 366
 			else
358
-				DBG("XJAB:xj_worker:%d: ERROR SENDING THE MESSAGE FROM "
359
-				" LOCAL QUEUE TO JABBER NETWORK ...\n", _xj_pid);
367
+				DBG("XJAB:xj_worker:%d: ERROR SENDING the message from "
368
+				" local queue to Jabber network ...\n", _xj_pid);
360 369
 				
361 370
 			if(jcp->jmqueue.jsm[i]!=NULL)
362 371
 			{
... ...
@@ -369,8 +378,9 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
369 378
 		
370 379
 		if(ret <= 0)
371 380
 			goto step_x;
372
-		
381
+#ifdef XJ_EXTRA_DEBUG
373 382
 		DBG("XJAB:xj_worker:%d: something is coming\n", _xj_pid);
383
+#endif
374 384
 		if(!FD_ISSET(pipe, &mset))
375 385
 			goto step_y;
376 386
 		
... ...
@@ -380,8 +390,10 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
380 390
 			break;
381 391
 		}
382 392
 
393
+#ifdef XJ_EXTRA_DEBUG
383 394
 		DBG("XJAB:xj_worker:%d: job <%p> from SER\n", _xj_pid, jsmsg);
384
-		
395
+#endif
396
+
385 397
 		if(jsmsg == NULL || jsmsg->jkey==NULL || jsmsg->jkey->id==NULL)
386 398
 			goto step_w;
387 399
 
... ...
@@ -397,7 +409,7 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
397 409
 				(!jbc||!xj_jcon_get_jconf(jbc,&jsmsg->to,jwl->aliases->dlm)))
398 410
 				{
399 411
 					xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
400
-						jwl->contact_h, XJ_DMSG_ERR_NOTJCONF, NULL);
412
+						XJ_DMSG_ERR_NOTJCONF, NULL);
401 413
 					goto step_w;
402 414
 				}
403 415
 				break;
... ...
@@ -415,7 +427,7 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
415 427
 					xj_jcon_del_jconf(jbc, &jsmsg->to, jwl->aliases->dlm,
416 428
 						XJ_JCMD_UNSUBSCRIBE);
417 429
 				xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
418
-					jwl->contact_h, XJ_DMSG_INF_JCONFEXIT, NULL);
430
+					XJ_DMSG_INF_JCONFEXIT, NULL);
419 431
 				goto step_w;
420 432
 			case XJ_GO_OFFLINE:
421 433
 				if(jbc != NULL)
... ...
@@ -428,22 +440,27 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
428 440
 		
429 441
 		if(jbc != NULL)
430 442
 		{
443
+#ifdef XJ_EXTRA_DEBUG
431 444
 			DBG("XJAB:xj_worker:%d: connection already exists"
432 445
 				" for <%s> ...\n", _xj_pid, buff);
446
+#endif
433 447
 			xj_jcon_update(jbc, jwl->cachet);
434 448
 			goto step_z;
435 449
 		}
436 450
 		
437 451
 		// NO OPEN CONNECTION FOR THIS SIP ID
438
-		DBG("XJAB:xj_worker:%d: new connection for <%s>.\n",
439
-			_xj_pid, buff);
440
-		
452
+#ifdef XJ_EXTRA_DEBUG
453
+		DBG("XJAB:xj_worker:%d: new connection for <%s>.\n", _xj_pid, buff);
454
+#endif		
441 455
 		if(db_query(db_con, keys, 0, vals, col, 2, 2, NULL, &res) != 0 ||
442 456
 			RES_ROW_N(res) <= 0)
443 457
 		{
444
-			DBG("XJAB:xj_worker:%d: no database result\n", _xj_pid);
458
+#ifdef XJ_EXTRA_DEBUG
459
+			DBG("XJAB:xj_worker:%d: no database result when looking"
460
+				" for associated Jabber account\n", _xj_pid);
461
+#endif
445 462
 			xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to, 
446
-				jwl->contact_h, XJ_DMSG_ERR_JGWFORB, NULL);
463
+				XJ_DMSG_ERR_JGWFORB, NULL);
447 464
 			
448 465
 			goto step_v;
449 466
 		}
... ...
@@ -455,15 +472,16 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
455 472
 			DBG("XJAB:xj_worker:%d: Cannot connect"
456 473
 				" to the Jabber server ...\n", _xj_pid);
457 474
 			xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to, 
458
-				jwl->contact_h, XJ_DMSG_ERR_NOJSRV, NULL);
475
+				XJ_DMSG_ERR_NOJSRV, NULL);
459 476
 
460 477
 			goto step_v;
461 478
 		}
462 479
 		
480
+#ifdef XJ_EXTRA_DEBUG
463 481
 		DBG("XJAB:xj_worker: auth to jabber as: [%s] / [%s]\n",
464 482
 			(char*)(ROW_VALUES(RES_ROWS(res))[0].val.string_val), 
465 483
 			(char*)(ROW_VALUES(RES_ROWS(res))[1].val.string_val));
466
-		
484
+#endif		
467 485
 		if(xj_jcon_user_auth(jbc,
468 486
 			(char*)(ROW_VALUES(RES_ROWS(res))[0].val.string_val),
469 487
 			(char*)(ROW_VALUES(RES_ROWS(res))[1].val.string_val),
... ...
@@ -473,8 +491,8 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
473 491
 				" failed ...\n", _xj_pid);
474 492
 			xj_jcon_disconnect(jbc);
475 493
 			
476
-			xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
477
-				jwl->contact_h, XJ_DMSG_ERR_JAUTH, NULL);
494
+			xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to, 
495
+					XJ_DMSG_ERR_JAUTH, NULL);
478 496
 			
479 497
 			xj_jcon_free(jbc);
480 498
 			goto step_v;
... ...
@@ -486,14 +504,16 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
486 504
 			DBG("XJAB:xj_worker:%d: Keeping connection to Jabber server"
487 505
 				" failed! Not enough memory ...\n", _xj_pid);
488 506
 			xj_jcon_disconnect(jbc);
489
-			xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to, jwl->contact_h,	
490
-				XJ_DMSG_ERR_JGWFULL, NULL);
507
+			xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,	
508
+					XJ_DMSG_ERR_JGWFULL, NULL);
491 509
 			xj_jcon_free(jbc);
492 510
 			goto step_v;
493 511
 		}
494 512
 								
495 513
 		/** add socket descriptor to select */
514
+#ifdef XJ_EXTRA_DEBUG
496 515
 		DBG("XJAB:xj_worker:%d: add connection on <%d> \n", _xj_pid, jbc->sock);
516
+#endif
497 517
 		if(jbc->sock > maxfd)
498 518
 			maxfd = jbc->sock;
499 519
 		FD_SET(jbc->sock, &set);
... ...
@@ -521,8 +541,10 @@ step_z:
521 541
 		{ // register a presence watcher
522 542
 			if(!xj_jconf_check_addr(&jsmsg->to, jwl->aliases->dlm))
523 543
 			{ // is for a conference - ignore?!?!
544
+#ifdef XJ_EXTRA_DEBUG
524 545
 				DBG("XJAB:xj_worker:%d: presence request for a conference.\n",
525 546
 					_xj_pid);
547
+#endif
526 548
 				// set as offline
527 549
 				(*(jsmsg->cbf))(&jsmsg->to, 0, jsmsg->p);
528 550
 				goto step_w;
... ...
@@ -583,8 +605,7 @@ step_z:
583 605
 						// unable to join the conference 
584 606
 						// --- send back to SIP user a msg
585 607
 						xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to, 
586
-							jwl->contact_h, XJ_DMSG_ERR_JOINJCONF,
587
-							&jbc->jkey->flag);
608
+							XJ_DMSG_ERR_JOINJCONF, &jbc->jkey->flag);
588 609
 						goto step_w;
589 610
 					}
590 611
 				}
... ...
@@ -595,7 +616,7 @@ step_z:
595 616
 				// unable to get the conference 
596 617
 				// --- send back to SIP user a msg
597 618
 				xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to, 
598
-					jwl->contact_h, XJ_DMSG_ERR_NEWJCONF, &jbc->jkey->flag);
619
+						XJ_DMSG_ERR_NEWJCONF, &jbc->jkey->flag);
599 620
 				goto step_w;
600 621
 			}
601 622
 		}
... ...
@@ -606,8 +627,10 @@ step_z:
606 627
 		switch(xj_jcon_is_ready(jbc,jsmsg->to.s,jsmsg->to.len,jwl->aliases->dlm))
607 628
 		{
608 629
 			case 0:
609
-				DBG("XJAB:xj_worker:%d: SENDING THE MESSAGE TO JABBER"
610
-					" NETWORK ...\n", _xj_pid);
630
+#ifdef XJ_EXTRA_DEBUG
631
+				DBG("XJAB:xj_worker:%d: SENDING the message to Jabber"
632
+					" network ...\n", _xj_pid);
633
+#endif
611 634
 				/*** address corection ***/
612 635
 				sto.s = buff; 
613 636
 				sto.len = 0;
... ...
@@ -620,25 +643,24 @@ step_z:
620 643
 						(flag&XJ_ADDRTR_CON)?XJ_JMSG_GROUPCHAT:XJ_JMSG_CHAT)<0)
621 644
 							
622 645
 						xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
623
-							jwl->contact_h, XJ_DMSG_ERR_SENDJMSG,
624
-							&jbc->jkey->flag);
646
+							XJ_DMSG_ERR_SENDJMSG, &jbc->jkey->flag);
625 647
 				}
626 648
 				else
627
-					DBG("XJAB:xj_worker:%d: ERROR SENDING AS JABBER"
628
-						" MESSAGE ...\n", _xj_pid);
649
+					DBG("XJAB:xj_worker:%d: ERROR SENDING as Jabber"
650
+						" message ...\n", _xj_pid);
629 651
 						
630 652
 				goto step_w;
631 653
 		
632 654
 			case 1:
633
-				DBG("XJAB:xj_worker:%d:SCHEDULING THE MESSAGE."
634
-					"\n", _xj_pid);
655
+#ifdef XJ_EXTRA_DEBUG
656
+				DBG("XJAB:xj_worker:%d:SCHEDULING the message.\n", _xj_pid);
657
+#endif
635 658
 				if(xj_jcon_pool_add_jmsg(jcp, jsmsg, jbc) < 0)
636 659
 				{
637
-					DBG("XJAB:xj_worker:%d: SCHEDULING THE"
638
-						" MESSAGE FAILED. Message was droped.\n",_xj_pid);
660
+					DBG("XJAB:xj_worker:%d: SCHEDULING the message FAILED."
661
+							" Message was dropped.\n",_xj_pid);
639 662
 					xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
640
-						jwl->contact_h, XJ_DMSG_ERR_STOREJMSG,
641
-						&jbc->jkey->flag);
663
+						XJ_DMSG_ERR_STOREJMSG, &jbc->jkey->flag);
642 664
 					goto step_w;
643 665
 				}
644 666
 				else // skip freeing the SIP message - now is in queue
... ...
@@ -646,17 +668,15 @@ step_z:
646 668
 	
647 669
 			case 2:
648 670
 				xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
649
-						jwl->contact_h, XJ_DMSG_ERR_NOREGIM,
650
-						&jbc->jkey->flag);
671
+						XJ_DMSG_ERR_NOREGIM, &jbc->jkey->flag);
651 672
 				goto step_w;
652 673
 			case 3: // not joined to Jabber conference
653 674
 				xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
654
-						jwl->contact_h, XJ_DMSG_ERR_NOTJCONF,
655
-						&jbc->jkey->flag);
675
+						XJ_DMSG_ERR_NOTJCONF, &jbc->jkey->flag);
656 676
 				goto step_w;
657 677
 				
658 678
 			default:
659
-				xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to, jwl->contact_h,
679
+				xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
660 680
 						XJ_DMSG_ERR_SENDJMSG, &jbc->jkey->flag);
661 681
 				goto step_w;
662 682
 		}
... ...
@@ -689,10 +709,10 @@ step_y:
689 709
 		{
690 710
 			if(jcp->ojc[i] == NULL)
691 711
 				continue;
692
-			
712
+#ifdef XJ_EXTRA_DEBUG
693 713
 			DBG("XJAB:xj_worker:%d: checking socket <%d>"
694 714
 				" ...\n", _xj_pid, jcp->ojc[i]->sock);
695
-			
715
+#endif
696 716
 			if(!FD_ISSET(jcp->ojc[i]->sock, &mset))
697 717
 				continue;
698 718
 			pos = nr = 0;
... ...
@@ -715,7 +735,7 @@ step_y:
715 735
 					if(flags!=-1 && !(flags & O_NONBLOCK))
716 736
    					{
717 737
     					/* set NONBLOCK bit to enable non-blocking */
718
-    					fcntl(jcp->ojc[i]->sock, F_SETFL, flags | O_NONBLOCK);
738
+    					fcntl(jcp->ojc[i]->sock, F_SETFL, flags|O_NONBLOCK);
719 739
    					}
720 740
 				}
721 741
 				
... ...
@@ -727,28 +747,28 @@ step_y:
727 747
 						" connection to jabber lost on socket <%d> ...\n",
728 748
 						_xj_pid, jcp->ojc[i]->sock);
729 749
 					xj_send_sip_msgz(jcp->ojc[i]->jkey->id, &jab_gw_name, 
730
-						jwl->contact_h, XJ_DMSG_ERR_DISCONNECTED,
731
-						&jbc->jkey->flag);
750
+						XJ_DMSG_ERR_DISCONNECTED, &jbc->jkey->flag);
732 751
 					// make sure that will ckeck expired connections
733 752
 					ltime = jcp->ojc[i]->expire = -1;
734 753
 					FD_CLR(jcp->ojc[i]->sock, &set);
735 754
 					goto step_xx;
736 755
 				}
756
+#ifdef XJ_EXTRA_DEBUG
737 757
 				DBG("XJAB:xj_worker:%d: received: %dbytes Err:%d/EA:%d\n", 
738
-						_xj_pid, nr, errno, EAGAIN);		
758
+						_xj_pid, nr, errno, EAGAIN);
759
+#endif
739 760
 				xj_jcon_update(jcp->ojc[i], jwl->cachet);
740 761
 
741 762
 				if(nr>0)
742 763
 					p[nr] = 0;
743 764
 				nr = strlen(recv_buff);
744 765
 				pos = 0;
745
-
766
+#ifdef XJ_EXTRA_DEBUG
746 767
 				DBG("XJAB:xj_worker: JMSG START ----------\n%.*s\n"
747 768
 					" JABBER: JMSGL:%d END ----------\n", nr, recv_buff, nr);
748
-
749
-			
750
-			} while(xj_manage_jab(recv_buff, nr, &pos, jwl->contact_h,
751
-					jwl->aliases, jcp->ojc[i]) == 9	&& main_loop);
769
+#endif
770
+			} while(xj_manage_jab(recv_buff, nr, &pos, jwl->aliases,
771
+							jcp->ojc[i]) == 9	&& main_loop);
752 772
 	
753 773
 			/**
754 774
 			 * flush out the socket - set it back to blocking 
... ...
@@ -759,9 +779,10 @@ step_y:
759 779
     			/* reset NONBLOCK bit to enable blocking */
760 780
     			fcntl(jcp->ojc[i]->sock, F_SETFL, flags & ~O_NONBLOCK);
761 781
    			}
762
-	
782
+#ifdef XJ_EXTRA_DEBUG
763 783
 			DBG("XJAB:xj_worker:%d: msgs from socket <%d> parsed"
764 784
 				" ...\n", _xj_pid, jcp->ojc[i]->sock);	
785
+#endif
765 786
 		} // end FOR(i = 0; i < jcp->len; i++)
766 787
 
767 788
 step_x:
... ...
@@ -785,8 +806,10 @@ step_xx:
785 806
 		if(ltime < 0 || ltime + jwl->sleept <= get_ticks())
786 807
 		{
787 808
 			ltime = get_ticks();
809
+#ifdef XJ_EXTRA_DEBUG
788 810
 			DBG("XJAB:xj_worker:%d: scanning for expired connection\n",
789 811
 				_xj_pid);
812
+#endif
790 813
 			xj_worker_check_jcons(jwl, jcp, ltime, &set);
791 814
 		}
792 815
 	} // END while
... ...
@@ -799,8 +822,7 @@ step_xx:
799 822
 /**
800 823
  * parse incoming message from Jabber server
801 824
  */
802
-int xj_manage_jab(char *buf, int len, int *pos, 
803
-		str *sct, xj_jalias als, xj_jcon jbc)
825
+int xj_manage_jab(char *buf, int len, int *pos, xj_jalias als, xj_jcon jbc)
804 826
 {
805 827
 	int i, err=0;
806 828
 	char *p, *to, *from, *msg, *type, *emsg, *ecode, lbuf[4096], fbuf[128];
... ...
@@ -815,8 +837,9 @@ int xj_manage_jab(char *buf, int len, int *pos,
815 837
 
816 838
 	sid = jbc->jkey->id;	
817 839
 	x = xode_from_strx(buf, len, &err, &i);
840
+#ifdef XJ_EXTRA_DEBUG
818 841
 	DBG("XJAB:xj_parse_jab: XODE ret:%d pos:%d\n", err, i);
819
-	
842
+#endif	
820 843
 	if(err && pos != NULL)
821 844
 		*pos= i;
822 845
 	if(x == NULL)
... ...
@@ -827,23 +850,31 @@ int xj_manage_jab(char *buf, int len, int *pos,
827 850
 	
828 851
 	if(!strncasecmp(xode_get_name(x), "message", 7))
829 852
 	{
853
+#ifdef XJ_EXTRA_DEBUG
830 854
 		DBG("XJAB:xj_manage_jab: jabber [message] received\n");
855
+#endif
831 856
 		if((to = xode_get_attrib(x, "to")) == NULL)
832 857
 		{
858
+#ifdef XJ_EXTRA_DEBUG
833 859
 			DBG("XJAB:xj_manage_jab: missing 'to' attribute\n");
860
+#endif
834 861
 			err = -1;
835 862
 			goto ready;
836 863
 		}
837 864
 		if((from = xode_get_attrib(x, "from")) == NULL)
838 865
 		{
866
+#ifdef XJ_EXTRA_DEBUG
839 867
 			DBG("XJAB:xj_manage_jab: missing 'from' attribute\n");
868
+#endif
840 869
 			err = -1;
841 870
 			goto ready;
842 871
 		}
843 872
 		if((y = xode_get_tag(x, "body")) == NULL
844 873
 				|| (msg = xode_get_data(y)) == NULL)
845 874
 		{
875
+#ifdef XJ_EXTRA_DEBUG
846 876
 			DBG("XJAB:xj_manage_jab: missing 'body' of message\n");
877
+#endif
847 878
 			err = -1;
848 879
 			goto ready;
849 880
 		}
... ...
@@ -852,20 +883,18 @@ int xj_manage_jab(char *buf, int len, int *pos,
852 883
 		{
853 884
 			if((y = xode_get_tag(x, "error")) == NULL
854 885
 					|| (emsg = xode_get_data(y)) == NULL)
855
-			{
856 886
 				strcpy(lbuf, "{Error sending following message} - ");
857
-			}
858 887
 			else
859 888
 			{
860 889
 				ecode = xode_get_attrib(y, "code");