Browse code

modules_s/registrar: moved to obsolete folder

- use instead the other module with same name

Daniel-Constantin Mierla authored on 28/12/2012 23:18:25
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,879 +0,0 @@
1
-/*
2
- * $Id$
3
- *
4
- * Process REGISTER request and send reply
5
- *
6
- * Copyright (C) 2001-2003 FhG Fokus
7
- *
8
- * This file is part of ser, a free SIP server.
9
- *
10
- * ser is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation; either version 2 of the License, or
13
- * (at your option) any later version
14
- *
15
- * For a license to use the ser software under conditions
16
- * other than those described here, or to purchase support for this
17
- * software, please contact iptel.org by e-mail at the following addresses:
18
- *    info@iptel.org
19
- *
20
- * ser is distributed in the hope that it will be useful,
21
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
- * GNU General Public License for more details.
24
- *
25
- * You should have received a copy of the GNU General Public License 
26
- * along with this program; if not, write to the Free Software 
27
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
- *
29
- * History:
30
- * ----------
31
- * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
32
- * 2003-02-28 scrathcpad compatibility abandoned (jiri)
33
- * 2003-03-21 save_noreply added, patch provided by 
34
- *            Maxim Sobolev <sobomax@sippysoft.com> (janakj)
35
- * 2005-02-25 incoming socket is saved in USRLOC (bogdan)
36
- * 2010-09-30 trust received info only if trust_received_flag is set (andrei)
37
- * 2010-10-01 if received info is available try to set the incoming socket
38
- *            to the information saved in received.
39
- */
40
-
41
-
42
-#include "../../comp_defs.h"
43
-#include "../../str.h"
44
-#include "../../dprint.h"
45
-#include "../../parser/parse_to.h"
46
-#include "../../parser/parse_param.h"
47
-#include "../../parser/parse_uri.h"
48
-#include "../../resolve.h"
49
-#include "../../socket_info.h"
50
-#include "../../trim.h"
51
-#include "../../ut.h"
52
-#include "../usrloc/usrloc.h"
53
-#include "../../qvalue.h"
54
-#include "../../id.h"
55
-#include "../../globals.h"
56
-#include "../../sr_module.h"
57
-#include "common.h"
58
-#include "sip_msg.h"
59
-#include "rerrno.h"
60
-#include "reply.h"
61
-#include "reg_mod.h"
62
-#include "regtime.h"
63
-#include "save.h"
64
-
65
-static int mem_only = 0;
66
-
67
-void remove_cont(urecord_t* _r, ucontact_t* _c)
68
-{
69
-	if (_c->prev) {
70
-		_c->prev->next = _c->next;
71
-		if (_c->next) {
72
-			_c->next->prev = _c->prev;
73
-		}
74
-	} else {
75
-		_r->contacts = _c->next;
76
-		if (_c->next) {
77
-			_c->next->prev = 0;
78
-		}
79
-	}
80
-}
81
-
82
-
83
-/*
84
- * Process request that contained a star, in that case, 
85
- * we will remove all bindings with the given username 
86
- * from the usrloc and return 200 OK response
87
- */
88
-static inline int star(udomain_t* _d, str* _u, str* aor_filter)
89
-{
90
-	urecord_t* r;
91
-	ucontact_t* c;
92
-	
93
-	ul.lock_udomain(_d);
94
-
95
-	if (!ul.get_urecord(_d, _u, &r)) {
96
-		c = r->contacts;
97
-		while(c) {
98
-			if (mem_only) {
99
-				c->flags |= FL_MEM;
100
-			} else {
101
-				c->flags &= ~FL_MEM;
102
-			}
103
-			c = c->next;
104
-		}
105
-	}
106
-
107
-	if (ul.delete_urecord(_d, _u) < 0) {
108
-		LOG(L_ERR, "star(): Error while removing record from usrloc\n");
109
-		
110
-		     /* Delete failed, try to get corresponding
111
-		      * record structure and send back all existing
112
-		      * contacts
113
-		      */
114
-		rerrno = R_UL_DEL_R;
115
-		if (!ul.get_urecord(_d, _u, &r)) {
116
-			build_contact(r->contacts, aor_filter);
117
-		}
118
-		ul.unlock_udomain(_d);
119
-		return -1;
120
-	}
121
-	ul.unlock_udomain(_d);
122
-	return 0;
123
-}
124
-
125
-
126
-/*
127
- * Process request that contained no contact header
128
- * field, it means that we have to send back a response
129
- * containing a list of all existing bindings for the
130
- * given aor
131
- */
132
-static inline int no_contacts(udomain_t* _d, str* _u, str* aor_filter)
133
-{
134
-	urecord_t* r;
135
-	int res;
136
-	
137
-	ul.lock_udomain(_d);
138
-	res = ul.get_urecord(_d, _u, &r);
139
-	if (res < 0) {
140
-		rerrno = R_UL_GET_R;
141
-		LOG(L_ERR, "no_contacts(): Error while retrieving record from usrloc\n");
142
-		ul.unlock_udomain(_d);
143
-		return -1;
144
-	}
145
-	
146
-	if (res == 0) {  /* Contacts found */
147
-		build_contact(r->contacts, aor_filter);
148
-	}
149
-	ul.unlock_udomain(_d);
150
-	return 0;
151
-}
152
-
153
-
154
-#define DSTIP_PARAM ";dstip="
155
-#define DSTIP_PARAM_LEN (sizeof(DSTIP_PARAM) - 1)
156
-
157
-#define DSTPORT_PARAM ";dstport="
158
-#define DSTPORT_PARAM_LEN (sizeof(DSTPORT_PARAM) - 1)
159
-
160
-
161
-/*
162
- * Create received SIP uri that will be either
163
- * passed to registrar in an AVP or apended
164
- * to Contact header field as a parameter
165
- */
166
-static int create_rcv_uri(str** uri, struct sip_msg* m)
167
-{
168
-	static str res;
169
-	static char buf[MAX_URI_SIZE];
170
-	char* p;
171
-	str src_ip, src_port, dst_ip, dst_port;
172
-	int len;
173
-	str proto;
174
-
175
-	if (!uri || !m) {
176
-		ERR("Invalid parameter value\n");
177
-		return -1;
178
-	}
179
-
180
-	src_ip.s = ip_addr2a(&m->rcv.src_ip);
181
-	src_ip.len = strlen(src_ip.s);
182
-	src_port.s = int2str(m->rcv.src_port, &src_port.len);
183
-
184
-	dst_ip = m->rcv.bind_address->address_str;
185
-	dst_port = m->rcv.bind_address->port_no_str;
186
-
187
-	switch(m->rcv.proto) {
188
-	case PROTO_NONE:
189
-	case PROTO_UDP:
190
-		proto.s = 0; /* Do not add transport parameter, UDP is default */
191
-		proto.len = 0;
192
-		break;
193
-
194
-	case PROTO_TCP:
195
-		proto.s = "TCP";
196
-		proto.len = 3;
197
-		break;
198
-
199
-	case PROTO_TLS:
200
-		proto.s = "TLS";
201
-		proto.len = 3;
202
-		break;
203
-
204
-	case PROTO_SCTP:
205
-		proto.s = "SCTP";
206
-		proto.len = 4;
207
-		break;
208
-
209
-	default:
210
-		ERR("BUG: Unknown transport protocol\n");
211
-		return -1;
212
-	}
213
-
214
-	len = 4 + src_ip.len + 1 + src_port.len;
215
-	if (proto.s) {
216
-		len += TRANSPORT_PARAM_LEN;
217
-		len += proto.len;
218
-	}
219
-
220
-	len += DSTIP_PARAM_LEN + dst_ip.len;
221
-	len += DSTPORT_PARAM_LEN + dst_port.len;
222
-
223
-	if (len > MAX_URI_SIZE) {
224
-		ERR("Buffer too small\n");
225
-		return -1;
226
-	}
227
-
228
-	p = buf;
229
-	memcpy(p, "sip:", 4);
230
-	p += 4;
231
-
232
-	memcpy(p, src_ip.s, src_ip.len);
233
-	p += src_ip.len;
234
-
235
-	*p++ = ':';
236
-
237
-	memcpy(p, src_port.s, src_port.len);
238
-	p += src_port.len;
239
-
240
-	if (proto.s) {
241
-		memcpy(p, TRANSPORT_PARAM, TRANSPORT_PARAM_LEN);
242
-		p += TRANSPORT_PARAM_LEN;
243
-
244
-		memcpy(p, proto.s, proto.len);
245
-		p += proto.len;
246
-	}
247
-
248
-	memcpy(p, DSTIP_PARAM, DSTIP_PARAM_LEN);
249
-	p += DSTIP_PARAM_LEN;
250
-	memcpy(p, dst_ip.s, dst_ip.len);
251
-	p += dst_ip.len;
252
-
253
-	memcpy(p, DSTPORT_PARAM, DSTPORT_PARAM_LEN);
254
-	p += DSTPORT_PARAM_LEN;
255
-	memcpy(p, dst_port.s, dst_port.len);
256
-	p += dst_port.len;
257
-
258
-	res.s = buf;
259
-	res.len = len;
260
-	*uri = &res;
261
-
262
-	return 0;
263
-}
264
-
265
-
266
-
267
-/** find send socket based on dst_ip saved in rcv_uri.
268
- * Based on usrloc(s) find_socket() (modules_s/usrloc/udomain.c),
269
- * but will try only IPs (no DNS lookups) and it is quiet on errors.
270
- *
271
- * @param received - received uri in the format:
272
- *                   sip:src_host:src_port;dstip=IP;dstport=port
273
- * @param ip - filled with the ip in dst_ip.
274
- * @param port - filled with the port in dst_ip (if present)
275
- * @param proto - filled with the uri protocol.
276
- * @return <0 on error, 0 on success
277
- */
278
-int parse_uri_dstip(str* received, struct ip_addr* ip, unsigned short* port,
279
-						unsigned short* proto)
280
-{
281
-	struct sip_uri puri;
282
-	param_hooks_t hooks;
283
-	struct ip_addr* p;
284
-	param_t* params = 0;
285
-	int error;
286
-
287
-	if (unlikely(!received)) return 0;
288
-	if (unlikely(parse_uri(received->s, received->len, &puri) < 0))
289
-		goto error_uri;
290
-	*proto = puri.proto;
291
-	if (unlikely(parse_params(&puri.params, CLASS_URI, &hooks, &params) < 0))
292
-		goto error_uri_params;
293
-	if (unlikely(hooks.uri.dstip == 0 || hooks.uri.dstip->body.s == 0 ||
294
-				 hooks.uri.dstip->body.len == 0))
295
-		goto end; /* no dst_ip param */
296
-	/* check if it's ipv4 or ipv6 */
297
-	if (
298
-#ifdef USE_IPV6
299
-			likely(((p = str2ip(&hooks.uri.dstip->body)) != 0) ||
300
-				((p = str2ip6(&hooks.uri.dstip->body)) != 0))
301
-#else /* ! USE_IPV6 */
302
-			likely(((p = str2ip(&hooks.uri.dstip->body)) != 0))
303
-#endif /* USE_IPV6 */
304
-				) {
305
-		*ip = *p;
306
-	} else
307
-		goto error_no_ip; /* no ip */
308
-	if (likely(hooks.uri.dstport != 0 && hooks.uri.dstport->body.s  != 0 &&
309
-			hooks.uri.dstport->body.len !=0)) {
310
-		*port = str2s(hooks.uri.dstport->body.s, hooks.uri.dstport->body.len,
311
-					&error);
312
-		if (unlikely(error != 0))
313
-			goto error_port;
314
-	} else {
315
-		*port = 0;
316
-	}
317
-	
318
-end:
319
-	if (params) free_params(params);
320
-	return 0;
321
-error_uri:
322
-error_uri_params:
323
-error_no_ip:
324
-error_port:
325
-	if (params) free_params(params);
326
-	return -1;
327
-}
328
-
329
-
330
-
331
-/** try to find the send socket based on saved received information in uri.
332
- * @param received - received uri in the format:
333
- *                   sip:src_host:src_port;dstip=IP;dstport=port
334
- * @return 0 on error or not found, socket_info pointer on success.
335
- */
336
-static struct socket_info* find_send_socket(str* received)
337
-{
338
-	struct ip_addr ip;
339
-	unsigned short port;
340
-	unsigned short proto;
341
-	struct socket_info* si;
342
-
343
-	if (unlikely(parse_uri_dstip(received, &ip, &port, &proto) < 0))
344
-		return 0;
345
-	si = find_si(&ip, port, proto);
346
-#if 0
347
-	/* FIXME: which would be the best fallback procedure, proto:ip:*
348
-	   (try to keep the ip, although unlikely to be possible for replication)
349
-	   or proto:*: port (try to keep the same port, usefull for proxies
350
-	   behind transparent proxies /LBs) */
351
-	if (si == 0)
352
-		si = find_si(&ip, 0, proto);
353
-#endif
354
-	return si;
355
-}
356
-
357
-
358
-
359
-/*
360
- * Message contained some contacts, but record with same address of record was
361
- * not found so we have to create a new record and insert all contacts from
362
- * the message that have expires > 0. The function returns a negative number
363
- * on error, a positive number if the number of contacts would exceed
364
- * max_contacts and 0 on success.
365
- */
366
-static inline int insert(struct sip_msg* _m, str* aor, contact_t* _c, udomain_t* _d, str* _u, str *ua, str* aor_filter, int sid)
367
-{
368
-	urecord_t* r = 0;
369
-	ucontact_t* c;
370
-	int e, cseq, num;
371
-	qvalue_t q;
372
-	str callid;
373
-	unsigned int flags;
374
-	str *recv, *inst;
375
-	struct socket_info* send_sock;
376
-
377
-	if (isflagset(_m, save_nat_flag) == 1) flags = FL_NAT;
378
-	else flags = FL_NONE;
379
-
380
-	flags |= mem_only;
381
-
382
-	num = 0;
383
-	while(_c) {
384
-		if (calc_contact_expires(_m, _c->expires, &e) < 0) {
385
-			LOG(L_ERR, "insert(): Error while calculating expires\n");
386
-			return -1;
387
-		}
388
-		     /* Skip contacts with zero expires */
389
-		if (e == 0) goto skip;
390
-
391
-		if (max_contacts && (num >= max_contacts)) {
392
-			rerrno = R_TOO_MANY;
393
-			ul.delete_urecord(_d, _u);
394
-			return 1;
395
-		}
396
-		num++;
397
-		
398
-	        if (r == 0) {
399
-			if (ul.insert_urecord(_d, _u, &r) < 0) {
400
-				rerrno = R_UL_NEW_R;
401
-				LOG(L_ERR, "insert(): Can't insert new record structure\n");
402
-				return -2;
403
-			}
404
-		}
405
-		
406
-		     /* Calculate q value of the contact */
407
-		if (calc_contact_q(_c->q, &q) < 0) {
408
-			LOG(L_ERR, "insert(): Error while calculating q\n");
409
-			ul.delete_urecord(_d, _u);
410
-			return -3;
411
-		}
412
-
413
-		     /* Get callid of the message */
414
-		callid = _m->callid->body;	
415
-		trim_trailing(&callid);
416
-		
417
-		     /* Get CSeq number of the message */
418
-		if (str2int(&get_cseq(_m)->number, (unsigned int*)&cseq) < 0) {
419
-			rerrno = R_INV_CSEQ;
420
-			LOG(L_ERR, "insert(): Error while converting cseq number\n");
421
-			ul.delete_urecord(_d, _u);
422
-			return -4;
423
-		}
424
-		
425
-		send_sock = 0;
426
-		if (_c->received &&
427
-				(((trust_received_flag >= 0) &&
428
-					(isflagset(_m, trust_received_flag) == 1)) ||
429
-				 (trust_received_flag == -2)) ) {
430
-			recv = &_c->received->body;
431
-			send_sock = find_send_socket(recv);
432
-		} else if (flags & FL_NAT && _m->first_line.type == SIP_REQUEST) {
433
-			if (create_rcv_uri(&recv, _m) < 0) {
434
-				ERR("Error while creating rcv URI\n");
435
-				ul.delete_urecord(_d, _u);
436
-				return -4;
437
-			}
438
-		} else {
439
-			recv = 0;
440
-		}
441
-
442
-		if(_c->instance) {
443
-			inst = &_c->instance->body;
444
-		} else {
445
-			inst = 0;
446
-		}
447
-
448
-		if (ul.insert_ucontact(r, aor, &_c->uri, e, q, &callid, cseq,
449
-								flags, &c, ua, recv,
450
-								send_sock?send_sock:_m->rcv.bind_address,
451
-								inst, sid) < 0)
452
-		{
453
-			rerrno = R_UL_INS_C;
454
-			LOG(L_ERR, "insert(): Error while inserting contact\n");
455
-			ul.delete_urecord(_d, _u);
456
-			return -5;
457
-		}
458
-		
459
-	skip:
460
-		_c = get_next_contact(_c);
461
-	}
462
-	
463
-	if (r) {
464
-		if (!r->contacts) {
465
-			ul.delete_urecord(_d, _u);
466
-		} else {
467
-			build_contact(r->contacts, aor_filter);
468
-		}
469
-	}
470
-	
471
-	return 0;
472
-}
473
-
474
-
475
-static int test_max_contacts(struct sip_msg* _m, urecord_t* _r, contact_t* _c)
476
-{
477
-	int num;
478
-	int e;
479
-	ucontact_t* ptr, *cont;
480
-	
481
-	num = 0;
482
-	ptr = _r->contacts;
483
-	while(ptr) {
484
-		if (VALID_CONTACT(ptr, act_time)) {
485
-			num++;
486
-		}
487
-		ptr = ptr->next;
488
-	}
489
-	DBG("test_max_contacts: %d valid contacts\n", num);
490
-	
491
-	while(_c) {
492
-		if (calc_contact_expires(_m, _c->expires, &e) < 0) {
493
-			LOG(L_ERR, "test_max_contacts: Error while calculating expires\n");
494
-			return -1;
495
-		}
496
-		
497
-		if (ul.get_ucontact(_r, &_c->uri, &cont) > 0) {
498
-			     /* Contact not found */
499
-			if (e != 0) num++;
500
-		} else {
501
-			if (e == 0) num--;
502
-		}
503
-		
504
-		_c = get_next_contact(_c);
505
-	}
506
-	
507
-	DBG("test_max_contacts: %d contacts after commit, max_contacts=%d\n", num, max_contacts);
508
-	if (num > max_contacts) {
509
-		rerrno = R_TOO_MANY;
510
-		return 1;
511
-	}
512
-	
513
-	return 0;
514
-}
515
-
516
-
517
-/*
518
- * Message contained some contacts and appropriate
519
- * record was found, so we have to walk through
520
- * all contacts and do the following:
521
- * 1) If contact in usrloc doesn't exists and
522
- *    expires > 0, insert new contact
523
- * 2) If contact in usrloc exists and expires
524
- *    > 0, update the contact
525
- * 3) If contact in usrloc exists and expires
526
- *    == 0, delete contact
527
- *
528
- * The function returns a negative number on error, a positive number if
529
- * max_contacts is set and the number of contacts after the change would
530
- * exceed that maximum number of allowed contacts. On success the function
531
- * returns 0.
532
- */
533
-static inline int update(struct sip_msg* _m, urecord_t* _r, str* aor, contact_t* _c, str* _ua, str* aor_filter, int sid)
534
-{
535
-	ucontact_t* c, *c2;
536
-	str callid;
537
-	int cseq, e, ret;
538
-	int set, reset;
539
-	qvalue_t q;
540
-	unsigned int nated;
541
-	str* recv, *inst;
542
-	struct socket_info* send_sock;
543
-	
544
-	if (isflagset(_m, save_nat_flag) == 1) {
545
-		nated = FL_NAT;
546
-	} else {
547
-		nated = FL_NONE;
548
-	}
549
-
550
-	if (max_contacts) {
551
-		ret = test_max_contacts(_m, _r, _c);
552
-		if (ret != 0) {
553
-			/* test_max_contacts returns a negative number on error and a
554
-			 * positive number if the number of contacts after the update
555
-			 * exceeds the configured max_contacts. In both cases we return
556
-			 * here. */
557
-			build_contact(_r->contacts, aor_filter);
558
-			return ret;
559
-		}
560
-	}
561
-
562
-	_c = get_first_contact(_m);
563
-
564
-	while(_c) {
565
-		if (calc_contact_expires(_m, _c->expires, &e) < 0) {
566
-			build_contact(_r->contacts, aor_filter);
567
-			LOG(L_ERR, "update(): Error while calculating expires\n");
568
-			return -1;
569
-		}
570
-
571
-		if(_c->instance) {
572
-			inst = &_c->instance->body;
573
-		} else {
574
-			inst = 0;
575
-		}
576
-
577
-		if (ul.get_ucontact_by_instance(_r, &_c->uri, inst, &c) > 0) {
578
-			     /* Contact not found */
579
-			if (e != 0) {
580
-				     /* Calculate q value of the contact */
581
-				if (calc_contact_q(_c->q, &q) < 0) {
582
-					LOG(L_ERR, "update(): Error while calculating q\n");
583
-					return -2;
584
-				}
585
-				
586
-				     /* Get callid of the message */
587
-				callid = _m->callid->body;
588
-				trim_trailing(&callid);
589
-				
590
-				     /* Get CSeq number of the message */
591
-				if (str2int(&(((struct cseq_body*)_m->cseq->parsed)->number), 
592
-								(unsigned int*) &cseq) < 0) {
593
-					rerrno = R_INV_CSEQ;
594
-					LOG(L_ERR, "update(): Error while converting cseq number\n");
595
-					return -3;
596
-				}
597
-				
598
-				send_sock = 0;
599
-				if (_c->received &&
600
-						(((trust_received_flag >=0 ) &&
601
-							(isflagset(_m, trust_received_flag) == 1)) ||
602
-						 (trust_received_flag == -2)) ) {
603
-					recv = &_c->received->body;
604
-					send_sock = find_send_socket(recv);
605
-				} else if (nated & FL_NAT && 
606
-							_m->first_line.type == SIP_REQUEST) {
607
-					if (create_rcv_uri(&recv, _m) < 0) {
608
-						ERR("Error while creating rcv URI\n");
609
-						rerrno = R_UL_INS_C;
610
-						return -4;
611
-					}
612
-				} else {
613
-					recv = 0;
614
-				}
615
-
616
-				if (ul.insert_ucontact(_r, aor, &_c->uri, e, q, &callid, cseq,
617
-						       nated | mem_only,
618
-						       &c2, _ua, recv,
619
-								send_sock?send_sock:_m->rcv.bind_address,
620
-									   inst, sid) < 0) {
621
-					rerrno = R_UL_INS_C;
622
-					LOG(L_ERR, "update(): Error while inserting contact\n");
623
-					return -4;
624
-				}
625
-			}
626
-		} else {
627
-			if (e == 0) {
628
-				if (mem_only) {
629
-					c->flags |= FL_MEM;
630
-				} else {
631
-					c->flags &= ~FL_MEM;
632
-				}
633
-
634
-				if (ul.delete_ucontact(_r, c) < 0) {
635
-					rerrno = R_UL_DEL_C;
636
-					LOG(L_ERR, "update(): Error while deleting contact\n");
637
-					return -5;
638
-				}
639
-			} else {
640
-				     /* Calculate q value of the contact */
641
-				if (calc_contact_q(_c->q, &q) < 0) {
642
-					LOG(L_ERR, "update(): Error while calculating q\n");
643
-					return -6;
644
-				}
645
-				
646
-				     /* Get callid of the message */
647
-				callid = _m->callid->body;				
648
-				trim_trailing(&callid);
649
-				
650
-				     /* Get CSeq number of the message */
651
-				if (str2int(&(((struct cseq_body*)_m->cseq->parsed)->number), (unsigned int*)&cseq)
652
-							< 0) {
653
-					rerrno = R_INV_CSEQ;
654
-					LOG(L_ERR, "update(): Error while converting cseq number\n");
655
-					return -7;
656
-				}
657
-				
658
-				send_sock = 0;
659
-				if (_c->received &&
660
-						(((trust_received_flag >=0 ) &&
661
-							(isflagset(_m, trust_received_flag) == 1)) ||
662
-						 (trust_received_flag == -2)) ) {
663
-					recv = &_c->received->body;
664
-					send_sock = find_send_socket(recv);
665
-				} else if (nated & FL_NAT && _m->first_line.type == SIP_REQUEST) {
666
-					if (create_rcv_uri(&recv, _m) < 0) {
667
-						ERR("Error while creating rcv URI\n");
668
-					        rerrno = R_UL_UPD_C;
669
-						return -4;
670
-					}
671
-				} else {
672
-					recv = 0;
673
-				}
674
-
675
-				set = nated | mem_only;
676
-				reset = ~(nated | mem_only) & (FL_NAT | FL_MEM);
677
-				if (ul.update_ucontact(c, &_c->uri, aor, e, q, &callid, cseq,
678
-							set, reset, _ua, recv,
679
-							send_sock?send_sock:_m->rcv.bind_address,
680
-							inst, sid) < 0) {
681
-					rerrno = R_UL_UPD_C;
682
-					LOG(L_ERR, "update(): Error while updating contact\n");
683
-					return -8;
684
-				}
685
-			}
686
-		}
687
-		_c = get_next_contact(_c);
688
-	}
689
-
690
-	return 0;
691
-}
692
-
693
-
694
-static int get_server_id(void)
695
-{
696
-	int_str name, val;
697
-	int sid;
698
-	
699
-
700
-	if (server_id_attr.len && server_id_attr.s) {
701
-		name.s.s = server_id_attr.s + 1; /* Skip the 1st char which is $ */
702
-		name.s.len = server_id_attr.len - 1;
703
-		if (search_first_avp(AVP_TRACK_FROM | AVP_NAME_STR, name, &val, 0)) {
704
-			if (str2sint(&val.s, &sid) == 0) return sid;
705
-		}
706
-	}
707
-
708
-	/* No server_id attribute found or the attribute doesn't have
709
-	 * meaningful value, return the server id of this SER server
710
-	 */
711
-	return server_id;
712
-}
713
-
714
-
715
-/* 
716
- * This function will process request that
717
- * contained some contact header fields
718
- */
719
-static inline int contacts(struct sip_msg* _m, contact_t* _c, udomain_t* _d, str* _u, str* _ua, str* aor_filter)
720
-{
721
-	int res, sid;
722
-	urecord_t* r;
723
-	str* aor;
724
-	int_str name, val;
725
-
726
-	if (aor_attr.len && aor_attr.s) {
727
-		name.s.s = aor_attr.s + 1; /* Skip the 1st char which is $ */
728
-		name.s.len = aor_attr.len - 1;
729
-		if (search_first_avp(AVP_TRACK_TO | AVP_NAME_STR, name, &val, 0)) {
730
-			aor = &val.s;
731
-		} else {
732
-			aor = &get_to(_m)->uri;
733
-		}
734
-	} else {
735
-		aor = &get_to(_m)->uri;
736
-	}
737
-
738
-	sid = get_server_id();
739
-
740
-	ul.lock_udomain(_d);
741
-	res = ul.get_urecord(_d, _u, &r);
742
-	if (res < 0) {
743
-		rerrno = R_UL_GET_R;
744
-		LOG(L_ERR, "contacts(): Error while retrieving record from usrloc\n");
745
-		ul.unlock_udomain(_d);
746
-		return -2;
747
-	}
748
-
749
-	if (res == 0) { /* Contacts found */
750
-		if ((res = update(_m, r, aor, _c, _ua, aor_filter, sid) < 0)) {
751
-			LOG(L_ERR, "contacts(): Error while updating record\n");
752
-		}
753
-		build_contact(r->contacts, aor_filter);
754
-		ul.release_urecord(r);
755
-	} else {
756
-		if ((res = insert(_m, aor, _c, _d, _u, _ua, aor_filter, sid) < 0)) {
757
-			LOG(L_ERR, "contacts(): Error while inserting record\n");
758
-		}
759
-	}
760
-	ul.unlock_udomain(_d);
761
-	return res;
762
-}
763
-
764
-#define UA_DUMMY_STR "Unknown"
765
-#define UA_DUMMY_LEN 7
766
-
767
-
768
-
769
-/*
770
- * Process REGISTER request and save it's contacts
771
- */
772
-static inline int save_real(struct sip_msg* _m, udomain_t* _t, char* aor_filt, int doreply)
773
-{
774
-	contact_t* c;
775
-	int st;
776
-	str uid, ua, aor_filter;
777
-
778
-	rerrno = R_FINE;
779
-
780
-	if (parse_message(_m) < 0) {
781
-		goto error;
782
-	}
783
-
784
-	if (check_contacts(_m, &st) > 0) {
785
-		goto error;
786
-	}
787
-	
788
-	if (aor_filt) {
789
-	    if (get_str_fparam(&aor_filter, _m, (fparam_t*)aor_filt) != 0) {
790
-		ERR("registrar:save: Unable to get the AOR value\n");
791
-		return -1;
792
-	    }
793
-	} else {
794
-	    aor_filter.s = 0;
795
-	    aor_filter.len = 0;
796
-	}
797
-
798
-	get_act_time();
799
-	c = get_first_contact(_m);
800
-
801
-	if (get_to_uid(&uid, _m) < 0) goto error;
802
-
803
-	ua.len = 0;
804
-	if (parse_headers(_m, HDR_USERAGENT_F, 0) != -1 && _m->user_agent &&
805
-	    _m->user_agent->body.len > 0) {
806
-		ua.len = _m->user_agent->body.len;
807
-		ua.s = _m->user_agent->body.s;
808
-	}
809
-	if (ua.len == 0) {
810
-		ua.len = UA_DUMMY_LEN;
811
-		ua.s = UA_DUMMY_STR;
812
-	}
813
-
814
-	if (c == 0) {
815
-		if (st) {
816
-			if (star(_t, &uid, &aor_filter) < 0) goto error;
817
-		} else {
818
-			if (no_contacts(_t, &uid, &aor_filter) < 0) goto error;
819
-		}
820
-	} else {
821
-		if (contacts(_m, c, _t, &uid, &ua, &aor_filter) != 0) goto error;
822
-	}
823
-
824
-	if (doreply) {
825
-		if (send_reply(_m) < 0) return -1;
826
-	} else {
827
-		     /* No reply sent, create attributes with values
828
-		      * of reply code, reason text, and contacts
829
-		      */
830
-		if (setup_attrs(_m) < 0) return -1;
831
-	}
832
-	return 1;
833
-
834
- error:
835
-	if (doreply) {
836
-		send_reply(_m);
837
-		return 0;
838
-	}
839
-	return -2;
840
-}
841
-
842
-
843
-/*
844
- * Process REGISTER request and save it's contacts
845
- */
846
-int save(struct sip_msg* _m, char* table, char* aor_filter)
847
-{
848
-	mem_only = FL_NONE;
849
-	return save_real(_m, (udomain_t*)table, aor_filter, 1);
850
-}
851
-
852
-
853
-/*
854
- * Process REGISTER request and save it's contacts, do not send any replies
855
- */
856
-int save_noreply(struct sip_msg* _m, char* table, char* aor_filter)
857
-{
858
-	mem_only = FL_NONE;
859
-	return save_real(_m, (udomain_t*)table, aor_filter, 0);
860
-}
861
-
862
-
863
-/*
864
- * Update memory cache only
865
- */
866
-int save_memory(struct sip_msg* _m, char* table, char* aor_filter)
867
-{
868
-	mem_only = FL_MEM;
869
-	return save_real(_m, (udomain_t*)table, aor_filter, 1);
870
-}
871
-
872
-/*
873
- * Update memory cache only and do not send reply back
874
- */
875
-int save_mem_nr(struct sip_msg* msg, char* table, char* aor_filter)
876
-{
877
-	mem_only = FL_MEM;
878
-	return save_real(msg, (udomain_t*)table, aor_filter, 0);
879
-}
Browse code

