1 /*
2 * pua_bla module - pua Bridged Line Appearance
3 *
4 * Copyright (C) 2007 Voice Sistem S.R.L.
5 *
6 * This file is part of Kamailio, a free SIP server.
7 *
8 * Kamailio is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version
12 *
13 * Kamailio is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25
26 #include "../../core/sr_module.h"
27 #include "../../core/dprint.h"
28 #include "../usrloc/usrloc.h"
29 #include "../../core/parser/msg_parser.h"
30 #include "../../core/parser/parse_from.h"
31 #include "pua_bla.h"
32 #include "registrar_cb.h"
33
34 MODULE_VERSION
35
36 /* Structure containing pointers to pua functions */
37 pua_api_t pua;
38 /* Structure containing pointers to usrloc functions */
39 usrloc_api_t ul;
40 str default_domain = STR_NULL;
41 str header_name = STR_NULL;
42 str bla_outbound_proxy = STR_NULL;
43 int is_bla_aor = 0;
44 str reg_from_uri = STR_NULL;
45 static int mod_init(void);
46
47 send_publish_t pua_send_publish;
48 send_subscribe_t pua_send_subscribe;
49 query_dialog_t pua_is_dialog;
50 int bla_set_flag(struct sip_msg *, char *, char *);
51 str server_address = STR_NULL;
52
53 /* clang-format off */
54 static cmd_export_t cmds[] = {
55 {"bla_set_flag", (cmd_function)bla_set_flag, 0, 0, 0, REQUEST_ROUTE},
56 {"bla_handle_notify", (cmd_function)bla_handle_notify, 0, 0, 0, REQUEST_ROUTE},
57 {0, 0, 0, 0, 0, 0}
58 };
59
60 static param_export_t params[] = {
61 {"server_address", PARAM_STR, &server_address},
62 {"default_domain", PARAM_STR, &default_domain},
63 {"header_name", PARAM_STR, &header_name},
64 {"outbound_proxy", PARAM_STR, &bla_outbound_proxy},
65 {0, 0, 0}
66 };
67
68 /** module exports */
69 struct module_exports exports = {
70 "pua_bla", /* module name */
71 DEFAULT_DLFLAGS, /* dlopen flags */
72 cmds, /* exported functions */
73 params, /* exported parameters */
74 0, /* RPC method exports */
75 0, /* exported pseudo-variables */
76 0, /* response handling function */
77 mod_init, /* module initialization function */
78 0, /* per-child init function */
79 0 /* module destroy function */
80 };
81 /* clang-format on */
82
83 /**
84 * init module function
85 */
mod_init(void)86 static int mod_init(void)
87 {
88 bind_pua_t bind_pua;
89 bind_usrloc_t bind_usrloc;
90
91 if(!server_address.s || server_address.len <= 0) {
92 LM_ERR("compulsory 'server_address' parameter not set!");
93 return -1;
94 }
95
96 if(!default_domain.s || default_domain.len <= 0) {
97 LM_ERR("default domain not found\n");
98 return -1;
99 }
100
101 if(!header_name.s || header_name.len <= 0) {
102 LM_ERR("header_name parameter not set\n");
103 return -1;
104 }
105
106 if(!bla_outbound_proxy.s || bla_outbound_proxy.len <= 0) {
107 LM_DBG("No outbound proxy set\n");
108 }
109
110 bind_pua = (bind_pua_t)find_export("bind_pua", 1, 0);
111 if(!bind_pua) {
112 LM_ERR("Can't bind pua\n");
113 return -1;
114 }
115
116 if(bind_pua(&pua) < 0) {
117 LM_ERR("Can't bind pua\n");
118 return -1;
119 }
120 if(pua.send_publish == NULL) {
121 LM_ERR("Could not import send_publish\n");
122 return -1;
123 }
124 pua_send_publish = pua.send_publish;
125
126 if(pua.send_subscribe == NULL) {
127 LM_ERR("Could not import send_subscribe\n");
128 return -1;
129 }
130 pua_send_subscribe = pua.send_subscribe;
131
132 if(pua.is_dialog == NULL) {
133 LM_ERR("Could not import send_subscribe\n");
134 return -1;
135 }
136 pua_is_dialog = pua.is_dialog;
137
138 if(pua.register_puacb == NULL) {
139 LM_ERR("Could not import register callback\n");
140 return -1;
141 }
142
143 bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
144 if(!bind_usrloc) {
145 LM_ERR("Can't bind usrloc\n");
146 return -1;
147 }
148 if(bind_usrloc(&ul) < 0) {
149 LM_ERR("Can't bind usrloc\n");
150 return -1;
151 }
152 if(ul.register_ulcb == NULL) {
153 LM_ERR("Could not import ul_register_ulcb\n");
154 return -1;
155 }
156
157 if(ul.register_ulcb(UL_CONTACT_INSERT, bla_cb, 0) < 0) {
158 LM_ERR("can not register callback for"
159 " insert\n");
160 return -1;
161 }
162 if(ul.register_ulcb(UL_CONTACT_EXPIRE, bla_cb, 0) < 0) {
163 LM_ERR("can not register callback for"
164 " insert\n");
165 return -1;
166 }
167 if(ul.register_ulcb(UL_CONTACT_UPDATE, bla_cb, 0) < 0) {
168 LM_ERR("can not register callback for"
169 " update\n");
170 return -1;
171 }
172 if(ul.register_ulcb(UL_CONTACT_DELETE, bla_cb, 0) < 0) {
173 LM_ERR("can not register callback for"
174 " delete\n");
175 return -1;
176 }
177
178 return 0;
179 }
180
181
bla_set_flag(struct sip_msg * msg,char * s1,char * s2)182 int bla_set_flag(struct sip_msg *msg, char *s1, char *s2)
183 {
184 LM_DBG("mark as bla aor\n");
185
186 is_bla_aor = 1;
187
188 if(parse_headers(msg, HDR_EOH_F, 0) == -1) {
189 LM_ERR("parsing headers\n");
190 return -1;
191 }
192
193
194 if(msg->from->parsed == NULL) {
195 if(parse_from_header(msg) < 0) {
196 LM_DBG("cannot parse From header\n");
197 return -1;
198 }
199 }
200
201 reg_from_uri = ((struct to_body *)(msg->from->parsed))->uri;
202
203 return 1;
204 }
205