Browse code

XJAB module - some bugs fixed - added a monitoring process for Jabber GW workers - confirmation message when someone leaves a conference or Jabber network

Daniel-Constantin Mierla authored on 08/11/2002 15:58:19
Showing 6 changed files
... ...
@@ -33,9 +33,11 @@
33 33
 #include <string.h>
34 34
 #include <stdlib.h>
35 35
 #include <sys/types.h>
36
+#include <sys/wait.h>
36 37
 #include <sys/ipc.h>
37 38
 #include <unistd.h>
38 39
 #include <fcntl.h>
40
+#include <errno.h>
39 41
 
40 42
 #include "../../sr_module.h"
41 43
 #include "../../error.h"
... ...
@@ -43,6 +45,7 @@
43 43
 #include "../../mem/shm_mem.h"
44 44
 #include "../../mem/mem.h"
45 45
 #include "../../globals.h"
46
+#include "../../timer.h"
46 47
 #include "../../parser/parse_uri.h"
47 48
 
48 49
 #include "../im/im_load.h"
... ...
@@ -52,6 +55,7 @@
52 52
 #include "xjab_util.h"
53 53
 #include "../../db/db.h"
54 54
 
55
+
55 56
 /** TM bind */
56 57
 struct tm_binds tmb;
57 58
 /** IM binds */
... ...
@@ -81,6 +85,7 @@ char *jdomain  = NULL;
81 81
 int delay_time = 90;
82 82
 int sleep_time = 20;
83 83
 int cache_time = 600;
84
+int check_time = 20;
84 85
 
85 86
 int **pipes = NULL;
86 87
 
... ...
@@ -88,6 +93,7 @@ static int mod_init(void);
88 88
 static int child_init(int rank);
89 89
 
90 90
 int xjab_manage_sipmsg(struct sip_msg *msg, int type);
91
+void xjab_check_workers(int mpid);
91 92
 
92 93
 static int jab_send_message(struct sip_msg*, char*, char*);
93 94
 static int jab_send_bye(struct sip_msg*, char*, char*);
... ...
@@ -135,7 +141,8 @@ struct module_exports exports= {
135 135
 		"max_jobs",
136 136
 		"cache_time",
137 137
 		"delay_time",
138
-		"sleep_time"
138
+		"sleep_time",
139
+		"check_time"
139 140
 	},
