Browse code

XJAB module - the special character (old %) in user part of the address can be now specified in module's jdomain parameter. Default is *

Daniel-Constantin Mierla authored on 26/11/2002 09:57:28
Showing 7 changed files
... ...
@@ -518,7 +518,7 @@ int xj_jcon_update(xj_jcon jbc, int cache_time)
518 518
 	return 0;	
519 519
 }
520 520
 
521
-int xj_jcon_is_ready(xj_jcon jbc, char *to, int tol)
521
+int xj_jcon_is_ready(xj_jcon jbc, char *to, int tol, char dl)
522 522
 {
523 523
 	char *p;
524 524
 	str sto;
... ...
@@ -528,11 +528,11 @@ int xj_jcon_is_ready(xj_jcon jbc, char *to, int tol)
528 528
 	
529 529
 	sto.s = to;
530 530
 	sto.len = tol;
531
-	if(!xj_jconf_check_addr(&sto))
531
+	if(!xj_jconf_check_addr(&sto, dl))
532 532
 	{
533 533
 		DBG("XJAB: xj_jcon_is_ready: destination=conference\n");
534 534
 		
535
-		if((jcf=xj_jcon_get_jconf(jbc, &sto))!=NULL)
535
+		if((jcf=xj_jcon_get_jconf(jbc, &sto, dl))!=NULL)
536 536
 			return (jcf->status & XJ_JCONF_READY)?0:3;
537 537
 		
538 538
 		DBG("XJAB: xj_jcon_is_ready: conference does not exist\n");
... ...
@@ -561,7 +561,7 @@ int xj_jcon_is_ready(xj_jcon jbc, char *to, int tol)
561 561
 	return 0;
562 562
 }
563 563
 
564
-xj_jconf  xj_jcon_get_jconf(xj_jcon jbc, str* sid)
564
+xj_jconf  xj_jcon_get_jconf(xj_jcon jbc, str* sid, char dl)
565 565
 {
566 566
 	xj_jconf jcf = NULL, p;
567 567
 
... ...
@@ -571,7 +571,7 @@ xj_jconf  xj_jcon_get_jconf(xj_jcon jbc, str* sid)
571 571
 	
572 572
 	if((jcf = xj_jconf_new(sid))==NULL)
573 573
 		return NULL;
574
-	if(xj_jconf_init_sip(jcf, jbc->jkey->id))
574
+	if(xj_jconf_init_sip(jcf, jbc->jkey->id, dl))
575 575
 		goto clean;
576 576
 	if(jbc->nrjconf && (p = find234(jbc->jconf, (void*)jcf, NULL)) != NULL)
577 577
 	{
... ...
@@ -643,7 +643,7 @@ int xj_jcon_jconf_presence(xj_jcon jbc, xj_jconf jcf, char* type,
643 643
 	return xj_jcon_send_presence(jbc,buff,type,status,NULL);
644 644
 }
645 645
 
646
-int  xj_jcon_del_jconf(xj_jcon jbc, str *sid, int flag)
646
+int  xj_jcon_del_jconf(xj_jcon jbc, str *sid, char dl, int flag)
647 647
 {
648 648
 	xj_jconf jcf = NULL, p = NULL;
649 649
 	
... ...
@@ -655,7 +655,7 @@ int  xj_jcon_del_jconf(xj_jcon jbc, str *sid, int flag)
655 655
 	
656 656
 	if((jcf = xj_jconf_new(sid))==NULL)
657 657
 		return -1;
658
-	if(xj_jconf_init_sip(jcf, jbc->jkey->id))
658
+	if(xj_jconf_init_sip(jcf, jbc->jkey->id, dl))
659 659
 	{
660 660
 		xj_jconf_free(jcf);
661 661
 		return -1;
... ...
@@ -97,11 +97,11 @@ int xj_jcon_send_presence(xj_jcon, char*, char*, char*, char*);
97 97
 int xj_jcon_send_msg(xj_jcon, char*, int, char*, int, int);
98 98
 int xj_jcon_send_sig_msg(xj_jcon, char*, int, char*, int, char*, int);
99 99
 
100
-int xj_jcon_is_ready(xj_jcon, char *, int);
100
+int xj_jcon_is_ready(xj_jcon, char *, int, char);
101 101
 
102
-xj_jconf xj_jcon_get_jconf(xj_jcon, str*);
102
+xj_jconf xj_jcon_get_jconf(xj_jcon, str*, char);
103 103
 xj_jconf xj_jcon_check_jconf(xj_jcon, char*);
104
-int xj_jcon_del_jconf(xj_jcon, str*, int);
104
+int xj_jcon_del_jconf(xj_jcon, str*, char, int);
105 105
 int xj_jcon_jconf_presence(xj_jcon, xj_jconf, char*, char*);
106 106
 
107 107
 /**********             ***/
... ...
@@ -76,7 +76,7 @@ xj_jconf xj_jconf_new(str *u)
76 76
 	return jcf;
77 77
 }
78 78
 
79
-int xj_jconf_init_sip(xj_jconf jcf, str *sid)
79
+int xj_jconf_init_sip(xj_jconf jcf, str *sid, char dl)
80 80
 {
81 81
 	char *p, *p0;
82 82
 	int n = 0;
... ...
@@ -96,7 +96,7 @@ int xj_jconf_init_sip(xj_jconf jcf, str *sid)
96 96
 	while(p0 > jcf->uri.s)
97 97
 	{
98 98
 		p0--;
99
-		if(*p0 == '%')
99
+		if(*p0 == dl)
100 100
 		{
101 101
 			switch(n)
102 102
 			{
... ...
@@ -120,7 +120,7 @@ int xj_jconf_init_sip(xj_jconf jcf, str *sid)
120 120
 	if(n != 2 || p0 != jcf->uri.s)
121 121
 		goto bad_format;
122 122
 
123
-	if(p0 == jcf->uri.s && *p0 != '%')
123
+	if(p0 == jcf->uri.s && *p0 != dl)
124 124
 	{
125 125
 		jcf->nick.s = p0;
126 126
 		jcf->nick.len = p - jcf->nick.s;
... ...
@@ -294,7 +294,7 @@ int xj_jconf_hash(str *x, str *y)
294 294
 	return (h)?h:1;
295 295
 }
296 296
 
297
-int xj_jconf_check_addr(str *addr)
297
+int xj_jconf_check_addr(str *addr, char dl)
298 298
 {
299 299
 	char *p;
300 300
 	int i;
... ...
@@ -306,7 +306,7 @@ int xj_jconf_check_addr(str *addr)
306 306
 	i= 0;
307 307
 	while((p < addr->s+addr->len) && *p != '@')
308 308
 	{
309
-		if(*p=='%')
309
+		if(*p==dl)
310 310
 			i++;
311 311
 		p++;
312 312
 	}
... ...
@@ -51,14 +51,14 @@ typedef struct _xj_jconf
51 51
 } t_xj_jconf, *xj_jconf;
52 52
 
53 53
 xj_jconf xj_jconf_new(str *u);
54
-int xj_jconf_init_sip(xj_jconf jcf, str *sid);
54
+int xj_jconf_init_sip(xj_jconf jcf, str *sid, char dl);
55 55
 int xj_jconf_init_jab(xj_jconf jcf);
56 56
 
57 57
 int xj_jconf_set_status(xj_jconf jcf, int s);
58 58
 
59 59
 int xj_jconf_cmp(void *a, void *b);
60 60
 int xj_jconf_free(xj_jconf jcf);
61
-int xj_jconf_check_addr(str *addr);
61
+int xj_jconf_check_addr(str *addr, char dl);
62 62
 
63 63
 #endif
64 64
 
... ...
@@ -38,6 +38,8 @@
38 38
 #include "xjab_worker.h"
39 39
 #include "mdefines.h"
40 40
 
41
+#define XJ_DEF_JDELIM '*'
42
+
41 43
 /**
42 44
  * init a workers list
43 45
  * - pipes : communication pipes
... ...
@@ -192,6 +194,9 @@ void xj_wlist_free(xj_wlist jwl)
192 192
 
193 193
 	if(jwl->aliases != NULL)
194 194
 	{
195
+		if(jwl->aliases->d)
196
+			_M_SHM_FREE(jwl->aliases->d);
197
+
195 198
 		if(jwl->aliases->jdm != NULL)
196 199
 		{
197 200
 			_M_SHM_FREE(jwl->aliases->jdm->s);
... ...
@@ -352,8 +357,8 @@ error:
352 352
 
353 353
 int  xj_wlist_set_aliases(xj_wlist jwl, char *als, char *jd)
354 354
 {
355
-	char *p, *p0;
356
-	int i;
355
+	char *p, *p0, *p1;
356
+	int i, n;
357 357
 	
358 358
 	DBG("XJAB:xj_wlist_set_aliases\n");
359 359
 	if(jwl == NULL)
... ...
@@ -368,11 +373,21 @@ int  xj_wlist_set_aliases(xj_wlist jwl, char *als, char *jd)
368 368
 	}
369 369
 	
370 370
 	jwl->aliases->jdm = NULL;
371
+	jwl->aliases->dlm = XJ_DEF_JDELIM; // default user part delimitator
371 372
 	jwl->aliases->size = 0;
372 373
 	jwl->aliases->a = NULL;
373
-	
374
-	if(jd != NULL && strlen(jd)>2)
374
+	jwl->aliases->d = NULL;
375
+
376
+	if(jd != NULL && (n=strlen(jd))>2)
375 377
 	{
378
+		p = jd;
379
+		while(p < jd+n && *p!='=')
380
+			p++;
381
+		if(p<jd+n-1)
382
+		{
383
+			jwl->aliases->dlm = *(p+1);
384
+			n = p - jd;
385
+		}
376 386
 		if((jwl->aliases->jdm = (str*)_M_SHM_MALLOC(sizeof(str)))== NULL)
377 387
 		{
378 388
 			DBG("XJAB:xj_wlist_set_aliases: not enough SHMemory!?\n");
... ...
@@ -380,7 +395,7 @@ int  xj_wlist_set_aliases(xj_wlist jwl, char *als, char *jd)
380 380
 			jwl->aliases = NULL;
381 381
 			return -1;		
382 382
 		}
383
-		jwl->aliases->jdm->len = strlen(jd);
383
+		jwl->aliases->jdm->len = n;
384 384
 		if((jwl->aliases->jdm->s=(char*)_M_SHM_MALLOC(jwl->aliases->jdm->len))
385 385
 				== NULL)
386 386
 		{
... ...
@@ -390,6 +405,8 @@ int  xj_wlist_set_aliases(xj_wlist jwl, char *als, char *jd)
390 390
 			jwl->aliases = NULL;
391 391
 		}
392 392
 		strncpy(jwl->aliases->jdm->s, jd, jwl->aliases->jdm->len);
393
+		DBG("XJAB:xj_wlist_set_aliases: jdomain=%.*s delim=%c\n",
394
+			jwl->aliases->jdm->len, jwl->aliases->jdm->s, jwl->aliases->dlm);
393 395
 	}
394 396
 	
395 397
 	if(!als || strlen(als)<2)
... ...
@@ -407,18 +424,19 @@ int  xj_wlist_set_aliases(xj_wlist jwl, char *als, char *jd)
407 407
 		return 0;
408 408
 	}
409 409
 	
410
-	if((jwl->aliases->a = (str*)_M_SHM_MALLOC(jwl->aliases->size*sizeof(str)))
411
-			== NULL)
410
+	jwl->aliases->d = (char*)_M_SHM_MALLOC(jwl->aliases->size*sizeof(char));
411
+	if(jwl->aliases->d == NULL)
412 412
 	{
413 413
 		DBG("XJAB:xj_wlist_set_aliases: not enough SHMemory..\n");
414
-		if(jwl->aliases->jdm)
415
-		{
416
-			_M_SHM_FREE(jwl->aliases->jdm->s);
417
-			_M_SHM_FREE(jwl->aliases->jdm);
418
-		}
419
-		_M_SHM_FREE(jwl->aliases);
420
-		jwl->aliases = NULL;
421
-		return -1;
414
+		goto clean2;
415
+	}
416
+	memset(jwl->aliases->d, 0, jwl->aliases->size);
417
+	
418
+	jwl->aliases->a = (str*)_M_SHM_MALLOC(jwl->aliases->size*sizeof(str));
419
+	if(jwl->aliases->a == NULL)
420
+	{
421
+		DBG("XJAB:xj_wlist_set_aliases: not enough SHMemory..\n");
422
+		goto clean1;
422 423
 	}
423 424
 	
424 425
 	p++;
... ...
@@ -429,7 +447,14 @@ int  xj_wlist_set_aliases(xj_wlist jwl, char *als, char *jd)
429 429
 			DBG("XJAB:xj_wlist_set_aliases: bad parameter value format\n");
430 430
 			goto clean;
431 431
 		}
432
-		jwl->aliases->a[i].len = p0 - p;
432
+		n = p0 - p;
433
+		p1 = strchr(p, '=');
434
+		if(p1 && p1<p0-1)
435
+		{
436
+			jwl->aliases->d[i] = *(p1+1);
437
+			n = p1 - p;
438
+		}
439
+		jwl->aliases->a[i].len = n;
433 440
 		if((jwl->aliases->a[i].s = (char*)_M_SHM_MALLOC(jwl->aliases->a[i].len))
434 441
 				== NULL)
435 442
 		{
... ...
@@ -438,25 +463,31 @@ int  xj_wlist_set_aliases(xj_wlist jwl, char *als, char *jd)
438 438
 		}
439 439
 			
440 440
 		strncpy(jwl->aliases->a[i].s, p, jwl->aliases->a[i].len);
441
-		DBG("XJAB:xj_wlist_set_aliases: alias[%d/%d]=%.*s\n", 
442
-				i+1, jwl->aliases->size, jwl->aliases->a[i].len, 
443
-				jwl->aliases->a[i].s);
441
+		DBG("XJAB:xj_wlist_set_aliases: alias[%d/%d]=%.*s delim=%c\n", 
442
+			i+1, jwl->aliases->size, jwl->aliases->a[i].len, 
443
+			jwl->aliases->a[i].s, jwl->aliases->d[i]?jwl->aliases->d[i]:'X');
444 444
 		p = p0 + 1;
445 445
 	}
446 446
 	return 0;
447 447
 
448 448
 clean:
449
-	if(jwl->aliases->jdm)
450
-	{
451
-		_M_SHM_FREE(jwl->aliases->jdm->s);
452
-		_M_SHM_FREE(jwl->aliases->jdm);
453
-	}
454 449
 	while(i>0)
455 450
 	{
456 451
 		_M_SHM_FREE(jwl->aliases->a[i-1].s);
457 452
 		i--;
458 453
 	}
459 454
 	_M_SHM_FREE(jwl->aliases->a);
455
+
456
+clean1:
457
+	if(jwl->aliases->d)
458
+		_M_SHM_FREE(jwl->aliases->d);
459
+
460
+clean2:
461
+	if(jwl->aliases->jdm)
462
+	{
463
+		_M_SHM_FREE(jwl->aliases->jdm->s);
464
+		_M_SHM_FREE(jwl->aliases->jdm);
465
+	}
460 466
 	_M_SHM_FREE(jwl->aliases);
461 467
 	jwl->aliases = NULL;
462 468
 	return -1;
... ...
@@ -71,27 +71,6 @@ int main_loop = 1;
71 71
 static str jab_gw_name = {"sip_to_jabber_gateway", 21};
72 72
 
73 73
 /**
74
- * send disconnected info to all SIP users associated with worker idx
75
- */
76
-int xj_wlist_send_info(xj_wlist jwl, int idx)
77
-{
78
-	int i;
79
-	xj_jkey p;
80
-	if(jwl==NULL || idx < 0 || idx >= jwl->len || !jwl->workers[idx].sip_ids)
81
-		return -1;
82
-	s_lock_at(jwl->sems, idx);
83
-	for(i=0; (p=(xj_jkey)index234(jwl->workers[idx].sip_ids, i))!=NULL; i++)
84
-	{
85
-		DBG("XJAB:xj_wlist_send_info: sending disconnect message to <%.*s>\n",
86
-			p->id->len, p->id->s);
87
-		xj_send_sip_msgz(p->id, &jab_gw_name, NULL, XJ_DMSG_INF_DISCONNECTED,
88
-			NULL);
89
-	}
90
-	s_unlock_at(jwl->sems, idx);
91
-	return 0;
92
-}
93
-
94
-/**
95 74
  * address corection
96 75
  * alias A~B: flag == 0 => A->B, otherwise B->A
97 76
  */
... ...
@@ -120,10 +99,41 @@ int xj_address_translation(str *src, str *dst, xj_jalias als, int flag)
120 120
 	
121 121
 	/*** checking aliases */
122 122
 	if(als->size > 0)
123
+	{
123 124
 		for(i=0; i<als->size; i++)
124 125
 			if(!strncasecmp(p, als->a[i].s, als->a[i].len))
126
+			{
127
+				if(als->d[i])
128
+				{
129
+					if(flag & XJ_ADDRTR_A2B)
130
+					{
131
+						strncpy(dst->s, src->s, src->len);
132
+						p0 = dst->s;
133
+						while(p0 < dst->s + (p-src->s)) 
134
+						{
135
+							if(*p0 == als->dlm)
136
+								*p0 = als->d[i];
137
+							p0++;
138
+						}
139
+						return 0;
140
+					}
141
+					if(flag & XJ_ADDRTR_B2A)
142
+					{
143
+						strncpy(dst->s, src->s, src->len);
144
+						p0 = dst->s;
145
+						while(p0 < dst->s + (p-src->s)) 
146
+						{
147
+							if(*p0 == als->d[i])
148
+								*p0 = als->dlm;
149
+							p0++;
150
+						}						
151
+						return 0;
152
+					}
153
+				}
125 154
 				goto done;
126
-	
155
+			}
156
+	}
157
+
127 158
 	DBG("XJAB:xj_address_translation:%d: - doing address corection\n", 
128 159
 			_xj_pid);	
129 160
 
... ...
@@ -140,22 +150,22 @@ int xj_address_translation(str *src, str *dst, xj_jalias als, int flag)
140 140
 			DBG("XJAB:xj_address_translation:%d: - that is for"
141 141
 				" Jabber conference\n", _xj_pid);
142 142
 			p0 = p-1;
143
-			while(p0 > src->s && *p0 != '%')
143
+			while(p0 > src->s && *p0 != als->dlm)
144 144
 				p0--;
145 145
 			if(p0 <= src->s)
146 146
 				return -1;
147 147
 			p0--;
148
-			while(p0 > src->s && *p0 != '%')
148
+			while(p0 > src->s && *p0 != als->dlm)
149 149
 				p0--;
150
-			if(*p0 != '%')
150
+			if(*p0 != als->dlm)
151 151
 				return -1;
152 152
 			dst->len = p - p0 - 2;
153 153
 			strncpy(dst->s, p0+1, dst->len);
154 154
 			dst->s[dst->len]=0;
155 155
 			p = dst->s;
156
-			while(p < (dst->s + dst->len) && *p!='%')
156
+			while(p < (dst->s + dst->len) && *p!=als->dlm)
157 157
 				p++;
158
-			if(*p=='%')
158
+			if(*p==als->dlm)
159 159
 				*p = '@';
160 160
 			return 0;
161 161
 		}
... ...
@@ -165,7 +175,7 @@ int xj_address_translation(str *src, str *dst, xj_jalias als, int flag)
165 165
 		dst->len = p - src->s - 1;
166 166
 		strncpy(dst->s, src->s, dst->len);
167 167
 		dst->s[dst->len]=0;
168
-		if((p = strchr(dst->s, '%')) != NULL)
168
+		if((p = strchr(dst->s, als->dlm)) != NULL)
169 169
 			*p = '@';
170 170
 		else
171 171
 		{
... ...
@@ -177,7 +187,7 @@ int xj_address_translation(str *src, str *dst, xj_jalias als, int flag)
177 177
 	}
178 178
 	if(flag & XJ_ADDRTR_B2A)
179 179
 	{
180
-		*(p-1) = '%';
180
+		*(p-1) = als->dlm;
181 181
 		p0 = src->s + src->len;
182 182
 		while(p0 > p)
183 183
 		{
... ...
@@ -238,7 +248,8 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
238 238
 	//signal(SIGQUIT, xj_sig_handler);
239 239
 	signal(SIGSEGV, xj_sig_handler);
240 240
 
241
-	if(!jwl || !jaddress || rank >= jwl->len)
241
+	if(!jwl || !jwl->aliases || !jwl->aliases->jdm 
242
+			|| !jaddress || rank >= jwl->len)
242 243
 	{
243 244
 		DBG("XJAB:xj_worker[%d]:%d: exiting - wrong parameters\n",
244 245
 				rank, _xj_pid);
... ...
@@ -313,13 +324,13 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
313 313
 					jcp->jmqueue.jsm[i]->to.len,jcp->jmqueue.jsm[i]->to.s,
314 314
 					jcp->jmqueue.jsm[i]->msg.len,jcp->jmqueue.jsm[i]->msg.s,
315 315
 					jcp->jmqueue.expire[i]);
316
-			if(xj_jcon_is_ready(jcp->jmqueue.ojc[i], 
317
-					jcp->jmqueue.jsm[i]->to.s, jcp->jmqueue.jsm[i]->to.len))
316
+			if(xj_jcon_is_ready(jcp->jmqueue.ojc[i], jcp->jmqueue.jsm[i]->to.s,
317
+					jcp->jmqueue.jsm[i]->to.len, jwl->aliases->dlm))
318 318
 				continue;
319 319
 
320 320
 			/*** address corection ***/
321 321
 			flag = XJ_ADDRTR_A2B;
322
-			if(!xj_jconf_check_addr(&jcp->jmqueue.jsm[i]->to))
322
+			if(!xj_jconf_check_addr(&jcp->jmqueue.jsm[i]->to,jwl->aliases->dlm))
323 323
 				flag |= XJ_ADDRTR_CON;
324 324
 			
325 325
 			sto.s = buff; 
... ...
@@ -376,8 +387,8 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
376 376
 		switch(jsmsg->type)
377 377
 		{
378 378
 			case XJ_SEND_MESSAGE:
379
-				if(!xj_jconf_check_addr(&jsmsg->to) &&
380
-					(!jbc || !xj_jcon_get_jconf(jbc, &jsmsg->to) ) )
379
+				if(!xj_jconf_check_addr(&jsmsg->to, jwl->aliases->dlm) &&
380
+				(!jbc||!xj_jcon_get_jconf(jbc,&jsmsg->to,jwl->aliases->dlm)))
381 381
 				{
382 382
 					xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
383 383
 						jwl->contact_h, XJ_DMSG_ERR_NOTJCONF, NULL);
... ...
@@ -393,8 +404,9 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
393 393
 				// close the conference session here
394 394
 				if(jbc->nrjconf <= 0)
395 395
 					goto step_w;
396
-				if(!xj_jconf_check_addr(&jsmsg->to))
397
-					xj_jcon_del_jconf(jbc, &jsmsg->to, XJ_JCMD_UNSUBSCRIBE);
396
+				if(!xj_jconf_check_addr(&jsmsg->to, jwl->aliases->dlm))
397
+					xj_jcon_del_jconf(jbc, &jsmsg->to, jwl->aliases->dlm,
398
+						XJ_JCMD_UNSUBSCRIBE);
398 399
 				xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
399 400
 					jwl->contact_h, XJ_DMSG_INF_JCONFEXIT, NULL);
400 401
 				goto step_w;
... ...
@@ -500,9 +512,10 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
500 500
 		
501 501
 step_z:
502 502
 		flag = 0;
503
-		if(!xj_jconf_check_addr(&jsmsg->to))
503
+		if(!xj_jconf_check_addr(&jsmsg->to, jwl->aliases->dlm))
504 504
 		{
505
-			if((jcf = xj_jcon_get_jconf(jbc, &jsmsg->to)) != NULL)
505
+			if((jcf = xj_jcon_get_jconf(jbc, &jsmsg->to, jwl->aliases->dlm))
506
+					!= NULL)
506 507
 			{
507 508
 				if((jsmsg->type == XJ_JOIN_JCONF) &&
508 509
 					!(jcf->status & XJ_JCONF_READY || 
... ...
@@ -535,7 +548,7 @@ step_z:
535 535
 			goto step_w;
536 536
 		
537 537
 		// here will come only XJ_SEND_MESSAGE
538
-		switch(xj_jcon_is_ready(jbc, jsmsg->to.s, jsmsg->to.len))
538
+		switch(xj_jcon_is_ready(jbc,jsmsg->to.s,jsmsg->to.len,jwl->aliases->dlm))
539 539
 		{
540 540
 			case 0:
541 541
 				DBG("XJAB:xj_worker:%d: SENDING THE MESSAGE TO JABBER"
... ...
@@ -1005,6 +1018,9 @@ ready:
1005 1005
 	return err;
1006 1006
 }
1007 1007
 
1008
+/**
1009
+ *
1010
+ */
1008 1011
 void xj_sig_handler(int s) 
1009 1012
 {
1010 1013
 	//signal(SIGTERM, xj_sig_handler);
... ...
@@ -1034,7 +1050,10 @@ int xj_send_sip_msg(str *to, str *from, str *contact, str *msg, int *cbp)
1034 1034
 	int **pcbp = NULL, beg, end, crt;
1035 1035
 	char buf1[1024];
1036 1036
 
1037
-	if(!to || !from || !msg || (cbp && *cbp!=0))
1037
+	if( !to || !to->s || to->len <= 0 
1038
+			|| !from || !from->s || from->len <= 0 
1039
+			|| !msg || !msg->s || msg->len <= 0
1040
+			|| (cbp && *cbp!=0) )
1038 1041
 		return -1;
1039 1042
 
1040 1043
 	// from correction
... ...
@@ -1114,6 +1133,31 @@ int xj_send_sip_msgz(str *to, str *from, str *contact, char *msg, int *cbp)
1114 1114
 	return n;
1115 1115
 }
1116 1116
 
1117
+/**
1118
+ * send disconnected info to all SIP users associated with worker idx
1119
+ */
1120
+int xj_wlist_send_info(xj_wlist jwl, int idx)
1121
+{
1122
+	int i;
1123
+	xj_jkey p;
1124
+	if(jwl==NULL || idx < 0 || idx >= jwl->len || !jwl->workers[idx].sip_ids)
1125
+		return -1;
1126
+	s_lock_at(jwl->sems, idx);
1127
+	for(i=0; (p=(xj_jkey)index234(jwl->workers[idx].sip_ids, i))!=NULL; i++)
1128
+	{
1129
+		DBG("XJAB:xj_wlist_send_info: sending disconnect message to <%.*s>\n",
1130
+			p->id->len, p->id->s);
1131
+		xj_send_sip_msgz(p->id, &jab_gw_name, NULL, XJ_DMSG_INF_DISCONNECTED,
1132
+			NULL);
1133
+	}
1134
+	s_unlock_at(jwl->sems, idx);
1135
+	return 0;
1136
+}
1137
+
1138
+
1139
+/**
1140
+ *
1141
+ */
1117 1142
 void xj_tuac_callback( struct cell *t, struct sip_msg *msg,
1118 1143
 			int code, void *param)
1119 1144
 {
... ...
@@ -42,9 +42,11 @@
42 42
 /**********             ***/
43 43
 typedef struct _xj_jalias
44 44
 {
45
-	int size;
46
-	str *jdm;
47
-	str *a;
45
+	int size;	// number of aliases
46
+	str *jdm;	// Jabber domain
47
+	char dlm;	// user part delimitator
48
+	str *a;		// aliases
49
+	char *d;	// user part delimitator for aliases
48 50
 } t_xj_jalias, *xj_jalias;
49 51
 
50 52
 typedef struct _xj_worker
... ...
@@ -64,7 +66,7 @@ typedef struct _xj_wlist
64 64
 	int delayt;
65 65
 	int sleept;
66 66
 	str *contact_h;		// contact header
67
-    smart_lock	*sems;	 // semaphores
67
+	smart_lock	*sems;	 // semaphores
68 68
 	xj_jalias	aliases; // addess aliases
69 69
 	xj_worker	workers; // the list of workers
70 70
 } t_xj_wlist, *xj_wlist;