Browse code

*** empty log message ***

Daniel-Constantin Mierla authored on 30/07/2002 17:38:44
Showing 2 changed files
... ...
@@ -38,12 +38,13 @@ char *db_table = "jusers";
38 38
 int nrw = 2;
39 39
 int max_jobs = 10;
40 40
 
41
-char *contact = "sip:193.175.135.68:5060";
41
+char *contact = "-";
42 42
 char *jaddress = "127.0.0.1";
43 43
 int jport = 5222;
44 44
 
45
+int delay_time = 10;
45 46
 int sleep_time = 20;
46
-int cache_time = 200;
47
+int cache_time = 600;
47 48
 
48 49
 int **pipes = NULL;
49 50
 
... ...
@@ -77,6 +78,7 @@ struct module_exports exports= {
77 78
 		"workers",
78 79
 		"max_jobs",
79 80
 		"cache_time",
81
+		"delay_time",
80 82
 		"sleep_time"
81 83
 	},
82 84
 	(modparam_t[]) {   /* Module parameter types */
... ...
@@ -87,6 +89,7 @@ struct module_exports exports= {
87 89
 		INT_PARAM,
88 90
 		INT_PARAM,
89 91
 		INT_PARAM,
92
+		INT_PARAM,
90 93
 		INT_PARAM
91 94
 	},
92 95
 	(void*[]) {   /* Module parameter variable pointers */
... ...
@@ -97,9 +100,10 @@ struct module_exports exports= {
97 100
 		&nrw,
98 101
 		&max_jobs,
99 102
 		&cache_time,
103
+		&delay_time,
100 104
 		&sleep_time
101 105
 	},
102
-	7,      /* Number of module paramers */
106
+	9,      /* Number of module paramers */
103 107
 	
104 108
 	mod_init,   /* module initialization function */
105 109
 	(response_function) 0,
... ...
@@ -218,7 +222,7 @@ static int child_init(int rank)
218 222
 			if (pids[i] == 0)
219 223
 			{
220 224
 				close(pipes[i][1]);
221
-				worker_process(jwl, jaddress, jport, pipes[i][0], max_jobs, cache_time, sleep_time, db_con[i]);
225
+				worker_process(jwl, jaddress, jport, pipes[i][0], max_jobs, cache_time, sleep_time, delay_time, db_con[i]);
222 226
 				exit(0);
223 227
 			}
224 228
 		}
... ...
@@ -25,7 +25,6 @@
25 25
 #define SEM_KEY		(key_t)ftok("/etc/passwd", 'A')
26 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 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
-#define TIME_2BE_READY 3
29 28
 
30 29
 /**
31 30
  * function used to compare two elements in B-Tree
... ...
@@ -339,8 +338,9 @@ void jab_wlist_del(jab_wlist jwl, str *sid, int _pid)
339 338
  */
340 339
 int jab_send_sip_msg(str *to, str *from, str *contact, str *msg)
341 340
 {
342
-	char buf[512];
343
-	str tfrom;
341
+	char buf[512], buf1[512];
342
+	str tfrom, tcontact;
343
+	// from correction
344 344
 	strcpy(buf, "<sip:");
345 345
 	strncat(buf, from->s, from->len);
346 346
 	tfrom.len = from->len;
... ...
@@ -352,7 +352,24 @@ int jab_send_sip_msg(str *to, str *from, str *contact, str *msg)
352 352
 	}
353 353
 	else
354 354
 		tfrom.s = buf+4;
355
-	return im_send_message(to, to, &tfrom, contact, msg);
355
+	if(contact != NULL && contact->len > 2)
356
+	{
357
+	    // contact correction
358
+	    strcpy(buf1, "<sip:");
359
+	    strncat(buf1, contact->s, contact->len);
360
+	    tcontact.len = contact->len;
361
+	    if(strstr(buf1+4, "sip:") == NULL)
362
+	    {
363
+		tcontact.len += 5;
364
+		buf1[tcontact.len++] = '>';
365
+		tcontact.s = buf1;
366
+	    }
367
+	    else
368
+		tcontact.s = buf1+4;
369
+	    return im_send_message(to, to, &tfrom, &tcontact, msg);
370
+	}
371
+	else
372
+	    return im_send_message(to, to, &tfrom, &tfrom, msg);
356 373
 }
357 374
 
