Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,821 +0,0 @@
1
-/**
2
- * Copyright (C) 2009 Daniel-Constantin Mierla (asipto.com)
3
- *
4
- * This file is part of Kamailio, a free SIP server.
5
- *
6
- * Kamailio is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version
10
- *
11
- * Kamailio is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
- */
20
-
21
-/*!
22
- * \file
23
- * \brief Kamailio uac :: UAC send functions
24
- * \ingroup uac
25
- * Module: \ref uac
26
- */
27
-
28
-#include "../../dprint.h"
29
-#include "../../trim.h"
30
-#include "../../route.h"
31
-
32
-#include "../../modules/tm/tm_load.h"
33
-
34
-#include "../../parser/parse_uri.h"
35
-#include "../../parser/parse_from.h"
36
-#include "../../parser/parse_to.h"
37
-#include "../../parser/contact/parse_contact.h"
38
-#include "../../fmsg.h"
39
-
40
-#include "auth.h"
41
-#include "auth_hdr.h"
42
-#include "uac_send.h"
43
-
44
-#define MAX_UACH_SIZE 2048
45
-#define MAX_UACB_SIZE 4086
46
-#define MAX_UACD_SIZE 128
47
-
48
-/** TM bind */
49
-struct tm_binds tmb;
50
-
51
-typedef struct _uac_send_info {
52
-	unsigned int flags;
53
-	char  b_method[32];
54
-	str   s_method;
55
-	char  b_ruri[MAX_URI_SIZE];
56
-	str   s_ruri;
57
-	char  b_turi[MAX_URI_SIZE];
58
-	str   s_turi;
59
-	char  b_furi[MAX_URI_SIZE];
60
-	str   s_furi;
61
-	char  b_callid[128];
62
-	str   s_callid;
63
-	char  b_hdrs[MAX_UACH_SIZE];
64
-	str   s_hdrs;
65
-	char  b_body[MAX_UACB_SIZE];
66
-	str   s_body;
67
-	char  b_ouri[MAX_URI_SIZE];
68
-	str   s_ouri;
69
-	char  b_sock[MAX_URI_SIZE];
70
-	str   s_sock;
71
-	char  b_auser[128];
72
-	str   s_auser;
73
-	char  b_apasswd[64];
74
-	str   s_apasswd;
75
-	char  b_evparam[MAX_UACD_SIZE];
76
-	str   s_evparam;
77
-	unsigned int evroute;
78
-	unsigned int evcode;
79
-	unsigned int evtype;
80
-} uac_send_info_t;
81
-
82
-static struct _uac_send_info _uac_req;
83
-
84
-void uac_send_info_copy(uac_send_info_t *src, uac_send_info_t *dst)
85
-{
86
-	memcpy(dst, src, sizeof(uac_send_info_t));
87
-	dst->s_method.s  = dst->b_method;
88
-	dst->s_ruri.s    = dst->b_ruri;
89
-	dst->s_turi.s    = dst->b_turi;
90
-	dst->s_furi.s    = dst->b_furi;
91
-	dst->s_hdrs.s    = dst->b_hdrs;
92
-	dst->s_body.s    = dst->b_body;
93
-	dst->s_ouri.s    = dst->b_ouri;
94
-	dst->s_auser.s   = dst->b_auser;
95
-	dst->s_apasswd.s = dst->b_apasswd;
96
-	dst->s_callid.s  = dst->b_callid;
97
-	dst->s_sock.s    = dst->b_sock;
98
-	dst->s_evparam.s = dst->b_evparam;
99
-}
100
-
101
-uac_send_info_t *uac_send_info_clone(uac_send_info_t *ur)
102
-{
103
-	uac_send_info_t *tp = NULL;
104
-	tp = (uac_send_info_t*)shm_malloc(sizeof(uac_send_info_t));
105
-	if(tp==NULL)
106
-	{
107
-		LM_ERR("no more shm memory\n");
108
-		return NULL;
109
-	}
110
-	uac_send_info_copy(ur, tp);
111
-
112
-	return tp;
113
-}
114
-
115
-int pv_get_uac_req(struct sip_msg *msg, pv_param_t *param,
116
-		pv_value_t *res)
117
-{
118
-	if(param==NULL || tmb.t_request==NULL)
119
-		return -1;
120
-
121
-	switch(param->pvn.u.isname.name.n)
122
-	{
123
-		case 0:
124
-			return pv_get_uintval(msg, param, res, _uac_req.flags);
125
-		case 1:
126
-			if(_uac_req.s_ruri.len<=0)
127
-				return pv_get_null(msg, param, res);
128
-			return pv_get_strval(msg, param, res, &_uac_req.s_ruri);
129
-		case 2:
130
-			if(_uac_req.s_turi.len<=0)
131
-				return pv_get_null(msg, param, res);
132
-			return pv_get_strval(msg, param, res, &_uac_req.s_turi);
133
-		case 3:
134
-			if(_uac_req.s_furi.len<=0)
135
-				return pv_get_null(msg, param, res);
136
-			return pv_get_strval(msg, param, res, &_uac_req.s_furi);
137
-		case 4:
138
-			if(_uac_req.s_hdrs.len<=0)
139
-				return pv_get_null(msg, param, res);
140
-			return pv_get_strval(msg, param, res, &_uac_req.s_hdrs);
141
-		case 5:
142
-			if(_uac_req.s_body.len<=0)
143
-				return pv_get_null(msg, param, res);
144
-			return pv_get_strval(msg, param, res, &_uac_req.s_body);
145
-		case 6:
146
-			if(_uac_req.s_ouri.len<=0)
147
-				return pv_get_null(msg, param, res);
148
-			return pv_get_strval(msg, param, res, &_uac_req.s_ouri);
149
-		case 7:
150
-			if(_uac_req.s_method.len<=0)
151
-				return pv_get_null(msg, param, res);
152
-			return pv_get_strval(msg, param, res, &_uac_req.s_method);
153
-		case 8:
154
-			return pv_get_uintval(msg, param, res, _uac_req.evroute);
155
-		case 9:
156
-			if(_uac_req.s_auser.len<=0)
157
-				return pv_get_null(msg, param, res);
158
-			return pv_get_strval(msg, param, res, &_uac_req.s_auser);
159
-		case 10:
160
-			if(_uac_req.s_apasswd.len<=0)
161
-				return pv_get_null(msg, param, res);
162
-			return pv_get_strval(msg, param, res, &_uac_req.s_apasswd);
163
-		case 11:
164
-			if(_uac_req.s_callid.len<=0)
165
-				return pv_get_null(msg, param, res);
166
-			return pv_get_strval(msg, param, res, &_uac_req.s_callid);
167
-		case 12:
168
-			if(_uac_req.s_sock.len<=0)
169
-				return pv_get_null(msg, param, res);
170
-			return pv_get_strval(msg, param, res, &_uac_req.s_sock);
171
-		case 14:
172
-			if(_uac_req.s_evparam.len<=0)
173
-				return pv_get_null(msg, param, res);
174
-			return pv_get_strval(msg, param, res, &_uac_req.s_evparam);
175
-		case 15:
176
-			return pv_get_uintval(msg, param, res, _uac_req.evcode);
177
-		case 16:
178
-			return pv_get_uintval(msg, param, res, _uac_req.evtype);
179
-		default:
180
-			return pv_get_uintval(msg, param, res, _uac_req.flags);
181
-	}
182
-	return 0;
183
-}
184
-
185
-int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
186
-		int op, pv_value_t *val)
187
-{
188
-	pv_value_t *tval;
189
-
190
-	if(param==NULL || tmb.t_request==NULL)
191
-		return -1;
192
-
193
-	tval = val;
194
-	if((tval!=NULL) && (tval->flags&PV_VAL_NULL)) {
195
-		tval = NULL;
196
-	}
197
-	switch(param->pvn.u.isname.name.n)
198
-	{
199
-		case 0:
200
-			if(tval==NULL)
201
-			{
202
-				_uac_req.flags = 0;
203
-				_uac_req.s_ruri.len = 0;
204
-				_uac_req.s_furi.len = 0;
205
-				_uac_req.s_turi.len = 0;
206
-				_uac_req.s_ouri.len = 0;
207
-				_uac_req.s_hdrs.len = 0;
208
-				_uac_req.s_body.len = 0;
209
-				_uac_req.s_method.len = 0;
210
-				_uac_req.s_callid.len = 0;
211
-				_uac_req.evroute = 0;
212
-				_uac_req.evtype = 0;
213
-				_uac_req.evcode = 0;
214
-				_uac_req.s_evparam.len = 0;
215
-			}
216
-			break;
217
-		case 1:
218
-			if(tval==NULL)
219
-			{
220
-				_uac_req.s_ruri.len = 0;
221
-				return 0;
222
-			}
223
-			if(!(tval->flags&PV_VAL_STR))
224
-			{
225
-				LM_ERR("Invalid value type\n");
226
-				return -1;
227
-			}
228
-			if(tval->rs.len>=MAX_URI_SIZE)
229
-			{
230
-				LM_ERR("Value size too big\n");
231
-				return -1;
232
-			}
233
-			memcpy(_uac_req.s_ruri.s, tval->rs.s, tval->rs.len);
234
-			_uac_req.s_ruri.s[tval->rs.len] = '\0';
235
-			_uac_req.s_ruri.len = tval->rs.len;
236
-			break;
237
-		case 2:
238
-			if(tval==NULL)
239
-			{
240
-				_uac_req.s_turi.len = 0;
241
-				return 0;
242
-			}
243
-			if(!(tval->flags&PV_VAL_STR))
244
-			{
245
-				LM_ERR("Invalid value type\n");
246
-				return -1;
247
-			}
248
-			if(tval->rs.len>=MAX_URI_SIZE)
249
-			{
250
-				LM_ERR("Value size too big\n");
251
-				return -1;
252
-			}
253
-			memcpy(_uac_req.s_turi.s, tval->rs.s, tval->rs.len);
254
-			_uac_req.s_turi.s[tval->rs.len] = '\0';
255
-			_uac_req.s_turi.len = tval->rs.len;
256
-			break;
257
-		case 3:
258
-			if(tval==NULL)
259
-			{
260
-				_uac_req.s_furi.len = 0;
261
-				return 0;
262
-			}
263
-			if(!(tval->flags&PV_VAL_STR))
264
-			{
265
-				LM_ERR("Invalid value type\n");
266
-				return -1;
267
-			}
268
-			if(tval->rs.len>=MAX_URI_SIZE)
269
-			{
270
-				LM_ERR("Value size too big\n");
271
-				return -1;
272
-			}
273
-			memcpy(_uac_req.s_furi.s, tval->rs.s, tval->rs.len);
274
-			_uac_req.s_furi.s[tval->rs.len] = '\0';
275
-			_uac_req.s_furi.len = tval->rs.len;
276
-			break;
277
-		case 4:
278
-			if(tval==NULL)
279
-			{
280
-				_uac_req.s_hdrs.len = 0;
281
-				return 0;
282
-			}
283
-			if(!(tval->flags&PV_VAL_STR))
284
-			{
285
-				LM_ERR("Invalid value type\n");
286
-				return -1;
287
-			}
288
-			if(tval->rs.len>=MAX_UACH_SIZE)
289
-			{
290
-				LM_ERR("Value size too big\n");
291
-				return -1;
292
-			}
293
-			memcpy(_uac_req.s_hdrs.s, tval->rs.s, tval->rs.len);
294
-			_uac_req.s_hdrs.s[tval->rs.len] = '\0';
295
-			_uac_req.s_hdrs.len = tval->rs.len;
296
-			break;
297
-		case 5:
298
-			if(tval==NULL)
299
-			{
300
-				_uac_req.s_body.len = 0;
301
-				return 0;
302
-			}
303
-			if(!(tval->flags&PV_VAL_STR))
304
-			{
305
-				LM_ERR("Invalid value type\n");
306
-				return -1;
307
-			}
308
-			if(tval->rs.len>=MAX_UACB_SIZE)
309
-			{
310
-				LM_ERR("Value size too big\n");
311
-				return -1;
312
-			}
313
-			memcpy(_uac_req.s_body.s, tval->rs.s, tval->rs.len);
314
-			_uac_req.s_body.s[tval->rs.len] = '\0';
315
-			_uac_req.s_body.len = tval->rs.len;
316
-			break;
317
-		case 6:
318
-			if(tval==NULL)
319
-			{
320
-				_uac_req.s_ouri.len = 0;
321
-				return 0;
322
-			}
323
-			if(!(tval->flags&PV_VAL_STR))
324
-			{
325
-				LM_ERR("Invalid value type\n");
326
-				return -1;
327
-			}
328
-			if(tval->rs.len>=MAX_URI_SIZE)
329
-			{
330
-				LM_ERR("Value size too big\n");
331
-				return -1;
332
-			}
333
-			memcpy(_uac_req.s_ouri.s, tval->rs.s, tval->rs.len);
334
-			_uac_req.s_ouri.s[tval->rs.len] = '\0';
335
-			_uac_req.s_ouri.len = tval->rs.len;
336
-			break;
337
-		case 7:
338
-			if(tval==NULL)
339
-			{
340
-				_uac_req.s_method.len = 0;
341
-				return 0;
342
-			}
343
-			if(!(tval->flags&PV_VAL_STR))
344
-			{
345
-				LM_ERR("Invalid value type\n");
346
-				return -1;
347
-			}
348
-			if(tval->rs.len>=32)
349
-			{
350
-				LM_ERR("Value size too big\n");
351
-				return -1;
352
-			}
353
-			memcpy(_uac_req.s_method.s, tval->rs.s, tval->rs.len);
354
-			_uac_req.s_method.s[tval->rs.len] = '\0';
355
-			_uac_req.s_method.len = tval->rs.len;
356
-			break;
357
-		case 8:
358
-			if(tval==NULL)
359
-			{
360
-				_uac_req.evroute = 0;
361
-				return 0;
362
-			}
363
-			if(!(tval->flags&PV_VAL_INT))
364
-			{
365
-				LM_ERR("Invalid value type\n");
366
-				return -1;
367
-			}
368
-			_uac_req.evroute = tval->ri;
369
-			break;
370
-		case 9:
371
-			if(tval==NULL)
372
-			{
373
-				_uac_req.s_auser.len = 0;
374
-				return 0;
375
-			}
376
-			if(!(tval->flags&PV_VAL_STR))
377
-			{
378
-				LM_ERR("Invalid auth user type\n");
379
-				return -1;
380
-			}
381
-			if(tval->rs.len>=128)
382
-			{
383
-				LM_ERR("Value size too big\n");
384
-				return -1;
385
-			}
386
-			memcpy(_uac_req.s_auser.s, tval->rs.s, tval->rs.len);
387
-			_uac_req.s_auser.s[tval->rs.len] = '\0';
388
-			_uac_req.s_auser.len = tval->rs.len;
389
-			break;
390
-		case 10:
391
-			if(tval==NULL)
392
-			{
393
-				_uac_req.s_apasswd.len = 0;
394
-				return 0;
395
-			}
396
-			if(!(tval->flags&PV_VAL_STR))
397
-			{
398
-				LM_ERR("Invalid auth password type\n");
399
-				return -1;
400
-			}
401
-			if(tval->rs.len>=64)
402
-			{
403
-				LM_ERR("Value size too big\n");
404
-				return -1;
405
-			}
406
-			memcpy(_uac_req.s_apasswd.s, tval->rs.s, tval->rs.len);
407
-			_uac_req.s_apasswd.s[tval->rs.len] = '\0';
408
-			_uac_req.s_apasswd.len = tval->rs.len;
409
-			break;
410
-		case 11:
411
-			if(tval==NULL)
412
-			{
413
-				_uac_req.s_callid.len = 0;
414
-				return 0;
415
-			}
416
-			if(!(tval->flags&PV_VAL_STR))
417
-			{
418
-				LM_ERR("Invalid value type\n");
419
-				return -1;
420
-			}
421
-			memcpy(_uac_req.s_callid.s, tval->rs.s, tval->rs.len);
422
-			_uac_req.s_callid.s[tval->rs.len] = '\0';
423
-			_uac_req.s_callid.len = tval->rs.len;
424
-			break;
425
-		case 12:
426
-			if(tval==NULL)
427
-			{
428
-				_uac_req.s_apasswd.len = 0;
429
-				return 0;
430
-			}
431
-			if(!(tval->flags&PV_VAL_STR))
432
-			{
433
-				LM_ERR("Invalid socket pv type\n");
434
-				return -1;
435
-			}
436
-			if(tval->rs.len>=MAX_URI_SIZE)
437
-			{
438
-				LM_ERR("Value size too big\n");
439
-				return -1;
440
-			}
441
-			memcpy(_uac_req.s_sock.s, tval->rs.s, tval->rs.len);
442
-			_uac_req.s_sock.s[tval->rs.len] = '\0';
443
-			_uac_req.s_sock.len = tval->rs.len;
444
-			break;
445
-		case 14:
446
-			if(tval==NULL)
447
-			{
448
-				_uac_req.s_evparam.len = 0;
449
-				return 0;
450
-			}
451
-			if(!(tval->flags&PV_VAL_STR))
452
-			{
453
-				LM_ERR("Invalid value type\n");
454
-				return -1;
455
-			}
456
-			if(tval->rs.len>=MAX_UACD_SIZE)
457
-			{
458
-				LM_ERR("Value size too big\n");
459
-				return -1;
460
-			}
461
-			memcpy(_uac_req.s_evparam.s, tval->rs.s, tval->rs.len);
462
-			_uac_req.s_evparam.s[tval->rs.len] = '\0';
463
-			_uac_req.s_evparam.len = tval->rs.len;
464
-			break;
465
-		case 15:
466
-			if(tval==NULL)
467
-			{
468
-				_uac_req.evcode = 0;
469
-				return 0;
470
-			}
471
-			if(!(tval->flags&PV_VAL_INT))
472
-			{
473
-				LM_ERR("Invalid value type\n");
474
-				return -1;
475
-			}
476
-			_uac_req.evcode = tval->ri;
477
-			break;
478
-		case 16:
479
-			if(tval==NULL)
480
-			{
481
-				_uac_req.evtype = 0;
482
-				return 0;
483
-			}
484
-			if(!(tval->flags&PV_VAL_INT))
485
-			{
486
-				LM_ERR("Invalid value type\n");
487
-				return -1;
488
-			}
489
-			_uac_req.evtype = tval->ri;
490
-			break;
491
-	}
492
-	return 0;
493
-}
494
-
495
-int pv_parse_uac_req_name(pv_spec_p sp, str *in)
496
-{
497
-	if(sp==NULL || in==NULL || in->len<=0)
498
-		return -1;
499
-
500
-	switch(in->len)
501
-	{
502
-		case 3: 
503
-			if(strncmp(in->s, "all", 3)==0)
504
-				sp->pvp.pvn.u.isname.name.n = 0;
505
-			else goto error;
506
-		break;
507
-		case 4: 
508
-			if(strncmp(in->s, "ruri", 4)==0)
509
-				sp->pvp.pvn.u.isname.name.n = 1;
510
-			else if(strncmp(in->s, "turi", 4)==0)
511
-				sp->pvp.pvn.u.isname.name.n = 2;
512
-			else if(strncmp(in->s, "furi", 4)==0)
513
-				sp->pvp.pvn.u.isname.name.n = 3;
514
-			else if(strncmp(in->s, "hdrs", 4)==0)
515
-				sp->pvp.pvn.u.isname.name.n = 4;
516
-			else if(strncmp(in->s, "body", 4)==0)
517
-				sp->pvp.pvn.u.isname.name.n = 5;
518
-			else if(strncmp(in->s, "ouri", 4)==0)
519
-				sp->pvp.pvn.u.isname.name.n = 6;
520
-			else if(strncmp(in->s, "sock", 4)==0)
521
-				sp->pvp.pvn.u.isname.name.n = 12;
522
-			else goto error;
523
-		break;
524
-		case 5:
525
-			if(strncmp(in->s, "auser", 5)==0)
526
-				sp->pvp.pvn.u.isname.name.n = 9;
527
-			else goto error;
528
-		break;
529
-		case 6: 
530
-			if(strncmp(in->s, "method", 6)==0)
531
-				sp->pvp.pvn.u.isname.name.n = 7;
532
-			else if(strncmp(in->s, "callid", 6)==0)
533
-				sp->pvp.pvn.u.isname.name.n = 11;
534
-			else if(strncmp(in->s, "evcode", 6)==0)
535
-				sp->pvp.pvn.u.isname.name.n = 15;
536
-			else if(strncmp(in->s, "evtype", 6)==0)
537
-				sp->pvp.pvn.u.isname.name.n = 16;
538
-			else goto error;
539
-		break;
540
-		case 7: 
541
-			if(strncmp(in->s, "evroute", 7)==0)
542
-				sp->pvp.pvn.u.isname.name.n = 8;
543
-			else if(strncmp(in->s, "apasswd", 7)==0)
544
-				sp->pvp.pvn.u.isname.name.n = 10;
545
-			else if(strncmp(in->s, "evparam", 7)==0)
546
-				sp->pvp.pvn.u.isname.name.n = 14;
547
-			else goto error;
548
-		break;
549
-		default:
550
-			goto error;
551
-	}
552
-	sp->pvp.pvn.type = PV_NAME_INTSTR;
553
-	sp->pvp.pvn.u.isname.type = 0;
554
-
555
-	return 0;
556
-
557
-error:
558
-	LM_ERR("unknown uac_req name %.*s\n", in->len, in->s);
559
-	return -1;
560
-}
561
-
562
-void uac_req_init(void)
563
-{
564
-	/* load the TM API */
565
-	if (load_tm_api(&tmb)!=0) {
566
-		LM_DBG("can't load TM API - disable it\n");
567
-		memset(&tmb, 0, sizeof(struct tm_binds));
568
-		return;
569
-	}
570
-	memset(&_uac_req, 0, sizeof(struct _uac_send_info));
571
-	_uac_req.s_ruri.s = _uac_req.b_ruri;
572
-	_uac_req.s_furi.s = _uac_req.b_furi;
573
-	_uac_req.s_turi.s = _uac_req.b_turi;
574
-	_uac_req.s_ouri.s = _uac_req.b_ouri;
575
-	_uac_req.s_hdrs.s = _uac_req.b_hdrs;
576
-	_uac_req.s_body.s = _uac_req.b_body;
577
-	_uac_req.s_method.s = _uac_req.b_method;
578
-	_uac_req.s_auser.s  = _uac_req.b_auser;
579
-	_uac_req.s_apasswd.s  = _uac_req.b_apasswd;
580
-	_uac_req.s_callid.s   = _uac_req.b_callid;
581
-	_uac_req.s_sock.s     = _uac_req.b_sock;
582
-	_uac_req.s_evparam.s  = _uac_req.b_evparam;
583
-	return;
584
-}
585
-
586
-int uac_send_tmdlg(dlg_t *tmdlg, sip_msg_t *rpl)
587
-{
588
-	if(tmdlg==NULL || rpl==NULL)
589
-		return -1;
590
-
591
-	if (parse_headers(rpl, HDR_EOH_F, 0) < 0) {
592
-		LM_ERR("error while parsing all headers in the reply\n");
593
-		return -1;
594
-	}
595
-	if(parse_to_header(rpl)<0 || parse_from_header(rpl)<0) {
596
-		LM_ERR("error while parsing From/To headers in the reply\n");
597
-		return -1;
598
-	}
599
-	memset(tmdlg, 0, sizeof(dlg_t));
600
-
601
-	str2int(&(get_cseq(rpl)->number), &tmdlg->loc_seq.value);
602
-	tmdlg->loc_seq.is_set = 1;
603
-
604
-	tmdlg->id.call_id = rpl->callid->body;
605
-	trim(&tmdlg->id.call_id);
606
-
607
-	if (get_from(rpl)->tag_value.len) {
608
-		tmdlg->id.loc_tag = get_from(rpl)->tag_value;
609
-	}
610
-#if 0
611
-	if (get_to(rpl)->tag_value.len) {
612
-		tmdlg->id.rem_tag = get_to(rpl)->tag_value;
613
-	}
614
-#endif
615
-	tmdlg->loc_uri = get_from(rpl)->uri;
616
-	tmdlg->rem_uri = get_to(rpl)->uri;
617
-	tmdlg->state= DLG_CONFIRMED;
618
-	return 0;
619
-}
620
-
621
-#define MAX_UACH_SIZE 2048
622
-
623
-/**
624
- *
625
- */
626
-void uac_req_run_event_route(sip_msg_t *msg, uac_send_info_t *tp, int rcode)
627
-{
628
-	char *evrtname = "uac:reply";
629
-	int rt, backup_rt;
630
-	struct run_act_ctx ctx;
631
-	sip_msg_t *fmsg;
632
-
633
-	rt = route_get(&event_rt, evrtname);
634
-	if (rt < 0 || event_rt.rlist[rt] == NULL)
635
-	{
636
-		LM_DBG("event_route[uac:reply] does not exist\n");
637
-		return;
638
-	}
639
-
640
-	uac_send_info_copy(tp, &_uac_req);
641
-	_uac_req.evcode = rcode;
642
-	if(msg==NULL)
643
-	{
644
-		_uac_req.evtype = 2;
645
-		fmsg = faked_msg_get_next();
646
-	} else {
647
-		_uac_req.evtype = 1;
648
-		fmsg = msg;
649
-	}
650
-
651
-	backup_rt = get_route_type();
652
-	set_route_type(REQUEST_ROUTE);
653
-	init_run_actions_ctx(&ctx);
654
-	run_top_route(event_rt.rlist[rt], fmsg, 0);
655
-	set_route_type(backup_rt);
656
-}
657
-
658
-/** 
659
- * TM callback function
660
- */
661
-void uac_send_tm_callback(struct cell *t, int type, struct tmcb_params *ps)
662
-{
663
-	int ret;
664
-	struct hdr_field *hdr;
665
-	HASHHEX response;
666
-	str *new_auth_hdr = NULL;
667
-	static struct authenticate_body auth;
668
-	struct uac_credential cred;
669
-	char  b_hdrs[MAX_UACH_SIZE];
670
-	str   s_hdrs;
671
-	uac_req_t uac_r;
672
-	dlg_t tmdlg;
673
-	uac_send_info_t *tp = NULL;
674
-
675
-	LM_DBG("tm callback with status %d\n", ps->code);
676
-
677
-	if(ps->param==NULL || *ps->param==0)
678
-	{
679
-		LM_DBG("callback param with message id not received\n");
680
-		goto done;
681
-	}
682
-	tp = (uac_send_info_t*)(*ps->param);
683
-
684
-	if(tp->evroute!=0) {
685
-		uac_req_run_event_route((ps->rpl==FAKED_REPLY)?NULL:ps->rpl,
686
-				tp, ps->code);
687
-	}
688
-
689
-	if((ps->code != 401 && ps->code != 407) || tp->s_apasswd.len<=0)
690
-	{
691
-		LM_DBG("completed with status %d\n", ps->code);
692
-		goto done;
693
-	}
694
-
695
-	LM_DBG("completed with status %d\n", ps->code);
696
-
697
-	hdr = get_autenticate_hdr(ps->rpl, ps->code);
698
-	if (hdr==0)
699
-	{
700
-		LM_ERR("failed to extract authenticate hdr\n");
701
-		goto error;
702
-	}
703
-
704
-	LM_DBG("auth header body [%.*s]\n",
705
-		hdr->body.len, hdr->body.s);
706
-
707
-	if (parse_authenticate_body(&hdr->body, &auth)<0)
708
-	{
709
-		LM_ERR("failed to parse auth hdr body\n");
710
-		goto error;
711
-	}
712
-
713
-	cred.realm  = auth.realm;
714
-	cred.user   = tp->s_auser;
715
-	cred.passwd = tp->s_apasswd;
716
-	cred.next   = NULL;
717
-
718
-	do_uac_auth(&tp->s_method, &tp->s_ruri, &cred, &auth, response);
719
-	new_auth_hdr=build_authorization_hdr(ps->code, &tp->s_ruri, &cred,
720
-						&auth, response);
721
-	if (new_auth_hdr==0)
722
-	{
723
-		LM_ERR("failed to build authorization hdr\n");
724
-		goto error;
725
-	}
726
-
727
-	if(tp->s_hdrs.len <= 0) {
728
-		snprintf(b_hdrs, MAX_UACH_SIZE,
729
-				"%.*s",
730
-				new_auth_hdr->len, new_auth_hdr->s);
731
-	} else {
732
-		snprintf(b_hdrs, MAX_UACH_SIZE,
733
-				"%.*s%.*s",
734
-				tp->s_hdrs.len, tp->s_hdrs.s,
735
-				new_auth_hdr->len, new_auth_hdr->s);
736
-	}
737
-
738
-	s_hdrs.s = b_hdrs; s_hdrs.len = strlen(s_hdrs.s);
739
-	pkg_free(new_auth_hdr->s);
740
-
741
-	memset(&uac_r, 0, sizeof(uac_r));
742
-	if(uac_send_tmdlg(&tmdlg, ps->rpl)<0)
743
-	{
744
-		LM_ERR("failed to build tm dialog\n");
745
-		goto error;
746
-	}
747
-	tmdlg.rem_target = tp->s_ruri;
748
-	if(tp->s_ouri.len>0)
749
-		tmdlg.dst_uri = tp->s_ouri;
750
-	uac_r.method = &tp->s_method;
751
-	uac_r.headers = &s_hdrs;
752
-	uac_r.body = (tp->s_body.len <= 0) ? NULL : &tp->s_body;
753
-	uac_r.ssock = (tp->s_sock.len <= 0) ? NULL : &tp->s_sock;
754
-	uac_r.dialog = &tmdlg;
755
-	uac_r.cb_flags = TMCB_LOCAL_COMPLETED;
756
-	ret = tmb.t_request_within(&uac_r);
757
-
758
-	if(ret<0) {
759
-		LM_ERR("failed to send request with authentication\n");
760
-		goto error;
761
-	}
762
-
763
-done:
764
-error:
765
-	if(tp!=NULL)
766
-		shm_free(tp);
767
-	return;
768
-}
769
-
770
-
771
-int uac_req_send(void)
772
-{
773
-	int ret;
774
-	uac_req_t uac_r;
775
-	uac_send_info_t *tp = NULL;
776
-
777
-	if(_uac_req.s_ruri.len<=0 || _uac_req.s_method.len == 0
778
-			|| tmb.t_request==NULL)
779
-		return -1;
780
-
781
-	memset(&uac_r, '\0', sizeof(uac_r));
782
-	uac_r.method = &_uac_req.s_method;
783
-	uac_r.headers = (_uac_req.s_hdrs.len <= 0) ? NULL : &_uac_req.s_hdrs;
784
-	uac_r.body = (_uac_req.s_body.len <= 0) ? NULL : &_uac_req.s_body;
785
-	uac_r.ssock = (_uac_req.s_sock.len <= 0) ? NULL : &_uac_req.s_sock;
786
-	if((_uac_req.s_auser.len > 0 && _uac_req.s_apasswd.len>0)
787
-			|| (_uac_req.evroute > 0))
788
-	{
789
-		tp = uac_send_info_clone(&_uac_req);
790
-		if(tp==NULL)
791
-		{
792
-			LM_ERR("cannot clone the uac structure\n");
793
-			return -1;
794
-		}
795
-
796
-		uac_r.cb_flags = TMCB_LOCAL_COMPLETED;
797
-		/* Callback function */
798
-		uac_r.cb  = uac_send_tm_callback;
799
-		/* Callback parameter */
800
-		uac_r.cbp = (void*)tp;
801
-	}
802
-	uac_r.callid = (_uac_req.s_callid.len <= 0) ? NULL : &_uac_req.s_callid;
803
-	ret = tmb.t_request(&uac_r,  /* UAC Req */
804
-			&_uac_req.s_ruri,        /* Request-URI */
805
-			(_uac_req.s_turi.len<=0)?&_uac_req.s_ruri:&_uac_req.s_turi, /* To */
806
-			(_uac_req.s_furi.len<=0)?&_uac_req.s_ruri:&_uac_req.s_furi, /* From */
807
-			(_uac_req.s_ouri.len<=0)?NULL:&_uac_req.s_ouri /* outbound uri */
808
-		);
809
-
810
-	if(ret<0) {
811
-		if(tp!=NULL)
812
-			shm_free(tp);
813
-		return -1;
814
-	}
815
-	return 1;
816
-}
817
-
818
-int w_uac_req_send(struct sip_msg *msg, char *s1, char *s2)
819
-{
820
-	return uac_req_send();
821
-}
Browse code