140 141
 	(modparam_t[]) {   /* Module parameter types */
141 142
 		STR_PARAM,
... ...
@@ -161,9 +168,10 @@ struct module_exports exports= {
161 161
 		&max_jobs,
162 162
 		&cache_time,
163 163
 		&delay_time,
164
-		&sleep_time
164
+		&sleep_time,
165
+		&check_time
165 166
 	},
166
-	11,      /* Number of module paramers */
167
+	12,      /* Number of module paramers */
167 168
 	
168 169
 	mod_init,   /* module initialization function */
169 170
 	(response_function) 0,
... ...
@@ -289,41 +297,49 @@ static int mod_init(void)
289 289
  */
290 290
 static int child_init(int rank)
291 291
 {
292
-	int i;
293
-	int *pids = NULL;
292
+	int i, j, mpid, cpid;
294 293
 	
295 294
 	DBG("XJAB:child_init: initializing child <%d>\n", rank);
296 295
 	if(rank == 0)
297 296
 	{
298
-		pids = (int*)pkg_malloc(nrw*sizeof(int));
299
-		if (pids == NULL)
297
+		if((mpid=fork())<0 )
300 298
 		{
301
-			DBG("XJAB:child_init: error while allocating pid's\n");
302
-			return -1;
299
+			DBG("XJAB:child_init: error - cannot launch worker's manager\n");
300
+				return -1;
303 301
 		}
304
-		/** launching the workers */
305
-		for(i=0;i<nrw;i++)
302
+		if(mpid == 0)
306 303
 		{
307
-			if ( (pids[i]=fork())<0 )
304
+			/** launching the workers */
305
+			for(i=0;i<nrw;i++)
308 306
 			{
309
-				DBG("XJAB:child_init: error - cannot launch worker\n");
310
-				return -1;
307
+				if ( (cpid=fork())<0 )
308
+				{
309
+					DBG("XJAB:child_init: error - cannot launch worker\n");
310
+					return -1;
311
+				}
312
+				if (cpid == 0)
313
+				{
314
+					for(j=0;j<nrw;j++)
315
+						if(j!=i) close(pipes[j][0]);
316
+					close(pipes[i][1]);
317
+					if(xj_wlist_set_pid(jwl, getpid(), i) < 0)
318
+					{
319
+						DBG("XJAB:child_init: error setting worker's pid\n");
320
+						return -1;
321
+					}
322
+					xj_worker_process(jwl,jaddress,jport,i,db_con[i]);
323
+					exit(0);
324
+				}
311 325
 			}
312
-			if (pids[i] == 0)
326
+
327
+			mpid = getpid();
328
+			while(1)
313 329
 			{
314
-				close(pipes[i][1]);
315
-				xj_worker_process(jwl,jaddress,jport,pipes[i][0],db_con[i]);
316
-				exit(0);
330
+				sleep(check_time);
331
+				xjab_check_workers(mpid);
317 332
 			}
333
+			exit(0);
318 334
 		}
319
-	
320
-		if(xj_wlist_set_pids(jwl, pids, nrw) < 0)
321
-		{
322
-			DBG("XJAB:child_init: error setting pid's\n");
323
-			return -1;
324
-		}
325
-		if(pids)
326
-			pkg_free(pids);
327 335
 	}
328 336
 	
329 337
 	if(pipes)
... ...
@@ -581,12 +597,13 @@ int xjab_manage_sipmsg(struct sip_msg *msg, int type)
581 581
 
582 582
 	jsmsg->jkey = p;
583 583
 	jsmsg->type = type;
584
-	jsmsg->jkey->hash = jkey.hash;
584
+	//jsmsg->jkey->hash = jkey.hash;
585 585
 
586 586
 	DBG("XJAB:xjab_manage_sipmsg:%d: sending <%p> to worker through <%d>\n",
587 587
 			getpid(), jsmsg, pipe);
588 588
 	// sending the SHM pointer of SIP message to the worker
589
-	if(write(pipe, &jsmsg, sizeof(jsmsg)) != sizeof(jsmsg))
589
+	fl = write(pipe, &jsmsg, sizeof(jsmsg));
590
+	if(fl != sizeof(jsmsg))
590 591
 	{
591 592
 		DBG("XJAB:xjab_manage_sipmsg: error when writting to worker pipe!\n");
592 593
 		if(type == XJ_SEND_MESSAGE)
... ...
@@ -630,3 +647,50 @@ void destroy(void)
630 630
 	DBG("XJAB: Unloaded\n");
631 631
 }
632 632
 
633
+void xjab_check_workers(int mpid)
634
+{
635
+	int i, n, stat;
636
+	DBG("XJAB:%d:xjab_check_workers: time=%d\n", mpid, get_ticks());
637
+	if(!jwl || jwl->len <= 0)
638
+		return;
639
+	for(i=0; i < jwl->len; i++)
640
+	{
641
+		if(jwl->workers[i].pid <= 0)
642
+			continue;
643
+				stat = 0;
644
+		n = waitpid(jwl->workers[i].pid, &stat, WNOHANG);
645
+		if(n == 0)
646
+			continue;
647
+		
648
+		DBG("XJAB:xjab_check_workers: worker[%d][pid=%d] has exited"
649
+			" - status %d err=%d errno=%d\n", i, 
650
+			jwl->workers[i].pid, stat, n, errno);
651
+		if(n==jwl->workers[i].pid)
652
+		{
653
+			DBG("XJAB:%d:xjab_check_workers: create a new worker\n", mpid);
654
+			xj_wlist_set_pid(jwl, -1, i);
655
+			if ( (stat=fork())<0 )
656
+			{
657
+				DBG("XJAB:xjab_check_workers: error - cannot launch worker\n");
658
+				return;
659
+			}
660
+			if (stat == 0)
661
+			{
662
+				if(xj_wlist_set_pid(jwl, getpid(), i) < 0)
663
+				{
664
+					DBG("XJAB:xjab_check_workers: error setting worker's pid\n");
665
+					return;
666
+				}
667
+				xj_worker_process(jwl,jaddress,jport,i,db_con[i]);
668
+				exit(0);
669
+			}
670
+		}
671
+		else
672
+		{
673
+			LOG(L_ERR, "XJAB:xjab_check_workers: error - worker[%d][pid=%d] lost"
674
+				" forever\n", i, jwl->workers[i].pid);
675
+			xj_wlist_set_pid(jwl, -1, i);
676
+		}
677
+	}			
678
+}
679
+
... ...
@@ -46,6 +46,7 @@
46 46
 typedef struct _xj_jkey
47 47
 {
48 48
 	int hash;
49
+	int flag;
49 50
 	str *id;
50 51
 } t_xj_jkey, *xj_jkey;
51 52
 
... ...
@@ -80,14 +80,6 @@ xj_jcon xj_jcon_init(char *hostname, int port)
80 80
 		_M_FREE(jbc);
81 81
 		return NULL;
82 82
 	}
83
-	if((jbc->close = (int*)_M_SHM_MALLOC(sizeof(int)))==NULL)
84
-	{
85
-		_M_FREE(jbc->hostname);
86
-		_M_FREE(jbc);
87
-		return NULL;
88
-
89
-	}
90
-	*jbc->close = 0;
91 83
     strcpy(jbc->hostname, hostname);
92 84
 	jbc->allowed = jbc->ready = XJ_NET_NUL;
93 85
 	jbc->jconf = NULL;
... ...
@@ -474,11 +466,7 @@ int xj_jcon_free(xj_jcon jbc)
474 474
 		_M_FREE(jbc->hostname);
475 475
 	if(jbc->stream_id != NULL)
476 476
 		_M_FREE(jbc->stream_id);
477
-	if(jbc->close != NULL)
478
-	{
479
-		_M_SHM_FREE(jbc->close);
480
-		jbc->close = NULL;
481
-	}
477
+	
482 478
 	if(jbc->resource != NULL)
483 479
 		_M_FREE(jbc->resource);
484 480
 	DBG("XJAB:xj_jcon_free: %d conferences\n", jbc->nrjconf);
... ...
@@ -545,7 +533,7 @@ int xj_jcon_is_ready(xj_jcon jbc, char *to, int tol)
545 545
 		DBG("XJAB: xj_jcon_is_ready: destination=conference\n");
546 546
 		
547 547
 		if((jcf=xj_jcon_get_jconf(jbc, &sto))!=NULL)
548
-			return (jcf->status & XJ_JCONF_READY)?0:1;
548
+			return (jcf->status & XJ_JCONF_READY)?0:3;
549 549
 		
550 550
 		DBG("XJAB: xj_jcon_is_ready: conference does not exist\n");
551 551
 		return -1;
... ...
@@ -75,7 +75,6 @@ typedef struct _xj_jcon
75 75
 	int allowed;	// allowed IM networks
76 76
 	int ready;		// time when the connection is ready for sending messages
77 77
 
78
-	int *close;		// t_uac callback parameter
79 78
 	int nrjconf;	// number of open conferences
80 79
 	tree234 *jconf; // open conferences
81 80
 } t_xj_jcon, *xj_jcon;
