Browse code

Jabber module

Daniel-Constantin Mierla authored on 12/08/2002 16:26:34
Showing 8 changed files
... ...
@@ -25,9 +25,10 @@
25 25
 #include "jc_pool.h"
26 26
 #include "../../db/db.h"
27 27
 
28
+/** workers list */
28 29
 jab_wlist jwl = NULL;
29 30
 
30
-/* Structure that represents database connection */
31
+/** Structure that represents database connection */
31 32
 db_con_t** db_con;
32 33
 
33 34
 /** parameters */
... ...
@@ -57,17 +58,17 @@ void destroy(void);
57 58
 struct module_exports exports= {
58 59
 	"jabber",
59 60
 	(char*[]){
60
-				"jab_send_message"
61
-			},
61
+		"jab_send_message"
62
+	},
62 63
 	(cmd_function[]){
63
-					jab_send_message
64
-					},
64
+		jab_send_message
65
+	},
65 66
 	(int[]){
66
-				0
67
-			},
67
+		0
68
+	},
68 69
 	(fixup_function[]){
69
-				0
70
-		},
70
+		0
71
+	},
71 72
 	1,
72 73
 
73 74
 	(char*[]) {   /* Module parameter names */
... ...
@@ -119,7 +120,7 @@ static int mod_init(void)
119 120
 {
120 121
 	int  i;
121 122
 
122
-	DBG("JABBER: initializing\n");
123
+	DBG("JABBER: initializing ...\n");
123 124
 	
124 125
 	if (bind_dbmod())
125 126
 	{
... ...
@@ -175,7 +176,8 @@ static int mod_init(void)
175 176
 			DBG("JABBER: ERROR: mod_init: cannot create pipe!\n");
176 177
 			return -4;
177 178
 		}
178
-		DBG("JABBER: INIT: pipe[%d] = <%d>-<%d>\n", i, pipes[i][0], pipes[i][1]);
179
+		DBG("JABBER: INIT: pipe[%d] = <%d>-<%d>\n", i, pipes[i][0],
180
+			pipes[i][1]);
179 181
 	}
180 182
 	
181 183
 	if((jwl = jab_wlist_init(pipes, nrw, max_jobs)) == NULL)
... ...
@@ -190,7 +192,7 @@ static int mod_init(void)
190 192
 		return -1;
191 193
 	}
192 194
 	
193
-	
195
+	DBG("JABBER: mod_init: initialized ...\n");	
194 196
 	return 0;
195 197
 }
196 198
 
... ...
@@ -222,7 +224,8 @@ static int child_init(int rank)
222 224
 			if (pids[i] == 0)
223 225
 			{
224 226
 				close(pipes[i][1]);
225
-				worker_process(jwl, jaddress, jport, pipes[i][0], max_jobs, cache_time, sleep_time, delay_time, db_con[i]);
227
+				worker_process(jwl, jaddress, jport, pipes[i][0], max_jobs,
228
+					cache_time,	sleep_time, delay_time, db_con[i]);
226 229
 				exit(0);
227 230
 			}
228 231
 		}
... ...
@@ -240,9 +243,6 @@ static int child_init(int rank)
240 243
 	{
241 244
 		for(i=0;i<nrw;i++)
242 245
 			close(pipes[i][0]);
243
-		//for(i = 0; i < nrw; i++)
244
-		//	pkg_free(pipes[i]);
245
-		//pkg_free(pipes);
246 246
 	}
247 247
 	return 0;
248 248
 }
... ...
@@ -268,7 +268,8 @@ static int jab_send_message(struct sip_msg *msg, char* foo1, char * foo2)
268 268
 	if(msg->from != NULL)
269 269
 	{
270 270
 		memset( &from , 0, sizeof(from) );
271
-		parse_to(msg->from->body.s, msg->from->body.s + msg->from->body.len + 1, &from);
271
+		parse_to(msg->from->body.s, msg->from->body.s + msg->from->body.len+1,
272
+						&from);
272 273
 		if(from.error == PARSE_OK)
273 274
 			DBG("JABBER: jab_send_message: From parsed OK.\n");
274 275
 		else
... ...
@@ -299,9 +300,10 @@ static int jab_send_message(struct sip_msg *msg, char* foo1, char * foo2)
299 300
 	} else if ( msg->first_line.u.request.uri.len > 0 )
300 301
 	{
301 302
 		DBG("JABBER: jab_send_message: parsing URI from first line\n");
302
-		if(parse_uri(msg->first_line.u.request.uri.s, msg->first_line.u.request.uri.len, &_uri) < 0)
303
+		if(parse_uri(msg->first_line.u.request.uri.s,
304
+					msg->first_line.u.request.uri.len, &_uri) < 0)
303 305
 		{
304
-			DBG("JABBER: jab_send_message: ERROR parsing URI from first line\n");
306
+			DBG("JABBER:jab_send_message:ERROR parsing URI from first line\n");
305 307
 			goto error;
306 308
 		}
307 309
 		if(_uri.user.len > 0)
... ...
@@ -315,10 +317,12 @@ static int jab_send_message(struct sip_msg *msg, char* foo1, char * foo2)
315 317
 	if(dst.len == 0 && msg->to != NULL)
316 318
 	{
317 319
 		memset( &to , 0, sizeof(to) );
318
-		parse_to(msg->to->body.s, msg->to->body.s + msg->to->body.len + 1, &to);
320
+		parse_to(msg->to->body.s, msg->to->body.s + msg->to->body.len + 1,
321
+				&to);
319 322
 		if(to.uri.len > 0) // to.error == PARSE_OK)
320 323
 		{
321
-			DBG("JABBER: jab_send_message: TO parsed OK <%.*s>.\n", to.uri.len, to.uri.s);
324
+			DBG("JABBER: jab_send_message: TO parsed OK <%.*s>.\n",
325
+				to.uri.len, to.uri.s);
322 326
 			dst.s = to.uri.s;
323 327
 			dst.len = to.uri.len;
324 328
 		}
... ...
@@ -330,7 +334,7 @@ static int jab_send_message(struct sip_msg *msg, char* foo1, char * foo2)
330 334
 	}
331 335
 	if(dst.len == 0)
332 336
 	{
333
-		DBG("JABBER: jab_send_message: destination not found in SIP message\n");
337
+		DBG("JABBER:jab_send_message: destination not found in SIP message\n");
334 338
 		goto error;
335 339
 	}
336 340
 	
... ...
@@ -355,7 +359,7 @@ static int jab_send_message(struct sip_msg *msg, char* foo1, char * foo2)
355 359
 		DBG("JABBER: DESTINATION corrected <%.*s>.\n", dst.len, dst.s);
356 360
 	}
357 361
 	
358
-	// putting the SIP message parts in share memory to be accessible by workers
362
+	//putting the SIP message parts in share memory to be accessible by workers
359 363
     jsmsg = (jab_sipmsg)shm_malloc(sizeof(t_jab_sipmsg));
360 364
     if(jsmsg == NULL)
361 365
     	return -1;
... ...
@@ -380,11 +384,12 @@ static int jab_send_message(struct sip_msg *msg, char* foo1, char * foo2)
380 384
 	
381 385
 	jsmsg->from = p;
382 386
 	
383
-	DBG("JABBER: jab_send_message[%d]: sending <%p> to worker through <%d>\n", getpid(), jsmsg, pipe);
387
+	DBG("JABBER: jab_send_message[%d]: sending <%p> to worker through <%d>\n",
388
+			getpid(), jsmsg, pipe);
384 389
 	// sending the SHM pointer of SIP message to the worker
385 390
 	if(write(pipe, &jsmsg, sizeof(jsmsg)) != sizeof(jsmsg))
386 391
 	{
387
-		DBG("JABBER: jab_send_message: error when writting to worker pipe!!!\n");
392
+		DBG("JABBER: jab_send_message: error when writting to worker pipe!\n");
388 393
 		goto error;
389 394
 	}
390 395
 	
... ...
@@ -406,6 +411,7 @@ void destroy(void)
406 411
 			pkg_free(pipes[i]);
407 412
 		pkg_free(pipes);
408 413
 	}
414
+	// cleaning MySQL connections
409 415
 	if(db_con != NULL)
