Browse code

bugfix: Call-ID generation repaired, from_tags introduced, stats allocation bug (process_cnt-related) fixed

Jiri Kuthan authored on 21/10/2002 03:08:20
Showing 10 changed files
... ...
@@ -58,8 +58,8 @@
58 58
 #define MY_VIA "Via: SIP/2.0/UDP "
59 59
 #define MY_VIA_LEN 17
60 60
 
61
-#define CONTENT_LEN "Content-Length: 0"
62
-#define CONTENT_LEN_LEN 17
61
+#define CONTENT_LENGTH "Content-Length: "
62
+#define CONTENT_LENGTH_LEN (sizeof(CONTENT_LENGTH)-1)
63 63
 
64 64
 #define USER_AGENT "User-Agent: Sip EXpress router"\
65 65
 		"(" VERSION " (" ARCH "/" OS"))"
... ...
@@ -25,7 +25,7 @@
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27 27
 
28
-
28
+#include <stdlib.h>
29 29
 #include "../../mem/shm_mem.h"
30 30
 #include "../../hash_func.h"
31 31
 #include "h_table.h"
... ...
@@ -136,13 +136,13 @@ struct cell*  build_cell( struct sip_msg* p_msg )
136 136
 {
137 137
 	struct cell* new_cell;
138 138
 	unsigned int i;
139
-	unsigned int rand;
139
+	unsigned int myrand;
140 140
 	int size;
141 141
 	char *c;
142 142
 	struct ua_client *uac;
143 143
 
144 144
 	/* avoid 'unitialized var use' warning */
145
-	rand=0;
145
+	myrand=0;
146 146
 
147 147
 	/* allocs a new cell */
148 148
 	new_cell = (struct cell*)shm_malloc( sizeof( struct cell ) );
... ...
@@ -192,8 +192,11 @@ struct cell*  build_cell( struct sip_msg* p_msg )
192 192
 	if (p_msg) {
193 193
 		new_cell->hash_index = p_msg->hash_index;
194 194
 	} else {
195
-		rand = random();
196
-		new_cell->hash_index = rand % TABLE_ENTRIES ;
195
+		/* note: unsatisfactory if 
196
+		   RAND_MAX < TABLE_ENTRIES
197
+		*/
198
+		myrand = rand();
199
+		new_cell->hash_index = myrand % TABLE_ENTRIES ;
197 200
 	}
198 201
 	new_cell->wait_tl.payload = new_cell;
199 202
 	new_cell->dele_tl.payload = new_cell;
... ...
@@ -219,7 +222,7 @@ struct cell*  build_cell( struct sip_msg* p_msg )
219 219
 			c=new_cell->md5;
220 220
 			size=MD5_LEN;
221 221
 			memset(c, '0', size );
222
-			int2reverse_hex( &c, &size, rand );
222
+			int2reverse_hex( &c, &size, myrand );
223 223
 		}
224 224
 	}
225 225
 
... ...
@@ -109,7 +109,7 @@ char *build_local(struct cell *Trans,unsigned int branch,
109 109
 		*len += USER_AGENT_LEN + CRLF_LEN;
110 110
 	}
111 111
 	/* Content Length, EoM */
112
-	*len+=CONTENT_LEN_LEN + CRLF_LEN + CRLF_LEN;
112
+	*len+=CONTENT_LENGTH_LEN+1 + CRLF_LEN + CRLF_LEN;
113 113
 
114 114
 	cancel_buf=shm_malloc( *len+1 );
115 115
 	if (!cancel_buf)
... ...
@@ -153,8 +153,8 @@ char *build_local(struct cell *Trans,unsigned int branch,
153 153
 		append_mem_block(p,USER_AGENT CRLF, USER_AGENT_LEN+CRLF_LEN );
154 154
 	}
155 155
 	/* Content Length, EoM */
156
-	append_mem_block(p, CONTENT_LEN CRLF CRLF ,
157
-		CONTENT_LEN_LEN + CRLF_LEN + CRLF_LEN);
156
+	append_mem_block(p, CONTENT_LENGTH "0" CRLF CRLF ,
157
+		CONTENT_LENGTH_LEN+1 + CRLF_LEN + CRLF_LEN);
158 158
 	*p=0;