modules: faked message api has moved to core

Mikko Lehto authored on 02/12/2016 10:46:37
Showing 1 changed files
... ...
@@ -35,7 +35,7 @@
35 35
 #include "../../parser/parse_from.h"
36 36
 #include "../../parser/parse_to.h"
37 37
 #include "../../parser/contact/parse_contact.h"
38
-#include "../../lib/kcore/faked_msg.h"
38
+#include "../../fmsg.h"
39 39
 
40 40
 #include "auth.h"
41 41
 #include "auth_hdr.h"
Browse code

uac Minor code cleanup, add a few doxygen headers

Olle E. Johansson authored on 23/04/2016 14:35:53
Showing 1 changed files
... ...
@@ -18,6 +18,13 @@
18 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 19
  */
20 20
 
21
+/*!
22
+ * \file
23
+ * \brief Kamailio uac :: UAC send functions
24
+ * \ingroup uac
25
+ * Module: \ref uac
26
+ */
27
+
21 28
 #include "../../dprint.h"
22 29
 #include "../../trim.h"
23 30
 #include "../../route.h"
... ...
@@ -794,10 +801,10 @@ int uac_req_send(void)
794 801
 	}
795 802
 	uac_r.callid = (_uac_req.s_callid.len <= 0) ? NULL : &_uac_req.s_callid;