... ...
@@ -65,6 +65,10 @@ extern struct tm_binds tmb;
65 65
 int _xj_pid = 0;
66 66
 int main_loop = 1;
67 67
 
68
+/** **/
69
+
70
+static str jab_gw_name = {"sip_to_jabber_gateway", 21};
71
+
68 72
 /**
69 73
  * init a workers list
70 74
  * - pipes : communication pipes
... ...
@@ -106,7 +110,9 @@ xj_wlist xj_wlist_init(int **pipes, int size, int max, int cache_time,
106 106
 	for(i = 0; i < size; i++)
107 107
 	{
108 108
 		jwl->workers[i].nr = 0;
109
-		jwl->workers[i].pipe = pipes[i][1];
109
+		jwl->workers[i].pid = 0;
110
+		jwl->workers[i].wpipe = pipes[i][1];
111
+		jwl->workers[i].rpipe = pipes[i][0];
110 112
 		if((jwl->workers[i].sip_ids = newtree234(xj_jkey_cmp)) == NULL)
111 113
 			goto clean;
112 114
 	}	
... ...
@@ -182,14 +188,13 @@ int xj_wlist_init_contact(xj_wlist jwl, char *ch)
182 182
  * - size : number of pids
183 183
  * #return : 0 on success or <0 on error
184 184
  */
185
-int xj_wlist_set_pids(xj_wlist jwl, int *pids, int size)
185
+int xj_wlist_set_pid(xj_wlist jwl, int pid, int idx)
186 186
 {
187
-	int i;
188
-
189
-	if(jwl == NULL || pids == NULL || size <= 0)
187
+	if(jwl == NULL || pid <= 0 || idx < 0 || idx >= jwl->len)
190 188
 		return -1;
191
-	for(i = 0; i < size; i++)
192
-		jwl->workers[i].pid = pids[i];
189
+	s_lock_at(jwl->sems, idx);
190
+	jwl->workers[idx].pid = pid;
191
+	s_unlock_at(jwl->sems, idx);
193 192
 	return 0;
194 193
 }
195 194
 
... ...
@@ -259,13 +264,19 @@ int xj_wlist_check(xj_wlist jwl, xj_jkey jkey, xj_jkey *p)
259 259
 	while(i < jwl->len)
