Browse code

- small but essential fixes

Andrei Pelinescu-Onciul authored on 30/11/2001 01:03:02
Showing 12 changed files
... ...
@@ -342,8 +342,8 @@ int do_action(struct action* a, struct sip_msg* msg)
342 342
 				}
343 343
 			break;
344 344
 		case MODULE_T:
345
-			if ( ((a->p1_type==CMDF_ST)&&a->p1.data)&&
346
-					((a->p2_type==STRING_ST)&&a->p2.data) ){
345
+			if ( ((a->p1_type==CMDF_ST)&&a->p1.data)/*&&
346
+					((a->p2_type==STRING_ST)&&a->p2.data)*/ ){
347 347
 				ret=((cmd_function)(a->p1.data))(msg, (char*)a->p2.data,
348 348
 													  (char*)a->p3.data);
349 349
 			}else{
... ...
@@ -300,7 +300,7 @@ static void sig_usr(int signo)
300 300
 		pkg_status();
301 301
 #endif
302 302
 #ifdef SHM_MEM
303
-		sh_status();
303
+		shm_status();
304 304
 #endif
305 305
 		DPrint("INT received, program terminates\n");
306 306
 		DPrint("Thank you for flying ser\n");
... ...
@@ -317,7 +317,7 @@ static void sig_usr(int signo)
317 317
 		pkg_status();
318 318
 #endif
319 319
 #ifdef SHM_MEM
320
-		sh_status();
320
+		shm_status();
321 321
 #endif
322 322
 	}
323 323
 }
... ...
@@ -23,9 +23,9 @@ extern struct qm_block* mem_block;
23 23
 
24 24
 #include "shm_mem.h"
25 25
 
26
-#define pkg_malloc(s) sh_malloc(s)
27
-#define pkg_free(p)   sh_free(p)
28
-#define pkg_status()  sh_status()
26
+#define pkg_malloc(s) shm_malloc(s)
27
+#define pkg_free(p)   shm_free(p)
28
+#define pkg_status()  shm_status()
29 29
 
30 30
 #else
31 31
 
... ...
@@ -13,7 +13,7 @@ depends= $(sources:.c=.d)
13 13
 NAME=tm.so
14 14
 
15 15
 SHLIB_LD_FLAGS= -shared
16
-LIBS= -lpthread
16
+LIBS= #-lpthread
17 17
 
18 18
 ifeq ($(ARCH), SunOS)
19 19
 LDFLAGS=-O2 -G
... ...
@@ -19,8 +19,10 @@ struct timer;
19 19
 #include "lock.h"
20 20
 #include "sip_msg.h"
21 21
 
22
+
22 23
 #define sh_malloc( size )     malloc(size)
23 24
 #define sh_free( ptr )           free(ptr)
25
+
24 26
 /* defined in msg_parser.h
25 27
 #define get_cseq( p_msg)    ((struct cseq_body*)p_msg->cseq->parsed)
26 28
 */
... ...
@@ -1,10 +1,10 @@
1 1
 #include "hash_func.h"
2
+#include "../../dprint.h"
2 3
 
3 4
 int hash( str  call_id, str cseq_nr )
4 5
 {
5 6
    int  hash_code = 0;
6 7
    int  i;
7
-
8 8
     if ( call_id.len>0 )
9 9
       for( i=0 ; i<call_id.len ; hash_code+=call_id.s[i++]  );
10 10
     if ( cseq_nr.len>0 )
... ...
@@ -23,7 +23,7 @@ int tm_startup()
23 23
 
24 24
    /*first msg id*/
25 25
    global_msg_id = 0;
26
-   T = 0;
26
+   T = (struct cell*)-1;
27 27
 
28 28
    return 0;
29 29
 }
... ...
@@ -47,7 +47,7 @@ int tm_shutdown()
47 47
  *      -1 - retransmission
48 48
  *      -2 - error
49 49
  */
