3 * Copyright (C) 2015 Voxbone SA
5 * This file is part of SIP-Router, a free SIP server.
7 * SIP-Router is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version
12 * SIP-Router is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "../../core/sr_module.h"
25 #include "../../core/parser/parse_param.h"
26 #include "../../core/data_lump.h"
27 #include "../../core/mem/mem.h"
28 #include "../../core/mod_fix.h"
29 #include "../../core/parser/parse_content.h"
30 #include "../../core/parser/parse_body.h"
31 #include "../../core/parser/parser_f.h"
32 #include "../../core/trim.h"
41 static int sipt_set_bci_1(struct sip_msg *msg, char *_charge_indicator, char *_called_status, char * _called_category, char * _e2e_indicator);
42 static int sipt_destination(struct sip_msg *msg, char *_destination, char *_hops, char * _nai);
43 static int sipt_destination2(struct sip_msg *msg, char *_destination, char *_hops, char * _nai, char * _terminator);
44 static int sipt_forwarding(struct sip_msg *msg, char *_fwdnumber, char * _nai);
45 static int sipt_set_calling(struct sip_msg *msg, char *_origin, char *_nai, char *_pres, char * _screen);
46 static int sipt_get_hop_counter(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
47 static int sipt_get_event_info(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
48 static int sipt_get_cpc(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
49 static int sipt_get_calling_party_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
50 static int sipt_get_calling_party(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
51 static int sipt_get_presentation(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
52 static int sipt_get_screening(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
53 static int sipt_get_called_party_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
54 static int sipt_get_called_party(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
55 static int sipt_get_charge_indicator(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
57 static int sipt_get_redirection_info(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
58 static int sipt_get_redirection_number_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
59 static int sipt_get_redirection_number(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
61 static int sipt_get_redirection_reason(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
62 static int sipt_get_original_redirection_reason(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
63 static int sipt_get_redirecting_number_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
64 static int sipt_get_redirecting_number(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
65 static int sipt_get_original_called_number_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
66 static int sipt_get_original_called_number(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
67 static int sipt_get_generic_number_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
68 static int sipt_get_generic_number(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
70 static int sipt_has_isup_body(struct sip_msg *msg, char *type, char *str2 );
73 int sipt_parse_pv_name(pv_spec_p sp, str *in);
74 static int sipt_get_pv(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
76 typedef struct _sipt_pv {
81 typedef struct sipt_header_map
85 struct sipt_subtype_map
92 static sipt_header_map_t sipt_header_mapping[] =
94 {"CALLING_PARTY_CATEGORY", ISUP_PARM_CALLING_PARTY_CAT,
96 {"CPC", ISUP_PARM_CALLING_PARTY_CAT,
98 {"CALLING_PARTY_NUMBER", ISUP_PARM_CALLING_PARTY_NUM,
99 {{"NATURE_OF_ADDRESS", 1},
105 {"CALLED_PARTY_NUMBER", ISUP_PARM_CALLED_PARTY_NUM,
106 {{"NATURE_OF_ADDRESS", 1},
110 {"HOP_COUNTER", ISUP_PARM_HOP_COUNTER,
112 {"EVENT_INFO", ISUP_PARM_EVENT_INFO,
114 {"BACKWARD_CALL_INDICATOR", ISUP_PARM_BACKWARD_CALL_IND,
115 {{"CHARGE_INDICATOR", 1},
118 {"REDIRECTION_INFO", ISUP_PARM_DIVERSION_INFORMATION,
120 {"REDIRECTION_NUMBER", ISUP_PARM_REDIRECTION_NUMBER,
121 {{"NATURE_OF_ADDRESS", 1},
125 {"REDIRECTION_INFORMATION", ISUP_PARM_REDIRECTION_INFO,
127 {"ORIGINAL_REASON", 2},
130 {"REDIRECTING_NUMBER", ISUP_PARM_REDIRECTING_NUMBER,
131 {{"NATURE_OF_ADDRESS", 1},
135 {"ORIGINAL_CALLED_NUMBER", ISUP_PARM_ORIGINAL_CALLED_NUM,
136 {{"NATURE_OF_ADDRESS", 1},
140 {"GENERIC_NUMBER", ISUP_PARM_GENERIC_ADDR,
141 {{"NATURE_OF_ADDRESS", 1},
150 static int mod_init(void);
151 static void mod_destroy(void);
155 static int fixup_str_str_str(void** param, int param_no)
157 if(param_no == 1 || param_no == 2 || param_no == 3 || param_no == 4)
159 return fixup_str_null(param, 1);
164 static int fixup_free_str_str_str(void** param, int param_no)
166 if(param_no == 1 || param_no == 2 || param_no == 3 || param_no == 4)
168 return fixup_free_str_null(param, 1);
174 static cmd_export_t cmds[]={
175 {"sipt_destination", /* action name as in scripts */
176 (cmd_function)sipt_destination, /* C function name */
177 3, /* number of parameters */
178 fixup_str_str_str, fixup_free_str_str_str, /* */
179 /* can be applied to original requests */
180 REQUEST_ROUTE|BRANCH_ROUTE},
181 {"sipt_destination", /* action name as in scripts */
182 (cmd_function)sipt_destination2, /* C function name */
183 4, /* number of parameters */
184 fixup_str_str_str, fixup_free_str_str_str, /* */
185 /* can be applied to original requests */
186 REQUEST_ROUTE|BRANCH_ROUTE},
187 {"sipt_forwarding", /* action name as in scripts */
188 (cmd_function)sipt_forwarding, /* C function name */
189 2, /* number of parameters */
190 fixup_str_str_str, fixup_free_str_str_str, /* */
191 /* can be applied to original requests */
192 REQUEST_ROUTE|BRANCH_ROUTE},
193 {"sipt_set_calling", /* action name as in scripts */
194 (cmd_function)sipt_set_calling, /* C function name */
195 4, /* number of parameters */
196 fixup_str_str_str, fixup_free_str_str_str, /* */
197 /* can be applied to original requests */
198 REQUEST_ROUTE|BRANCH_ROUTE},
199 {"sipt_set_bci_1", /* action name as in scripts */
200 (cmd_function)sipt_set_bci_1, /* C function name */
201 4, /* number of parameters */
202 fixup_str_str_str, fixup_free_str_str_str, /* */
203 /* can be applied to original requests */
205 {"sipt_has_isup_body", /* action name as in scripts */
206 (cmd_function)sipt_has_isup_body, /* C function name */
207 0, /* number of parameters */
209 /* can be applied to original requests */
214 static param_export_t params[]={
218 static pv_export_t mod_items[] = {
219 { {"sipt_presentation", sizeof("sipt_presentation")-1}, PVT_OTHER, sipt_get_presentation, 0,
221 { {"sipt_screening", sizeof("sipt_screening")-1}, PVT_OTHER, sipt_get_screening, 0,
223 { {"sipt_hop_counter", sizeof("sipt_hop_counter")-1}, PVT_OTHER, sipt_get_hop_counter, 0,
225 { {"sipt_cpc", sizeof("sipt_cpc")-1}, PVT_OTHER, sipt_get_cpc, 0,
227 { {"sipt_calling_party_nai", sizeof("sipt_calling_party_nai")-1}, PVT_OTHER, sipt_get_calling_party_nai, 0,
229 { {"sipt_called_party_nai", sizeof("sipt_called_party_nai")-1}, PVT_OTHER, sipt_get_called_party_nai, 0,
231 { {"sipt", sizeof("sipt")-1}, PVT_OTHER, sipt_get_pv, 0,
232 sipt_parse_pv_name, 0, 0, 0 },
233 { {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
236 struct module_exports exports = {
237 "sipt", /* module name */
238 DEFAULT_DLFLAGS, /* dlopen flags */
239 cmds, /* exported functions */
240 params, /* exported parameters */
241 0, /* exported RPC methods */
242 mod_items, /* exported pseudo-variables */
243 0, /* response function*/
244 mod_init, /* module initialization function */
245 0, /* per-child init function */
246 mod_destroy /* destroy function */
249 static inline int sipt_check_IAM(struct sip_msg *msg, str *body)
251 body->s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP, &body->len);
255 LM_INFO("No ISUP Message Found");
259 if(body->s[0] != ISUP_IAM)
261 LM_DBG("message not an IAM\n");
267 static int sipt_get_hop_counter(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
271 if(sipt_check_IAM(msg, &body) != 1)
273 LM_INFO("could not check IAM\n");
277 pv_get_sintval(msg, param, res, isup_get_hop_counter((unsigned char*)body.s, body.len));
281 static int sipt_get_event_info(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
284 body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
288 LM_INFO("No ISUP Message Found");
292 if(body.s[0] != ISUP_CPG)
294 LM_DBG("message not an CPG\n");
298 pv_get_sintval(msg, param, res, isup_get_event_info((unsigned char*)body.s, body.len));
302 static int sipt_get_cpc(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
306 if(sipt_check_IAM(msg, &body) != 1)
308 LM_INFO("could not check IAM\n");
312 pv_get_sintval(msg, param, res, isup_get_cpc((unsigned char*)body.s, body.len));
316 static int sipt_get_calling_party_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
320 if(sipt_check_IAM(msg, &body) != 1)
322 LM_INFO("could not check IAM\n");
326 pv_get_sintval(msg, param, res, isup_get_calling_party_nai((unsigned char*)body.s, body.len));
330 static int sipt_get_calling_party(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
332 static char sb_s_buf[26];
334 memset(sb_s_buf, 0, 26);
336 if(sipt_check_IAM(msg, &body) != 1)
338 LM_INFO("could not check IAM\n");
342 isup_get_calling_party((unsigned char*)body.s, body.len, sb_s_buf);
344 if (strlen(sb_s_buf) > 0)
346 pv_get_strzval(msg, param, res, sb_s_buf);
348 pv_get_sintval(msg, param, res, -1);
353 static int sipt_get_redirection_info(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
356 body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
360 LM_INFO("No ISUP Message Found");
364 if((body.s[0] != ISUP_ACM) && (body.s[0] != ISUP_CPG))
366 LM_DBG("message not an ACM or CPG\n");
370 pv_get_sintval(msg, param, res, isup_get_redirection_info((unsigned char*)body.s, body.len));
374 static int sipt_get_redirection_number_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
377 body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
381 LM_INFO("No ISUP Message Found");
385 if((body.s[0] != ISUP_ACM) && (body.s[0] != ISUP_CPG))
387 LM_DBG("message not an ACM or CPG\n");
391 pv_get_sintval(msg, param, res, isup_get_redirection_number_nai((unsigned char*)body.s, body.len));
395 static int sipt_get_redirection_number(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
397 static char sb_s_buf[26];
399 body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
401 memset(sb_s_buf, 0, 26);
404 LM_INFO("No ISUP Message Found");
408 if((body.s[0] != ISUP_ACM) && (body.s[0] != ISUP_CPG))
410 LM_DBG("message not an ACM or CPG\n");
414 isup_get_redirection_number((unsigned char*)body.s, body.len, sb_s_buf);
416 if (strlen(sb_s_buf) > 0)
418 pv_get_strzval(msg, param, res, sb_s_buf);
420 pv_get_sintval(msg, param, res, -1);
425 static int sipt_get_redirection_reason(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
429 if(sipt_check_IAM(msg, &body) != 1)
431 LM_INFO("could not check IAM\n");
435 pv_get_sintval(msg, param, res, isup_get_redirection_reason((unsigned char*)body.s, body.len));
439 static int sipt_get_original_redirection_reason(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
443 if(sipt_check_IAM(msg, &body) != 1)
445 LM_INFO("could not check IAM\n");
449 pv_get_sintval(msg, param, res, isup_get_original_redirection_reason((unsigned char*)body.s, body.len));
453 static int sipt_get_redirecting_number_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
457 if(sipt_check_IAM(msg, &body) != 1)
459 LM_INFO("could not check IAM\n");
463 pv_get_sintval(msg, param, res, isup_get_redirecting_number_nai((unsigned char*)body.s, body.len));
467 static int sipt_get_redirecting_number(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
469 static char sb_s_buf[26];
471 memset(sb_s_buf, 0, 26);
473 if(sipt_check_IAM(msg, &body) != 1)
475 LM_INFO("could not check IAM\n");
479 isup_get_redirecting_number((unsigned char*)body.s, body.len, sb_s_buf);
481 if (strlen(sb_s_buf) > 0)
483 pv_get_strzval(msg, param, res, sb_s_buf);
485 pv_get_sintval(msg, param, res, -1);
490 static int sipt_get_original_called_number_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
494 if(sipt_check_IAM(msg, &body) != 1)
496 LM_INFO("could not check IAM\n");
500 pv_get_sintval(msg, param, res, isup_get_original_called_number_nai((unsigned char*)body.s, body.len));
504 static int sipt_get_original_called_number(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
506 static char sb_s_buf[26];
508 memset(sb_s_buf, 0, 26);
510 if(sipt_check_IAM(msg, &body) != 1)
512 LM_INFO("could not check IAM\n");
516 isup_get_original_called_number((unsigned char*)body.s, body.len, sb_s_buf);
518 if (strlen(sb_s_buf) > 0)
520 pv_get_strzval(msg, param, res, sb_s_buf);
522 pv_get_sintval(msg, param, res, -1);
527 static int sipt_get_generic_number_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
531 if(sipt_check_IAM(msg, &body) != 1)
533 LM_INFO("could not check IAM\n");
537 pv_get_sintval(msg, param, res, isup_get_generic_number_nai((unsigned char*)body.s, body.len));
541 static int sipt_get_generic_number(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
543 static char sb_s_buf[26];
545 memset(sb_s_buf, 0, 26);
546 if(sipt_check_IAM(msg, &body) != 1)
548 LM_INFO("could not check IAM\n");
551 isup_get_generic_number((unsigned char*)body.s, body.len, sb_s_buf);
553 if (strlen(sb_s_buf) > 0)
555 pv_get_strzval(msg, param, res, sb_s_buf);
557 pv_get_sintval(msg, param, res, -1);
562 static int sipt_get_presentation(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
565 if(sipt_check_IAM(msg, &body) != 1)
567 LM_INFO("could not check IAM\n");
571 pv_get_sintval(msg, param, res, isup_get_presentation((unsigned char*)body.s, body.len));
575 static int sipt_get_screening(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
578 if(sipt_check_IAM(msg, &body) != 1)
580 LM_INFO("could not check IAM\n");
584 LM_DBG("about to get screening\n");
586 pv_get_sintval(msg, param, res, isup_get_screening((unsigned char*)body.s, body.len));
590 static int sipt_get_charge_indicator(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
593 body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
597 LM_INFO("No ISUP Message Found");
601 if(body.s[0] != ISUP_COT && body.s[0] != ISUP_ACM)
603 LM_DBG("message not a COT or ACM\n");
606 LM_DBG("about to get charge indicator\n");
608 pv_get_sintval(msg, param, res, isup_get_charging_indicator((unsigned char*)body.s, body.len));
612 static int sipt_get_called_party_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
615 if(sipt_check_IAM(msg, &body) != 1)
617 LM_INFO("could not check IAM\n");
621 pv_get_sintval(msg, param, res, isup_get_called_party_nai((unsigned char*)body.s, body.len));
625 static int sipt_get_called_party(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
627 static char sb_s_buf[26];
629 memset(sb_s_buf, 0, 26);
630 if(sipt_check_IAM(msg, &body) != 1)
632 LM_INFO("could not check IAM\n");
636 isup_get_called_party((unsigned char*)body.s, body.len, sb_s_buf);
638 if (strlen(sb_s_buf) > 0)
640 pv_get_strzval(msg, param, res, sb_s_buf);
642 pv_get_sintval(msg, param, res, -1);
647 static int sipt_has_isup_body(struct sip_msg *msg, char* foo, char* bar)
650 body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
651 return (body.s == NULL)?-1:1;
654 int sipt_parse_pv_name(pv_spec_p sp, str *in)
660 if(sp==NULL || in==NULL || in->len<=0)
663 spv = (sipt_pv_t*)pkg_malloc(sizeof(sipt_pv_t));
667 memset(spv, 0, sizeof(sipt_pv_t));
671 while(p<in->s+in->len && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
673 if(p>in->s+in->len || *p=='\0')
678 while(p < in->s + in->len)
680 if(*p=='.' || *p==' ' || *p=='\t' || *p=='\n' || *p=='\r')
684 pvtype.len = p - pvtype.s;
685 if(p>in->s+in->len || *p=='\0')
687 // only one parameter stop parsing
690 goto parse_parameters;
695 while(p<in->s+in->len && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
697 if(p>in->s+in->len || *p=='\0' || *p!='.')
699 // only one parameter w trailing whitespace
702 goto parse_parameters;
707 pvsubtype.len = in->len - (int)(p - in->s);
712 LM_DBG("sipt type[%.*s] - subtype[%.*s]\n", pvtype.len, pvtype.s,
713 pvsubtype.len, pvsubtype.s);
716 for(i=0;sipt_header_mapping[i].name != NULL; i++)
718 if(strncasecmp(pvtype.s, sipt_header_mapping[i].name, pvtype.len) == 0)
720 spv->type = sipt_header_mapping[i].type;
722 if(pvsubtype.len == 0)
725 for(j=0;sipt_header_mapping[i].subtypes[j].name != NULL;j++)
727 if(strncasecmp(pvsubtype.s, sipt_header_mapping[i].subtypes[j].name, pvsubtype.len) == 0)
728 spv->sub_type = sipt_header_mapping[i].subtypes[j].type;
730 if(spv->sub_type == 0)
732 LM_ERR("Unknown SIPT subtype [%.*s]\n", pvsubtype.len, pvsubtype.s);
739 LM_DBG("Type=%d subtype=%d\n",spv->type, spv->sub_type);
742 LM_ERR("Unknown SIPT type [%.*s]\n",pvtype.len, pvtype.s);
746 sp->pvp.pvn.u.dname = (void*)spv;
747 sp->pvp.pvn.type = PV_NAME_OTHER;
751 LM_ERR("error at PV sipt name: %.*s\n", in->len, in->s);
757 static int sipt_get_pv(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
761 if(msg==NULL || param==NULL)
764 spv = (sipt_pv_t*)param->pvn.u.dname;
770 case ISUP_PARM_CALLING_PARTY_CAT:
771 return sipt_get_cpc(msg, param, res);
772 case ISUP_PARM_CALLING_PARTY_NUM:
773 switch(spv->sub_type)
776 return sipt_get_calling_party(msg, param, res);
778 return sipt_get_calling_party_nai(msg, param, res);
779 case 2: /* SCREENIG */
780 return sipt_get_screening(msg, param, res);
781 case 3: /* PRESENTATION */
782 return sipt_get_presentation(msg, param, res);
785 case ISUP_PARM_CALLED_PARTY_NUM:
786 switch(spv->sub_type)
789 return sipt_get_called_party(msg, param, res);
791 return sipt_get_called_party_nai(msg, param, res);
794 case ISUP_PARM_HOP_COUNTER:
795 return sipt_get_hop_counter(msg, param, res);
796 case ISUP_PARM_EVENT_INFO:
797 return sipt_get_event_info(msg, param, res);
798 case ISUP_PARM_BACKWARD_CALL_IND:
799 switch(spv->sub_type)
801 case 1: /* charge_indicator */
802 return sipt_get_charge_indicator(msg, param, res);
805 case ISUP_PARM_DIVERSION_INFORMATION:
806 return sipt_get_redirection_info(msg, param, res);
807 case ISUP_PARM_REDIRECTION_NUMBER:
808 switch(spv->sub_type)
811 return sipt_get_redirection_number(msg, param, res);
813 return sipt_get_redirection_number_nai(msg, param, res);
816 case ISUP_PARM_REDIRECTION_INFO:
817 switch(spv->sub_type)
820 return sipt_get_redirection_reason(msg, param, res);
821 case 2: /* ORIGINAL_REASON */
822 return sipt_get_original_redirection_reason(msg, param, res);
825 case ISUP_PARM_REDIRECTING_NUMBER:
826 switch(spv->sub_type)
829 return sipt_get_redirecting_number(msg, param, res);
831 return sipt_get_redirecting_number_nai(msg, param, res);
834 case ISUP_PARM_GENERIC_ADDR:
835 switch(spv->sub_type)
838 return sipt_get_generic_number(msg, param, res);
840 return sipt_get_generic_number_nai(msg, param, res);
843 case ISUP_PARM_ORIGINAL_CALLED_NUM:
844 switch(spv->sub_type)
847 return sipt_get_original_called_number(msg, param, res);
849 return sipt_get_original_called_number_nai(msg, param, res);
857 static int sipt_set_bci_1(struct sip_msg *msg, char *_charge_indicator, char *_called_status, char * _called_category, char * _e2e_indicator)
859 str * str_charge_indicator = (str*)_charge_indicator;
860 unsigned int charge_indicator = 0;
861 str2int(str_charge_indicator, &charge_indicator);
862 str * str_called_status = (str*)_called_status;
863 unsigned int called_status = 0;
864 str2int(str_called_status, &called_status);
865 str * str_called_category = (str*)_called_category;
866 unsigned int called_category = 0;
867 str2int(str_called_category, &called_category);
868 str * str_e2e_indicator = (str*)_e2e_indicator;
869 unsigned int e2e_indicator = 0;
870 str2int(str_e2e_indicator, &e2e_indicator);
871 struct sdp_mangler mangle;
873 // update forwarded iam
875 body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
879 LM_INFO("No ISUP Message Found");
883 sdp.s = get_body_part(msg, TYPE_APPLICATION, SUBTYPE_SDP, &sdp.len);
885 unsigned char newbuf[1024];
886 memset(newbuf, 0, 1024);
888 LM_ERR("failed to get the message body\n");
891 body.len = msg->len -(int)(body.s-msg->buf);
893 LM_DBG("message body has zero length\n");
897 if(body.s[0] != ISUP_ACM && body.s[0] != ISUP_COT)
899 LM_DBG("message not an ACM or COT\n");
904 mangle.body_offset = (int)(body.s - msg->buf);
908 int res = isup_update_bci_1(&mangle, charge_indicator, called_status, called_category, e2e_indicator, (unsigned char*)body.s, body.len);
911 LM_DBG("error updating ACM\n");
918 static int sipt_destination(struct sip_msg *msg, char *_destination, char *_hops, char * _nai) {
919 str terminator = str_init("1");
920 return sipt_destination2(msg, _destination, _hops, _nai, (char*)&terminator);
923 static int sipt_destination2(struct sip_msg *msg, char *_destination, char *_hops, char * _nai, char * _terminator)
925 str * str_hops = (str*)_hops;
926 unsigned int hops = 0;
927 str2int(str_hops, &hops);
928 str * nai = (str*)_nai;
929 unsigned int int_nai = 0;
930 str2int(nai, &int_nai);
931 str * terminator = (str*)_terminator;
932 unsigned int int_terminator = 0; /* if the str2int later fail */
933 str2int(terminator, &int_terminator);
934 str * destination = (str*)_destination;
935 struct sdp_mangler mangle;
937 // update forwarded iam
939 body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
943 LM_INFO("No ISUP Message Found");
947 sdp.s = get_body_part(msg, TYPE_APPLICATION, SUBTYPE_SDP, &sdp.len);
949 unsigned char newbuf[1024];
950 memset(newbuf, 0, 1024);
952 LM_ERR("failed to get the message body\n");
955 body.len = msg->len -(int)(body.s-msg->buf);
957 LM_DBG("message body has zero length\n");
961 if(body.s[0] != ISUP_IAM)
963 LM_DBG("message not an IAM\n");
968 mangle.body_offset = (int)(body.s - msg->buf);
971 char * digits = calloc(1,destination->len+2);
972 memcpy(digits, destination->s, destination->len);
974 if (int_terminator) {
975 digits[destination->len] = '#';
978 int res = isup_update_destination(&mangle, digits, hops, int_nai, (unsigned char*)body.s, body.len);
982 LM_DBG("error updating IAM\n");
989 static int sipt_set_calling(struct sip_msg *msg, char *_origin, char *_nai, char * _pres, char *_screen)
991 unsigned int pres = 0;
992 str * str_pres = (str*)_pres;
993 str2int(str_pres, &pres);
994 unsigned int screen = 0;
995 str * str_screen = (str*)_screen;
996 str2int(str_screen, &screen);
997 str * nai = (str*)_nai;
998 unsigned int int_nai = 0;
999 str2int(nai, &int_nai);
1000 str * origin = (str*)_origin;
1001 struct sdp_mangler mangle;
1003 // update forwarded iam
1005 body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
1009 LM_INFO("No ISUP Message Found");
1014 LM_ERR("failed to get the message body\n");
1017 body.len = msg->len -(int)(body.s-msg->buf);
1019 LM_DBG("message body has zero length\n");
1023 if(body.s[0] != ISUP_IAM)
1025 LM_DBG("message not an IAM\n");
1031 mangle.body_offset = (int)(body.s - msg->buf);
1033 char * digits = calloc(1,origin->len+2);
1034 memcpy(digits, origin->s, origin->len);
1036 int res = isup_update_calling(&mangle, digits, int_nai, pres, screen, (unsigned char*)body.s, body.len);
1040 LM_DBG("error updating IAM\n");
1047 static int sipt_forwarding(struct sip_msg *msg, char *_fwdnumber, char * _nai)
1049 str * nai = (str*)_nai;
1050 unsigned int int_nai = 0;
1051 str2int(nai, &int_nai);
1052 str * fwdnumber = (str*)_fwdnumber;
1053 struct sdp_mangler mangle;
1055 // update forwarded iam
1057 body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
1061 LM_INFO("No ISUP Message Found");
1065 sdp.s = get_body_part(msg, TYPE_APPLICATION, SUBTYPE_SDP, &sdp.len);
1067 unsigned char newbuf[1024];
1068 memset(newbuf, 0, 1024);
1070 LM_ERR("failed to get the message body\n");
1073 body.len = msg->len -(int)(body.s-msg->buf);
1075 LM_DBG("message body has zero length\n");
1079 if(body.s[0] != ISUP_IAM)
1081 LM_DBG("message not an IAM\n");
1086 mangle.body_offset = (int)(body.s - msg->buf);
1088 char * digits = calloc(1,fwdnumber->len+2);
1089 memcpy(digits, fwdnumber->s, fwdnumber->len);
1091 int res = isup_update_forwarding(&mangle, digits, int_nai, (unsigned char*)body.s, body.len);
1095 LM_DBG("error updating IAM\n");
1103 static int mod_init(void)
1109 static void mod_destroy(void)