Browse code

modules_k/*: moved k modules in directory modules/

Daniel-Constantin Mierla authored on 20/01/2013 11:57:52
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,774 +0,0 @@
1
-/* $Id$
2
- *
3
- * Copyright (C) 2006-2007 VozTelecom Sistemas S.L
4
- *
5
- * This file is part of Kamailio, a free SIP server.
6
- *
7
- * Kamailio is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version
11
- *
12
- * Kamailio is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License 
18
- * along with this program; if not, write to the Free Software 
19
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
- */
21
-
22
-#include <string.h>/*memset*/
23
-#include <errno.h>/*errno*/
24
-#include <unistd.h>/*close(),pipe,fork,pid_t*/
25
-#include <sys/wait.h>/*wait*/
26
-#include <signal.h>/*SIGINT,etc*/
27
-
28
-#include "../../sr_module.h"
29
-#include "../../ip_addr.h" /*ip_addr,hostent2ip_addr*/
30
-#include "../../tags.h" /*init_tags*/
31
-#include "../../socket_info.h" /*get_first_socket()*/
32
-#include "../../resolve.h" /*resolvehost*/
33
-#include "../../mem/mem.h" /*pkg_malloc*/
34
-#include "../../mem/shm_mem.h" /*shm_malloc*/
35
-#include "../../dprint.h" /*LM_**/
36
-#include "../../error.h" /*ser_error*/
37
-#include "../../modules/tm/tm_load.h" /*load_tm_api*/
38
-#include "../../modules/tm/h_table.h" /*cell*/
39
-#include "../../modules/tm/t_lookup.h" /*T_UNDEFINED*/
40
-#include "../../cfg/cfg_struct.h"
41
-
42
-#include "encode_msg.h" /*encode_msg*/
43
-
44
-#include "seas.h"
45
-#include "seas_action.h"
46
-#include "event_dispatcher.h"
47
-#include "statistics.h"/*pstart_stats_server*/
48
-#include "ha.h"
49
-#include "cluster.h"
50
-
51
-MODULE_VERSION
52
-
53
-
54
-/* Exported Functions */
55
-static int w_as_relay_t(struct sip_msg *msg, char *as_name, char *foo);
56
-static int w_as_relay_sl(struct sip_msg *msg, char *as_name, char *foo);
57
-
58
-/* Local functions */
59
-static int seas_init(void);
60
-static int seas_child_init(int rank);
61
-static int seas_exit();
62
-static int fixup_as_relay(void** param, int param_no);
63
-
64
-/*utility functions*/
65
-static void seas_init_tags();
66
-static inline int is_e2e_ack(struct cell *t,struct sip_msg *msg);
67
-
68
-char seas_tags[TOTAG_VALUE_LEN+1];
69
-char *seas_tag_suffix;
70
-char whoami[MAX_WHOAMI_LEN];
71
-int is_dispatcher=0;
72
-extern int sig_flag;
73
-
74
-static char *seas_listen_socket=0;
75
-static char *seas_stats_socket=0;
76
-
77
-struct ip_addr *seas_listen_ip=0;
78
-unsigned short seas_listen_port=0;
79
-
80
-struct as_entry *as_table=0;
81
-
82
-struct as_entry *as_list=0;
83
-
84
-int write_pipe=0;
85
-int read_pipe=0;
86
-
87
-struct seas_functions seas_f;
88
-
89
-static cmd_export_t cmds[]=
90
-{
91
-	{"as_relay_t",   (cmd_function)w_as_relay_t,  1,  fixup_as_relay,
92
-			0, REQUEST_ROUTE},
93
-	{"as_relay_sl",  (cmd_function)w_as_relay_sl, 1,  fixup_as_relay,
94
-			0, REQUEST_ROUTE},
95
-	{0,0,0,0,0,0}
96
-};
97
-
98
-static param_export_t params[]=
99
-{
100
-   {"listen_sockets",STR_PARAM, &seas_listen_socket},
101
-   {"stats_socket",  STR_PARAM, &seas_stats_socket},
102
-   {"jain_ping",     STR_PARAM, &jain_ping_config},
103
-   {"servlet_ping",  STR_PARAM, &servlet_ping_config},
104
-   {"clusters",      STR_PARAM, &cluster_cfg},
105
-   {0,0,0}
106
-};
107
-
108
-static proc_export_t seas_procs[] = {
109
-	{"SEAS",  0,  0,  0,  1 },
110
-	{0,0,0,0,0}
111
-};
112
-
113
-struct module_exports exports= 
114
-{
115
-   "seas",
116
-   DEFAULT_DLFLAGS,
117
-   cmds,        /* exported commands */
118
-   params,      /* exported parameters */
119
-   0,           /* exported statistics */
120
-   0,           /* exported mi commands */
121
-   0,           /* exported module-items (pseudo variables) */
122
-   seas_procs,  /* extra processes */
123
-   seas_init,   /* module initialization function */
124
-   0,           /* response function */
125
-   (destroy_function) seas_exit,   /* module exit function */
126
-   (child_init_function) seas_child_init  /* per-child init function */
127
-};
128
-
129
-static int fixup_as_relay(void** param, int param_no)
130
-{
131
-   int len;
132
-   char *parameter;
133
-   struct as_entry **entry,*tmp;
134
-
135
-   parameter=(char *)(*param);
136
-
137
-   if (param_no!=1)
138
-      return 0;
139
-   len=strlen(parameter);
140
-   
141
-   for (entry=&as_list;*entry;entry=&((*entry)->next)) {
142
-      if (len== (*entry)->name.len && 
143
-	    !memcmp((*entry)->name.s,parameter,len)) {
144
-	 pkg_free(*param);
145
-	 *param=*entry;
146
-	 return 1;
147
-      }
148
-   }
149
-   if (!(*entry)) {
150
-      if (!(*entry=(struct as_entry *)shm_malloc(sizeof(struct as_entry)))) {
151
-	 LM_ERR("no more shm_mem\n");
152
-	 goto error;
153
-      }
154
-      memset(*entry,0,sizeof(struct as_entry));
155
-      if(!((*entry)->name.s=shm_malloc(len))){
156
-	 LM_ERR("no more share mem\n");
157
-	 goto error;
158
-      }
159
-      (*entry)->name.len=len;
160
-      memcpy((*entry)->name.s,parameter,len);
161
-      (*entry)->u.as.name=(*entry)->name;
162
-      (*entry)->u.as.event_fd=(*entry)->u.as.action_fd=-1;
163
-      (*entry)->type=AS_TYPE;
164
-      pkg_free(*param);
165
-      *param=*entry;
166
-   }
167
-   for (tmp=as_list;tmp;tmp=tmp->next)
168
-      LM_DBG("%.*s\n",tmp->name.len,tmp->name.s);
169
-   return 1;
170
-error:
171
-   return -1;
172
-}
173
-
174
-/**
175
- * Sets up signal handlers
176
- */
177
-void seas_sighandler(int signo)
178
-{
179
-   struct as_entry *as;
180
-   if(is_dispatcher)
181
-      sig_flag=signo;
182
-   switch(signo){
183
-      case SIGPIPE:
184
-	 if(is_dispatcher)
185
-	    return;
186
-	 LM_INFO("%s exiting\n",whoami);
187
-	 if(my_as->u.as.ac_buffer.s){
188
-	    pkg_free(my_as->u.as.ac_buffer.s);
189
-	    my_as->u.as.ac_buffer.s=0;
190
-	 }
191
-	 if(my_as->u.as.action_fd!=-1){
192
-	    close(my_as->u.as.action_fd);
193
-	    my_as->u.as.action_fd=-1;
194
-	 }
195
-	 exit(0);
196
-	 break;
197
-      case SIGCHLD:
198
-	 LM_INFO("Child stopped or terminated\n");
199
-	 break;
200
-      case SIGUSR1:
201
-      case SIGUSR2:
202
-	 LM_DBG("Memory status (pkg):\n");
203
-#ifdef PKG_MALLOC
204
-	 pkg_status();
205
-#endif
206
-	 break;
207
-      case SIGINT:
208
-      case SIGTERM:
209
-	 LM_INFO("INFO: signal %d received\n",signo);
210
-#ifdef PKG_MALLOC
211
-	 pkg_status();
212
-#endif
213
-	 if(is_dispatcher){
214
-	    for (as=as_list;as;as=as->next) {
215
-	       if(as->type==AS_TYPE && as->connected)
216
-		  kill(as->u.as.action_pid,signo);
217
-	    }
218
-	    while(wait(0) > 0);
219
-	    exit(0);
220
-	 }else{
221
-	    LM_INFO("%s exiting\n",whoami);
222
-	    if(my_as && my_as->u.as.ac_buffer.s)
223
-	       pkg_free(my_as->u.as.ac_buffer.s);
224
-	    if(my_as && my_as->u.as.action_fd!=-1)
225
-	       close(my_as->u.as.action_fd);
226
-	    exit(0);
227
-	 }
228
-	 break;
229
-   }
230
-}
231
-
232
-/**
233
- * wrapper for the AS transaction-stateful relay script function.
234
- *
235
- */
236
-static int w_as_relay_t(struct sip_msg *msg, char *entry, char *foo)
237
-{
238
-   as_msg_p my_as_ev;
239
-   int new_tran,ret=0,len;
240
-   char *buffer,processor_id;
241
-   struct cell *mycel;
242
-   struct as_entry *as;
243
-   char *msg100="Your call is important to us";
244
-   char *msg500="Server Internal Error!";
245
-
246
-   buffer=(char*)0;
247
-   my_as_ev=(as_msg_p)0;
248
-
249
-   /**
250
-    * returns <0 on error
251
-    * 1 if (new transaction was created) or if (ACK for locally replied 200 with totag) or if (ACK for code>=300)
252
-    * 0 if it was a retransmission 
253
-    */
254
-   new_tran = seas_f.tmb.t_newtran(msg);
255
-   if(new_tran<0) {
256
-      ret = (ser_error==E_BAD_VIA && reply_to_via) ? 0 : new_tran;
257
-      goto done;
258
-   }
259
-   /*retransmission: script processing should be stopped*/
260
-   if (new_tran==0 && !(msg->REQ_METHOD==METHOD_ACK)){
261
-      ret = 0;
262
-      goto done;
263
-   }
264
-   /*new transaction created, let's pass it to an APP SERVER*/
265
-   if (msg->REQ_METHOD==METHOD_INVITE )
266
-   {
267
-      LM_DBG("new INVITE\n");
268
-      if(!seas_f.tmb.t_reply(msg,100,msg100)){
269
-	 LM_DBG("t_reply (100)\n");
270
-	 goto error;
271
-      }
272
-   }
273
-   as=(struct as_entry *)entry;
274
-   if(!as->connected){
275
-      LM_ERR("app server %.*s not connected\n",as->name.len,as->name.s);
276
-      goto error;
277
-   }
278
-   if(as->type==AS_TYPE){
279
-      if((processor_id=get_processor_id(&msg->rcv,&(as->u.as)))<0){
280
-	 LM_ERR("no processor found for packet dst %s:%d\n",ip_addr2a(&msg->rcv.dst_ip),msg->rcv.dst_port);
281
-	 goto error;
282
-      }
283
-   }else if(as->type==CLUSTER_TYPE){
284
-      LM_ERR("clustering not fully implemented\n");
285
-      return 0;
286
-   }else{
287
-      LM_ERR("unknown type of as (neither cluster nor as)\n");
288
-      return -1;
289
-   }
290
-   LM_DBG("as found ! (%.*s) processor id = %d\n",as->name.len,as->name.s,processor_id);
291
-   if(new_tran==1 && msg->REQ_METHOD==METHOD_ACK){
292
-      LM_DBG("message handled in transaction callbacks. skipping\n");
293
-      ret = 0;
294
-      goto done;
295
-      /* core should forward statelessly (says t_newtran)
296
-      LM_DBG("forwarding statelessly !!!\n");
297
-      if(!(buffer=create_as_event_sl(msg,processor_id,&len,0))){
298
-	 LM_ERR("create_as_event_sl() unable to create event code\n");
299
-	 goto error;
300
-      }
301
-      */
302
-   }else if(!(buffer=create_as_event_t(seas_f.tmb.t_gett(),msg,processor_id,&len,0))){
303
-      LM_ERR("unable to create event code\n");
304
-      goto error;
305
-   }
306
-   if(!(my_as_ev=shm_malloc(sizeof(as_msg_t)))){
307
-      LM_ERR("Out of shared mem!\n");
308
-      goto error;
309
-   }
310
-   my_as_ev->msg = buffer;
311
-   my_as_ev->as = as;
312
-   my_as_ev->type = T_REQ_IN;
313
-   my_as_ev->len = len;
314
-   my_as_ev->transaction=seas_f.tmb.t_gett(); /*does not refcount*/
315
-   if(use_stats && new_tran>0)
316
-      as_relay_stat(seas_f.tmb.t_gett());
317
-again:
318
-   ret=write(write_pipe,&my_as_ev,sizeof(as_msg_p));
319
-   if(ret==-1){
320
-      if(errno==EINTR)
321
-	 goto again;
322
-      else if(errno==EPIPE){
323
-	 LM_ERR("SEAS Event Dispatcher has closed the pipe. Invalidating it !\n");
324
-	 goto error;
325
-	 /** TODO handle this correctly !!!*/
326
-      }
327
-   }
328
-   /* seas_f.tmb.t_setkr(REQ_FWDED); */
329
-   ret=0;
330
-done:
331
-   return ret;
332
-error:
333
-   mycel=seas_f.tmb.t_gett();
334
-   if(mycel && mycel!=T_UNDEFINED){
335
-      if(!seas_f.tmb.t_reply(msg,500,msg500)){
336
-	 LM_ERR("t_reply (500)\n");
337
-      }
338
-   }
339
-   if(my_as_ev)
340
-      shm_free(my_as_ev);
341
-   if(buffer)
342
-      shm_free(buffer);
343
-   return ret;
344
-}
345
-
346
-
347
-/**
348
- * wrapper for the AS stateless relay script function.
349
- *
350
- */
351
-static int w_as_relay_sl(struct sip_msg *msg, char *as_name, char *foo)
352
-{
353
-   as_msg_p my_as_ev=0;
354
-   int ret=0,len;
355
-   char *buffer=0,processor_id;
356
-   struct as_entry *as;
357
-
358
-   as=(struct as_entry *)as_name;
359
-
360
-   if(as->type==AS_TYPE){
361
-      if((processor_id=get_processor_id(&msg->rcv,&(as->u.as)))<0){
362
-	 LM_ERR("no processor found for packet with dst port:%d\n",msg->rcv.dst_port);
363
-	 goto error;
364
-      }
365
-   }else if (as->type==CLUSTER_TYPE) {
366
-      LM_ERR("clustering not fully implemented\n");
367
-      goto error;
368
-   }else{
369
-      LM_ERR("unknown type of as\n");
370
-      goto error;
371
-   }
372
-
373
-   LM_DBG("as found ! (%.*s) processor id = %d\n",as->name.len,as->name.s,processor_id);
374
-   if(!(buffer=create_as_event_sl(msg,processor_id,&len,0))){
375
-      LM_ERR("unable to create event code\n");
376
-      goto error;
377
-   }
378
-   if(!(my_as_ev=shm_malloc(sizeof(as_msg_t))))
379
-      goto error;
380
-   my_as_ev->msg = buffer;
381
-   my_as_ev->as = as;
382
-   my_as_ev->type = SL_REQ_IN;
383
-   my_as_ev->len = len;
384
-   my_as_ev->transaction=seas_f.tmb.t_gett(); /*does not refcount*/
385
-   if(use_stats)
386
-      as_relay_stat(seas_f.tmb.t_gett());
387
-again:
388
-   ret=write(write_pipe,&my_as_ev,sizeof(as_msg_p));
389
-   if(ret==-1){
390
-      if(errno==EINTR)
391
-	 goto again;
392
-      else if(errno==EPIPE){
393
-	 LM_ERR("SEAS Event Dispatcher has closed the pipe. Invalidating it !\n");
394
-	 return -2;
395
-	 /** TODO handle this correctly !!!*/
396
-      }
397
-   }
398
-   //this shouln't be here, because it will remove the transaction from memory, but
399
-   //if transaction isn't unref'ed iw will be released anyway at t_unref if kr (killreason)==0
400
-   // a wait timer will be put to run with WT_TIME_OUT (5 seconds, within which the AS should respond)      
401
-   // this is a bug !!! I think this is why we lose calls at high load !!
402
-   //t_release(msg, 0, 0);
403
-   /* seas_f.tmb.t_setkr(REQ_FWDED); */
404
-
405
-   ret=0;
406
-   return ret;
407
-error:
408
-   if(my_as_ev)
409
-      shm_free(my_as_ev);
410
-   if(buffer)
411
-      shm_free(buffer);
412
-   return ret;
413
-}
414
-
415
-/**
416
- * creates an as_event in shared memory and returns its address or NULL if error.
417
- * event_length(4) UNSIGNED INT includes the length 4 bytes itself
418
- * type(1), 
419
- * flags(4),
420
- * transport(1).
421
- * src_ip_len(1), 
422
- * src_ip(4 or 16), 
423
- * dst_ip_len(1), 
424
- * dst_ip(4 or 16), 
425
- * src_port(2), 
426
- * dst_port(2), 
427
- * hash index(4), 
428
- * label(4), 
429
- * [cancelled hash_index,label]
430
- *
431
- */
432
-char * create_as_event_t(struct cell *t,struct sip_msg *msg,char processor_id,int *evt_len,int flags)
433
-{
434
-   unsigned int i,hash_index,label;
435
-   unsigned short int port;
436
-   unsigned int k,len;
437
-   char *buffer=NULL;
438
-   struct cell *originalT;
439
-
440
-   originalT=0;
441
-
442
-   if(!(buffer=shm_malloc(ENCODED_MSG_SIZE))){
443
-      LM_ERR("Out Of Memory !!\n");
444
-      return 0;
445
-   }
446
-   *evt_len=0;
447
-   if(t){
448
-      hash_index=t->hash_index;
449
-      label=t->label;
450
-   }else{
451
-      /**seas_f.tmb.t_get_trans_ident(msg,&hash_index,&label); this is bad, because it ref-counts !!!*/
452
-      LM_ERR("no transaction provided...\n");
453
-      goto error;
454
-   }
455
-
456
-   k=4;
457
-   /*type*/
458
-   buffer[k++]=(unsigned char)T_REQ_IN;
459
-   /*processor_id*/
460
-   buffer[k++]=(unsigned char)processor_id;
461
-   /*flags*/
462
-   if(is_e2e_ack(t,msg)){
463
-      flags|=E2E_ACK;
464
-   }else if(msg->REQ_METHOD==METHOD_CANCEL){
465
-      LM_DBG("new CANCEL\n");
466
-      originalT=seas_f.tmb.t_lookup_original(msg);
467
-      if(!originalT || originalT==T_UNDEFINED){
468
-	 /** we dont even pass the unknown CANCEL to JAIN*/
469
-	 LM_WARN("CANCEL does not match any existing transaction!!\n");
470
-	 goto error;
471
-      }else{
472
-	 flags|=CANCEL_FOUND;
473
-	 //seas_f.tmb.unref_cell(originalT);
474
-      }
475
-      LM_DBG("Cancelling transaction !!\n");
476
-   }
477
-   flags=htonl(flags);
478
-   memcpy(buffer+k,&flags,4);
479
-   k+=4;
480
-   /*protocol should be UDP,TCP,TLS or whatever*/
481
-   buffer[k++]=(unsigned char)msg->rcv.proto;
482
-   /*src ip len + src ip*/
483
-   len=msg->rcv.src_ip.len;
484
-   buffer[k++]=(unsigned char)len;
485
-   memcpy(buffer+k,&(msg->rcv.src_ip.u),len);
486
-   k+=len;
487
-   /*dst ip len + dst ip*/
488
-   len=msg->rcv.dst_ip.len;
489
-   buffer[k++]=(unsigned char)len;
490
-   memcpy(buffer+k,&(msg->rcv.dst_ip.u),len);
491
-   k+=len;
492
-   /*src port */
493
-   port=htons(msg->rcv.src_port);
494
-   memcpy(buffer+k,&port,2);
495
-   k+=2;
496
-   /*dst port */
497
-   port=htons(msg->rcv.dst_port);
498
-   memcpy(buffer+k,&port,2);
499
-   k+=2;
500
-   /*hash_index*/
501
-   i=htonl(hash_index);
502
-   memcpy(buffer+k,&i,4);
503
-   k+=4;
504
-   /*label (is the collision slot in the hash-table)*/
505
-   i=htonl(label);
506
-   memcpy(buffer+k,&i,4);
507
-   k+=4;
508
-   if(msg->REQ_METHOD==METHOD_CANCEL && originalT){
509
-      LM_DBG("Cancelled transaction: Hash_Index=%d, Label=%d\n",originalT->hash_index,originalT->label);
510
-      /*hash_index*/
511
-      i=htonl(originalT->hash_index);
512
-      memcpy(buffer+k,&i,4);
513
-      k+=4;
514
-      /*label (is the collision slot in the hash-table)*/
515
-      i=htonl(originalT->label);
516
-      memcpy(buffer+k,&i,4);
517
-      k+=4;
518
-   }
519
-
520
-   /*length of event (hdr+payload-4), copied at the beginning*/
521
-   if(encode_msg(msg,buffer+k,ENCODED_MSG_SIZE-k)<0){
522
-      LM_ERR("Unable to encode msg\n");
523
-      goto error;
524
-   }
525
-   i = GET_PAY_SIZE(buffer+k);
526
-   k+=i;
527
-   *evt_len=k;
528
-   k=htonl(k);
529
-   memcpy(buffer,&k,4);
530
-   return buffer;
531
-error:
532
-   if(buffer)
533
-      shm_free(buffer);
534
-   return 0;
535
-}
536
-
537
-
538
-/**
539
- * creates an as_event in shared memory and returns its address or NULL if error.
540
- * event_length(4) UNSIGNED INT includes the length 4 bytes itself
541
- * type(1), 
542
- * processor_id(4), 
543
- * flags(4),
544
- * transport(1).
545
- * src_ip_len(1), 
546
- * src_ip(4 or 16), 
547
- * dst_ip_len(1), 
548
- * dst_ip(4 or 16), 
549
- * src_port(2), 
550
- * dst_port(2), 
551
- *
552
- */
553
-char * create_as_event_sl(struct sip_msg *msg,char processor_id,int *evt_len,int flags)
554
-{
555
-   unsigned int i;
556
-   unsigned short int port;
557
-   unsigned int k,len;
558
-   char *buffer=NULL;
559
-
560
-   if(!(buffer=shm_malloc(ENCODED_MSG_SIZE))){
561
-      LM_ERR("create_as_event_t Out Of Memory !!\n");
562
-      return 0;
563
-   }
564
-   *evt_len=0;
565
-
566
-   /*leave 4 bytes for event length*/
567
-   k=4;
568
-   /*type*/
569
-   buffer[k++]=(unsigned char)SL_REQ_IN;
570
-   /*processor_id*/
571
-   buffer[k++]=(unsigned char)processor_id;
572
-   /*flags*/
573
-   flags=htonl(flags);
574
-   memcpy(buffer+k,&flags,4);
575
-   k+=4;
576
-   /*protocol should be UDP,TCP,TLS or whatever*/
577
-   buffer[k++]=(unsigned char)msg->rcv.proto;
578
-   /*src ip len + src ip*/
579
-   len=msg->rcv.src_ip.len;
580
-   buffer[k++]=(unsigned char)len;
581
-   memcpy(buffer+k,&(msg->rcv.src_ip.u),len);
582
-   k+=len;
583
-   /*dst ip len + dst ip*/
584
-   len=msg->rcv.dst_ip.len;
585
-   buffer[k++]=(unsigned char)len;
586
-   memcpy(buffer+k,&(msg->rcv.dst_ip.u),len);
587
-   k+=len;
588
-   /*src port */
589
-   port=htons(msg->rcv.src_port);
590
-   memcpy(buffer+k,&port,2);
591
-   k+=2;
592
-   /*dst port */
593
-   port=htons(msg->rcv.dst_port);
594
-   memcpy(buffer+k,&port,2);
595
-   k+=2;
596
-   /*length of event (hdr+payload-4), copied at the beginning*/
597
-   if(encode_msg(msg,buffer+k,ENCODED_MSG_SIZE-k)<0){
598
-      LM_ERR("Unable to encode msg\n");
599
-      goto error;
600
-   }
601
-   i = GET_PAY_SIZE(buffer+k);
602
-   k+=i;
603
-   *evt_len=k;
604
-   k=htonl(k);
605
-   memcpy(buffer,&k,4);
606
-   return buffer;
607
-error:
608
-   if(buffer)
609
-      shm_free(buffer);
610
-   return 0;
611
-}
612
-
613
-
614
-static inline int is_e2e_ack(struct cell *t,struct sip_msg *msg)
615
-{
616
-   if(msg->REQ_METHOD != METHOD_ACK)
617
-      return 0;
618
-   if (t->uas.status<300)
619
-      return 1;
620
-   return 0;
621
-}
622
-
623
-/** Initializes seas module. It first parses the listen_sockets parameter
624
- * which has the form "ip_address[:port]", creates the pipe to
625
- * communicate with the dispatcher.
626
- */
627
-static int seas_init(void)
628
-{
629
-   char *p,*port;
630
-   struct hostent *he;
631
-   struct socket_info *si;
632
-   int c_pipe[2],mierr,i;
633
-   /** Populate seas_functions*/
634
-   if (load_tm_api(&seas_f.tmb)!=0) {
635
-      LM_ERR( "can't load TM API\n");
636
-      return -1;
637
-   }
638
-   if(!(seas_f.t_check_orig_trans = find_export("t_check_trans", 0, 0))){
639
-      LM_ERR( "Seas requires transaction module (t_check_trans not found)\n");
640
-      return -1;
641
-   }
642
-   /** Populate seas_functions*/
643
-   c_pipe[0]=c_pipe[1]=-1;
644
-   p=seas_listen_socket;
645
-   port=(char *)0;
646
-   seas_listen_port=5080;
647
-   /*if the seas_listen_socket configuration string is empty, use default values*/
648
-   if(p==NULL || *p==0){
649
-      si=get_first_socket();
650
-      seas_listen_ip=&si->address;
651
-   } else {/*if config string is not empty, then try to find host first, and maybe port..*/
652
-      while(*p){
653
-	 if(*p == ':'){
654
-	    *p=0;
655
-	    port=p+1;
656
-	    break;
657
-	 }
658
-	 p++;
659
-      }
660
-      if(!(he=resolvehost(seas_listen_socket)))
661
-	 goto error;
662
-      if(!(seas_listen_ip=pkg_malloc(sizeof(struct ip_addr))))
663
-	 goto error;
664
-      hostent2ip_addr(seas_listen_ip, he, 0);
665
-      if(port!=(char *)0 && (seas_listen_port=str2s(port,strlen(port),&mierr))==0){
666
-	 LM_ERR("invalid port %s \n",port);
667
-	 goto error;
668
-      }
669
-   }
670
-   memset(unc_as_t,0,2*MAX_UNC_AS_NR*sizeof(struct unc_as));//useless because unc_as_t is in bss?
671
-   if (pipe(c_pipe)==-1) {
672
-      LM_ERR("cannot create pipe!\n");
673
-      goto error;
674
-   }
675
-   read_pipe=c_pipe[0];
676
-   write_pipe=c_pipe[1];
677
-   seas_init_tags();
678
-   if(0>start_stats_server(seas_stats_socket))
679
-      goto error;
680
-   if(0>prepare_ha())
681
-      goto error;
682
-   if(0>parse_cluster_cfg())
683
-      goto error;
684
-   register_procs(1);
685
-	/* add child to update local config framework structures */
686
-	cfg_register_child(1);
687
-
688
-   return 0;
689
-error:
690
-   for(i=0;i<2;i++)
691
-      if(c_pipe[i]!=-1)
692
-	 close(c_pipe[i]);
693
-   if(seas_listen_ip!=0)
694
-      pkg_free(seas_listen_ip);
695
-   if(use_stats)
696
-      stop_stats_server();
697
-   return -1;
698
-}
699
-
700
-
701
-/**Initializes SEAS to-tags
702
-*/
703
-static void seas_init_tags(void)
704
-{
705
-   init_tags(seas_tags, &seas_tag_suffix,"VozTele-Seas/tags",'-');
706
-   LM_DBG("seas_init_tags, seas_tags=%s\n",seas_tags);
707
-}
708
-
709
-/**
710
- * This function initializes each one of the processes spawn by the server.
711
- * the rank is 1 only when the main process is being initialized, so in that
712
- * case the function spawns the SEAS process to handle as_events triggered
713
- * from the other SER processes (executing the script).
714
- * the new process created, then goes into dispatcher_main_loop(), where
715
- * it reads() the pipe waiting for events produced by other SER processes.
716
- */
717
-static int seas_child_init(int rank)
718
-{
719
-   int pid;
720
-
721
-   /* only the child 1 will execute this */
722
-   if (rank != PROC_MAIN){
723
-      /* only dispatcher needs to read from the pipe, so close reading fd*/
724
-      /*close(read_pipe);*/
725
-      return 0;
726
-   }
727
-   if ((pid=fork_process(PROC_NOCHLDINIT,"SEAS",0))<0) {
728
-      LM_ERR("forking failed\n");
729
-      return -1;
730
-   }
731
-   if (!pid) {
732
-      /*dispatcher child. we leave writing end open so that new childs spawned
733
-       * by event dispatcher can also write to pipe.. */
734
-
735
-		/* initialize the config framework */
736
-		if (cfg_child_init())
737
-			return -1;
738
-
739
-      /* close(write_pipe); */
740
-      return dispatcher_main_loop();
741
-   }
742
-   return 0;
743
-}
744
-
745
-/* this should close the sockets open to any of the application servers, and
746
- * send them an EOF event or something that signals that SER is beeing shutdown,
747
- * so they could do their cleanup, etc.
748
- */
749
-static int seas_exit(void)
750
-{
751
-   if( seas_listen_ip!=NULL && seas_listen_ip!=&(get_first_socket()->address))
752
-      pkg_free(seas_listen_ip);
753
-   return 0;
754
-}
755
-
756
-/**
757
- * search within a given AS, if any of the registered processors is bound
758
- * to the receive_info structure passed. If there is one, it returns its 
759
- * identifier (number between 0 and 128), otherwise it returns -1;
760
- */
761
-char get_processor_id(struct receive_info *rcv,as_p as)
762
-{
763
-   int i;
764
-   for(i=0;i<MAX_BINDS;i++){
765
-      if(as->bound_processor[i]!=0 &&
766
-	    (rcv->dst_ip.len == as->binds[i]->address.len) &&
767
-	    (rcv->dst_ip.af==as->binds[i]->address.af) &&
768
-	    (!memcmp(rcv->dst_ip.u.addr,as->binds[i]->address.u.addr,rcv->dst_ip.len))/* &&
769
-										       (rcv->dst_port==as->binds[i].dst_port) &&
770
-										       (rcv->proto==as->binds[i].proto)*/)
771
-	 return as->bound_processor[i];
772
-   }
773
-   return -1;
774
-}
Browse code

