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