159 159
 
160 160
 	pkg_free(via);
... ...
@@ -168,16 +168,21 @@ error:
168 168
 
169 169
 
170 170
 char *build_uac_request(  str msg_type, str dst, str from,
171
-    	str headers, str body, int branch, 
172
-		struct cell *t, unsigned int *len)
171
+	str fromtag, int cseq, str callid, str headers, 
172
+	str body, int branch, 
173
+	struct cell *t, unsigned int *len)
173 174
 {
174 175
 	char *via;
175 176
 	unsigned int via_len;
176 177
 	char content_len[10];
177 178
 	int content_len_len;
179
+	char cseq_str[10];
180
+	int cseq_str_len;
178 181
 	char *buf;
179 182
 	char *w;
183
+#ifdef _OBSOLETED
180 184
 	int dummy;
185
+#endif
181 186
 
182 187
 	char branch_buf[MAX_BRANCH_PARAM_LEN];
183 188
 	int branch_len;
... ...
@@ -187,6 +192,23 @@ char *build_uac_request(  str msg_type, str dst, str from,
187 187
 
188 188
 	buf=0;
189 189
 
190
+	/* print content length */
191
+	content_len_len=snprintf(
192
+		content_len, sizeof(content_len), 
193
+		"%d", body.len );
194
+	if (content_len_len==-1) {
195
+		LOG(L_ERR, "ERROR: uac: content_len too big\n");
196
+		return 0;
197
+	}
198
+	/* print cseq */
199
+	cseq_str_len=snprintf( 
200
+		cseq_str, sizeof(cseq_str),
201
+		"%d", cseq );
202
+	if (cseq_str_len==-1) {
203
+		LOG(L_ERR, "ERROR: uac: cseq too big\n");
204
+		return 0;
205
+	}
206
+
190 207
 	if (from.len) {
191 208
 		from_len=from.len;
192 209
 		from_str=from.s;
... ...
@@ -210,9 +232,6 @@ char *build_uac_request(  str msg_type, str dst, str from,
210 210
 		goto error;
211 211
 	}
212 212
 	*len+=via_len;
213
-	/* content length */
214
-	content_len_len=snprintf(
215
-		content_len, sizeof(content_len), "%d", body.len );
216 213
 	/* header names and separators */
217 214
 	*len+=
218 215
 		+CSEQ_LEN+CRLF_LEN
... ...
@@ -223,10 +242,10 @@ char *build_uac_request(  str msg_type, str dst, str from,
223 223
 		+FROM_LEN+CRLF_LEN
224 224
 		+CRLF_LEN; /* EoM */
225 225
 	/* header field value and body length */
226
-	*len+= msg_type.len+1+UAC_CSEQNR_LEN /* CSeq: method, delimitor, number  */
226
+	*len+= msg_type.len+1+cseq_str_len /* CSeq: method, delimitor, number  */
227 227
 		+ dst.len /* To */
228
-		+ RAND_DIGITS+1+MAX_PID_LEN+1+MAX_SEQ_LEN /* call-id */
229
-		+ from_len+FROMTAG_LEN+MD5_LEN+
228
+		+ callid.len /* call-id */
229
+		+ from_len+FROMTAG_LEN+fromtag.len
230 230
 		+ content_len_len
231 231
 		+ headers.len
232 232
 		+ body.len;
... ...
@@ -243,17 +262,22 @@ char *build_uac_request(  str msg_type, str dst, str from,
243 243
 	memapp( w, dst.s, dst.len ); 
244 244
 	memapp( w, " " SIP_VERSION CRLF, 1+SIP_VERSION_LEN+CRLF_LEN );
245 245
 	memapp( w, via, via_len );
246
-	t->cseq_n.s=w; t->cseq_n.len=CSEQ_LEN+UAC_CSEQNR_LEN;
247
-	memapp( w, CSEQ UAC_CSEQNR " ", CSEQ_LEN + UAC_CSEQNR_LEN+ 1 );
246
+
247
+	/* CSeq */
248
+	t->cseq_n.s=w; 
249
+	t->cseq_n.len=CSEQ_LEN+cseq_str_len;
250
+	memapp(w, CSEQ, CSEQ_LEN );
251
+	memapp(w, cseq_str, cseq_str_len );
252
+	memapp(w, " ", 1 );
253
+
248 254
 	memapp( w, msg_type.s, msg_type.len );
249 255
 	t->to.s=w+CRLF_LEN; t->to.len=TO_LEN+dst.len;
250 256
 	memapp( w, CRLF TO, CRLF_LEN + TO_LEN  );
251 257
 	memapp( w, dst.s, dst.len );
252
-	t->callid.s=w+CRLF_LEN; t->callid.len=CALLID_LEN+RAND_DIGITS+1+
253
-		MAX_PID_LEN+1+MAX_SEQ_LEN;
258
+	t->callid.s=w+CRLF_LEN; t->callid.len=callid.len;
254 259
 	memapp( w, CRLF CALLID, CRLF_LEN + CALLID_LEN  );
255
-	memapp( w, call_id, RAND_DIGITS+1+MAX_PID_LEN+1+MAX_SEQ_LEN );
256
-	memapp( w, CRLF CONTENT_LEN, CRLF_LEN + CONTENT_LEN_LEN);
260
+	memapp( w, callid.s, callid.len );
261
+	memapp( w, CRLF CONTENT_LENGTH, CRLF_LEN + CONTENT_LENGTH_LEN);
257 262
 	memapp( w, content_len, content_len_len );
258 263
 	if (server_signature) {
259 264
 		memapp( w, CRLF USER_AGENT CRLF FROM, 
... ...
@@ -262,10 +286,11 @@ char *build_uac_request(  str msg_type, str dst, str from,
262 262
 		memapp( w, CRLF  FROM, 
263 263
 			CRLF_LEN+FROM_LEN);
264 264
 	}
265
-	t->from.s=w-FROM_LEN; t->from.len=FROM_LEN+from_len+FROMTAG_LEN+MD5_LEN;
265
+	t->from.s=w-FROM_LEN; 
266
+	t->from.len=FROM_LEN+from_len+FROMTAG_LEN+fromtag.len;
266 267
 	memapp( w, from_str, from_len );
267 268
 	memapp( w, FROMTAG, FROMTAG_LEN );
268
-	memapp( w, from_tag, MD5_LEN );
269
+	memapp( w, fromtag.s, fromtag.len );
269 270
 	memapp( w, CRLF, CRLF_LEN );
270 271
 
271 272
 	memapp( w, headers.s, headers.len );
... ...
@@ -274,9 +299,11 @@ char *build_uac_request(  str msg_type, str dst, str from,
274 274
 	if ( body.s ) {
275 275
 		memapp( w, body.s, body.len );
276 276
 	}
277
+#ifdef _OBSOLETED
277 278
 	/* ugly HACK -- debugging has shown len shorter by one */
278 279
 	dummy=*len+1;
279 280
 	*len=dummy;
281
+#endif
280 282
 #	ifdef EXTRA_DEBUG
281 283
 	if (w-buf != *len ) abort();
282 284
 #	endif
... ...
@@ -31,23 +31,23 @@
31 31
 #define _MSGBUILDER_H
32 32
 
33 33
 #define CSEQ "CSeq: "
34
-#define CSEQ_LEN 6
34
+#define CSEQ_LEN (sizeof(CSEQ)-1)
35 35
 #define TO "To: "
36
-#define TO_LEN 4
36
+#define TO_LEN (sizeof(TO)-1)
37 37
 #define CALLID "Call-ID: "
38
-#define CALLID_LEN 9
39
-#define CONTENT_LENGTH "Content-Length: "
40
-#define CONTENT_LENGTH_LEN 16
38
+#define CALLID_LEN (sizeof(CALLID)-1)
41 39
 #define FROM "From: "
42
-#define FROM_LEN 6
40
+#define FROM_LEN (sizeof(FROM)-1)
43 41
 #define FROMTAG ";tag="
44
-#define FROMTAG_LEN 5
42
+#define FROMTAG_LEN (sizeof(FROMTAG)-1)
45 43
 
44
+#ifdef _OBSOLETED
46 45
 #define UAC_CSEQNR "1"
47 46
 #define UAC_CSEQNR_LEN 1
47
+#define CONTENT_LENGTH "Content-Length: "
48
+#define CONTENT_LENGTH_LEN (sizeof(CONTENT_LENGTH)-1)
49
+#endif
48 50
 
49
-#define UAC_CSEQNR "1"
50
-#define UAC_CSEQNR_LEN 1
51 51
 
52 52
 /* convenience macros */
53 53
 #define memapp(_d,_s,_len) \
... ...
@@ -74,7 +74,8 @@ char *build_local(struct cell *Trans, unsigned int branch,
74 74
 	unsigned int *len, char *method, int method_len, str *to);
75 75
 
76 76
 char *build_uac_request(  str msg_type, str dst, str from,
77
-	str headers, str body, int branch,
77
+	str fromtag, int cseq, str callid, str headers, 
78
+	str body, int branch,
78 79
 	struct cell *t, unsigned int *len);
79 80
 
80 81
 int t_calc_branch(struct cell *t,
... ...
@@ -114,7 +114,7 @@ int init_tm_stats(void)
114 114
 	}
115 115
 	memset(tm_stats, 0, sizeof(struct t_stats) );
116 116
 
117
-	size=sizeof(int)*process_count();
117
+	size=sizeof(stat_counter)*process_count();
118 118
 	tm_stats->s_waiting=shm_malloc(size);
119 119
 	if (tm_stats->s_waiting==0) {
120 120
 		LOG(L_ERR, "ERROR: init_stats: no mem for stats\n");
... ...
@@ -35,19 +35,20 @@
35 35
 
36 36
 
37 37
 extern struct t_stats *tm_stats;
38
+typedef unsigned long stat_counter;
38 39
 
39 40
 struct t_stats {
40 41
 	/* number of transactions in wait state */
41
-	unsigned long *s_waiting;
42
+	stat_counter *s_waiting;
42 43
 	/* number of server transactions */
43
-	unsigned long *s_transactions;
44
+	stat_counter *s_transactions;
44 45
 	/* number of UAC transactions (part of transactions) */
45
-	unsigned long *s_client_transactions;
46
+	stat_counter *s_client_transactions;
46 47
 	/* number of transactions which completed with this status */
47
-	unsigned long completed_3xx, completed_4xx, completed_5xx, 
48
+	stat_counter completed_3xx, completed_4xx, completed_5xx, 
48 49
 		completed_6xx, completed_2xx;
49
-	unsigned long replied_localy;
50
-	unsigned long deleted;
50
+	stat_counter replied_localy;
51
+	stat_counter deleted;
51 52
 };
52 53
 
53 54
 inline void static t_stats_new(int local)
... ...
@@ -281,6 +281,8 @@ static int mod_init(void)
281 281
 			MAX_BRANCHES );
282 282
 		return -1;
283 283
 	}
284
+
285
+
284 286
 	if (register_fifo_cmd(fifo_uac, "t_uac", 0)<0) {
285 287
 		LOG(L_CRIT, "cannot register fifo uac\n");
286 288
 		return -1;
... ...
@@ -293,39 +295,57 @@ static int mod_init(void)
293 293
 		LOG(L_CRIT, "cannot register hash\n");
294 294
 		return -1;
295 295
 	}
296
-	
297
-	if (init_tm_stats()<0) {
298
-		LOG(L_CRIT, "ERROR: mod_init: failed to init stats\n");
299
-		return -1;
300
-	}
301 296
 
302
-	/* building the hash table*/
303 297
 	if (!init_hash_table()) {
304 298
 		LOG(L_ERR, "ERROR: mod_init: initializing hash_table failed\n");
305 299
 		return -1;
306 300
 	}
307 301
 
302
+
303
+	/* init static hidden values */
304
+	init_t();
305
+
308 306
 	if (!tm_init_timers()) {
309 307
 		LOG(L_ERR, "ERROR: mod_init: timer init failed\n");
310 308
 		return -1;
311 309
 	}
310
+	/* register the timer function */
311
+	register_timer( timer_routine , 0 /* empty attr */, 1 );
312
+
313
+	/* init_tm_stats calls process_count, which should
314
+	 * NOT be called from mod_init, because one does not
315
+	 * now, if a timer is used and thus how many processes
316
+	 * will be started; however we started already our
317
+	 * timers, so we know and process_count should not
318
+	 * change any more
319
+	 */	
320
+	if (init_tm_stats()<0) {
321
+		LOG(L_CRIT, "ERROR: mod_init: failed to init stats\n");
322
+		return -1;
323
+	}
312 324
 
313
-	/* init static hidden values */
314
-	init_t();
325
+	/* building the hash table*/
315 326
 
316
-	uac_init();
317
-	register_tmcb( TMCB_ON_NEGATIVE, on_negative_reply, 0 /* empty param */);
318
-    /* register the timer function */
319
-    register_timer( timer_routine , 0 /* empty attr */, 1 );
320
-    /* register post-script clean-up function */
321
-    register_script_cb( w_t_unref, POST_SCRIPT_CB, 0 /* empty param */ );
322
-    register_script_cb( script_init, PRE_SCRIPT_CB , 0 /* empty param */ );
327
+	if (uac_init()==-1) {
328
+		LOG(L_ERR, "ERROR: mod_init: uac_init failed\n");
329
+		return -1;
330
+	}
331
+	register_tmcb( TMCB_ON_NEGATIVE, on_negative_reply, 
332
+			0 /* empty param */);
333
+	/* register post-script clean-up function */
334
+	register_script_cb( w_t_unref, POST_SCRIPT_CB, 
335
+			0 /* empty param */ );
336
+	register_script_cb( script_init, PRE_SCRIPT_CB , 
337
+			0 /* empty param */ );
323 338
 
324 339
 	return 0;
325 340
 }
326 341
 
327 342
 static int child_init(int rank) {
328
-	uac_child_init(rank);
343
+	if (uac_child_init(rank)==-1) {
344
+		LOG(L_ERR, "ERROR: child_init: uac_child_init error\n");
345
+		return -1;
346
+	}
329 347
 	return 1;
330 348
 }
331 349
 
... ...
@@ -41,6 +41,7 @@
41 41
 #include <sys/stat.h>
42 42
 #include <fcntl.h>
43 43
 #include <signal.h>
44
+#include <limits.h>
44 45
 #include "../../dprint.h"
45 46
 #include "../../ut.h"
46 47
 #include "../../hash_func.h"
... ...
@@ -48,6 +49,8 @@
48 48
 #include "../../mem/mem.h"
49 49
 #include "../../fifo_server.h"
50 50
 #include "../../error.h"
51
+#include "../../pt.h"
52
+#include "../../crc.h"
51 53
 #include "t_funcs.h"
52 54
 #include "config.h"
53 55
 #include "sip_msg.h"
... ...
@@ -55,77 +58,118 @@
55 55
 #include "t_msgbuilder.h"
56 56
 #include "uac.h"
57 57
 
58
-/* Call-ID has the following form: call_id_rand-pid-seq */
58
+/* Call-ID has the following form: <callid_nr>-<pid>@<ip>
59
+ * callid_nr is initialized as a random number and continually
60
+ * increases; -<pid>@<ip> is kept in callid_suffix
61
+ */
62
+
63
+#define CALLID_SUFFIX_LEN (1 /* - */ + 5 /* pid */ \
64
+	+ 42 /* embedded v4inv6 address can be looong '128.' */ \
65
+	+ 2 /* parenthessis [] */ + 1 /* ZT 0 */ \
66
+	+ 16 /* one never knows ;-) */ )
67
+#define CALLID_NR_LEN 20
68
+
69
+/* the character which separates random from constant part */
70
+#define CID_SEP	'-'
71
+
72
+/* length of FROM tags */
73
+#define FROM_TAG_LEN (MD5_LEN +1 /* - */ + CRC16_LEN)
59 74
 
60
-char call_id[RAND_DIGITS+1+MAX_PID_LEN+1+MAX_SEQ_LEN+1];
61
-static unsigned long callid_seq;
75
+static unsigned long callid_nr;
76
+static char *callid_suffix;
77
+static int callid_suffix_len;
78
+static int rand_len;	/* number of chars to display max rand */
79
+static char callid[CALLID_NR_LEN+CALLID_SUFFIX_LEN];
62 80
 
63 81
 char *uac_from="\"UAC Account\" <sip:uac@dev.null:9>";
64 82
 
65
-char from_tag[ MD5_LEN +1];
83
+static char from_tag[ FROM_TAG_LEN+1 ];
66 84
 
67
-void uac_init() {
68
-	unsigned long init_nr;
69
-	char *c;
70
-	int len;
71 85
 
86
+
87
+int uac_init() {
88
+
89
+	int i; 
90
+	unsigned long uli;
91
+	int rand_len_bits;
92
+	int rand_cnt; /* number of rands() to be long enough */
93
+	int rand_bits; /* length of rands() in bits */
72 94
 	str src[3];
73 95
 
74
-	init_nr=random() % (1<<(RAND_DIGITS*4));
75
-	c=call_id;
76
-	len=RAND_DIGITS;
77
-	int2reverse_hex( &c, &len, init_nr );
78
-	while (len) { *c='z'; len--; c++; }
79
-	*c='-';
96
+	if (RAND_MAX<TABLE_ENTRIES) {
97
+		LOG(L_WARN, "Warning: uac does not spread "
98
+			"accross the whole hash table\n");
99
+	}
100
+
101
+	/* calculate the initial call-id */
102
+
103
+	/* how many bits and chars do we need to display the 
104
+	 * whole ULONG number */
105
+	for (rand_len_bits=0,uli=ULONG_MAX;uli;
106
+			uli>>=1, rand_len_bits++ );
107
+	rand_len=rand_len_bits/4;
108
+	if (rand_len>CALLID_NR_LEN) {
109
+		LOG(L_ERR, "ERROR: Too small callid buffer\n");
110
+		return -1;
111
+	}
112
+
113
+	/* how long are the rand()s ? */
114
+	for (rand_bits=0,i=RAND_MAX;i;i>>=1,rand_bits++);
115
+	/* how many rands() fit in the ULONG ? */
116
+	rand_cnt=rand_len_bits / rand_bits;
117
+
118
+	/* now fill in the callid with as many random
119
+	 * numbers as you can + 1 */
120
+	callid_nr=rand(); /* this is the + 1 */
121
+	while(rand_cnt) {
122
+		rand_cnt--;
123
+		callid_nr<<=rand_bits;
124
+		callid_nr|=rand();
125
+	}
126
+	callid_suffix=callid+rand_len;
127
+	DBG("CALLID initialization: %lx (len=%d)\n", 
128
+			callid_nr, rand_len );
129
+	DBG("CALLID0=%0*lx\n", rand_len, callid_nr );
130
+
131
+
132
+	/* calculate the initial From tag */
80 133
 
81 134
 	src[0].s="Long live SER server";
82 135
 	src[0].len=strlen(src[0].s);
83
-	src[1].s=sock_info[0].address_str.s;
136
+	src[1].s=sock_info[bind_idx].address_str.s;
84 137
 	src[1].len=strlen(src[1].s);
85
-	src[2].s=sock_info[0].port_no_str.s;
138
+	src[2].s=sock_info[bind_idx].port_no_str.s;
86 139
 	src[2].len=strlen(src[2].s);
87 140
 
88 141
 	MDStringArray( from_tag, src, 3 );
89
-	from_tag[MD5_LEN]=0;
90
-}
91
-
92
-
93
-void uac_child_init( int rank ) {
94
-	int pid_nr;
95
-	char *c;
96
-	int len;
97
-
98
-	pid_nr=getpid() % (1<<(MAX_PID_LEN*4));
99
-	c=call_id+RAND_DIGITS+1;
100
-	len=MAX_PID_LEN;
101
-	int2reverse_hex( &c, &len, pid_nr );
102
-	while (len) { *c='z'; len--; c++; }
103
-	*c='-';
104
-
105
-	callid_seq=random() % TABLE_ENTRIES;
142
+	from_tag[MD5_LEN]=CID_SEP;
106 143
 
144
+	return 1;
107 145
 }
108 146
 
109
-void generate_callid() {
110
-	char *c;
111
-	int len;
112 147
 
113
-	/* HACK: not long enough */
114
-	callid_seq = (callid_seq+1) % TABLE_ENTRIES;
115
-	c=call_id+RAND_DIGITS+1+MAX_PID_LEN+1;
116
-	len=MAX_SEQ_LEN;
117
-	int2reverse_hex( &c, &len, callid_seq );
118
-	while (len) { *c='z'; len--; c++; }
148
+int uac_child_init( int rank ) 
149
+{
150
+	callid_suffix_len=snprintf(callid_suffix,CALLID_SUFFIX_LEN,
151
+			"%c%d@%*s", CID_SEP, my_pid(), 
152
+			sock_info[bind_idx].address_str.len,
153
+			sock_info[bind_idx].address_str.s );
154
+	if (callid_suffix_len==-1) {
155
+		LOG(L_ERR, "ERROR: uac_child_init: 
156
+			buffer too small\n");
157
+		return -1;
158
+	}
159
+	DBG("DEBUG: callid_suffix: %s\n", callid_suffix );
160
+	return 1;
119 161
 }
120 162
 
121
-
122
-
123 163
 int t_uac( str *msg_type, str *dst, 
124 164
 	str *headers, str *body, str *from, 
125 165
 	transaction_cb completion_cb, void *cbp, 
126 166
 	dlg_t dlg)
127 167
 {
128 168
 
169
+	int r;
129 170
 	struct cell *new_cell;
130 171
 	struct proxy_l *proxy;
131 172
 	int branch;
... ...
@@ -136,6 +180,11 @@ int t_uac( str *msg_type, str *dst,
136 136
 	struct socket_info* send_sock;
137 137
 	struct retr_buf *request;
138 138
 	str dummy_from;
139
+	str callid_s;
140
+	str fromtag;
141
+
142
+	/* make -Wall shut up */
143
+	ret=0;
139 144
 
140 145
 	proxy=uri2proxy( dst );
141 146
 	if (proxy==0) {
... ...
@@ -155,7 +204,20 @@ int t_uac( str *msg_type, str *dst,
155 155
 		ret=E_NO_SOCKET;
156 156
 		goto error00;
157 157
 	}
158
-	generate_callid();
158
+
159
+	/* update callid */
160
+	/* generate_callid(); */
161
+	callid_nr++;
162
+	r=snprintf(callid, rand_len+1, "%0*lx", rand_len, callid_nr );
163
+	if (r==-1) {
164
+		LOG(L_CRIT, "BUG: SORRY, callid calculation failed\n");
165
+		goto error00;
166
+	}
167
+	/* fix the ZT 0 */
168
+	callid[rand_len]=CID_SEP;
169
+	callid_s.s=callid;
170
+	callid_s.len=rand_len+callid_suffix_len;
171
+	DBG("DEBUG: NEW CALLID:%*s\n", callid_s.len, callid_s.s );
159 172
 
160 173
 	new_cell = build_cell( NULL ) ; 
161 174
 	if (!new_cell) {
... ...
@@ -183,17 +245,22 @@ int t_uac( str *msg_type, str *dst,
183 183
 	UNLOCK_HASH(new_cell->hash_index);
184 184
 
185 185
 	if (from) dummy_from=*from; else { dummy_from.s=0; dummy_from.len=0; }
186
-	buf=build_uac_request(  *msg_type, *dst, dummy_from, *headers, *body,
187
-							branch,
188
-							new_cell, /* t carries hash_index, label, md5,
189
-										uac[].send_sock and other pieces of
190
-										information needed to print a message*/
191
-							 &req_len );
192
-    if (!buf) {
193
-        ret=E_OUT_OF_MEM;
194
-        LOG(L_ERR, "ERROR: t_uac: short of req shmem\n");
195
-        goto error01;
196
-    }      
186
+	/* calculate from tag from callid */
187
+	crcitt_string_array(&from_tag[MD5_LEN+1], &callid_s, 1 );
188
+	fromtag.s=from_tag; fromtag.len=FROM_TAG_LEN;
189
+	buf=build_uac_request(  *msg_type, *dst, 
190
+			dummy_from, fromtag,
191
+			DEFAULT_CSEQ, callid_s, 
192
+			*headers, *body, branch,
193
+			new_cell, /* t carries hash_index, label, md5,
194
+				uac[].send_sock and other pieces of
195
+				information needed to print a message*/
196
+		&req_len );
197
+	if (!buf) {
198
+		ret=E_OUT_OF_MEM;
199
+		LOG(L_ERR, "ERROR: t_uac: short of req shmem\n");
200
+		goto error01;
201
+	}      
197 202
 	new_cell->method.s=buf;new_cell->method.len=msg_type->len;
198 203
 
199 204
 
... ...
@@ -34,23 +34,26 @@
34 34
 #include "config.h"
35 35
 #include "t_dlg.h"
36 36
 
37
+#ifdef _DEPRECATED
37 38
 /* number of random digits in beginning of a string --
38 39
    please multiples of 2 */
39 40
 #define RAND_DIGITS	6
40
-/* maximum size of pid in hex characters */
41
-#define MAX_PID_LEN	4
42 41
 /* maximum seq size in hex chars */
43 42
 #define MAX_SEQ_LEN (T_TABLE_POWER*2)
43
+/* maximum size of pid in hex characters */
44
+#define MAX_PID_LEN	4
45
+extern char call_id[RAND_DIGITS+1+MAX_PID_LEN+1+MAX_SEQ_LEN+1];
46
+void generate_callid();
47
+#endif
48
+
49
+#define DEFAULT_CSEQ	10
44 50
 
45 51
 extern char *uac_from;
46 52
 extern char *fifo;
47 53
 extern int fifo_mode;
48
-extern char call_id[RAND_DIGITS+1+MAX_PID_LEN+1+MAX_SEQ_LEN+1];
49
-extern char from_tag[ MD5_LEN +1];
50 54
 
51
-void uac_init();
52
-void uac_child_init( int rank );
53
-void generate_callid();
55
+int uac_init();
56
+int uac_child_init( int rank );
54 57
 
55 58
 typedef int (*tuac_f)(str *msg_type, str *dst, str *headers,str *body,
56 59
 	str *from, transaction_cb completion_cb, void *cbp,
... ...
@@ -655,7 +655,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
655 655
 		/*server header*/
656 656
 		len += SERVER_HDR_LEN + CRLF_LEN;
657 657
 		/*content length header*/
658
-		len +=CONTENT_LEN_LEN + CRLF_LEN;
658
+		len +=CONTENT_LENGTH_LEN+1 + CRLF_LEN;
659 659
 	}
660 660
 	if (sip_warning) {
661 661
 		warning = warning_builder(msg,&warning_len);
... ...
@@ -743,8 +743,8 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
743 743
 		memcpy( p, CRLF, CRLF_LEN );
744 744
 		p+=CRLF_LEN;
745 745
 		/* content length header*/
746
-		memcpy( p, CONTENT_LEN , CONTENT_LEN_LEN );
747
-		p+=CONTENT_LEN_LEN;
746
+		memcpy( p, CONTENT_LENGTH "0" , CONTENT_LENGTH_LEN+1 );
747
+		p+=CONTENT_LENGTH_LEN+1;
748 748
 		memcpy( p, CRLF, CRLF_LEN );
749 749
 		p+=CRLF_LEN;
750 750
 	}