410 416
 	{
411 417
 		for(i = 0; i<nrw; i++)
... ...
@@ -22,9 +22,6 @@
22 22
 #include "xml_jab.h"
23 23
 #include "mdefines.h"
24 24
 
25
-#define SEM_KEY		(key_t)ftok("/etc/passwd", 'A')
26
-//#define SIP_MESSAGE "MESSAGE %s SIP/2.0\r\nVia: SIP/2.0/UDP 193.175.135.68:7895\r\nFrom: <sip:%s>;tag=xwer-gfshs-2537-yui\r\nTo: <%s>\r\nCall-ID: asd88asd77a@193.175.135.68\r\nContact: <sip:193.175.135.68:7895>\r\nCSeq: %d MESSAGE\r\nContent-Type: text/plain\r\nContent-Length: %d\r\n\r\n%s"
27
-#define SIP_MESSAGE "MESSAGE %.*s SIP/2.0\r\nVia: SIP/2.0/UDP 193.175.135.68:9\r\nFrom: <sip:%s>;tag=xwer-gfshs-2537-yuQi\r\nTo: <%.*s>\r\n%sCall-ID: %s_%d@193.175.135.68\r\nCSeq: %d MESSAGE\r\nContent-Type: text/plain\r\nContent-Length: %d\r\n\r\n%s"
28 25
 
29 26
 /**
30 27
  * function used to compare two elements in B-Tree
... ...
@@ -36,7 +33,8 @@ int k_cmp(void *a, void *b)
36 33
 	    return -1;
37 34
 	if(a == NULL)
38 35
 	    return 1;
39
-	// DBG("JABBER: k_kmp: comparing <%.*s> / <%.*s>\n", ((str *)a)->len, ((str *)a)->s, ((str *)b)->len, ((str *)b)->s);
36
+	// DBG("JABBER: k_kmp: comparing <%.*s> / <%.*s>\n", ((str *)a)->len,
37
+	// 		((str *)a)->s, ((str *)b)->len, ((str *)b)->s);
40 38
 	if(((str *)a)->len != ((str *)b)->len)
41 39
 		return -1;
42 40
 	n = strncmp(((str *)a)->s, ((str *)b)->s, ((str *)a)->len);
... ...
@@ -99,7 +97,6 @@ jab_wlist jab_wlist_init(int **pipes, int size, int max)
99 97
 	jwl->len = size;
100 98
 	jwl->maxj = max;
101 99
 	jwl->contact_h = NULL;
102
-	//jwl->semid = init_mutex(SEM_KEY);
103 100
 	if((jwl->sems = create_semaphores(size)) == NULL)
104 101
 	{
105 102
 		_M_SHM_FREE(jwl);
... ...
@@ -139,7 +136,7 @@ int jab_wlist_init_contact(jab_wlist jwl, char *ch)
139 136
 	if((jwl->contact_h = (str*)_M_SHM_MALLOC(sizeof(str))) == NULL)
140 137
 		return -1;
141 138
 	jwl->contact_h->len = strlen(ch);
142
-	if((jwl->contact_h->s = (char*)_M_SHM_MALLOC(jwl->contact_h->len+1)) == NULL)
139
+	if((jwl->contact_h->s=(char*)_M_SHM_MALLOC(jwl->contact_h->len+1))==NULL)
143 140
 	{
144 141
 		_M_SHM_FREE(jwl->contact_h);
145 142
 		return -2;
... ...
@@ -199,9 +196,11 @@ void jab_wlist_free(jab_wlist jwl)
199 196
 }
200 197
 
201 198
 /**
202
- * return communication pipe with the worker that will process the message for the id 'sid', or -1 if error
199
+ * return communication pipe with the worker that will process the message for
200
+ * 		the id 'sid', or -1 if error
203 201
  * - jwl : pointer to the workers list
204
- * - sid : id of the entity (connection to Jabber - usually SHOULD be FROM header of the incomming SIP message)
202
+ * - sid : id of the entity (connection to Jabber - usually SHOULD be FROM 
203
+ *   header of the incomming SIP message)
205 204
  * - p : will point to the SHM location of the 'sid' in jwl
206 205
  */
207 206
 int jab_wlist_get(jab_wlist jwl, str *sid, str **p)
... ...
@@ -224,7 +223,8 @@ int jab_wlist_get(jab_wlist jwl, str *sid, str **p)
224 223
 			if(pos >= 0)
225 224
 				s_unlock_at(jwl->sems, pos);
226 225
 			s_unlock_at(jwl->sems, i);
227
-			DBG("JABBER: JC_WLIST_GET: entry already exists for <%.*s> in the pool of <%d> [%d]\n", sid->len, sid->s, jwl->workers[i].pid, i);
226
+			DBG("JABBER: JC_WLIST_GET: entry already exists for <%.*s> in the" 
227
+				" pool of <%d> [%d]\n",sid->len, sid->s,jwl->workers[i].pid,i);
228 228
 			return jwl->workers[i].pipe;
229 229
 		}
230 230
 		if(min > jwl->workers[i].nr)
... ...
@@ -243,14 +243,17 @@ int jab_wlist_get(jab_wlist jwl, str *sid, str **p)
243 243
 		jwl->workers[pos].nr++;
244 244
 		
245 245
 		msid = (str*)_M_SHM_MALLOC(sizeof(str));
246
-		if((msid != NULL) && (*p = add234(jwl->workers[pos].sip_ids, msid)) != NULL)
246
+		if((msid != NULL) && 
247
+			(*p = add234(jwl->workers[pos].sip_ids, msid)) != NULL)
247 248
 		{
248 249
 			msid->s = (char*)_M_SHM_MALLOC(sid->len);
249 250
 			msid->len = sid->len;
250 251
 			memcpy(msid->s, sid->s, sid->len);
251 252
 			s_unlock_at(jwl->sems, pos);
252 253
 			//mutex_unlock(jwl->semid);
253
-			DBG("JABBER: JC_WLIST_GET: new entry for <%.*s> in the pool of <%d> - [%d]\n", sid->len, sid->s,  jwl->workers[pos].pid, pos);
254
+			DBG("JABBER: JC_WLIST_GET: new entry for <%.*s> in the pool of"
255
+				" <%d> - [%d]\n", sid->len, sid->s,
256
+				jwl->workers[pos].pid, pos);
254 257
 			return jwl->workers[pos].pipe;
255 258
 		}
256 259
 	}
... ...
@@ -265,7 +268,8 @@ int jab_wlist_get(jab_wlist jwl, str *sid, str **p)
265 268
 /**
266 269
  * delete an entity from working list of a worker
267 270
  * - jwl : pointer to the workers list
268
- * - sid : id of the entity (connection to Jabber - usually SHOULD be FROM header of the incomming SIP message
271
+ * - sid : id of the entity (connection to Jabber - usually SHOULD be FROM
272
+ *   header of the incomming SIP message
269 273
  * - _pid : process id of the worker
270 274
  */
271 275
 void jab_wlist_del(jab_wlist jwl, str *sid, int _pid)
... ...
@@ -279,10 +283,12 @@ void jab_wlist_del(jab_wlist jwl, str *sid, int _pid)
279 283
 			break;
280 284
 	if(i >= jwl->len)
281 285
 	{
282
-		DBG("JABBER: jab_wlist_del:%d: key <%.*s> not found in [%d]...\n", _pid, sid->len, sid->s, i);		
286
+		DBG("JABBER: jab_wlist_del:%d: key <%.*s> not found in [%d]...\n", 
287
+			_pid, sid->len, sid->s, i);		
283 288
 		return;
284 289
 	}
285
-	DBG("JABBER: jab_wlist_del:%d: trying to delete entry for <%.*s>...\n", _pid, sid->len, sid->s);
290
+	DBG("JABBER: jab_wlist_del:%d: trying to delete entry for <%.*s>...\n", 
291
+		_pid, sid->len, sid->s);
286 292
 	
287 293
 	s_lock_at(jwl->sems, i);
288 294
 	p = del234(jwl->workers[i].sip_ids, (void*)sid);	
... ...
@@ -291,7 +297,8 @@ void jab_wlist_del(jab_wlist jwl, str *sid, int _pid)
291 297
 	{
292 298
 		jwl->workers[i].nr--;
293 299
 		
294
-		DBG("JABBER: jab_wlist_del:%d: sip id <%.*s> deleted\n", _pid, sid->len, sid->s);
300
+		DBG("JABBER: jab_wlist_del:%d: sip id <%.*s> deleted\n", _pid, 
301
+			sid->len, sid->s);
295 302
 		free_str_p(p);
296 303
 	}
297 304
 		
... ...
@@ -314,28 +321,28 @@ int jab_send_sip_msg(str *to, str *from, str *contact, str *msg)
314 321
 	strcpy(buf, "<sip:");
315 322
 	strncat(buf, from->s, from->len);
316 323
 	tfrom.len = from->len;
317
-	if(strstr(buf+4, "sip:") == NULL)
324
+	if(strstr(buf+5, "sip:") == NULL)
318 325
 	{
319 326
 		tfrom.len += 5;
320 327
 		buf[tfrom.len++] = '>';
321 328
 		tfrom.s = buf;
322 329
 	}
323 330
 	else
324
-		tfrom.s = buf+4;
331
+		tfrom.s = buf+5;
325 332
 	if(contact != NULL && contact->len > 2)