50
-int t_add_transaction( struct sip_msg* p_msg )
50
+int t_add_transaction( struct sip_msg* p_msg, char* foo, char* bar )
51 51
 {
52 52
    struct cell*    new_cell;
53 53
 
... ...
@@ -61,7 +61,7 @@ int t_add_transaction( struct sip_msg* p_msg )
61 61
     /* if the transaction is not found yet we are tring to look for it*/
62 62
    if ( (int)T==-1 )
63 63
       /* if the lookup's result is not 0 means that it's a retransmission */
64
-      if ( t_lookup_request( p_msg ) )	{
64
+      if ( t_lookup_request( p_msg, foo, bar ) )	{
65 65
 	 DBG("DEBUG: t_add_transaction: won't add a retransmission\n");
66 66
          return -1;
67 67
       }
... ...
@@ -84,7 +84,7 @@ int t_add_transaction( struct sip_msg* p_msg )
84 84
  *       0 - transaction wasn't found
85 85
  *       1 - transaction found
86 86
  */
87
-int t_lookup_request( struct sip_msg* p_msg )
87
+int t_lookup_request( struct sip_msg* p_msg, char* foo, char* bar  )
88 88
 {
89 89
    struct cell      *p_cell;
90 90
    struct cell      *tmp_cell;
... ...
@@ -110,10 +110,19 @@ int t_lookup_request( struct sip_msg* p_msg )
110 110
       return 0;
111 111
    }
112 112
 
113
+   DBG("t_lookup_request: start searching\n");
114
+   /* parse all*/
115
+   if (check_transaction_quadruple(p_msg)==0) {
116
+	   LOG(L_ERR, "ERROR: TM module: t_lookup_request: too few headers\n");
117
+	   T=0;
118
+	   return -1;
119
+   }
113 120
    /* start searching into the table */
114
-   hash_index = hash( p_msg->callid , get_cseq(p_msg)->number ) ;
121
+   hash_index = hash( p_msg->callid->body , get_cseq(p_msg)->number ) ;
122
+   DBG("hash_index=%d\n", hash_index);
115 123
    if ( p_msg->first_line.u.request.method_value==METHOD_ACK  )
116 124
       isACK = 1;
125
+   DBG("t_lookup_request: 1.continue searching\n");
117 126
 
118 127
    /* all the transactions from the entry are compared */
119 128
    p_cell     = hash_table->entrys[hash_index].first_cell;
... ...
@@ -195,11 +204,12 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
195 195
       T = (struct cell*)-1;
196 196
       global_msg_id = p_msg->id;
197 197
    }
198
-
198
+	DBG("t_forward: 1. T=%x\n", T);
199 199
    /* if  T hasn't been previous searched -> search for it */
200
-   if ( (int)T !=-1 )
201
-      t_lookup_request( p_msg );
200
+   if ( (int)T ==-1 )
201
+      t_lookup_request( p_msg, 0 , 0 );
202 202
 
203
+	DBG("t_forward: 2. T=%x\n", T);
203 204
    /*if T hasn't been found after all -> return not found (error) */
204 205
    if ( !T )
205 206
       return -1;
... ...
@@ -253,8 +263,8 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
253 253
       T->outbound_request[branch]->dest_ip         = dest_ip;
254 254
       T->outbound_request[branch]->dest_port      = dest_port;
255 255
       T->outbound_request[branch]->to.sin_family = AF_INET;
256
-      T->outbound_request[branch]->to.sin_port     = htonl( dest_port ) ;
257
-      T->outbound_request[branch]->to.sin_addr.s_addr = ntohl( dest_ip ) ;
256
+      T->outbound_request[branch]->to.sin_port     =  dest_port;
257
+      T->outbound_request[branch]->to.sin_addr.s_addr =  dest_ip;
258 258
 
259 259
       if (add_branch_label( T, p_msg , branch )==-1) return -1;
260 260
       buf = build_req_buf_from_sip_req  ( p_msg, &len);
... ...
@@ -408,7 +418,7 @@ int t_put_on_wait(  struct sip_msg  *p_msg  )
408 408
   * Returns  -1 -error
409 409
   *                0 - OK
410 410
   */
411
-int t_retransmit_reply( struct sip_msg* p_msg )
411
+int t_retransmit_reply( struct sip_msg* p_msg, char* foo, char* bar  )
412 412
 {
413 413
    t_check( hash_table, p_msg );
414 414
 
... ...
@@ -486,7 +496,7 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
486 486
          insert_into_timer_list( hash_table , &(T->inbound_response->tl[FR_TIMER_LIST]) , FR_TIMER_LIST , FR_TIME_OUT );
487 487
       }
488 488
 
489
-      t_retransmit_reply( p_msg );
489
+      t_retransmit_reply( p_msg, 0 , 0);
490 490
    }
491 491
 }
492 492
 
... ...
@@ -723,7 +733,7 @@ int t_check( struct s_table *hash_table , struct sip_msg* p_msg )
723 723
       global_msg_id = p_msg->id;
724 724
       /* transaction lookup */
725 725
      if ( p_msg->first_line.type=SIP_REQUEST )
726
-         t_lookup_request( p_msg );
726
+         t_lookup_request( p_msg, 0, 0 );
727 727
       else
728 728
          t_reply_matching( hash_table , p_msg , &T , &branch );
729 729
 