260 260
 	{
261 261
 		s_lock_at(jwl->sems, i);
262
+		if(jwl->workers[i].pid <= 0)
263
+		{
264
+			s_unlock_at(jwl->sems, i);
265
+			i++;
266
+			continue;
267
+		}
262 268
 		if((*p = find234(jwl->workers[i].sip_ids, (void*)jkey, NULL)) != NULL)
263 269
 		{
264 270
 			s_unlock_at(jwl->sems, i);
265 271
 			DBG("XJAB:xj_wlist_check: entry exists for <%.*s> in the"
266 272
 				" pool of <%d> [%d]\n",jkey->id->len, jkey->id->s,
267 273
 				jwl->workers[i].pid,i);
268
-			return jwl->workers[i].pipe;
274
+			return jwl->workers[i].wpipe;
269 275
 		}
270 276
 		s_unlock_at(jwl->sems, i);
271 277
 		i++;
... ...
@@ -295,6 +306,12 @@ int xj_wlist_get(xj_wlist jwl, xj_jkey jkey, xj_jkey *p)
295 295
 	while(i < jwl->len)
296 296
 	{
297 297
 		s_lock_at(jwl->sems, i);
298
+		if(jwl->workers[i].pid <= 0)
299
+		{
300
+			s_unlock_at(jwl->sems, i);
301
+			i++;
302
+			continue;
303
+		}
298 304
 		if((*p = find234(jwl->workers[i].sip_ids, (void*)jkey, NULL))!=NULL)
299 305
 		{
300 306
 			if(pos >= 0)
... ...
@@ -303,7 +320,7 @@ int xj_wlist_get(xj_wlist jwl, xj_jkey jkey, xj_jkey *p)
303 303
 			DBG("XJAB:xj_wlist_get: entry already exists for <%.*s> in the"
304 304
 				" pool of <%d> [%d]\n",jkey->id->len, jkey->id->s,
305 305
 				jwl->workers[i].pid,i);
306
-			return jwl->workers[i].pipe;
306
+			return jwl->workers[i].wpipe;
307 307
 		}
308 308
 		if(min > jwl->workers[i].nr)
309 309
 		{
... ...
@@ -343,11 +360,12 @@ int xj_wlist_get(xj_wlist jwl, xj_jkey jkey, xj_jkey *p)
343 343
 			msid->id->len = jkey->id->len;
344 344
 			memcpy(msid->id->s, jkey->id->s, jkey->id->len);
345 345
 			msid->hash = jkey->hash;
346
-						s_unlock_at(jwl->sems, pos);
346
+			msid->flag = 0;
347
+			s_unlock_at(jwl->sems, pos);
347 348
 			DBG("XJAB:xj_wlist_get: new entry for <%.*s> in the pool of"
348 349
 				" <%d> - [%d]\n", jkey->id->len, jkey->id->s,
349 350
 				jwl->workers[pos].pid, pos);
350
-			return jwl->workers[pos].pipe;
351
+			return jwl->workers[pos].wpipe;
351 352
 		}
352 353
 		_M_SHM_FREE(msid->id->s);
353 354
 		_M_SHM_FREE(msid->id);
... ...
@@ -639,19 +657,19 @@ done:
639 639
  * - db_con : connection to database
640 640
  * #return : 0 on success or <0 on error
641 641
  */
642
-int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int pipe,
642
+int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int rank,
643 643
 		db_con_t* db_con)
644 644
 {
645
-	int ret, i, pos, maxfd, flag;
645
+	int pipe, ret, i, pos, maxfd, flag;
646 646
 	xj_jcon_pool jcp;
647 647
 	struct timeval tmv;
648 648
 	fd_set set, mset;
649 649
 	xj_sipmsg jsmsg;
650
-	xj_jcon jbc;
651
-	xj_jconf jcf;
650
+	str sto;
651
+	xj_jcon jbc = NULL;
652
+	xj_jconf jcf = NULL;
652 653
 	char *p, buff[1024], recv_buff[4096];
653 654
 	int flags, nr, ltime = 0;
654
-	str sto;
655 655
 	
656 656
 	db_key_t keys[] = {"sip_id", "type"};
657 657
 	db_val_t vals[] = { {DB_STRING, 0, {.string_val = buff}},
... ...
@@ -664,9 +682,19 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int pipe,
664 664
 	signal(SIGTERM, xj_sig_handler);
665 665
 	signal(SIGINT, xj_sig_handler);
666 666
 	signal(SIGQUIT, xj_sig_handler);
667
-	
668
-	DBG("XJAB:xj_worker:%d: started - pipe=<%d> : 1st message delay"
669
-		" <%d>\n", _xj_pid, pipe, jwl->delayt);
667
+	signal(SIGSEGV, xj_sig_handler);
668
+
669
+	if(!jwl || !jaddress || rank >= jwl->len)
670
+	{
671
+		DBG("XJAB:xj_worker[%d]:%d: exiting - wrong parameters\n",
672
+				rank, _xj_pid);
673
+		return -1;
674
+	}
675
+
676
+	pipe = jwl->workers[rank].rpipe;
677
+
678
+	DBG("XJAB:xj_worker[%d]:%d: started - pipe=<%d> : 1st message delay"
679
+		" <%d>\n", rank, _xj_pid, pipe, jwl->delayt);
670 680
 
671 681
 	if((jcp=xj_jcon_pool_init(jwl->maxj,XJ_POOL_SIZE,jwl->delayt))==NULL)
672 682
 	{
... ...
@@ -685,8 +713,8 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int pipe,
685 685
 		mset = set;
686 686
 
687 687
 		tmv.tv_sec = (jcp->jmqueue.size == 0)?jwl->sleept:1;
688
-		DBG("XJAB:xj_worker:%d: select waiting %ds - queue=%d\n",_xj_pid,
689
-				(int)tmv.tv_sec, jcp->jmqueue.size);
688
+		DBG("XJAB:xj_worker[%d]:%d: select waiting %ds - queue=%d\n",rank,
689
+				_xj_pid, (int)tmv.tv_sec, jcp->jmqueue.size);
690 690
 		tmv.tv_usec = 0;
691 691
 
692 692
 		ret = select(maxfd+1, &mset, NULL, NULL, &tmv);
... ...
@@ -713,7 +741,7 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int pipe,
713 713
 				xj_send_sip_msgz(jcp->jmqueue.jsm[i]->jkey->id, 
714 714
 						&jcp->jmqueue.jsm[i]->to, jwl->contact_h, 
715 715
 						"ERROR: Your message was not sent. Conection to IM"
716
-						" network failed.", jcp->jmqueue.ojc[i]->close);
716
+						" network failed.", &jcp->jmqueue.ojc[i]->jkey->flag);
717 717
 				if(jcp->jmqueue.jsm[i]!=NULL)
718 718
 				{
719 719
 					xj_sipmsg_free(jcp->jmqueue.jsm[i]);
... ...
@@ -724,6 +752,14 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int pipe,
724 724
 				continue;
725 725
 			}
726 726
 
727
+			DBG("XJAB:xj_worker:%d:%d: QUEUE: message[%d] from [%.*s]/to [%.*s]/"
728
+					"body[%.*s] expires at %d\n",
729
+					_xj_pid, get_ticks(), i, 
730
+					jcp->jmqueue.jsm[i]->jkey->id->len,
731
+					jcp->jmqueue.jsm[i]->jkey->id->s,
732
+					jcp->jmqueue.jsm[i]->to.len,jcp->jmqueue.jsm[i]->to.s,
733
+					jcp->jmqueue.jsm[i]->msg.len,jcp->jmqueue.jsm[i]->msg.s,
734
+					jcp->jmqueue.expire[i]);
727 735
 			if(xj_jcon_is_ready(jcp->jmqueue.ojc[i], 
728 736
 					jcp->jmqueue.jsm[i]->to.s, jcp->jmqueue.jsm[i]->to.len))
729 737
 				continue;
... ...
@@ -740,8 +776,8 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int pipe,
740 740
 			{
741 741
 		
742 742
 				/** send message from queue */
743
-				DBG("XJAB:xj_worker:%d: SENDING AS JABBER MESSAGE FROM "
744
-					" LOCAL QUEUE ...\n", _xj_pid);
743
+				DBG("XJAB:xj_worker:%d: SENDING THE MESSAGE FROM "
744
+					" LOCAL QUEUE TO JABBER NETWORK ...\n", _xj_pid);
745 745
 				xj_jcon_send_msg(jcp->jmqueue.ojc[i],
746 746
 					sto.s, sto.len,
747 747
 					jcp->jmqueue.jsm[i]->msg.s,
... ...
@@ -749,8 +785,8 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int pipe,
749 749
 					(flag&XJ_ADDRTR_CON)?XJ_JMSG_GROUPCHAT:XJ_JMSG_CHAT);
750 750
 			}
751 751
 			else
752
-				DBG("XJAB:xj_worker:%d: ERROR SENDING AS JABBER MESSAGE FROM "
753
-				" LOCAL QUEUE ...\n", _xj_pid);
752
+				DBG("XJAB:xj_worker:%d: ERROR SENDING THE MESSAGE FROM "
753
+				" LOCAL QUEUE TO JABBER NETWORK ...\n", _xj_pid);
754 754
 				
755 755
 			if(jcp->jmqueue.jsm[i]!=NULL)
756 756
 			{
... ...
@@ -787,6 +823,16 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int pipe,
787 787
 		switch(jsmsg->type)
788 788
 		{
789 789
 			case XJ_SEND_MESSAGE:
790
+				if(!xj_jconf_check_addr(&jsmsg->to) &&
791
+					(!jbc || !xj_jcon_get_jconf(jbc, &jsmsg->to) ) )
792
+				{
793
+					xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
794
+						jwl->contact_h, "ERROR: Your message was not"
795
+						" sent. You are not joined in the conference.",
796
+						NULL);
797
+					goto step_w;
798
+				}
799
+				break;
790 800
 			case XJ_JOIN_JCONF:
791 801
 			case XJ_GO_ONLINE:
792 802
 				break;
... ...
@@ -798,10 +844,13 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int pipe,
798 798
 					goto step_w;
799 799
 				if(!xj_jconf_check_addr(&jsmsg->to))
800 800
 					xj_jcon_del_jconf(jbc, &jsmsg->to, XJ_JCMD_UNSUBSCRIBE);
801
+				xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
802
+					jwl->contact_h, "INFO: Your have just left"
803
+					" the conference.", NULL);
801 804
 				goto step_w;
802 805
 			case XJ_GO_OFFLINE:
803 806
 				if(jbc != NULL)
804
-					jbc->expire = ltime = 0;
807
+					jbc->expire = ltime = -1;
805 808
 				goto step_w;
806 809
 			case XJ_SEND_SUBSCRIBE:
807 810
 			case XJ_SEND_BYE:
... ...
@@ -842,7 +891,7 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int pipe,
842 842
 			xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to, 
843 843
 				jwl->contact_h, "ERROR: Your message was"
844 844
 				" not sent. Cannot connect to the Jabber"
845
-				" server.", jbc->close);
845
+				" server.", &jbc->jkey->flag);
846 846
 
847 847
 			goto step_v;
848 848
 		}