326 333
 	{
327 334
 	    // contact correction
328 335
 	    strcpy(buf1, "<sip:");
329 336
 	    strncat(buf1, contact->s, contact->len);
330 337
 	    tcontact.len = contact->len;
331
-	    if(strstr(buf1+4, "sip:") == NULL)
338
+	    if(strstr(buf1+5, "sip:") == NULL)
332 339
 	    {
333
-		tcontact.len += 5;
334
-		buf1[tcontact.len++] = '>';
335
-		tcontact.s = buf1;
340
+			tcontact.len += 5;
341
+			buf1[tcontact.len++] = '>';
342
+			tcontact.s = buf1;
336 343
 	    }
337 344
 	    else
338
-		tcontact.s = buf1+4;
345
+			tcontact.s = buf1+5;
339 346
 	    return im_send_message(to, to, &tfrom, &tcontact, msg);
340 347
 	}
341 348
 	else
... ...
@@ -357,9 +364,11 @@ int jab_send_sip_msgz(str *to, str *from, str *contact, char *msg)
357 364
 	tstr.s = msg;
358 365
 	tstr.len = strlen(msg);
359 366
 	if((n = jab_send_sip_msg(to, from, contact, &tstr)) < 0)
360
-		DBG("JABBER: jab_send_sip_msgz: ERROR SIP MESSAGE was not sent to [%.*s]...\n", tstr.len, tstr.s);
367
+		DBG("JABBER: jab_send_sip_msgz: ERROR SIP MESSAGE wasn't sent to"
368
+			" [%.*s]...\n", tstr.len, tstr.s);
361 369
 	else
362
-		DBG("JABBER: jab_send_sip_msgz: SIP MESSAGE was sent to [%.*s]...\n", tstr.len, tstr.s);
370
+		DBG("JABBER: jab_send_sip_msgz: SIP MESSAGE was sent to [%.*s]...\n", 
371
+			tstr.len, tstr.s);
363 372
 	return n;
364 373
 }
365 374
 
... ...
@@ -376,7 +385,8 @@ int jab_send_sip_msgz(str *to, str *from, str *contact, char *msg)
376 385
  * - db_con : connection to database
377 386
  * #return : 0 on success or <0 on error
378 387
  */