... ...
@@ -837,7 +847,7 @@ int push_reply_from_uac_to_uas( struct sip_msg *p_msg , unsigned int branch )
837 837
             insert_into_timer_list( hash_table , &(T->inbound_response->tl[FR_TIMER_LIST]) , FR_TIMER_LIST , FR_TIME_OUT );
838 838
          }
839 839
 
840
-   t_retransmit_reply( p_msg );
840
+   t_retransmit_reply( p_msg, 0 , 0 );
841 841
 }
842 842
 
843 843
 
... ...
@@ -38,21 +38,22 @@ int tm_shutdown();
38 38
  *      -1 - retransmission
39 39
  *      -2 - error
40 40
  */
41
-int  t_add_transaction( struct sip_msg* p_msg );
41
+int  t_add_transaction( struct sip_msg* p_msg, char* foo, char* bar  );
42 42
 
43 43
 
44 44
 /* function returns:
45 45
  *       0 - transaction wasn't found
46 46
  *       1 - transaction found
47 47
  */
48
-int  t_lookup_request( struct sip_msg* p_msg );
48
+int  t_lookup_request( struct sip_msg* p_msg, char* foo, char* bar  );
49 49
 
50 50
 
51 51
 /* function returns:
52 52
  *       0 - forward successfull
53 53
  *      -1 - error during forward
54 54
  */
55
-int t_forward( struct sip_msg* p_msg , unsigned int dst_ip , unsigned int dst_port);
55
+int t_forward( struct sip_msg* p_msg , unsigned int dst_ip ,
56
+				unsigned int dst_port);
56 57
 
57 58
 
58 59
 
... ...
@@ -75,7 +76,7 @@ int t_put_on_wait(  struct sip_msg  *p_msg  );
75 75
 
76 76
 /* Retransmits the last sent inbound reply.
77 77
   */
78
-int t_retransmit_reply( struct sip_msg *  );
78
+int t_retransmit_reply( struct sip_msg *, char* , char* );
79 79
 
80 80
 
81 81
 
... ...
@@ -1,6 +1,6 @@
1 1
 /*$Id$
2 2
  *
3
- * Example ser module, it will just print its string parameter to stdout
3
+ * TM module
4 4
  *
5 5
  */
6 6
 
... ...
@@ -8,64 +8,174 @@
8 8
 
9 9
 #include "../../sr_module.h"
10 10
 #include "../../dprint.h"
11
+#include "../../error.h"
12
+#include "../../ut.h"
11 13
 #include "sip_msg.h"
12 14
 #include <stdio.h>
13
-#include "h_table.h"
15
+#include <string.h>
16
+#include <netdb.h>
14 17
 
15
-static int test_f(struct sip_msg*, char*,char*);
18
+#include "h_table.h"
19
+#include "t_funcs.h"
20
+
21
+
22
+
23
+/*static int test_f(struct sip_msg*, char*,char*);*/
24
+static int w_t_send_reply(struct sip_msg* msg, char* str, char* str2);
25
+static int w_t_forward(struct sip_msg* msg, char* str, char* str2);
26
+static int t_forward_uri(struct sip_msg* msg, char* str, char* str2);
27
+static int fixup_t_forward(void** param, int param_no);
28
+static int fixup_t_send_reply(void** param, int param_no);
29
+
30
+static struct module_exports nm_exports= {
31
+	"tm_module", 
32
+	(char*[]){	"t_add_transaction",
33
+				"t_lookup_request",
34
+				"t_forward",
35
+				"t_forward_uri",
36
+				"t_send_reply",
37
+				"t_retransmit_reply"
38
+			},
39
+	(cmd_function[]){
40
+					t_add_transaction,
41
+					t_lookup_request,
42
+					w_t_forward,
43
+					t_forward_uri,
44
+					w_t_send_reply,
45
+					t_retransmit_reply,
46
+					},
47
+	(int[]){
48
+				0,
49
+				0,
50
+				2,
51
+				0,
52
+				2,
53
+				0
54
+			},
55
+	(fixup_function[]){
56
+				0,
57
+				0,
58
+				fixup_t_forward,
59
+				0,
60
+				fixup_t_send_reply,
61
+				0
62
+		},
63
+	6,
64
+	(response_function) t_on_reply_received
65
+};
16 66
 
17
-static struct module_exports nm_exports= {	"tm_module", 
18
-												(char*[]){"tm_test"},
19
-												(cmd_function[]){test_f},
20
-												(int[]){1},
21
-												(fixup_function[]){0},
22
-												1,
23
-												0
24
-											};
25 67
 
26 68
 
27 69
 struct module_exports* mod_register()