... ...
@@ -863,7 +912,7 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int pipe,
863 863
 			xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
864 864
 				jwl->contact_h, "ERROR: Your message"
865 865
 				" was not sent. Authentication to the"
866
-				" Jabber server failed.", jbc->close);
866
+				" Jabber server failed.", &jbc->jkey->flag);
867 867
 			
868 868
 			xj_jcon_free(jbc);
869 869
 			goto step_v;
... ...
@@ -877,7 +926,7 @@ int xj_worker_process(xj_wlist jwl, char* jaddress, int jport, int pipe,
877 877
 			xj_jcon_disconnect(jbc);
878 878
 			xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to, jwl->contact_h,	
879 879
 				"ERROR:Your message was	not sent. SIP-2-JABBER"
880
-				" gateway is full.", jbc->close);
880
+				" gateway is full.", &jbc->jkey->flag);
881 881
 			xj_jcon_free(jbc);
882 882
 			goto step_v;
883 883
 		}
... ...
@@ -912,7 +961,8 @@ step_z:
912 912
 		{
913 913
 			if((jcf = xj_jcon_get_jconf(jbc, &jsmsg->to)) != NULL)
914 914
 			{
915
-				if(!(jcf->status & XJ_JCONF_READY || 
915
+				if((jsmsg->type == XJ_JOIN_JCONF) &&
916
+					!(jcf->status & XJ_JCONF_READY || 
916 917
 						jcf->status & XJ_JCONF_WAITING))
917 918
 				{
918 919
 					if(!xj_jcon_jconf_presence(jbc,jcf,NULL,"online"))
... ...
@@ -923,7 +973,7 @@ step_z:
923 923
 						// --- send back to SIP user a msg
924 924
 						xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to, 
925 925
 							jwl->contact_h,"ERROR:Cannot join the"
926
-							" conference room.", jbc->close);
926
+							" conference room.", &jbc->jkey->flag);
927 927
 						goto step_w;
928 928
 					}
929 929
 				}
... ...
@@ -935,7 +985,7 @@ step_z:
935 935
 				// --- send back to SIP user a msg
936 936
 				xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to, 
937 937
 					jwl->contact_h,"ERROR:Cannot create a new"
938
-					" conference session.", jbc->close);
938
+					" conference session.", &jbc->jkey->flag);
939 939
 				goto step_w;