modules_s/register Prevented crash in case of incorrect uri

Error logic performed a free_params on an garbage value (not initialized)
Reported by clang & llvm

Marius Zbihlei authored on 14/01/2011 14:58:03
Showing 1 changed files
... ...
@@ -281,7 +281,7 @@ int parse_uri_dstip(str* received, struct ip_addr* ip, unsigned short* port,
281 281
 	struct sip_uri puri;
282 282
 	param_hooks_t hooks;
283 283
 	struct ip_addr* p;
284
-	param_t* params;
284
+	param_t* params = 0;
285 285
 	int error;
286 286
 
287 287
 	if (unlikely(!received)) return 0;
Browse code

registrar(s): support for disabled aor_attr and server_id_attr

If aor_attr or server_id_attr are empty ("") don't try to use
them.

Andrei Pelinescu-Onciul authored on 06/10/2010 16:53:14
Showing 1 changed files
... ...
@@ -697,10 +697,12 @@ static int get_server_id(void)
697 697
 	int sid;
698 698
 	
699 699
 
700
-	name.s.s = server_id_attr.s + 1; /* Skip the 1st char which is $ */
701
-	name.s.len = server_id_attr.len - 1;
702
-	if (search_first_avp(AVP_TRACK_FROM | AVP_NAME_STR, name, &val, 0)) {
703
-		if (str2sint(&val.s, &sid) == 0) return sid;
700
+	if (server_id_attr.len && server_id_attr.s) {
701
+		name.s.s = server_id_attr.s + 1; /* Skip the 1st char which is $ */
702
+		name.s.len = server_id_attr.len - 1;
703
+		if (search_first_avp(AVP_TRACK_FROM | AVP_NAME_STR, name, &val, 0)) {
704
+			if (str2sint(&val.s, &sid) == 0) return sid;
705
+		}
704 706
 	}