seas(k): enable cfg framework for module's extra process

Daniel-Constantin Mierla authored on 10/04/2011 10:47:55
Showing 1 changed files
... ...
@@ -37,6 +37,7 @@
37 37
 #include "../../modules/tm/tm_load.h" /*load_tm_api*/
38 38
 #include "../../modules/tm/h_table.h" /*cell*/
39 39
 #include "../../modules/tm/t_lookup.h" /*T_UNDEFINED*/
40
+#include "../../cfg/cfg_struct.h"
40 41
 
41 42
 #include "encode_msg.h" /*encode_msg*/
42 43
 
... ...
@@ -681,6 +682,9 @@ static int seas_init(void)
681 682
    if(0>parse_cluster_cfg())
682 683
       goto error;
683 684
    register_procs(1);
685
+	/* add child to update local config framework structures */
686
+	cfg_register_child(1);
687
+
684 688
    return 0;
685 689
 error:
686 690
    for(i=0;i<2;i++)
... ...
@@ -728,6 +732,10 @@ static int seas_child_init(int rank)
728 732
       /*dispatcher child. we leave writing end open so that new childs spawned
729 733
        * by event dispatcher can also write to pipe.. */
730 734
 
735
+		/* initialize the config framework */
736
+		if (cfg_child_init())
737
+			return -1;
738
+
731 739
       /* close(write_pipe); */