940 940
 			}
941 941
 		}
... ...
@@ -946,8 +996,8 @@ step_z:
946 946
 		switch(xj_jcon_is_ready(jbc, jsmsg->to.s, jsmsg->to.len))
947 947
 		{
948 948
 			case 0:
949
-				DBG("XJAB:xj_worker:%d: SENDING AS JABBER"
950
-					" MESSAGE ...\n", _xj_pid);
949
+				DBG("XJAB:xj_worker:%d: SENDING THE MESSAGE TO JABBER"
950
+					" NETWORK ...\n", _xj_pid);
951 951
 				/*** address corection ***/
952 952
 				sto.s = buff; 
953 953
 				sto.len = 0;
... ...
@@ -962,7 +1012,7 @@ step_z:
962 962
 						xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
963 963
 							jwl->contact_h, "ERROR: Your message was not"
964 964
 							" sent. Something wrong during transmition to"
965
-							" Jabber.", jbc->close);
965
+							" Jabber.", &jbc->jkey->flag);
966 966
 				}
967 967
 				else
968 968
 					DBG("XJAB:xj_worker:%d: ERROR SENDING AS JABBER"
... ...
@@ -977,6 +1027,10 @@ step_z:
977 977
 				{
978 978
 					DBG("XJAB:xj_worker:%d: SCHEDULING THE"
979 979
 						" MESSAGE FAILED. Message was droped.\n",_xj_pid);
980
+					xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
981
+						jwl->contact_h, "ERROR: Your message was not"
982
+						" sent. Something wrong during transmition to"
983
+						" Jabber!", &jbc->jkey->flag);
980 984
 					goto step_w;
981 985
 				}
982 986
 				else // skip freeing the SIP message - now is in queue
... ...
@@ -986,14 +1040,20 @@ step_z:
986 986
 				xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