28 70
 {
29 71
 
30
-/* Jiri's testing playground
72
+	DBG( "TM - registering...\n");
73
+	if (tm_startup()==-1) return 0;
74
+	return &nm_exports;
75
+}
31 76
 
32
-	struct s_table *hash_table;
33
-	int p,i,j,k;
34 77
 
35
-	DBG("tm module registering\n");
36
-	DBG("tm init table\n");
37
-	hash_table = init_hash_table( );
38 78
 
39
-#define DELAY for(i=0,j=0;i<100000;i++) j=j+3*i+1;
79
+static int fixup_t_forward(void** param, int param_no)
80
+{
81
+	char* name;
82
+	struct hostent* he;
83
+	unsigned int port;
84
+	int err;
85
+#ifdef DNS_IP_HACK
86
+	unsigned int ip;
87
+	int len;
88
+#endif
89
+
90
+	DBG("TM module: fixup_t_forward(%s, %d)\n", (char*)*param, param_no);
91
+	if (param_no==1){
92
+		name=*param;
93
+#ifdef DNS_IP_HACK
94
+		len=strlen(name);
95
+		ip=str2ip(name, len, &err);
96
+		if (err==0){
97
+			goto copy;
98
+		}
99
+#endif
100
+		/* fail over to normal lookup */
101
+		he=gethostbyname(name);
102
+		if (he==0){
103
+			LOG(L_CRIT, "ERROR: mk_proxy: could not resolve hostname:"
104
+						" \"%s\"\n", name);
105
+			return E_BAD_ADDRESS;
106
+		}
107
+		memcpy(&ip, he->h_addr_list[0], sizeof(unsigned int));
108
+	copy:
109
+		free(*param);
110
+		*param=(void*)ip;
111
+		return 0;
112
+	}else if (param_no==2){
113
+		port=htons(str2s(*param, strlen(*param), &err));
114
+		if (err==0){
115
+			free(*param);
116
+			*param=(void*)port;
117
+			return 0;
118
+		}else{
119
+			LOG(L_ERR, "TM module:fixup_t_forward: bad port number <%s>\n",
120
+					*param);
121
+			return E_UNSPEC;
122
+		}
123
+	}
124
+	return 0;
125
+}
126
+
127
+
40 128
 
41
-	p=fork();
42
-	sleep(2);
43
-	for(k=0;k<50;k++){	
44
-		DBG("DEBUG: trying to lock %d in\n", p );
45
-		lock( hash_table->entrys[1].mutex );
46
-		DBG("DEBUG: lock %d in\n", p );
47
-		DELAY; DELAY; DELAY; DELAY; DELAY;
48
-		DELAY; DELAY; DELAY; DELAY; DELAY;
49
-		unlock( hash_table->entrys[1].mutex );
50
-		DBG("DEBUG: lock %d out\n", p );
51
-		DELAY
129
+static int fixup_t_send_reply(void** param, int param_no)
130
+{
131
+	unsigned int code;
132
+	int err;
133
+
134
+	if (param_no==1){
135
+		code=str2s(*param, strlen(*param), &err);
136
+		if (err==0){
137
+			free(*param);
138
+			*param=(void*)code;
139
+			return 0;
140
+		}else{
141
+			LOG(L_ERR, "TM module:fixup_t_send_reply: bad  number <%s>\n",
142
+					*param);
143
+			return E_UNSPEC;
144
+		}
52 145
 	}
146
+	/* second param => no conversion*/
147
+	return 0;
148
+}
53 149
 
54
-	DBG("tm free table\n");
55
-	free_hash_table( hash_table );
56
-*/
57
-	fprintf(stderr, "nm - registering...\n");
58
-	return &nm_exports;
150
+
151
+
152
+static int t_forward_uri(struct sip_msg* msg, char* str, char* str2)
153
+{
154
+
155
+	LOG(L_CRIT, "BUG: TM module: t_forwad_uri not implemented!");
156
+	return -1;
157
+}
158
+
159
+
160
+
161
+static int w_t_forward(struct sip_msg* msg, char* str, char* str2)
162
+{
163
+	DBG("TM module: w_t_forward entered\n");
164
+	DBG("TM module: w_t_forward params: %x %d\n", 
165
+			 str, (unsigned int)str2);
166
+	return t_forward(msg, (unsigned int) str, (unsigned int) str2);
59 167
 }
60 168
 
61 169
 
62
-static int print_f(struct sip_msg* msg, char* str, char* str2)
170
+
171
+static int w_t_send_reply(struct sip_msg* msg, char* str, char* str2)
63 172
 {
64
-	/*we registered only 1 param, so we ignore str2*/
65
-	printf("%s\n",str);
66
-	return 1;
173
+	return t_send_reply(msg, (unsigned int) str, str2);
67 174
 }
68 175
 
176
+
177
+
178
+#if 0
69 179
 static int test_f(struct sip_msg* msg, char* s1, char* s2)
70 180
 {
71 181
 	struct sip_msg* tst;
... ...
@@ -113,5 +223,6 @@ static int test_f(struct sip_msg* msg, char* s1, char* s2)
113 113
 	free(tst);
114 114
 }
115 115
 
116
+#endif
116 117
 
117 118
 
... ...
@@ -948,16 +948,22 @@ void free_sip_msg(struct sip_msg* msg)
948 948
 }