732 740
       return dispatcher_main_loop();
733 741
    }
Browse code

seas: fixed header-encoding for longest headers

-refactorings for newer sip-router TM apis
-some headers longer than 255 bytes were wrongly encoded

Elias Baixas authored on 04/10/2010 10:39:46
Showing 1 changed files
... ...
@@ -104,18 +104,23 @@ static param_export_t params[]=
104 104
    {0,0,0}
105 105
 };
106 106
 
107
+static proc_export_t seas_procs[] = {
108
+	{"SEAS",  0,  0,  0,  1 },
109
+	{0,0,0,0,0}
110
+};
111
+
107 112
 struct module_exports exports= 
108 113
 {
109 114
    "seas",
110 115
    DEFAULT_DLFLAGS,
111
-   cmds,
112
-   params,
113
-   0,
114
-   0,
115
-   0,
116
-   0,           /* extra processes */
116
+   cmds,        /* exported commands */
117
+   params,      /* exported parameters */
118
+   0,           /* exported statistics */
119
+   0,           /* exported mi commands */
120
+   0,           /* exported module-items (pseudo variables) */
121
+   seas_procs,  /* extra processes */
117 122
    seas_init,   /* module initialization function */
118
-   0,
123
+   0,           /* response function */
119 124
    (destroy_function) seas_exit,   /* module exit function */
120 125
    (child_init_function) seas_child_init  /* per-child init function */
121 126
 };