987 987
 						jwl->contact_h, "ERROR: Your message was not"
988 988
 						" sent. You are not registered with this transport.",
989
-						jbc->close);
989
+						&jbc->jkey->flag);
990 990
 				goto step_w;
991
-			
991
+			case 3:
992
+				xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
993
+						jwl->contact_h, "ERROR: Your message was not"
994
+						" sent. You are not joined in the conference.",
995
+						&jbc->jkey->flag);
996
+				goto step_w;
997
+				
992 998
 			default:
993 999
 				xj_send_sip_msgz(jsmsg->jkey->id, &jsmsg->to,
994 1000
 						jwl->contact_h, "ERROR: Your message was not"
995 1001
 						" sent. Something wrong during transmition to"
996
-						" Jabber.", jbc->close);
1002
+						" Jabber.", &jbc->jkey->flag);
997 1003
 				goto step_w;
998 1004
 		}
999 1005
 
... ...
@@ -1057,9 +1117,13 @@ step_y:
1057 1057
 					DBG("XJAB:xj_worker:%d: ERROR -"
1058 1058
 						" connection to jabber lost on socket <%d> ...\n",
1059 1059
 						_xj_pid, jcp->ojc[i]->sock);
1060
-					jcp->ojc[i]->sock = -1;
1061
-					jcp->ojc[i]->expire = ltime = 0;
1062
-					break;
1060
+					xj_send_sip_msgz(jcp->ojc[i]->jkey->id, &jab_gw_name, 
1061
+						jwl->contact_h,"ERROR:Connection to Jabber server"
1062
+						" lost. You have to re-login.", &jbc->jkey->flag);
1063
+					// make sure that will ckeck expired connections
1064
+					ltime = jcp->ojc[i]->expire = -1;
1065
+					FD_CLR(jcp->ojc[i]->sock, &set);
1066
+					goto step_xx;
1063 1067
 				}
1064 1068
 				DBG("XJAB:xj_worker:%d: received: %dbytes Err:%d/EA:%d\n", 
1065 1069
 						_xj_pid, nr, errno, EAGAIN);		
... ...
@@ -1109,8 +1173,8 @@ step_x:
1109 1109
 				}
1110 1110
 			}
1111 1111
 		}
1112
-
1113
-		if(ltime + jwl->sleept <= get_ticks())
1112
+step_xx:
1113
+		if(ltime < 0 || ltime + jwl->sleept <= get_ticks())
1114 1114
 		{
1115 1115
 			ltime = get_ticks();
1116 1116
 			DBG("XJAB:xj_worker:%d: scanning for expired connection\n",
... ...
@@ -1119,16 +1183,20 @@ step_x:
1119 1119
 			{
1120 1120
 				if(jcp->ojc[i] == NULL)
1121 1121
 					continue;
1122
-				if((jcp->ojc[i]->close == NULL || *(jcp->ojc[i]->close)==0) &&
1122
+				if(jcp->ojc[i]->jkey->flag==0 &&
1123 1123
 					jcp->ojc[i]->expire > ltime)
1124 1124
 					continue;
1125 1125
 				
1126 1126
 				DBG("XJAB:xj_worker:%d: connection expired for"
1127 1127
 					" <%.*s> \n", _xj_pid, jcp->ojc[i]->jkey->id->len,
1128 1128
 					jcp->ojc[i]->jkey->id->s);
1129
-				if(jcp->ojc[i]->close != NULL)
1130
-					DBG("XJAB:xj_worker:%d: connection's close flag [%p=%d]\n",
1131
-						_xj_pid, jcp->ojc[i]->close, *(jcp->ojc[i]->close));
1129
+
1130
+				xj_send_sip_msgz(jcp->ojc[i]->jkey->id,  &jab_gw_name,
1131
+					jwl->contact_h, "INFO: Your are now offline in"
1132
+					" Jabber network.", NULL);
1133
+
1134
+				DBG("XJAB:xj_worker:%d: connection's close flag =%d\n",
1135
+						_xj_pid, jcp->ojc[i]->jkey->flag);
1132 1136
 				// CLEAN JAB_WLIST
1133 1137
 				xj_wlist_del(jwl, jcp->ojc[i]->jkey, _xj_pid);
1134 1138
 
... ...
@@ -1152,10 +1220,10 @@ step_x:
1152 1152
 				jcp->ojc[i] = NULL;
1153 1153
 			}
1154 1154
 		}
1155
-
1156 1155
 	} // END while
1157 1156
 
1158 1157
 	DBG("XJAB:xj_worker:%d: cleaning procedure\n", _xj_pid);
1158
+
1159 1159
 	return 0;
1160 1160
 } // end xj_worker_process
1161 1161
 