796 803
 	ret = tmb.t_request(&uac_r,  /* UAC Req */
797
-						&_uac_req.s_ruri,        /* Request-URI */
798
-						(_uac_req.s_turi.len<=0)?&_uac_req.s_ruri:&_uac_req.s_turi, /* To */
799
-						(_uac_req.s_furi.len<=0)?&_uac_req.s_ruri:&_uac_req.s_furi, /* From */
800
-						(_uac_req.s_ouri.len<=0)?NULL:&_uac_req.s_ouri /* outbound uri */
804
+			&_uac_req.s_ruri,        /* Request-URI */
805
+			(_uac_req.s_turi.len<=0)?&_uac_req.s_ruri:&_uac_req.s_turi, /* To */
806
+			(_uac_req.s_furi.len<=0)?&_uac_req.s_ruri:&_uac_req.s_furi, /* From */
807
+			(_uac_req.s_ouri.len<=0)?NULL:&_uac_req.s_ouri /* outbound uri */
801 808
 		);
802 809
 
803 810
 	if(ret<0) {
Browse code

uac: reset the $uac_req(...) fields when assigning $null

- was done only when NULL was passed, not for values with PV_VAL_NULL

Daniel-Constantin Mierla authored on 19/01/2016 19:24:28
Showing 1 changed files
... ...
@@ -178,13 +178,19 @@ int pv_get_uac_req(struct sip_msg *msg, pv_param_t *param,
178 178
 int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
179 179
 		int op, pv_value_t *val)
180 180
 {
181
+	pv_value_t *tval;
182
+
181 183
 	if(param==NULL || tmb.t_request==NULL)
182 184
 		return -1;
183 185
 
186
+	tval = val;
187
+	if((tval!=NULL) && (tval->flags&PV_VAL_NULL)) {
188
+		tval = NULL;
189
+	}
184 190
 	switch(param->pvn.u.isname.name.n)
185 191
 	{
186 192
 		case 0:
187
-			if(val==NULL)
193
+			if(tval==NULL)
188 194
 			{
189 195
 				_uac_req.flags = 0;
190 196
 				_uac_req.s_ruri.len = 0;
... ...
@@ -202,278 +208,278 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
202 208
 			}
203 209
 			break;
204 210
 		case 1:
205
-			if(val==NULL)
211
+			if(tval==NULL)
206 212
 			{
207 213
 				_uac_req.s_ruri.len = 0;
208 214
 				return 0;
209 215
 			}
210
-			if(!(val->flags&PV_VAL_STR))
216
+			if(!(tval->flags&PV_VAL_STR))
211 217
 			{
212 218
 				LM_ERR("Invalid value type\n");
213 219
 				return -1;
214 220
 			}
215
-			if(val->rs.len>=MAX_URI_SIZE)
221
+			if(tval->rs.len>=MAX_URI_SIZE)
216 222
 			{
217 223
 				LM_ERR("Value size too big\n");
218 224
 				return -1;
219 225
 			}
220
-			memcpy(_uac_req.s_ruri.s, val->rs.s, val->rs.len);