... ...
@@ -234,8 +239,8 @@ static int w_as_relay_t(struct sip_msg *msg, char *entry, char *foo)
234 239
    char *buffer,processor_id;
235 240
    struct cell *mycel;
236 241
    struct as_entry *as;
237
-   static str msg100={"Your call is important to us",sizeof("Your call is important to us")-1};
238
-   static str msg500={"Server Internal Error!",sizeof("Server Internal Error!")-1};
242
+   char *msg100="Your call is important to us";
243
+   char *msg500="Server Internal Error!";
239 244
 
240 245
    buffer=(char*)0;
241 246
    my_as_ev=(as_msg_p)0;
... ...
@@ -259,7 +264,7 @@ static int w_as_relay_t(struct sip_msg *msg, char *entry, char *foo)
259 264
    if (msg->REQ_METHOD==METHOD_INVITE )
260 265
    {
261 266
       LM_DBG("new INVITE\n");
262
-      if(!seas_f.tmb.t_reply(msg,100,&msg100)){
267
+      if(!seas_f.tmb.t_reply(msg,100,msg100)){
263 268
 	 LM_DBG("t_reply (100)\n");
264 269
 	 goto error;
265 270
       }
... ...
@@ -271,7 +276,7 @@ static int w_as_relay_t(struct sip_msg *msg, char *entry, char *foo)
271 276
    }
272 277
    if(as->type==AS_TYPE){
273 278
       if((processor_id=get_processor_id(&msg->rcv,&(as->u.as)))<0){
274
-	 LM_ERR("no processor found for packet with dst port:%d\n",msg->rcv.dst_port);
279
+	 LM_ERR("no processor found for packet dst %s:%d\n",ip_addr2a(&msg->rcv.dst_ip),msg->rcv.dst_port);
275 280
 	 goto error;
276 281
       }
277 282
    }else if(as->type==CLUSTER_TYPE){
... ...
@@ -283,12 +288,16 @@ static int w_as_relay_t(struct sip_msg *msg, char *entry, char *foo)
283 288
    }
284 289
    LM_DBG("as found ! (%.*s) processor id = %d\n",as->name.len,as->name.s,processor_id);
285 290
    if(new_tran==1 && msg->REQ_METHOD==METHOD_ACK){
286
-      /* core should forward statelessly (says t_newtran)*/
291
+      LM_DBG("message handled in transaction callbacks. skipping\n");
292
+      ret = 0;
293
+      goto done;
294
+      /* core should forward statelessly (says t_newtran)
287 295
       LM_DBG("forwarding statelessly !!!\n");
288 296
       if(!(buffer=create_as_event_sl(msg,processor_id,&len,0))){
289 297
 	 LM_ERR("create_as_event_sl() unable to create event code\n");
290 298
 	 goto error;
291 299
       }
300
+      */
292 301
    }else if(!(buffer=create_as_event_t(seas_f.tmb.t_gett(),msg,processor_id,&len,0))){
293 302
       LM_ERR("unable to create event code\n");
294 303
       goto error;
... ...
@@ -315,14 +324,14 @@ again:
315 324
 	 /** TODO handle this correctly !!!*/
316 325
       }
317 326
    }
318
-   seas_f.tmb.t_setkr(REQ_FWDED);
327
+   /* seas_f.tmb.t_setkr(REQ_FWDED); */
319 328
    ret=0;
320 329
 done:
321 330
    return ret;
322 331
 error:
323 332
    mycel=seas_f.tmb.t_gett();
324 333
    if(mycel && mycel!=T_UNDEFINED){
325
-      if(!seas_f.tmb.t_reply(msg,500,&msg500)){
334
+      if(!seas_f.tmb.t_reply(msg,500,msg500)){
326 335
 	 LM_ERR("t_reply (500)\n");
327 336
       }
328 337
    }
... ...
@@ -390,7 +399,7 @@ again:
390 399
    // a wait timer will be put to run with WT_TIME_OUT (5 seconds, within which the AS should respond)      
391 400
    // this is a bug !!! I think this is why we lose calls at high load !!
392 401
    //t_release(msg, 0, 0);
393
-   seas_f.tmb.t_setkr(REQ_FWDED);
402
+   /* seas_f.tmb.t_setkr(REQ_FWDED); */