... ...
@@ -1245,7 +1313,7 @@ int xj_manage_jab(char *buf, int len, int *pos, str *sid,
1245 1245
 			ts.s = lbuf;
1246 1246
 			ts.len = strlen(lbuf);
1247 1247
 	
1248
-			if(xj_send_sip_msg(sid, &jcf->uri, sct, &ts, jbc->close) < 0)
1248
+			if(xj_send_sip_msg(sid, &jcf->uri, sct, &ts, &jbc->jkey->flag)<0)
1249 1249
 				DBG("XJAB:xj_manage_jab: ERROR SIP MESSAGE was not sent!\n");
1250 1250
 			else
1251 1251
 				DBG("XJAB:xj_manage_jab: SIP MESSAGE was sent!\n");
... ...
@@ -1262,7 +1330,7 @@ int xj_manage_jab(char *buf, int len, int *pos, str *sid,
1262 1262
 			ts.s = lbuf;
1263 1263
 			ts.len = strlen(lbuf);
1264 1264
 	
1265
-			if(xj_send_sip_msg(sid, &tf, sct, &ts, jbc->close) < 0)
1265
+			if(xj_send_sip_msg(sid, &tf, sct, &ts, &jbc->jkey->flag) < 0)
1266 1266
 				DBG("XJAB:xj_manage_jab: ERROR SIP MESSAGE was not sent ...\n");
1267 1267
 			else
1268 1268
 				DBG("XJAB:xj_manage_jab: SIP MESSAGE was sent.\n");
... ...
@@ -1293,11 +1361,11 @@ int xj_manage_jab(char *buf, int len, int *pos, str *sid,
1293 1293
 				{
1294 1294
 					xj_send_sip_msgz(sid, &tf, sct, "ERROR: Your nickname"
1295 1295
 					" already exists in the room. Please choose a new one.",
1296
-					jbc->close);
1296
+					&jbc->jkey->flag);
1297 1297
 					goto ready;
1298 1298
 				}
1299 1299
 				xj_send_sip_msgz(sid, &tf, sct, "ERROR: Your participation"
1300
-					" to the conference room was refused.", jbc->close);
1300
+					" to the conference room was refused.", &jbc->jkey->flag);
1301 1301
 			}
1302 1302
 
1303 1303
 			goto ready;
... ...
@@ -1395,6 +1463,9 @@ ready:
1395 1395
 void xj_sig_handler(int s) 
1396 1396
 {
1397 1397
 	signal(SIGTERM, xj_sig_handler);
1398
+	signal(SIGINT, xj_sig_handler);
1399
+	signal(SIGQUIT, xj_sig_handler);
1400
+	signal(SIGSEGV, xj_sig_handler);
1398 1401
 	main_loop = 0;
1399 1402
 	DBG("XJAB:xj_worker:%d: SIGNAL received=%d\n", _xj_pid, s);
1400 1403
 }
... ...
@@ -1498,10 +1569,14 @@ void xj_tuac_callback( struct cell *t, struct sip_msg *msg,
1498 1498
 		DBG("XJAB: m_tuac_callback: parameter not received\n");
1499 1499
 		return;
1500 1500
 	}
1501
-	DBG("XJAB: xj_tuac_callback: parameter [%p == %d]\n", t->cbp,
1502
-					(t->cbp)?*(*((int**)t->cbp)):0);
1501
+	DBG("XJAB: xj_tuac_callback: parameter [%p : ex-value=%d]\n", t->cbp,
1502
+					*(*((int**)t->cbp)) );
1503 1503
 	if(code < 200 || code >= 300)
1504
+	{
1505
+		DBG("XJAB: xj_tuac_callback: no 2XX return code - connection set"
1506
+			" as expired \n");
1504 1507
 		*(*((int**)t->cbp)) = 1;	
1508
+	}
1505 1509
 }
1506 1510
 
1507 1511
 /*****************************     ****************************************/
... ...
@@ -50,7 +50,8 @@ typedef struct _xj_jalias
50 50
 typedef struct _xj_worker
51 51
 {
52 52
 	int pid;			// process id
53
-	int pipe;			// communication pipe
53
+	int wpipe;			// communication pipe - write
54
+	int rpipe;			// communication pipe - read
54 55
 	int nr;				// number of jobs
55 56
 	tree234 *sip_ids;   // sip ids allocated for the worker
56 57
 } t_xj_worker, *xj_worker;
... ...
@@ -72,7 +73,7 @@ typedef struct _xj_wlist
72 72
 
73 73
 xj_wlist xj_wlist_init(int **, int, int, int, int, int);
74 74
 int  xj_wlist_init_contact(xj_wlist, char *);
75
-int  xj_wlist_set_pids(xj_wlist, int *, int);
75
+int  xj_wlist_set_pid(xj_wlist, int, int);
76 76
 int  xj_wlist_get(xj_wlist, xj_jkey, xj_jkey*);
77 77
 int  xj_wlist_check(xj_wlist, xj_jkey, xj_jkey*);
78 78
 void xj_wlist_del(xj_wlist, xj_jkey, int);