949 949
 
950 950
 
951
+#if 0
952
+/* it's a macro now*/
951 953
 /* make sure all HFs needed for transaction identification have been
952 954
    parsed; return 0 if those HFs can't be found
953 955
 */
954 956
 int check_transaction_quadruple( struct sip_msg* msg )
955 957
 {
956 958
    return 
959
+	(parse_headers(msg, HDR_FROM|HDR_TO|HDR_CALLID|HDR_CSEQ)!=-1 &&
960
+	 msg->from && msg->to && msg->callid && msg->cseq);
961
+  /* replaced by me ( :) andrei)
957 962
    ( (msg->from || (parse_headers( msg, HDR_FROM)!=-1 && msg->from)) &&
958 963
    (msg->to|| (parse_headers( msg, HDR_TO)!=-1 && msg->to)) &&
959 964
    (msg->callid|| (parse_headers( msg, HDR_CALLID)!=-1 && msg->callid)) &&
960 965
    (msg->cseq|| (parse_headers( msg, HDR_CSEQ)!=-1 && msg->cseq)) ) ? 1 : 0;
966
+  */
961 967
 
962 968
 }
963
-
969
+#endif
... ...
@@ -222,7 +222,12 @@ void clean_hdr_field(struct hdr_field* hf);
222 222
 void free_hdr_field_lst(struct hdr_field* hf);
223 223
 void free_sip_msg(struct sip_msg* msg);
224 224
 
225
-int check_transaction_quadruple( struct sip_msg* msg );
225
+/* make sure all HFs needed for transaction identification have been
226
+   parsed; return 0 if those HFs can't be found
227
+ */
228
+#define check_transaction_quadruple(msg ) \
229
+	(parse_headers(msg, HDR_FROM|HDR_TO|HDR_CALLID|HDR_CSEQ)!=-1 && \
230
+	 msg->from && msg->to && msg->callid && msg->cseq)
226 231
 
227 232
 
228 233
 #endif
... ...
@@ -30,7 +30,7 @@ void shm_mem_destroy();
30 30
 
31 31
 
32 32
 
33
-inline static void sh_lock()
33
+inline static void shm_lock()
34 34
 {
35 35
 	struct sembuf sop;
36 36
 	
... ...
@@ -55,7 +55,7 @@ again:
55 55
 
56 56
 
57 57
 
58
-inline static void sh_unlock()
58
+inline static void shm_unlock()
59 59
 {
60 60
 	struct sembuf sop;
61 61
 	
... ...
@@ -80,14 +80,14 @@ again:
80 80
 }
81 81
 
82 82
 
83
-inline static void* sh_malloc(unsigned int size)
83
+inline static void* shm_malloc(unsigned int size)
84 84
 {
85 85
 	void *p;
86 86
 	
87
-	/*if (sh_lock()==0){*/
88
-		sh_lock();
87
+	/*if (shm_lock()==0){*/
88
+		shm_lock();
89 89
 		p=qm_malloc(shm_block, size);
90
-		sh_unlock();
90
+		shm_unlock();
91 91
 	/*
92 92
 	}else{
93 93
 		p=0;
... ...
@@ -97,20 +97,20 @@ inline static void* sh_malloc(unsigned int size)
97 97
 
98 98
 
99 99
 
100
-#define sh_free(p) \
100
+#define shm_free(p) \
101 101
 do { \
102
-		sh_lock(); \
102
+		shm_lock(); \
103 103
 		qm_free(shm_block, p); \
104
-		sh_unlock(); \
104
+		shm_unlock(); \
105 105
 }while(0)
106 106
 
107 107
 
108 108
 
109
-#define sh_status() \
109
+#define shm_status() \
110 110
 do { \
111
-		sh_lock(); \
111
+		shm_lock(); \
112 112
 		qm_status(shm_block); \
113
-		sh_unlock(); \
113
+		shm_unlock(); \
114 114
 }while(0)
115 115
 
116 116