358 375
 /**
... ...
@@ -385,10 +402,11 @@ int jab_send_sip_msgz(str *to, str *from, str *contact, char *msg)
385 402
  * - size : maximun number of jobs - open connections to Jabber server
386 403
  * - ctime : cache time for a connection to Jabber
387 404
  * - wtime : wait time between cache checking
405
+ * - dtime : delay time for first message
388 406
  * - db_con : connection to database
389 407
  * #return : 0 on success or <0 on error
390 408
  */
391
-int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size, int ctime, int wtime, db_con_t* db_con)
409
+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)
392 410
 {
393 411
 	int ret, i, n, maxfd, error, cseq;
394 412
 	jc_pool jcp;
... ...
@@ -408,7 +426,7 @@ int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size,
408 426
 	db_key_t col[] = {"jab_id", "jab_passwd"};
409 427
 	db_res_t* res = NULL;
410 428
 	
411
-	DBG("JABBER: WORKER_PROCESS:%d: started - pipe=<%d>\n", _pid, pipe);
429
+	DBG("JABBER: WORKER_PROCESS:%d: started - pipe=<%d> : 1st message delay <%d>\n", _pid, pipe, dtime);
412 430
 	
413 431
 	if((jcp = jc_pool_init(size, 10)) == NULL)
414 432
 	{
... ...
@@ -436,6 +454,7 @@ int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size,
436 454
 		while(jcp->jmqueue.size != 0 && jcp->jmqueue.ojc[jcp->jmqueue.head]->ready < get_ticks())
437 455
 		{
438 456
 			/** send message from queue */
457
+			DBG("JABBER: worker_process:%d: SENDING AS JABBER MESSAGE FROM LOCAL QUEUE ...\n", _pid);
439 458
 			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,
440 459
 				jcp->jmqueue.jsm[jcp->jmqueue.head]->msg.s, jcp->jmqueue.jsm[jcp->jmqueue.head]->msg.len);
441 460
 			jab_sipmsg_free(jcp->jmqueue.jsm[jcp->jmqueue.head]);
... ...
@@ -476,7 +495,7 @@ int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size,
476 495
 								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));
477 496
 								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)
478 497
 	        		            {
479
-									ojc = open_jc_create(jsmsg->from, jbc, ctime);
498
+									ojc = open_jc_create(jsmsg->from, jbc, ctime, dtime);
480 499
 									if((ojc != NULL) && (jc_pool_add( jcp, ojc) == 0))
481 500
 		                            {
482 501
 										/** add socket descriptor to select */
... ...
@@ -604,6 +623,7 @@ int worker_process(jab_wlist jwl, char* jaddress, int jport, int pipe, int size,
604 623
 											{
605 624
 												tstr.s = tbuff;
606 625
 												tstr.len = n;
626
+												// if(jab_send_sip_msg(jcp->ojc[i]->id, &tjmsg.from, &tjmsg.from, &tstr) < 0)
607 627
 												if(jab_send_sip_msg(jcp->ojc[i]->id, &tjmsg.from, jwl->contact_h, &tstr) < 0)
608 628
 													DBG("JABBER: worker_process:%d: ERROR SIP MESSAGE was not sent ...\n", _pid);
609 629
 												else
... ...
@@ -895,9 +915,10 @@ void jc_pool_free(jc_pool jcp)
895 915
  * - id : id of the connection
896 916
  * - jbc : pointer to Jabber connection
897 917
  * - cache_time : life time of the connection
918
+ * - delay_time : time needed to became an active connection
898 919
  * #return : pointer to the structure or NULL on error
899 920
  */
900
-open_jc open_jc_create(str *id, jbconnection jbc, int cache_time)
921
+open_jc open_jc_create(str *id, jbconnection jbc, int cache_time, int delay_time)
901 922
 {
902 923
 	open_jc ojc;
903 924
 	int t;
... ...
@@ -908,7 +929,7 @@ open_jc open_jc_create(str *id, jbconnection jbc, int cache_time)
908 929
 	ojc->id = id;
909 930
 	t = get_ticks();
910 931
 	ojc->expire = t + cache_time;
911
-	ojc->ready = t + TIME_2BE_READY;
932
+	ojc->ready = t + delay_time;
912 933
 	ojc->jbc = jbc;
913 934
 	return ojc;
914 935
 }