379
-int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size, int ctime, int wtime, int dtime, db_con_t* db_con)
388
+int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe,
389
+		int size, int ctime, int wtime, int dtime, db_con_t* db_con)
380 390
 {
381 391
 	int ret, i, n, maxfd, error, cseq;
382 392
 	jc_pool jcp;
... ...
@@ -396,7 +406,8 @@ int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size,
396 406
 	db_key_t col[] = {"jab_id", "jab_passwd"};
397 407
 	db_res_t* res = NULL;
398 408
 	
399
-	DBG("JABBER: WORKER_PROCESS:%d: started - pipe=<%d> : 1st message delay <%d>\n", _pid, pipe, dtime);
409
+	DBG("JABBER: WORKER_PROCESS:%d: started - pipe=<%d> : 1st message delay"
410
+		" <%d>\n", _pid, pipe, dtime);
400 411
 	
401 412
 	if((jcp = jc_pool_init(size, 10)) == NULL)
402 413
 	{
... ...
@@ -416,17 +427,24 @@ int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size,
416 427
 		mset = set;
417 428
 			
418 429
 		tmv.tv_sec = (jcp->jmqueue.size == 0)?wtime:1;
419
-		DBG("JABBER: worker_process:%d: select waiting %dsec\n", _pid, (int)tmv.tv_sec);
430
+		DBG("JABBER: worker_process:%d: select waiting %dsec\n", _pid, 
431
+						(int)tmv.tv_sec);
420 432
 		tmv.tv_usec = 0;
421 433
 		
422 434
 		ret = select(maxfd+1, &mset, NULL, NULL, &tmv);
423 435
 		/** check the queue AND conecction of head element is ready */
424
-		while(jcp->jmqueue.size != 0 && jcp->jmqueue.ojc[jcp->jmqueue.head]->ready < get_ticks())
436
+		while(jcp->jmqueue.size != 0 
437
+			&& jcp->jmqueue.ojc[jcp->jmqueue.head]->ready < get_ticks())
425 438
 		{
426 439
 			/** send message from queue */
427
-			DBG("JABBER: worker_process:%d: SENDING AS JABBER MESSAGE FROM LOCAL QUEUE ...\n", _pid);
428
-			jb_send_msg(jcp->jmqueue.ojc[jcp->jmqueue.head]->jbc, jcp->jmqueue.jsm[jcp->jmqueue.head]->to.s, jcp->jmqueue.jsm[jcp->jmqueue.head]->to.len,
429
-				jcp->jmqueue.jsm[jcp->jmqueue.head]->msg.s, jcp->jmqueue.jsm[jcp->jmqueue.head]->msg.len);
440
+			DBG("JABBER: worker_process:%d: SENDING AS JABBER MESSAGE FROM "
441
+				" LOCAL QUEUE ...\n", _pid);
442
+			jb_send_msg(jcp->jmqueue.ojc[jcp->jmqueue.head]->jbc, 
443
+						jcp->jmqueue.jsm[jcp->jmqueue.head]->to.s, 
444
+						jcp->jmqueue.jsm[jcp->jmqueue.head]->to.len,
445
+						jcp->jmqueue.jsm[jcp->jmqueue.head]->msg.s, 
446
+						jcp->jmqueue.jsm[jcp->jmqueue.head]->msg.len);
447
+			
430 448
 			jab_sipmsg_free(jcp->jmqueue.jsm[jcp->jmqueue.head]);
431 449
 			
432 450
 			/** delete message from queue */
... ...
@@ -441,8 +459,9 @@ int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size,
441 459
 			{ // new job from ser
442 460
 				read(pipe, &jsmsg, sizeof(jsmsg));
443 461
 
444
-				DBG("JABBER: worker_process <%d>: job <%p> from SER\n", _pid, jsmsg);
445
-				if( jsmsg== NULL || jsmsg->from == NULL)
462
+				DBG("JABBER: worker_process <%d>: job <%p> from SER\n", 
463
+								_pid, jsmsg);
464
+				if( jsmsg == NULL || jsmsg->from == NULL)
446 465
 					continue;
447 466
 				
448 467
 				strncpy(buff, jsmsg->from->s, jsmsg->from->len);
... ...
@@ -451,8 +470,9 @@ int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size,
451 470
 				ojc = jc_pool_get(jcp, jsmsg->from);
452 471
 				if(ojc == NULL)
453 472
 				{ // NO OPEN CONNECTION FOR THIS SIP ID
454
-					DBG("JABBER:worker_process:%d: new connection for <%s> ...\n", _pid, buff);
455
-					if (db_query(db_con, keys, vals, col, 1, 2, NULL, &res) == 0)
473
+					DBG("JABBER:worker_process:%d: new connection for <%s>.\n",
474
+									_pid, buff);
475
+					if(db_query(db_con, keys, vals, col, 1, 2, NULL, &res)==0)
456 476
 					{
457 477
 
458 478
 						if (RES_ROW_N(res) != 0)
... ...
@@ -462,61 +482,91 @@ int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size,
462 482
     	        		
463 483
 							if(!jb_connect_to_server(jbc))
464 484
                             {
465
-								DBG("JABBER: auth to jabber as: [%s] / [%s]\n", (char*)(ROW_VALUES(RES_ROWS(res))[0].val.string_val), (char*)(ROW_VALUES(RES_ROWS(res))[1].val.string_val));
466
-								if(jb_user_auth_to_server(jbc,(char*)(ROW_VALUES(RES_ROWS(res))[0].val.string_val), (char*)(ROW_VALUES(RES_ROWS(res))[1].val.string_val), "jbcl") == 0)
485
+								DBG("JABBER: auth to jabber as: [%s] / [%s]\n",
486
+									(char*)(ROW_VALUES(RES_ROWS(res))[0].val.string_val), 
487
+									(char*)(ROW_VALUES(RES_ROWS(res))[1].val.string_val));
488
+								if(jb_user_auth_to_server(jbc,
489
+									(char*)(ROW_VALUES(RES_ROWS(res))[0].val.string_val),
490
+									(char*)(ROW_VALUES(RES_ROWS(res))[1].val.string_val), "jbcl") == 0)
467 491
 	        		            {
468
-									ojc = open_jc_create(jsmsg->from, jbc, ctime, dtime);
469
-									if((ojc != NULL) && (jc_pool_add( jcp, ojc) == 0))
492
+									ojc = open_jc_create(jsmsg->from, jbc, 
493
+													ctime, dtime);
494
+									if((ojc != NULL) 
495
+										&& (jc_pool_add( jcp, ojc) == 0))
470 496
 		                            {
471 497
 										/** add socket descriptor to select */
472
-										DBG("JABBER: worker_process <%d>: add connection on <%d> \n", _pid, jbc->sock);
498
+										DBG("JABBER: worker_process <%d>: add"
499
+											" connection on <%d> \n", _pid, 
500
+											jbc->sock);
473 501
 										if(jbc->sock > maxfd)
474 502
 											maxfd = jbc->sock;
475 503
 										FD_SET(jbc->sock, &set);
476 504
 										
477 505
 										jb_get_roster(jbc);
478
-										jb_send_presence(jbc, NULL, "Online", "9");
506
+										jb_send_presence(jbc, NULL,
507
+											"Online", "9");
479 508
 										/** wait for a while - SER is tired */
480 509
 										//sleep(3);
481 510
 									}
482 511
 									else
483 512
 									{
484
-										DBG("JABBER:worker_process:%d: Keeping connection to Jabber server failed! Not enough memory ...\n", _pid);
513
+										DBG("JABBER:worker_process:%d: Keeping"
514
+											" connection to Jabber server"
515
+											" failed! Not enough memory ...\n", 
516
+											_pid);
485 517
 										jb_disconnect(jbc);
486 518
 										jb_free_jbconnection(jbc);
487 519
 										if(ojc != NULL)
488 520
 											open_jc_free(ojc);
489
-										jab_send_sip_msgz(jsmsg->from, &jsmsg->to, jwl->contact_h, "ERROR: Your message was not sent. SIP-2-JABBER gateway is full.");
521
+										jab_send_sip_msgz(jsmsg->from, 
522
+											&jsmsg->to,	jwl->contact_h,	
523
+											"ERROR:Your message was	not"
524
+											" sent. SIP-2-JABBER"
525
+											" gateway is full.");
490 526
 										error = 1;
491 527
 									}	
492 528
 								}
493 529
 								else
494 530
 								{
495
-									DBG("JABBER:worker_process:%d: Authentication to the Jabber server failed ...\n", _pid);
531
+									DBG("JABBER:worker_process:%d: "
532
+										" Authentication to the Jabber server"
533
+										" failed ...\n", _pid);
496 534
 									jb_disconnect(jbc);
497 535
 									jb_free_jbconnection(jbc);
498
-									jab_send_sip_msgz(jsmsg->from, &jsmsg->to, jwl->contact_h, "ERROR: Your message was not sent. Authentication to the Jabber server failed.");
536
+									jab_send_sip_msgz(jsmsg->from, &jsmsg->to,
537
+										jwl->contact_h, "ERROR: Your message"
538
+										" was not sent. Authentication to the"
539
+										" Jabber server failed.");
499 540
 									error = 1;
500 541
 								}
501 542
 
502 543
 							}
503 544
 							else
504 545
 							{
505
-								DBG("JABBER:worker_process:%d: Cannot connect to the Jabber server ...\n", _pid);
506
-								jab_send_sip_msgz(jsmsg->from, &jsmsg->to, jwl->contact_h, "ERROR: Your message was not sent. Cannot connect to the Jabber server.");
546
+								DBG("JABBER:worker_process:%d: Cannot connect"
547
+									" to the Jabber server ...\n", _pid);
548
+								jab_send_sip_msgz(jsmsg->from, &jsmsg->to, 
549
+									jwl->contact_h, "ERROR: Your message was"
550
+									" not sent. Cannot connect to the Jabber"
551
+									" server.");
507 552
 								error = 1;
508 553
 							}
509 554
 
510 555
 						}
511 556
 						else
512 557
 						{
513
-							DBG("JABBER:worker_process:%d: no database result\n", _pid);
514
-							jab_send_sip_msgz(jsmsg->from, &jsmsg->to, jwl->contact_h, "ERROR: Your message was not sent. You do not have permision to use the gateway.");
558
+							DBG("JABBER:worker_process:%d: no database"
559
+								" result\n", _pid);
560
+							jab_send_sip_msgz(jsmsg->from, &jsmsg->to, 
561
+								jwl->contact_h, "ERROR: Your message was not"
562
+								" sent. You do not have permision to use the"
563
+								" gateway.");
515 564
 							error = 1;
516 565
 						}
517
-						if ((res != NULL) && (db_free_query(db_con, res) < 0))
566
+						if ((res != NULL) && (db_free_query(db_con,res) < 0))
518 567
 						{
519
-							DBG("JABBER:worker_process:%d: Error while freeing SQL result\n", _pid);
568
+							DBG("JABBER:worker_process:%d:Error while freeing"
569
+								" SQL result\n", _pid);
520 570
 							return -1;
521 571
 						}
522 572
 						else
... ...
@@ -525,7 +575,8 @@ int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size,
525 575
 				}
526 576
 				else
527 577
 				{
528
-					DBG("JABBER:worker_process:%d: connection already exists for <%s> ...\n", _pid, buff);
578
+					DBG("JABBER:worker_process:%d: connection already exists"
579
+						" for <%s> ...\n", _pid, buff);
529 580
 					open_jc_update(ojc, ctime);
530 581
 				}
531 582
 				
... ...
@@ -533,18 +584,25 @@ int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size,
533 584
 				{
534 585
 					if(ojc->ready < get_ticks())
535 586
 					{
536
-						DBG("JABBER: worker_process:%d: SENDING AS JABBER MESSAGE ...\n", _pid);
537
-						if(jb_send_msg(ojc->jbc, jsmsg->to.s, jsmsg->to.len, jsmsg->msg.s, jsmsg->msg.len)<0)
538
-							jab_send_sip_msgz(jsmsg->from, &jsmsg->to, jwl->contact_h, "ERROR: Your message was not sent. Something wrong during transmition to Jabber.");
587
+						DBG("JABBER: worker_process:%d: SENDING AS JABBER"
588
+							" MESSAGE ...\n", _pid);
589
+						if(jb_send_msg(ojc->jbc, jsmsg->to.s, jsmsg->to.len,
590
+								jsmsg->msg.s, jsmsg->msg.len)<0)
591
+							jab_send_sip_msgz(jsmsg->from, &jsmsg->to,
592
+								jwl->contact_h, "ERROR: Your message was not"
593
+								" sent. Something wrong during transmition to"
594
+								" Jabber.");
539 595
 						
540 596
 						jab_sipmsg_free(jsmsg);
541 597
 					}
542 598
 					else
543 599
 					{
544
-						DBG("JABBER: worker_process:%d: SCHEDULING THE MESSAGE ...\n", _pid);
600
+						DBG("JABBER:worker_process:%d:SCHEDULING THE MESSAGE."
601
+							"\n", _pid);
545 602
 						if(jc_pool_add_jmsg(jcp, jsmsg, ojc) < 0)
546 603
 						{
547
-							DBG("JABBER: worker_process:%d: SCHEDULING THE MESSAGE FAILED. Message was droped.\n", _pid);
604
+							DBG("JABBER: worker_process:%d: SCHEDULING THE"
605
+								" MESSAGE FAILED. Message was droped.\n",_pid);
548 606
 							jab_sipmsg_free(jsmsg);
549 607
 						}
550 608
 					}
... ...
@@ -558,57 +616,77 @@ int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size,
558 616
 				{
559 617
 					if(jcp->ojc[i] != NULL && jcp->ojc[i]->jbc != NULL)
560 618
 					{
561
-						DBG("JABBER: worker_process:%d: checking socket <%d> ...\n", _pid, jcp->ojc[i]->jbc->sock);
619
+						DBG("JABBER: worker_process:%d: checking socket <%d>"
620
+							" ...\n", _pid, jcp->ojc[i]->jbc->sock);
562 621
 						if(FD_ISSET(jcp->ojc[i]->jbc->sock, &mset))
563 622
 						{
564
-							if((n = read(jcp->ojc[i]->jbc->sock, recv_buff, sizeof(recv_buff))) > 0)
623
+							if((n = read(jcp->ojc[i]->jbc->sock, recv_buff,
624
+										sizeof(recv_buff))) > 0)
565 625
 							{
566 626
 								open_jc_update(jcp->ojc[i], ctime);
567 627
 								
568
-								write(1, "JABBER: JMSG START ----------\n", 30);
569
-								write(1, recv_buff, n);
570
-								write(1, "\nJABBER: JMSG END ----------\n", 29);
628
+								DBG("JABBER: JMSG START ----------\n%.*s\n"
629
+									" JABBER: JMSG END ----------\n", 
630
+									n, recv_buff);
631
+								
571 632
 								recv_buff[n] = 0;
572 633
 								if(strstr(recv_buff, "<message ") != NULL)
573 634
 								{
574
-									if(j2s_parse_jmsgx(recv_buff, n, &tjmsg) >=0)
635
+									if(j2s_parse_jmsgx(recv_buff,n,&tjmsg)>=0)
575 636
 									{
576
-										DBG("JABBER: worker_process:%d: sending as SIP ...\n", _pid);
637
+										DBG("JABBER: worker_process:%d:"
638
+											" sending as SIP ...\n", _pid);
577 639
 										buff[0] = 0;
578 640
 										if(tjmsg.error.len > 0)
579 641
 										{
580 642
 											strcpy(buff, "{Error: ");
581 643
 											if(tjmsg.errcode.len > 0)
582 644
 											{
583
-												strncat(buff, tjmsg.errcode.s, tjmsg.errcode.len);
645
+												strncat(buff, tjmsg.errcode.s, 
646
+													tjmsg.errcode.len);
584 647
 												strncat(buff, " - ", 3);
585 648
 											}
586
-											strncat(buff, tjmsg.error.s, tjmsg.error.len);
587
-											strcat(buff, ". The following message was NOT sent}: ");
649
+											strncat(buff, tjmsg.error.s, 
650
+												tjmsg.error.len);
651
+											strcat(buff, ". The following"
652
+												" message was NOT sent}: ");
588 653
 										}
589
-										strncat(buff, tjmsg.body.s, tjmsg.body.len);
590
-										if((n= xml_unescape(buff, strlen(buff), tbuff, 1024)) > 0)
654
+										strncat(buff, tjmsg.body.s, 
655
+											tjmsg.body.len);
656
+										if((n=xml_unescape(buff, strlen(buff),
657
+													tbuff, 1024)) > 0)
591 658
 										{
592 659
 											tstr.s = tbuff;
593 660
 											tstr.len = n;
594
-											// if(jab_send_sip_msg(jcp->ojc[i]->id, &tjmsg.from, &tjmsg.from, &tstr) < 0)
595
-											if(jab_send_sip_msg(jcp->ojc[i]->id, &tjmsg.from, jwl->contact_h, &tstr) < 0)
596
-												DBG("JABBER: worker_process:%d: ERROR SIP MESSAGE was not sent ...\n", _pid);
661
+											if(jab_send_sip_msg(jcp->ojc[i]->id,
662
+													&tjmsg.from,jwl->contact_h,
663
+													&tstr) < 0)
664
+												DBG("JABBER:worker_process:%d:"
665
+													" ERROR SIP MESSAGE was not"
666
+													" sent ...\n", _pid);
597 667
 											else
598
-												DBG("JABBER: worker_process:%d: SIP MESSAGE was sent ...\n", _pid);
668
+												DBG("JABBER:worker_process:%d:"
669
+													" SIP MESSAGE was sent.\n",
670
+													_pid);
599 671
 										}
600 672
 										else
601 673
 										{
602
-											DBG("JABBER: worker_process:%d: ERROR sending as sip: output buffer too small ...\n", _pid);
674
+											DBG("JABBER: worker_process:%d:"
675
+												" ERROR sending as sip: output"
676
+												" buffer too small.\n", _pid);
603 677
 										}
604 678
 									}
605 679
 									else
606
-										DBG("JABBER: worker_process:%d: ERROR parsing jabber message ...\n", _pid);
680
+										DBG("JABBER: worker_process:%d: ERROR"
681
+											" parsing jabber message ...\n",
682
+											_pid);
607 683
 								}
608 684
 							}
609 685
 							else
610 686
 							{
611
-								DBG("JABBER: worker_process:%d: ERROR - connection to jabber lost on socket <%d> ...\n", _pid, jcp->ojc[i]->jbc->sock);
687
+								DBG("JABBER: worker_process:%d: ERROR -"
688
+									" connection to jabber lost on socket <%d>"
689
+									" ...\n", _pid, jcp->ojc[i]->jbc->sock);
612 690
 								jcp->ojc[i]->expire = ltime = 0;
613 691
 							}
614 692
 						}
... ...
@@ -619,7 +697,7 @@ int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size,
619 697
 		
620 698
 		if(ret < 0)
621 699
 		{
622
-			DBG("JABBER: worker_process:%d: SIGNAL received!!!!!!!!!!!!!!!!!!\n", _pid);
700
+			DBG("JABBER: worker_process:%d: SIGNAL received!!!!!!!!\n", _pid);
623 701
 			maxfd = pipe;
624 702
 			FD_ZERO(&set);
625 703
 			FD_SET(pipe, &set);
... ...
@@ -633,20 +711,21 @@ int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size,
633 711
 				}
634 712
 			}
635 713
 		}
636
-		//if(ret == 0)
637
-			//DBG("JABBER: worker_process:%d: select <%d> timeout <%d>\n", _pid, maxfd, wtime);
638 714
 		
639 715
 		if(ltime + wtime <= get_ticks())
640 716
 		{
641 717
 			ltime = get_ticks();
642
-			DBG("JABBER: worker_process:%d: scanning for expired connection\n", _pid);
718
+			DBG("JABBER: worker_process:%d: scanning for expired connection\n",
719
+				_pid);
643 720
 			for(i = 0; i < jcp->len; i++)
644 721
 			{
645 722
 				if((jcp->ojc[i] != NULL) && (jcp->ojc[i]->expire <= ltime))
646 723
 				{
647
-					DBG("JABBER: worker_process:%d: connection expired for <%.*s>\n", _pid, jcp->ojc[i]->id->len, jcp->ojc[i]->id->s);
724
+					DBG("JABBER: worker_process:%d: connection expired for"
725
+						" <%.*s>\n", _pid, jcp->ojc[i]->id->len, 
726
+						jcp->ojc[i]->id->s);
648 727
 					
649
-					// CLEAR JAB_WLIST
728
+					// CLEAN JAB_WLIST
650 729
 					jab_wlist_del(jwl, jcp->ojc[i]->id, _pid);
651 730
 					
652 731
 					FD_CLR(jcp->ojc[i]->jbc->sock, &set);
... ...
@@ -655,7 +734,6 @@ int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size,
655 734
 					jcp->ojc[i] = NULL;
656 735
 				}
657 736
 			}
658
-			//DBG("JABBER: worker_process:%d: scanning finished ...\n", _pid);
659 737
 		}
660 738
 				
661 739
 	} // END while
... ...
@@ -790,10 +868,12 @@ open_jc  jc_pool_get(jc_pool jcp, str *id)
790 868
 	if(jcp == NULL || id == NULL)
791 869
 		return NULL;
792 870
 	
793
-	DBG("JABBER: JC_POOL_GET: looking for the connection of <%.*s> into the pool\n", id->len, id->s);
871
+	DBG("JABBER: JC_POOL_GET: looking for the connection of <%.*s>"
872
+		" into the pool\n", id->len, id->s);
794 873
 	while(i < jcp->len)
795 874
 	{
796
-	 	if((jcp->ojc[i]!=NULL) && (!strncmp(jcp->ojc[i]->id->s, id->s, id->len)))
875
+	 	if((jcp->ojc[i]!=NULL) && (!strncmp(jcp->ojc[i]->id->s, id->s, 
876
+				id->len)))
797 877
 	 	{
798 878
 	 		_ojc = jcp->ojc[i];
799 879
 	 		//jcp->ojc[i] = NULL;
... ...
@@ -822,7 +902,8 @@ int jc_pool_del(jc_pool jcp, str *id)
822 902
 	
823 903
 	while(i < jcp->len)
824 904
 	{
825
-	 	if((jcp->ojc[i]!=NULL) && (!strncmp(jcp->ojc[i]->id->s, id->s, id->len)))
905
+	 	if((jcp->ojc[i]!=NULL) && (!strncmp(jcp->ojc[i]->id->s, id->s, 
906
+			id->len)))
826 907
 	 	{
827 908
 	 		open_jc_free(jcp->ojc[i]);
828 909
 	 		jcp->ojc[i] = NULL;
... ...
@@ -871,7 +952,8 @@ void jc_pool_free(jc_pool jcp)
871 952
  * - delay_time : time needed to became an active connection
872 953
  * #return : pointer to the structure or NULL on error
873 954
  */
874
-open_jc open_jc_create(str *id, jbconnection jbc, int cache_time, int delay_time)
955
+open_jc open_jc_create(str *id, jbconnection jbc, int cache_time, 
956
+				int delay_time)
875 957
 {
876 958
 	open_jc ojc;
877 959
 	int t;
... ...
@@ -922,3 +1004,4 @@ void open_jc_free(open_jc ojc)
922 1004
 	_M_FREE(ojc);
923 1005
 	DBG("JABBER: OPEN_JC_FREE ---END---\n");
924 1006
 }
1007
+
... ...
@@ -35,7 +35,6 @@ typedef struct _jab_wlist
35 35
 	int maxj;			// maximum jobs / worker
36 36
 	struct sockaddr_in sserver;  // sip server address
37 37
 	str *contact_h;	// contact header
38
-    //int semid;          // semaphore for mutual access to the list
39 38
     smart_lock *sems;	//
40 39
 	jab_worker workers; // the list of workers
41 40
 } t_jab_wlist, *jab_wlist;
... ...
@@ -125,9 +125,7 @@ void destroy_semaphores(smart_lock *sem_set)
125 125
 	if (sem_set && semctl( sem_set[0].entry_semaphore,0,IPC_RMID,0)==-1)
126 126
 		LOG(L_ERR, "ERROR: lock_cleanup, entry_semaphore cleanup failed\n");
127 127
 #endif
128
-	shm_free(sem_set);
128
+	shm_free((void*)sem_set);
129 129
 	sem_set = 0;
130 130
 }
131 131
 
132
-
133
-
... ...
@@ -26,12 +26,18 @@
26 26
 #define JB_ID_BASE	"SJ"
27 27
 
28 28
 #define JB_CLIENT_OPEN_STREAM	"<stream:stream to='%s' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>"
29
-#define JB_IQ_AUTH_REQ	"<iq id='%s%d' type='get'><query xmlns='jabber:iq:auth'><username>%s</username></query></iq>"
30
-#define JB_IQ_AUTH_PL_SEND	"<iq id='%s%d' type='set'><query xmlns='jabber:iq:auth'><username>%s</username><password>%s</password><resource>%s</resource></query></iq>"
31
-#define JB_IQ_AUTH_DG_SEND	"<iq id='%s%d' type='set'><query xmlns='jabber:iq:auth'><username>%s</username><digest>%s</digest><resource>%s</resource></query></iq>"
32
-#define JB_IQ_ROSTER_GET	"<iq type='get'><query xmlns='jabber:iq:roster'/></iq>"
33
-#define JB_MSG_NORMAL	"<message to='%s' type='normal'><body>%s</body></message>"
34
-#define JB_MSG_CHAT		"<message to='%s' type='chat'><body>%s</body></message><message to='%s' type='chat'><body>%s</body></message>"
29
+
30
+#define JB_IQ_AUTH_REQ			"<iq id='%s%d' type='get'><query xmlns='jabber:iq:auth'><username>%s</username></query></iq>"
31
+
32
+#define JB_IQ_AUTH_PL_SEND		"<iq id='%s%d' type='set'><query xmlns='jabber:iq:auth'><username>%s</username><password>%s</password><resource>%s</resource></query></iq>"
33
+
34
+#define JB_IQ_AUTH_DG_SEND		"<iq id='%s%d' type='set'><query xmlns='jabber:iq:auth'><username>%s</username><digest>%s</digest><resource>%s</resource></query></iq>"
35
+
36
+#define JB_IQ_ROSTER_GET		"<iq type='get'><query xmlns='jabber:iq:roster'/></iq>"
37
+
38
+#define JB_MSG_NORMAL			"<message to='%s' type='normal'><body>%s</body></message>"
39
+
40
+#define JB_MSG_CHAT				"<message to='%s' type='chat'><body>%s</body></message><message to='%s' type='chat'><body>%s</body></message>"
35 41
 
36 42
 
37 43
 /**
... ...
@@ -75,7 +81,7 @@ int jb_connect_to_server(jbconnection jbc)
75 81
     he=gethostbyname(jbc->hostname);
76 82
     if(he == NULL)
77 83
     {
78
-    	_M_PRINTF("S2JB: Error to get the information about Jabber server address\n");
84
+    	_M_PRINTF("S2JB: Error getting info about Jabber server address\n");
79 85
         return -1;
80 86
     }
81 87
 
... ...
@@ -137,7 +143,8 @@ int jb_disconnect(jbconnection jbc)
137 143
 /**
138 144
  * authentication to the JABBER server
139 145
  */
140
-int jb_user_auth_to_server(jbconnection jbc, char *username, char *passwd, char *resource)
146
+int jb_user_auth_to_server(jbconnection jbc, char *username, char *passwd,
147
+				char *resource)
141 148
 {
142 149
 	char msg_buff[4096];
143 150
 	int n;
... ...
@@ -180,11 +187,13 @@ int jb_user_auth_to_server(jbconnection jbc, char *username, char *passwd, char
180 187
 		sprintf(msg_buff, "%s%s", jbc->stream_id, passwd);
181 188
 		DBG("JABBER: JB_USER_AUTH_TO_SERVER: [%s:%s]\n", jbc->stream_id, passwd);
182 189
 		p0 = shahash(msg_buff);
183
-		sprintf(msg_buff, JB_IQ_AUTH_DG_SEND, JB_ID_BASE, jbc->seq_nr, username, p0, resource);
190
+		sprintf(msg_buff, JB_IQ_AUTH_DG_SEND, JB_ID_BASE, jbc->seq_nr, username,
191
+						p0, resource);
184 192
 	}
185 193
 	else
186 194
 	{ // plaint text authentication
187
-		sprintf(msg_buff, JB_IQ_AUTH_PL_SEND, JB_ID_BASE, jbc->seq_nr, username, passwd, resource);
195
+		sprintf(msg_buff, JB_IQ_AUTH_PL_SEND, JB_ID_BASE, jbc->seq_nr, username,
196
+						passwd, resource);
188 197
 	}
189 198
 
190 199
 	send(jbc->sock, msg_buff, strlen(msg_buff), 0);
... ...
@@ -201,12 +210,6 @@ int jb_user_auth_to_server(jbconnection jbc, char *username, char *passwd, char
201 210
 	if(p0 != NULL)
202 211
 		return -3;
203 212
 		
204
-    /**************
205
-	jbc->username = (char*)_M_MALLOC(strlen(username));
206
-	strcpy(jbc->username, username);
207
-	jbc->passwd = (char*)_M_MALLOC(strlen(passwd));
208
-	strcpy(jbc->passwd, passwd);
209
-	*/
210 213
 	jbc->resource = (char*)_M_MALLOC(strlen(resource));
211 214
 	strcpy(jbc->resource, resource);
212 215
 	
... ...
@@ -244,13 +247,15 @@ int jb_send_msg(jbconnection jbc, char *to, int tol, char *msg, int msgl)
244 247
 	p = msg_buff + l;
245 248
 	if((i = xml_escape(msg, msgl, p, 4096-l)) < 0)
246 249
 	{
247
-		DBG("JABBER: JB_SEND_MSG: error: message not sent - output buffer too small\n");
250
+		DBG("JABBER: JB_SEND_MSG: error: message not sent"
251
+			" - output buffer too small\n");
248 252
 		return -2;
249 253
 	}
250 254
 
251 255
 	if(l+i > 4076)
252 256
 	{
253
-		DBG("JABBER: JB_SEND_MSG: error: message not sent -- output buffer too small\n");
257
+		DBG("JABBER: JB_SEND_MSG: error: message not sent"
258
+			" - output buffer too small\n");
254 259
 		return -2;
255 260
 	}
256 261
 	strcat(msg_buff, "</body></message>");
... ...
@@ -270,7 +275,8 @@ int jb_send_msg(jbconnection jbc, char *to, int tol, char *msg, int msgl)
270 275
  * send a signed message through a JABBER connection
271 276
  * params are pairs (buffer, len)
272 277
  */
273
-int jb_send_sig_msg(jbconnection jbc, char *to, int tol, char *msg, int msgl, char *sig, int sigl)
278
+int jb_send_sig_msg(jbconnection jbc, char *to, int tol, char *msg, int msgl,
279
+				char *sig, int sigl)
274 280
 {
275 281
 	char msg_buff[4096], *p;
276 282
 	int i, l;
... ...
@@ -283,7 +289,8 @@ int jb_send_sig_msg(jbconnection jbc, char *to, int tol, char *msg, int msgl, ch
283 289
 	p = msg_buff + l;
284 290
 	if((i = xml_escape(msg, msgl, p, 4096-l)) < 0)
285 291
 	{
286
-		DBG("JABBER: JB_SEND_SIG_MSG: error: message not sent - output buffer too small\n");
292
+		DBG("JABBER: JB_SEND_SIG_MSG: error: message not sent"
293
+			" - output buffer too small\n");
287 294
 		return -2;
288 295
 	}
289 296
 	
... ...
@@ -294,7 +301,8 @@ int jb_send_sig_msg(jbconnection jbc, char *to, int tol, char *msg, int msgl, ch
294 301
 	p = msg_buff + l;
295 302
 	if((i=xml_escape(sig, sigl, p, 4096-l)) < 0)
296 303
 	{
297
-		DBG("JABBER: JB_SEND_SIG_MSG: error: message not sent -- output buffer too small\n");
304
+		DBG("JABBER: JB_SEND_SIG_MSG: error: message not sent"
305
+			" -- output buffer too small\n");
298 306
 		return -2;
299 307
 	}
300 308
 
... ...
@@ -328,9 +336,9 @@ int jb_recv_msg(jbconnection jbc, char *from, char *msg)
328 336
  * status - "online", "away", "unavailable" ...
329 337
  * priority - "0", "1", ...
330 338
  */
331
-int jb_send_presence(jbconnection jbc, char *type, char *status, char *priority)
339
+int jb_send_presence(jbconnection jbc, char *type, char *status,
340
+				char *priority)
332 341
 {
333
-	//JB_PRESENCE		"<presence type='%s'><status>%s</status><priority>%d</priority></presence>"
334 342
 	char msg_buff[4096];
335 343
 	int n;
336 344
 	if(jbc == NULL)
... ...
@@ -405,3 +413,4 @@ int jb_free_jbconnection(jbconnection jbc)
405 413
 	DBG("JABBER: JB_FREE_JBCONNECTION ---END---\n");
406 414
 	return 0;
407 415
 }
416
+
... ...
@@ -47,3 +47,4 @@ int jb_send_sig_msg(jbconnection, char*, int, char*, int, char*, int);
47 47
 char *shahash(const char *);
48 48
 
49 49
 #endif
50
+
... ...
@@ -13,69 +13,92 @@
13 13
 
14 14
 #include "../../dprint.h"
15 15
 
16
-#define EAT_SPACES_R(_p, _e)	while((*(_p)) && ((_p) <= (_e)) && (*(_p)==' ' || *(_p)=='\t')) (_p)++; \
17
-								if((_p)>(_e)) return -2
16
+#define EAT_SPACES_R(_p, _e)	\
17
+			while((*(_p)) && ((_p) <= (_e)) && (*(_p)==' '\
18
+					|| *(_p)=='\t')) (_p)++; \
19
+				if((_p)>(_e)) return -2
18 20
 
19 21
 #define EAT_SPACES(_p)	while((*(_p)) && (*(_p)==' ' || *(_p)=='\t')) (_p)++
20
-#define NEXT_ALCHAR(_p, _pos)	(_pos) = 0; \
21
-							while((*((_p)+(_pos))) && (*((_p)+(_pos))<'A' || *((_p)+(_pos))>'Z') \
22
-								&& (*((_p)+(_pos))<'a' || *((_p)+(_pos))>'z')) (_pos)++
23
-#define NEXT_ALCHARX(_p, _pos, _e)	(_pos) = 0; \
24
-							while((*((_p)+(_pos))) && ((_p)+(_pos) <= (_e)) && (*((_p)+(_pos))<'A' || *((_p)+(_pos))>'Z') \
25
-								&& (*((_p)+(_pos))<'a' || *((_p)+(_pos))>'z') && (*((_p)+(_pos))!='>') \
26
-								 && (*((_p)+(_pos))!='<') && (*((_p)+(_pos))!='/')) (_pos)++; \
27
-							if((_p)+(_pos) > (_e)) return -2
28
-
29
-#define NEXT_CHAR(_p, _c, _pos) (_pos) = 0; \
30
-							while((*((_p)+(_pos))) && *((_p)+(_pos))!=(_c)) (_pos)++
31
-#define NEXT_CHAR_R(_p, _c, _pos, _e) (_pos) = 0; \
32
-							while( (*((_p)+(_pos))) && ((_p)+(_pos) <= (_e)) && (*((_p)+(_pos)) != (_c)) ) (_pos)++; \
33
-							if((_p)+(_pos) > (_e)) return -2
34
-
35
-#define NEXT_TAGSEP_R(_p, _pos, _e) (_pos) = 0; \
36
-							while( (*((_p)+(_pos))) && ((_p)+(_pos) <= (_e)) && (*((_p)+(_pos)) != ' ') \
37
-							&& (*((_p)+(_pos)) != '\t') && (*((_p)+(_pos)) != '>')  && (*((_p)+(_pos)) != '/') ) (_pos)++; \
38
-							if((_p)+(_pos) > (_e)) return -2
22
+
23
+#define NEXT_ALCHAR(_p, _pos)	\
24
+			(_pos) = 0; \
25
+			while((*((_p)+(_pos))) && \
26
+						(*((_p)+(_pos))<'A' || *((_p)+(_pos))>'Z') \
27
+						&& (*((_p)+(_pos))<'a' || *((_p)+(_pos))>'z')) \
28
+				(_pos)++
29
+
30
+#define NEXT_ALCHARX(_p, _pos, _e)	\
31
+			(_pos) = 0; \
32
+			while((*((_p)+(_pos))) && ((_p)+(_pos) <= (_e)) && \
33
+						(*((_p)+(_pos))<'A' || *((_p)+(_pos))>'Z') \
34
+						&& (*((_p)+(_pos))<'a' || *((_p)+(_pos))>'z') \
35
+						&& (*((_p)+(_pos))!='>') \
36
+						&& (*((_p)+(_pos))!='<') && (*((_p)+(_pos))!='/')) \
37
+				(_pos)++; \
38
+			if((_p)+(_pos) > (_e)) return -2
39
+
40
+#define NEXT_CHAR(_p, _c, _pos) \
41
+			(_pos) = 0; \
42
+			while((*((_p)+(_pos))) && *((_p)+(_pos))!=(_c)) (_pos)++
43
+
44
+#define NEXT_CHAR_R(_p, _c, _pos, _e) \
45
+			(_pos) = 0; \
46
+			while( (*((_p)+(_pos))) && ((_p)+(_pos) <= (_e)) && \
47
+					(*((_p)+(_pos)) != (_c)) ) (_pos)++; \
48
+			if((_p)+(_pos) > (_e)) return -2
49
+
50
+#define NEXT_TAGSEP_R(_p, _pos, _e) \
51
+			(_pos) = 0; \
52
+			while( (*((_p)+(_pos))) && ((_p)+(_pos) <= (_e)) && \
53
+					(*((_p)+(_pos)) != ' ') \
54
+					&& (*((_p)+(_pos)) != '\t') && (*((_p)+(_pos)) != '>') \
55
+					&& (*((_p)+(_pos)) != '/') ) \
56
+				(_pos)++; \
57
+			if((_p)+(_pos) > (_e)) return -2
39 58
 
40 59
 #define SKIP_CHARS(_p, _n)	(_p) += (_n)
41
-#define SKIP_CHARS_R(_p, _n, _e) if( (_p)+(_n) < (_e) ) (_p) += (_n); else return -2
60
+#define SKIP_CHARS_R(_p, _n, _e) \
61
+			if( (_p)+(_n) < (_e) ) (_p) += (_n); else return -2
42 62
 
43
-#define IGNORE_TAG(_p, _p1, _l1, _e, _s)  (_s) = 0;\
44
-							while(1)\
45
-							{\
46
-								while( (*(_p)) && ((_p)+2<=(_e)) && (*(_p) != '<') && (*(_p) != '>') ) (_p)++; \
47
-								if( !(*(_p)) || ((_p)+(_l1)>(_e)) ) \
63
+#define IGNORE_TAG(_p, _p1, _l1, _e, _s)  \
64
+			(_s) = 0;\
65
+			while(1)\
66
+			{\
67
+				while( (*(_p)) && ((_p)+2<=(_e)) && (*(_p) != '<') && \
68
+						(*(_p) != '>') ) \
69
+					(_p)++; \
70
+				if( !(*(_p)) || ((_p)+(_l1)>(_e)) ) \
48 71
 									return -2; \
49
-								if((_s)==0 && *(_p)=='>') \
50
-								{ \
51
-									if(*((_p)-1) == '/') \
52
-									{ \
53
-										(_p)++; \
54
-										break; \
55
-									} \
56
-									else \
57
-										(_p)++; \
58
-									(_s) = 1; \
59
-								} else if(*(_p) == '<' && *((_p)+1)=='/') \
60
-								{ \
61
-									(_p) += 2; \
62
-									if(!strncasecmp((_p), (_p1), (_l1)) ) \
63
-									{ \
64
-										(_p) += (_l1); \
65
-										if(*(_p) == '>') \
66
-										{ \
67
-											(_p)++; \
68
-											break; \
69
-										} \
70
-										else \
71
-											return -2; \
72
-									} \
73
-									else \
74
-										(_p)++; \
75
-								} \
76
-								else \
77
-									(_p)++; \
78
-							}
72
+				if((_s)==0 && *(_p)=='>') \
73
+				{ \
74
+					if(*((_p)-1) == '/') \
75
+					{ \
76
+						(_p)++; \
77
+							break; \
78
+					} \
79
+					else \
80
+					(_p)++; \
81
+					(_s) = 1; \
82
+				} else if(*(_p) == '<' && *((_p)+1)=='/') \
83
+				{ \
84
+					(_p) += 2; \
85
+					if(!strncasecmp((_p), (_p1), (_l1)) ) \
86
+					{ \
87
+					(_p) += (_l1); \
88
+					if(*(_p) == '>') \
89
+					{ \
90
+						(_p)++; \
91
+						break; \
92
+					} \
93
+					else \
94
+						return -2; \
95
+				} \
96
+				else \
97
+					(_p)++; \
98
+			} \
99
+			else \
100
+				(_p)++; \
101
+		}
79 102
 
80 103
 /*****  XML Escaping  *****/
81 104
 /**
... ...
@@ -285,7 +308,8 @@ int j2s_parse_jmsgx(const char *msg, int len, jab_jmsg jmsg)
285 308
 					SKIP_CHARS(p0, pos);
286 309
 					if(attrf)
287 310
 					{
288
-						if((jmsg->from.len == 0) && !strncasecmp(p0, "from", 4))
311
+						if((jmsg->from.len == 0) 
312
+							&& !strncasecmp(p0, "from", 4))
289 313
 						{
290 314
 							SKIP_CHARS_R(p0, 4, end);
291 315
 							DBG("JABBER: j2s_parse_jmsg: from\n");
... ...
@@ -296,14 +320,16 @@ int j2s_parse_jmsgx(const char *msg, int len, jab_jmsg jmsg)
296 320
 								SKIP_CHARS(p0, pos+1);
297 321
 								jmsg->from.s = p0;
298 322
 								NEXT_CHAR_R(p0, '\'', pos, end);
299
-								DBG("JABBER: j2s_parse_jmsg: from %d,%d\n", (int)(jmsg->from.s - msg), pos-1);
323
+								DBG("JABBER: j2s_parse_jmsg: from %d,%d\n",
324
+									(int)(jmsg->from.s - msg), pos-1);
300 325
 								jmsg->from.len = pos;
301 326
 								SKIP_CHARS(p0, pos+1);
302 327
 							}
303 328
 							else
304 329
 								return -2;
305 330
 						}
306
-						else if((jmsg->to.len == 0) && !strncasecmp(p0, "to", 2))
331
+						else if((jmsg->to.len == 0) 
332
+								&& !strncasecmp(p0, "to", 2))
307 333
 						{
308 334
 							SKIP_CHARS(p0, 2);
309 335
 							DBG("JABBER: j2s_parse_jmsg: to\n");
... ...
@@ -314,14 +340,16 @@ int j2s_parse_jmsgx(const char *msg, int len, jab_jmsg jmsg)
314 340
 								SKIP_CHARS(p0, pos+1);
315 341
 								jmsg->to.s = p0;
316 342
 								NEXT_CHAR_R(p0, '\'', pos, end);
317
-								DBG("JABBER: j2s_parse_jmsg: to %d,%d\n", (int)(jmsg->to.s - msg), pos-1);
343
+								DBG("JABBER: j2s_parse_jmsg: to %d,%d\n", 
344
+									(int)(jmsg->to.s - msg), pos-1);
318 345
 								jmsg->to.len = pos;
319 346
 								SKIP_CHARS(p0, pos+1);
320 347
 							}
321 348
 							else
322 349
 								return -2;
323 350
 						}
324
-						else if((jmsg->id.len == 0) && !strncasecmp(p0, "id", 2))
351
+						else if((jmsg->id.len == 0) 
352
+								&& !strncasecmp(p0, "id", 2))
325 353
 						{
326 354
 							SKIP_CHARS(p0, 2);
327 355
 							DBG("JABBER: j2s_parse_jmsg: id\n");
... ...
@@ -338,7 +366,8 @@ int j2s_parse_jmsgx(const char *msg, int len, jab_jmsg jmsg)
338 366
 							else
339 367
 								return -2;
340 368
 						}
341
-						else if((jmsg->type.len == 0) && !strncasecmp(p0, "type", 4))
369
+						else if((jmsg->type.len == 0) 
370
+								&& !strncasecmp(p0, "type", 4))
342 371
 						{
343 372
 							DBG("JABBER: j2s_parse_jmsg: type\n");
344 373
 							SKIP_CHARS(p0, 4);
... ...
@@ -359,7 +388,8 @@ int j2s_parse_jmsgx(const char *msg, int len, jab_jmsg jmsg)
359 388
 						{
360 389
 							SKIP_CHARS(p0, 1);
361 390
 							attrf = 0;
362
-							DBG("JABBER: j2s_parse_jmsg: message attributes parsed\n");
391
+							DBG("JABBER: j2s_parse_jmsg: message attributes \
392
+								parsed\n");
363 393
 						}
364 394
 						else if(!strncasecmp(p0, "/>", 2))
365 395
 						{
... ...
@@ -368,13 +398,15 @@ int j2s_parse_jmsgx(const char *msg, int len, jab_jmsg jmsg)
368 398
 						else
369 399
 						{
370 400
 							NEXT_CHAR_R(p0, '=', pos, end);
371
-							DBG("JABBER: j2s_parse_jmsg: unknow message attribute [%.*s]\n", pos, p0);
401
+							DBG("JABBER: j2s_parse_jmsg: unknow message \
402
+								attribute [%.*s]\n", pos, p0);
372 403
 							SKIP_CHARS(p0, pos+1);
373 404
 							NEXT_CHAR_R(p0, '\'', pos, end);
374 405
 							SKIP_CHARS(p0, pos+1);
375 406
 							NEXT_CHAR_R(p0, '\'', pos, end);
376 407
 							SKIP_CHARS(p0, pos+1);
377
-							DBG("JABBER: j2s_parse_jmsg: unknow message attribute was skipped\n");
408
+							DBG("JABBER: j2s_parse_jmsg: unknow message \
409
+								attribute was skipped\n");
378 410
 							// return -2;
379 411
 						}
380 412
 					}
... ...
@@ -408,9 +440,11 @@ int j2s_parse_jmsgx(const char *msg, int len, jab_jmsg jmsg)
408 440
 								p1 = p0;
409 441
 								l1 = pos;
410 442
 								SKIP_CHARS(p0, pos);
411
-								DBG("JABBER: j2s_parse_jmsg: ignoring tag <%.*s>\n", l1, p1);
443
+								DBG("JABBER: j2s_parse_jmsg: ignoring tag \
444
+									<%.*s>\n", l1, p1);
412 445
 								IGNORE_TAG(p0, p1, l1, end, sflag);
413
-								DBG("JABBER: j2s_parse_jmsg: tag <%.*s> ignored\n", l1, p1);
446
+								DBG("JABBER: j2s_parse_jmsg: tag <%.*s> \
447
+									ignored\n", l1, p1);
414 448
 							}
415 449
 						}
416 450
 						else
... ...
@@ -428,7 +462,8 @@ int j2s_parse_jmsgx(const char *msg, int len, jab_jmsg jmsg)
428 462
 						SKIP_CHARS(p0, pos+1);
429 463
 						if(!strncasecmp(p0, "/body", 5))
430 464
 						{
431
-							DBG("JABBER: j2s_parse_jmsg: body %d,%d\n", (int)(jmsg->body.s - msg), pos-1);
465
+							DBG("JABBER: j2s_parse_jmsg: body %d,%d\n", 
466
+								(int)(jmsg->body.s - msg), pos-1);
432 467
 							jmsg->body.len = pos;
433 468
 							SKIP_CHARS(p0, 5);
434 469
 							EAT_SPACES_R(p0, end);
... ...
@@ -541,7 +576,8 @@ int j2s_parse_jmsg(const char *msg, int len, jab_jmsg jmsg)
541 576
 				SKIP_CHARS(p0, pos+1);
542 577
 				if(!strncasecmp(p0, "/body", 5))
543 578
 				{
544
-					DBG("JABBER: j2s_parse_jmsg: body %d,%d\n", (int)(jmsg->body.s - msg), pos-1);
579
+					DBG("JABBER: j2s_parse_jmsg: body %d,%d\n", 
580
+						(int)(jmsg->body.s - msg), pos-1);
545 581
 					jmsg->body.len = pos;
546 582
 					SKIP_CHARS(p0, 5);
547 583
 				}
... ...
@@ -560,7 +596,8 @@ int j2s_parse_jmsg(const char *msg, int len, jab_jmsg jmsg)
560 596
 				SKIP_CHARS(p0, pos+1);
561 597
 				jmsg->from.s = p0;
562 598
 				NEXT_CHAR(p0, '\'', pos);
563
-				DBG("JABBER: j2s_parse_jmsg: from %d,%d\n", (int)(jmsg->from.s - msg), pos-1);
599
+				DBG("JABBER: j2s_parse_jmsg: from %d,%d\n", 
600
+					(int)(jmsg->from.s - msg), pos-1);
564 601
 				jmsg->from.len = pos;
565 602
 				SKIP_CHARS(p0, pos);
566 603
 			}
... ...
@@ -636,3 +673,4 @@ int j2s_parse_jmsg(const char *msg, int len, jab_jmsg jmsg)
636 673
 	}
637 674
 	return 0;
638 675
 }
676
+
... ...
@@ -70,5 +70,5 @@ int xml_unescape(char *, int, char *, int);
70 70
 int j2s_parse_jmsgx(const char *, int, jab_jmsg);
71 71
 int j2s_parse_jmsg(const char *, int, jab_jmsg);
72 72
 
73
-
74 73
 #endif
74
+