File: | src/mod/endpoints/mod_sofia/sofia_glue.c |
Location: | line 798, column 3 |
Description: | Value stored to 'url_str' is never read |
1 | /* |
2 | * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application |
3 | * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org> |
4 | * |
5 | * Version: MPL 1.1 |
6 | * |
7 | * The contents of this file are subject to the Mozilla Public License Version |
8 | * 1.1 (the "License"); you may not use this file except in compliance with |
9 | * the License. You may obtain a copy of the License at |
10 | * http://www.mozilla.org/MPL/ |
11 | * |
12 | * Software distributed under the License is distributed on an "AS IS" basis, |
13 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
14 | * for the specific language governing rights and limitations under the |
15 | * License. |
16 | * |
17 | * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application |
18 | * |
19 | * The Initial Developer of the Original Code is |
20 | * Anthony Minessale II <anthm@freeswitch.org> |
21 | * Portions created by the Initial Developer are Copyright (C) |
22 | * the Initial Developer. All Rights Reserved. |
23 | * |
24 | * Contributor(s): |
25 | * |
26 | * Anthony Minessale II <anthm@freeswitch.org> |
27 | * Ken Rice <krice@freeswitch.org> |
28 | * Paul D. Tinsley <pdt at jackhammer.org> |
29 | * Bret McDanel <trixter AT 0xdecafbad.com> |
30 | * Eliot Gable <egable AT.AT broadvox.com> |
31 | * |
32 | * |
33 | * sofia_glue.c -- SOFIA SIP Endpoint (code to tie sofia to freeswitch) |
34 | * |
35 | */ |
36 | #include "mod_sofia.h" |
37 | #include <switch_stun.h> |
38 | |
39 | switch_cache_db_handle_t *_sofia_glue_get_db_handle(sofia_profile_t *profile, const char *file, const char *func, int line); |
40 | #define sofia_glue_get_db_handle(_p)_sofia_glue_get_db_handle(_p, "sofia_glue.c", (const char *)__func__ , 40) _sofia_glue_get_db_handle(_p, __FILE__"sofia_glue.c", __SWITCH_FUNC__(const char *)__func__, __LINE__40) |
41 | |
42 | |
43 | int sofia_glue_check_nat(sofia_profile_t *profile, const char *network_ip) |
44 | { |
45 | switch_assert(network_ip)((network_ip) ? (void) (0) : __assert_fail ("network_ip", "sofia_glue.c" , 45, __PRETTY_FUNCTION__)); |
46 | |
47 | return (profile->extsipip && |
48 | !switch_check_network_list_ip(network_ip, "loopback.auto")switch_check_network_list_ip_token(network_ip, "loopback.auto" , ((void*)0)) && |
49 | !switch_check_network_list_ip(network_ip, profile->local_network)switch_check_network_list_ip_token(network_ip, profile->local_network , ((void*)0))); |
50 | } |
51 | |
52 | private_object_t *sofia_glue_new_pvt(switch_core_session_t *session) |
53 | { |
54 | private_object_t *tech_pvt = (private_object_t *) switch_core_session_alloc(session, sizeof(private_object_t))switch_core_perform_session_alloc(session, sizeof(private_object_t ), "sofia_glue.c", (const char *)__func__, 54); |
55 | switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED0x1, switch_core_session_get_pool(session)); |
56 | switch_mutex_init(&tech_pvt->sofia_mutex, SWITCH_MUTEX_NESTED0x1, switch_core_session_get_pool(session)); |
57 | return tech_pvt; |
58 | } |
59 | |
60 | void sofia_glue_set_name(private_object_t *tech_pvt, const char *channame) |
61 | { |
62 | char name[256]; |
63 | char *p; |
64 | |
65 | switch_snprintf(name, sizeof(name), "sofia/%s/%s", tech_pvt->profile->name, channame); |
66 | if ((p = strchr(name, ';')(__extension__ (__builtin_constant_p (';') && !__builtin_constant_p (name) && (';') == '\0' ? (char *) __rawmemchr (name , ';') : __builtin_strchr (name, ';'))))) { |
67 | *p = '\0'; |
68 | } |
69 | switch_channel_set_name(tech_pvt->channel, name); |
70 | } |
71 | |
72 | void sofia_glue_attach_private(switch_core_session_t *session, sofia_profile_t *profile, private_object_t *tech_pvt, const char *channame) |
73 | { |
74 | |
75 | unsigned int x, i; |
76 | |
77 | switch_assert(session != NULL)((session != ((void*)0)) ? (void) (0) : __assert_fail ("session != ((void*)0)" , "sofia_glue.c", 77, __PRETTY_FUNCTION__)); |
78 | switch_assert(profile != NULL)((profile != ((void*)0)) ? (void) (0) : __assert_fail ("profile != ((void*)0)" , "sofia_glue.c", 78, __PRETTY_FUNCTION__)); |
79 | switch_assert(tech_pvt != NULL)((tech_pvt != ((void*)0)) ? (void) (0) : __assert_fail ("tech_pvt != ((void*)0)" , "sofia_glue.c", 79, __PRETTY_FUNCTION__)); |
80 | |
81 | switch_core_session_add_stream(session, NULL((void*)0)); |
82 | |
83 | switch_mutex_lock(tech_pvt->flag_mutex); |
84 | switch_mutex_lock(profile->flag_mutex); |
85 | |
86 | /* copy flags from profile to the sofia private */ |
87 | for (x = 0; x < TFLAG_MAX; x++) { |
88 | tech_pvt->flags[x] = profile->flags[x]; |
89 | } |
90 | |
91 | tech_pvt->x_freeswitch_support_local = FREESWITCH_SUPPORT"update_display,send_info"; |
92 | |
93 | tech_pvt->profile = profile; |
94 | |
95 | tech_pvt->mparams.rtpip = switch_core_session_strdup(session, profile->rtpip[profile->rtpip_next++])switch_core_perform_session_strdup(session, profile->rtpip [profile->rtpip_next++], "sofia_glue.c", (const char *)__func__ , 95); |
96 | if (profile->rtpip_next >= profile->rtpip_index) { |
97 | profile->rtpip_next = 0; |
98 | } |
99 | |
100 | profile->inuse++; |
101 | switch_mutex_unlock(profile->flag_mutex); |
102 | switch_mutex_unlock(tech_pvt->flag_mutex); |
103 | |
104 | if (tech_pvt->bte) { |
105 | tech_pvt->recv_te = tech_pvt->te = tech_pvt->bte; |
106 | } else if (!tech_pvt->te) { |
107 | tech_pvt->mparams.recv_te = tech_pvt->mparams.te = profile->te; |
108 | } |
109 | |
110 | tech_pvt->mparams.dtmf_type = tech_pvt->profile->dtmf_type; |
111 | |
112 | if (!sofia_test_media_flag(tech_pvt->profile, SCMF_SUPPRESS_CNG)((tech_pvt->profile)->media_flags[SCMF_SUPPRESS_CNG] ? 1 : 0)) { |
113 | if (tech_pvt->bcng_pt) { |
114 | tech_pvt->cng_pt = tech_pvt->bcng_pt; |
115 | } else if (!tech_pvt->cng_pt) { |
116 | tech_pvt->cng_pt = profile->cng_pt; |
117 | } |
118 | } |
119 | |
120 | tech_pvt->session = session; |
121 | tech_pvt->channel = switch_core_session_get_channel(session); |
122 | |
123 | if (sofia_test_pflag(profile, PFLAG_TRACK_CALLS)((profile)->pflags[PFLAG_TRACK_CALLS] ? 1 : 0)) { |
124 | switch_channel_set_flag(tech_pvt->channel, CF_TRACKABLE)switch_channel_set_flag_value(tech_pvt->channel, CF_TRACKABLE , 1); |
125 | } |
126 | |
127 | |
128 | if (profile->flags[PFLAG_PASS_RFC2833]) { |
129 | switch_channel_set_flag(tech_pvt->channel, CF_PASS_RFC2833)switch_channel_set_flag_value(tech_pvt->channel, CF_PASS_RFC2833 , 1); |
130 | } |
131 | |
132 | if (sofia_test_pflag(tech_pvt->profile, PFLAG_RTP_NOTIMER_DURING_BRIDGE)((tech_pvt->profile)->pflags[PFLAG_RTP_NOTIMER_DURING_BRIDGE ] ? 1 : 0)) { |
133 | switch_channel_set_flag(tech_pvt->channel, CF_RTP_NOTIMER_DURING_BRIDGE)switch_channel_set_flag_value(tech_pvt->channel, CF_RTP_NOTIMER_DURING_BRIDGE , 1); |
134 | } |
135 | |
136 | if (sofia_test_pflag(tech_pvt->profile, PFLAG_T38_PASSTHRU)((tech_pvt->profile)->pflags[PFLAG_T38_PASSTHRU] ? 1 : 0 )) { |
137 | switch_channel_set_flag(tech_pvt->channel, CF_T38_PASSTHRU)switch_channel_set_flag_value(tech_pvt->channel, CF_T38_PASSTHRU , 1); |
138 | } |
139 | |
140 | switch_core_media_check_dtmf_type(session); |
141 | switch_channel_set_cap(tech_pvt->channel, CC_MEDIA_ACK)switch_channel_set_cap_value(tech_pvt->channel, CC_MEDIA_ACK , 1); |
142 | switch_channel_set_cap(tech_pvt->channel, CC_BYPASS_MEDIA)switch_channel_set_cap_value(tech_pvt->channel, CC_BYPASS_MEDIA , 1); |
143 | switch_channel_set_cap(tech_pvt->channel, CC_PROXY_MEDIA)switch_channel_set_cap_value(tech_pvt->channel, CC_PROXY_MEDIA , 1); |
144 | switch_channel_set_cap(tech_pvt->channel, CC_JITTERBUFFER)switch_channel_set_cap_value(tech_pvt->channel, CC_JITTERBUFFER , 1); |
145 | switch_channel_set_cap(tech_pvt->channel, CC_FS_RTP)switch_channel_set_cap_value(tech_pvt->channel, CC_FS_RTP, 1); |
146 | switch_channel_set_cap(tech_pvt->channel, CC_QUEUEABLE_DTMF_DELAY)switch_channel_set_cap_value(tech_pvt->channel, CC_QUEUEABLE_DTMF_DELAY , 1); |
147 | |
148 | |
149 | |
150 | tech_pvt->mparams.ndlb = tech_pvt->profile->mndlb; |
151 | tech_pvt->mparams.inbound_codec_string = profile->inbound_codec_string; |
152 | tech_pvt->mparams.outbound_codec_string = profile->outbound_codec_string; |
153 | tech_pvt->mparams.auto_rtp_bugs = profile->auto_rtp_bugs; |
154 | tech_pvt->mparams.timer_name = profile->timer_name; |
155 | tech_pvt->mparams.vflags = profile->vflags; |
156 | tech_pvt->mparams.manual_rtp_bugs = profile->manual_rtp_bugs; |
157 | tech_pvt->mparams.manual_video_rtp_bugs = profile->manual_video_rtp_bugs; |
158 | tech_pvt->mparams.extsipip = profile->extsipip; |
159 | tech_pvt->mparams.extrtpip = profile->extrtpip; |
160 | tech_pvt->mparams.local_network = profile->local_network; |
161 | tech_pvt->mparams.sipip = profile->sipip; |
162 | tech_pvt->mparams.jb_msec = profile->jb_msec; |
163 | tech_pvt->mparams.rtcp_audio_interval_msec = profile->rtcp_audio_interval_msec; |
164 | tech_pvt->mparams.rtcp_video_interval_msec = profile->rtcp_video_interval_msec; |
165 | tech_pvt->mparams.sdp_username = profile->sdp_username; |
166 | tech_pvt->mparams.cng_pt = tech_pvt->cng_pt; |
167 | tech_pvt->mparams.rtp_timeout_sec = profile->rtp_timeout_sec; |
168 | tech_pvt->mparams.rtp_hold_timeout_sec = profile->rtp_hold_timeout_sec; |
169 | |
170 | |
171 | switch_media_handle_create(&tech_pvt->media_handle, session, &tech_pvt->mparams); |
172 | switch_media_handle_set_media_flags(tech_pvt->media_handle, tech_pvt->profile->media_flags); |
173 | |
174 | |
175 | for(i = 0; i < profile->cand_acl_count; i++) { |
176 | switch_core_media_add_ice_acl(session, SWITCH_MEDIA_TYPE_AUDIO, profile->cand_acl[i]); |
177 | switch_core_media_add_ice_acl(session, SWITCH_MEDIA_TYPE_VIDEO, profile->cand_acl[i]); |
178 | } |
179 | |
180 | |
181 | switch_core_session_set_private(session, tech_pvt)switch_core_session_set_private_class(session, tech_pvt, SWITCH_PVT_PRIMARY ); |
182 | |
183 | if (channame) { |
184 | sofia_glue_set_name(tech_pvt, channame); |
185 | } |
186 | |
187 | } |
188 | |
189 | |
190 | |
191 | |
192 | switch_status_t sofia_glue_ext_address_lookup(sofia_profile_t *profile, char **ip, switch_port_t *port, |
193 | const char *sourceip, switch_memory_pool_t *pool) |
194 | { |
195 | char *error = ""; |
196 | switch_status_t status = SWITCH_STATUS_FALSE; |
197 | int x; |
198 | switch_port_t stun_port = SWITCH_STUN_DEFAULT_PORT3478; |
199 | char *stun_ip = NULL((void*)0); |
200 | |
201 | if (!sourceip) { |
202 | return status; |
203 | } |
204 | |
205 | if (!strncasecmp(sourceip, "host:", 5)) { |
206 | status = (*ip = switch_stun_host_lookup(sourceip + 5, pool)) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; |
207 | } else if (!strncasecmp(sourceip, "stun:", 5)) { |
208 | char *p; |
209 | |
210 | stun_ip = strdup(sourceip + 5)(__extension__ (__builtin_constant_p (sourceip + 5) && ((size_t)(const void *)((sourceip + 5) + 1) - (size_t)(const void *)(sourceip + 5) == 1) ? (((const char *) (sourceip + 5 ))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (sourceip + 5) + 1; char *__retval = ( char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, sourceip + 5, __len); __retval; } )) : __strdup (sourceip + 5))); |
211 | |
212 | if ((p = strchr(stun_ip, ':')(__extension__ (__builtin_constant_p (':') && !__builtin_constant_p (stun_ip) && (':') == '\0' ? (char *) __rawmemchr (stun_ip , ':') : __builtin_strchr (stun_ip, ':'))))) { |
213 | int iport; |
214 | *p++ = '\0'; |
215 | iport = atoi(p); |
216 | if (iport > 0 && iport < 0xFFFF) { |
217 | stun_port = (switch_port_t) iport; |
218 | } |
219 | } |
220 | |
221 | if (zstr(stun_ip)_zstr(stun_ip)) { |
222 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 222, ((void*)0), SWITCH_LOG_ERROR, "STUN Failed! NO STUN SERVER\n"); |
223 | goto out; |
224 | } |
225 | |
226 | |
227 | for (x = 0; x < 5; x++) { |
228 | if ((status = switch_stun_lookup(ip, port, stun_ip, stun_port, &error, pool)) != SWITCH_STATUS_SUCCESS) { |
229 | switch_yield(100000)switch_sleep(100000);; |
230 | } else { |
231 | break; |
232 | } |
233 | } |
234 | |
235 | if (!*ip) { |
236 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 236, ((void*)0), SWITCH_LOG_ERROR, "STUN Failed! No IP returned\n"); |
237 | goto out; |
238 | } |
239 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 239, ((void*)0), SWITCH_LOG_DEBUG, "STUN Success [%s]:[%d]\n", *ip, *port); |
240 | status = SWITCH_STATUS_SUCCESS; |
241 | } else { |
242 | *ip = (char *) sourceip; |
243 | status = SWITCH_STATUS_SUCCESS; |
244 | } |
245 | |
246 | out: |
247 | |
248 | switch_safe_free(stun_ip)if (stun_ip) {free(stun_ip);stun_ip=((void*)0);}; |
249 | |
250 | return status; |
251 | } |
252 | |
253 | |
254 | const char *sofia_glue_get_unknown_header(sip_t const *sip, const char *name) |
255 | { |
256 | sip_unknown_t *un; |
257 | for (un = sip->sip_unknown; un; un = un->un_next) { |
258 | if (!strcasecmp(un->un_name, name)) { |
259 | if (!zstr(un->un_value)_zstr(un->un_value)) { |
260 | return un->un_value; |
261 | } |
262 | } |
263 | } |
264 | return NULL((void*)0); |
265 | } |
266 | |
267 | sofia_transport_t sofia_glue_str2transport(const char *str) |
268 | { |
269 | if (!strncasecmp(str, "udp", 3)) { |
270 | return SOFIA_TRANSPORT_UDP; |
271 | } else if (!strncasecmp(str, "tcp", 3)) { |
272 | return SOFIA_TRANSPORT_TCP; |
273 | } else if (!strncasecmp(str, "sctp", 4)) { |
274 | return SOFIA_TRANSPORT_SCTP; |
275 | } else if (!strncasecmp(str, "tls", 3)) { |
276 | return SOFIA_TRANSPORT_TCP_TLS; |
277 | } |
278 | |
279 | return SOFIA_TRANSPORT_UNKNOWN; |
280 | } |
281 | |
282 | enum tport_tls_verify_policy sofia_glue_str2tls_verify_policy(const char * str){ |
283 | char *ptr_next; |
284 | int len; |
285 | enum tport_tls_verify_policy ret; |
286 | char *ptr_cur = (char *) str; |
287 | ret = TPTLS_VERIFY_NONE; |
288 | |
289 | while (ptr_cur) { |
290 | if ((ptr_next = strchr(ptr_cur, '|')(__extension__ (__builtin_constant_p ('|') && !__builtin_constant_p (ptr_cur) && ('|') == '\0' ? (char *) __rawmemchr (ptr_cur , '|') : __builtin_strchr (ptr_cur, '|'))))) { |
291 | len = (int)(ptr_next++ - ptr_cur); |
292 | } else { |
293 | len = (int)strlen(ptr_cur); |
294 | } |
295 | if (!strncasecmp(ptr_cur, "in",len)) { |
296 | ret |= TPTLS_VERIFY_IN; |
297 | } else if (!strncasecmp(ptr_cur, "out",len)) { |
298 | ret |= TPTLS_VERIFY_OUT; |
299 | } else if (!strncasecmp(ptr_cur, "all",len)) { |
300 | ret |= TPTLS_VERIFY_ALL; |
301 | } else if (!strncasecmp(ptr_cur, "subjects_in",len)) { |
302 | ret |= TPTLS_VERIFY_SUBJECTS_IN; |
303 | } else if (!strncasecmp(ptr_cur, "subjects_out",len)) { |
304 | ret |= TPTLS_VERIFY_SUBJECTS_OUT; |
305 | } else if (!strncasecmp(ptr_cur, "subjects_all",len)) { |
306 | ret |= TPTLS_VERIFY_SUBJECTS_ALL; |
307 | } |
308 | ptr_cur = ptr_next; |
309 | } |
310 | return ret; |
311 | } |
312 | |
313 | char *sofia_glue_find_parameter_value(switch_core_session_t *session, const char *str, const char *param) |
314 | { |
315 | const char *param_ptr; |
316 | char *param_value; |
317 | char *tmp; |
318 | switch_size_t param_len; |
319 | |
320 | if (zstr(str)_zstr(str) || zstr(param)_zstr(param) || !session) return NULL((void*)0); |
321 | |
322 | if (end_of(param)*(*param == '\0' ? param : param + strlen(param) - 1) != '=') { |
323 | param = switch_core_session_sprintf(session, "%s=", param); |
324 | if (zstr(param)_zstr(param)) return NULL((void*)0); |
325 | } |
326 | |
327 | param_len = strlen(param); |
328 | param_ptr = sofia_glue_find_parameter(str, param); |
329 | |
330 | if (zstr(param_ptr)_zstr(param_ptr)) return NULL((void*)0); |
331 | |
332 | param_value = switch_core_session_strdup(session, param_ptr + param_len)switch_core_perform_session_strdup(session, param_ptr + param_len , "sofia_glue.c", (const char *)__func__, 332); |
333 | |
334 | if (zstr(param_value)_zstr(param_value)) return NULL((void*)0); |
335 | |
336 | if ((tmp = strchr(param_value, ';')(__extension__ (__builtin_constant_p (';') && !__builtin_constant_p (param_value) && (';') == '\0' ? (char *) __rawmemchr (param_value, ';') : __builtin_strchr (param_value, ';'))))) *tmp = '\0'; |
337 | |
338 | return param_value; |
339 | } |
340 | |
341 | char *sofia_glue_find_parameter(const char *str, const char *param) |
342 | { |
343 | char *ptr = NULL((void*)0); |
344 | |
345 | ptr = (char *) str; |
346 | while (ptr) { |
347 | if (!strncasecmp(ptr, param, strlen(param))) |
348 | return ptr; |
349 | |
350 | if ((ptr = strchr(ptr, ';')(__extension__ (__builtin_constant_p (';') && !__builtin_constant_p (ptr) && (';') == '\0' ? (char *) __rawmemchr (ptr, ';' ) : __builtin_strchr (ptr, ';'))))) |
351 | ptr++; |
352 | } |
353 | |
354 | return NULL((void*)0); |
355 | } |
356 | |
357 | sofia_transport_t sofia_glue_url2transport(const url_t *url) |
358 | { |
359 | char *ptr = NULL((void*)0); |
360 | int tls = 0; |
361 | |
362 | if (!url) |
363 | return SOFIA_TRANSPORT_UNKNOWN; |
364 | |
365 | if (url->url_scheme && !strcasecmp(url->url_scheme, "sips")) { |
366 | tls++; |
367 | } |
368 | |
369 | if ((ptr = sofia_glue_find_parameter(url->url_params, "transport="))) { |
370 | return sofia_glue_str2transport(ptr + 10); |
371 | } |
372 | |
373 | return (tls) ? SOFIA_TRANSPORT_TCP_TLS : SOFIA_TRANSPORT_UDP; |
374 | } |
375 | |
376 | sofia_transport_t sofia_glue_via2transport(const sip_via_t * via) |
377 | { |
378 | char *ptr = NULL((void*)0); |
379 | |
380 | if (!via || !via->v_protocol) |
381 | return SOFIA_TRANSPORT_UNKNOWN; |
382 | |
383 | if ((ptr = strrchr(via->v_protocol, '/'))) { |
384 | ptr++; |
385 | |
386 | if (!strncasecmp(ptr, "udp", 3)) { |
387 | return SOFIA_TRANSPORT_UDP; |
388 | } else if (!strncasecmp(ptr, "tcp", 3)) { |
389 | return SOFIA_TRANSPORT_TCP; |
390 | } else if (!strncasecmp(ptr, "tls", 3)) { |
391 | return SOFIA_TRANSPORT_TCP_TLS; |
392 | } else if (!strncasecmp(ptr, "sctp", 4)) { |
393 | return SOFIA_TRANSPORT_SCTP; |
394 | } else if (!strncasecmp(ptr, "wss", 3)) { |
395 | return SOFIA_TRANSPORT_WSS; |
396 | } else if (!strncasecmp(ptr, "ws", 2)) { |
397 | return SOFIA_TRANSPORT_WS; |
398 | } |
399 | } |
400 | |
401 | return SOFIA_TRANSPORT_UNKNOWN; |
402 | } |
403 | |
404 | const char *sofia_glue_transport2str(const sofia_transport_t tp) |
405 | { |
406 | switch (tp) { |
407 | case SOFIA_TRANSPORT_TCP: |
408 | return "tcp"; |
409 | |
410 | case SOFIA_TRANSPORT_TCP_TLS: |
411 | return "tls"; |
412 | |
413 | case SOFIA_TRANSPORT_SCTP: |
414 | return "sctp"; |
415 | |
416 | case SOFIA_TRANSPORT_WS: |
417 | return "ws"; |
418 | |
419 | case SOFIA_TRANSPORT_WSS: |
420 | return "wss"; |
421 | |
422 | default: |
423 | return "udp"; |
424 | } |
425 | } |
426 | |
427 | char *sofia_glue_create_external_via(switch_core_session_t *session, sofia_profile_t *profile, sofia_transport_t transport) |
428 | { |
429 | return sofia_glue_create_via(session, profile->extsipip, (sofia_glue_transport_has_tls(transport)) |
430 | ? profile->tls_sip_port : profile->extsipport, transport); |
431 | } |
432 | |
433 | char *sofia_glue_create_via(switch_core_session_t *session, const char *ip, switch_port_t port, sofia_transport_t transport) |
434 | { |
435 | if (port && port != 5060) { |
436 | if (session) { |
437 | return switch_core_session_sprintf(session, "SIP/2.0/%s %s:%d;rport", sofia_glue_transport2str(transport), ip, port); |
438 | } else { |
439 | return switch_mprintf("SIP/2.0/%s %s:%d;rport", sofia_glue_transport2str(transport), ip, port); |
440 | } |
441 | } else { |
442 | if (session) { |
443 | return switch_core_session_sprintf(session, "SIP/2.0/%s %s;rport", sofia_glue_transport2str(transport), ip); |
444 | } else { |
445 | return switch_mprintf("SIP/2.0/%s %s;rport", sofia_glue_transport2str(transport), ip); |
446 | } |
447 | } |
448 | } |
449 | |
450 | char *sofia_glue_strip_uri(const char *str) |
451 | { |
452 | char *p; |
453 | char *r; |
454 | |
455 | if ((p = strchr(str, '<')(__extension__ (__builtin_constant_p ('<') && !__builtin_constant_p (str) && ('<') == '\0' ? (char *) __rawmemchr (str , '<') : __builtin_strchr (str, '<'))))) { |
456 | p++; |
457 | r = strdup(p)(__extension__ (__builtin_constant_p (p) && ((size_t) (const void *)((p) + 1) - (size_t)(const void *)(p) == 1) ? ( ((const char *) (p))[0] == '\0' ? (char *) calloc ((size_t) 1 , (size_t) 1) : ({ size_t __len = strlen (p) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, p, __len); __retval; })) : __strdup (p))); |
458 | if ((p = strchr(r, '>')(__extension__ (__builtin_constant_p ('>') && !__builtin_constant_p (r) && ('>') == '\0' ? (char *) __rawmemchr (r, '>' ) : __builtin_strchr (r, '>'))))) { |
459 | *p = '\0'; |
460 | } |
461 | } else { |
462 | r = strdup(str)(__extension__ (__builtin_constant_p (str) && ((size_t )(const void *)((str) + 1) - (size_t)(const void *)(str) == 1 ) ? (((const char *) (str))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (str) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, str, __len); __retval ; })) : __strdup (str))); |
463 | } |
464 | |
465 | return r; |
466 | } |
467 | |
468 | |
469 | |
470 | int sofia_glue_transport_has_tls(const sofia_transport_t tp) |
471 | { |
472 | switch (tp) { |
473 | case SOFIA_TRANSPORT_TCP_TLS: |
474 | return 1; |
475 | |
476 | default: |
477 | return 0; |
478 | } |
479 | } |
480 | |
481 | void sofia_glue_get_addr(msg_t *msg, char *buf, size_t buflen, int *port) |
482 | { |
483 | su_addrinfo_t *addrinfo = msg_addrinfo(msg); |
484 | |
485 | if (buf) { |
486 | get_addr(buf, buflen, addrinfo->ai_addr, (socklen_t)addrinfo->ai_addrlen); |
487 | } |
488 | |
489 | if (port) { |
490 | *port = get_port(addrinfo->ai_addr); |
491 | } |
492 | } |
493 | |
494 | char *sofia_overcome_sip_uri_weakness(switch_core_session_t *session, const char *uri, const sofia_transport_t transport, switch_bool_t uri_only, |
495 | const char *params, const char *invite_tel_params) |
496 | { |
497 | char *stripped = switch_core_session_strdup(session, uri)switch_core_perform_session_strdup(session, uri, "sofia_glue.c" , (const char *)__func__, 497); |
498 | char *new_uri = NULL((void*)0); |
499 | char *p; |
500 | const char *url_params = NULL((void*)0); |
501 | |
502 | if (!zstr(params)_zstr(params) && *params == '~') { |
503 | url_params = params + 1; |
504 | params = NULL((void*)0); |
505 | } |
506 | |
507 | stripped = sofia_glue_get_url_from_contact(stripped, 0); |
508 | |
509 | /* remove our params so we don't make any whiny moronic device piss it's pants and forget who it is for a half-hour */ |
510 | if ((p = (char *) switch_stristr(";fs_", stripped))) { |
511 | *p = '\0'; |
512 | } |
513 | |
514 | if (transport && transport != SOFIA_TRANSPORT_UDP) { |
515 | |
516 | if (switch_stristr("port=", stripped)) { |
517 | new_uri = switch_core_session_sprintf(session, "%s%s%s", uri_only ? "" : "<", stripped, uri_only ? "" : ">"); |
518 | } else { |
519 | |
520 | if (strchr(stripped, ';')(__extension__ (__builtin_constant_p (';') && !__builtin_constant_p (stripped) && (';') == '\0' ? (char *) __rawmemchr ( stripped, ';') : __builtin_strchr (stripped, ';')))) { |
521 | if (params) { |
522 | new_uri = switch_core_session_sprintf(session, "%s%s;transport=%s;%s%s", |
523 | uri_only ? "" : "<", stripped, sofia_glue_transport2str(transport), params, uri_only ? "" : ">"); |
524 | } else { |
525 | new_uri = switch_core_session_sprintf(session, "%s%s;transport=%s%s", |
526 | uri_only ? "" : "<", stripped, sofia_glue_transport2str(transport), uri_only ? "" : ">"); |
527 | } |
528 | } else { |
529 | if (params) { |
530 | new_uri = switch_core_session_sprintf(session, "%s%s;transport=%s;%s%s", |
531 | uri_only ? "" : "<", stripped, sofia_glue_transport2str(transport), params, uri_only ? "" : ">"); |
532 | } else { |
533 | new_uri = switch_core_session_sprintf(session, "%s%s;transport=%s%s", |
534 | uri_only ? "" : "<", stripped, sofia_glue_transport2str(transport), uri_only ? "" : ">"); |
535 | } |
536 | } |
537 | } |
538 | } else { |
539 | if (params) { |
540 | new_uri = switch_core_session_sprintf(session, "%s%s;%s%s", uri_only ? "" : "<", stripped, params, uri_only ? "" : ">"); |
541 | } else { |
542 | if (uri_only) { |
543 | new_uri = stripped; |
544 | } else { |
545 | new_uri = switch_core_session_sprintf(session, "<%s>", stripped); |
546 | } |
547 | } |
548 | } |
549 | |
550 | if (url_params && !uri_only) { |
551 | new_uri = switch_core_session_sprintf(session, "%s;%s", new_uri, url_params); |
552 | } |
553 | |
554 | if (!zstr(invite_tel_params)_zstr(invite_tel_params)) { |
555 | char *lhs, *rhs = strchr(new_uri, '@')(__extension__ (__builtin_constant_p ('@') && !__builtin_constant_p (new_uri) && ('@') == '\0' ? (char *) __rawmemchr (new_uri , '@') : __builtin_strchr (new_uri, '@'))); |
556 | |
557 | if (!zstr(rhs)_zstr(rhs)) { |
558 | *rhs++ = '\0'; |
559 | lhs = new_uri; |
560 | new_uri = switch_core_session_sprintf(session, "%s;%s@%s", lhs, invite_tel_params, rhs); |
561 | } |
562 | } |
563 | |
564 | return new_uri; |
565 | } |
566 | |
567 | char *sofia_glue_get_extra_headers(switch_channel_t *channel, const char *prefix) |
568 | { |
569 | char *extra_headers = NULL((void*)0); |
570 | switch_stream_handle_t stream = { 0 }; |
571 | switch_event_header_t *hi = NULL((void*)0); |
572 | const char *exclude_regex = NULL((void*)0); |
573 | switch_regex_t *re = NULL((void*)0); |
574 | int ovector[30] = {0}; |
575 | int proceed; |
576 | |
577 | exclude_regex = switch_channel_get_variable(channel, "exclude_outgoing_extra_header")switch_channel_get_variable_dup(channel, "exclude_outgoing_extra_header" , SWITCH_TRUE, -1); |
578 | SWITCH_STANDARD_STREAM(stream)memset(&stream, 0, sizeof(stream)); stream.data = malloc( 1024); ((stream.data) ? (void) (0) : __assert_fail ("stream.data" , "sofia_glue.c", 578, __PRETTY_FUNCTION__)); memset(stream.data , 0, 1024); stream.end = stream.data; stream.data_size = 1024 ; stream.write_function = switch_console_stream_write; stream .raw_write_function = switch_console_stream_raw_write; stream .alloc_len = 1024; stream.alloc_chunk = 1024; |
579 | if ((hi = switch_channel_variable_first(channel))) { |
580 | for (; hi; hi = hi->next) { |
581 | const char *name = (char *) hi->name; |
582 | char *value = (char *) hi->value; |
583 | |
584 | if (!strcasecmp(name, "sip_geolocation")) { |
585 | stream.write_function(&stream, "Geolocation: %s\r\n", value); |
586 | } |
587 | |
588 | if (!strncasecmp(name, prefix, strlen(prefix))) { |
589 | if ( !exclude_regex || !(proceed = switch_regex_perform(name, exclude_regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) { |
590 | const char *hname = name + strlen(prefix); |
591 | stream.write_function(&stream, "%s: %s\r\n", hname, value); |
592 | switch_regex_safe_free(re)if (re) { switch_regex_free(re); re = ((void*)0); }; |
593 | } else { |
594 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 594, ((void*)0), SWITCH_LOG_DEBUG, "Ignoring Extra Header [%s] , matches exclude_outgoing_extra_header [%s]\n", name, exclude_regex); |
595 | } |
596 | } |
597 | } |
598 | switch_channel_variable_last(channel); |
599 | } |
600 | |
601 | if (!zstr((char *) stream.data)_zstr((char *) stream.data)) { |
602 | extra_headers = stream.data; |
603 | } else { |
604 | switch_safe_free(stream.data)if (stream.data) {free(stream.data);stream.data=((void*)0);}; |
605 | } |
606 | |
607 | return extra_headers; |
608 | } |
609 | |
610 | void sofia_glue_set_extra_headers(switch_core_session_t *session, sip_t const *sip, const char *prefix) |
611 | { |
612 | sip_unknown_t *un; |
613 | char name[512] = ""; |
614 | switch_channel_t *channel = switch_core_session_get_channel(session); |
615 | char *pstr; |
616 | |
617 | |
618 | if (!sip || !channel) { |
619 | return; |
620 | } |
621 | |
622 | for (un = sip->sip_unknown; un; un = un->un_next) { |
623 | if ((!strncasecmp(un->un_name, "X-", 2) && strncasecmp(un->un_name, "X-FS-", 5)) || !strncasecmp(un->un_name, "P-", 2)) { |
624 | if (!zstr(un->un_value)_zstr(un->un_value)) { |
625 | switch_snprintf(name, sizeof(name), "%s%s", prefix, un->un_name); |
626 | switch_channel_set_variable(channel, name, un->un_value)switch_channel_set_variable_var_check(channel, name, un->un_value , SWITCH_TRUE); |
627 | } |
628 | } |
629 | } |
630 | |
631 | pstr = switch_core_session_sprintf(session, "execute_on_%sprefix", prefix); |
632 | switch_channel_execute_on(channel, pstr); |
633 | switch_channel_api_on(channel, pstr); |
634 | |
635 | switch_channel_execute_on(channel, "execute_on_sip_extra_headers"); |
636 | switch_channel_api_on(channel, "api_on_sip_extra_headers"); |
637 | } |
638 | |
639 | char *sofia_glue_get_extra_headers_from_event(switch_event_t *event, const char *prefix) |
640 | { |
641 | char *extra_headers = NULL((void*)0); |
642 | switch_stream_handle_t stream = { 0 }; |
643 | switch_event_header_t *hp; |
644 | |
645 | SWITCH_STANDARD_STREAM(stream)memset(&stream, 0, sizeof(stream)); stream.data = malloc( 1024); ((stream.data) ? (void) (0) : __assert_fail ("stream.data" , "sofia_glue.c", 645, __PRETTY_FUNCTION__)); memset(stream.data , 0, 1024); stream.end = stream.data; stream.data_size = 1024 ; stream.write_function = switch_console_stream_write; stream .raw_write_function = switch_console_stream_raw_write; stream .alloc_len = 1024; stream.alloc_chunk = 1024; |
646 | for (hp = event->headers; hp; hp = hp->next) { |
647 | if (!zstr(hp->name)_zstr(hp->name) && !zstr(hp->value)_zstr(hp->value) && !strncasecmp(hp->name, prefix, strlen(prefix))) { |
648 | char *name = strdup(hp->name)(__extension__ (__builtin_constant_p (hp->name) && ((size_t)(const void *)((hp->name) + 1) - (size_t)(const void *)(hp->name) == 1) ? (((const char *) (hp->name))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (hp->name) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, hp->name, __len); __retval; })) : __strdup (hp ->name))); |
649 | const char *hname = name + strlen(prefix); |
650 | stream.write_function(&stream, "%s: %s\r\n", hname, (char *)hp->value); |
651 | free(name); |
652 | } |
653 | } |
654 | |
655 | if (!zstr((char *) stream.data)_zstr((char *) stream.data)) { |
656 | extra_headers = stream.data; |
657 | } else { |
658 | switch_safe_free(stream.data)if (stream.data) {free(stream.data);stream.data=((void*)0);}; |
659 | } |
660 | |
661 | return extra_headers; |
662 | } |
663 | |
664 | switch_status_t sofia_glue_do_invite(switch_core_session_t *session) |
665 | { |
666 | char *alert_info = NULL((void*)0); |
667 | const char *max_forwards = NULL((void*)0); |
668 | const char *alertbuf; |
669 | private_object_t *tech_pvt = switch_core_session_get_private(session)switch_core_session_get_private_class(session, SWITCH_PVT_PRIMARY ); |
670 | switch_channel_t *channel = switch_core_session_get_channel(session); |
671 | switch_caller_profile_t *caller_profile; |
672 | const char *cid_name, *cid_num; |
673 | char *e_dest = NULL((void*)0); |
674 | const char *holdstr = ""; |
675 | char *extra_headers = NULL((void*)0); |
676 | switch_status_t status = SWITCH_STATUS_FALSE; |
677 | uint32_t session_timeout = 0; |
678 | const char *val; |
679 | const char *rep; |
680 | const char *call_id = NULL((void*)0); |
681 | char *route = NULL((void*)0); |
682 | char *route_uri = NULL((void*)0); |
683 | sofia_destination_t *dst = NULL((void*)0); |
684 | sofia_cid_type_t cid_type = tech_pvt->profile->cid_type; |
685 | sip_cseq_t *cseq = NULL((void*)0); |
686 | const char *invite_record_route = switch_channel_get_variable(tech_pvt->channel, "sip_invite_record_route")switch_channel_get_variable_dup(tech_pvt->channel, "sip_invite_record_route" , SWITCH_TRUE, -1); |
687 | const char *invite_route_uri = switch_channel_get_variable(tech_pvt->channel, "sip_invite_route_uri")switch_channel_get_variable_dup(tech_pvt->channel, "sip_invite_route_uri" , SWITCH_TRUE, -1); |
688 | const char *invite_full_from = switch_channel_get_variable(tech_pvt->channel, "sip_invite_full_from")switch_channel_get_variable_dup(tech_pvt->channel, "sip_invite_full_from" , SWITCH_TRUE, -1); |
689 | const char *invite_full_to = switch_channel_get_variable(tech_pvt->channel, "sip_invite_full_to")switch_channel_get_variable_dup(tech_pvt->channel, "sip_invite_full_to" , SWITCH_TRUE, -1); |
690 | const char *handle_full_from = switch_channel_get_variable(tech_pvt->channel, "sip_handle_full_from")switch_channel_get_variable_dup(tech_pvt->channel, "sip_handle_full_from" , SWITCH_TRUE, -1); |
691 | const char *handle_full_to = switch_channel_get_variable(tech_pvt->channel, "sip_handle_full_to")switch_channel_get_variable_dup(tech_pvt->channel, "sip_handle_full_to" , SWITCH_TRUE, -1); |
692 | const char *force_full_from = switch_channel_get_variable(tech_pvt->channel, "sip_force_full_from")switch_channel_get_variable_dup(tech_pvt->channel, "sip_force_full_from" , SWITCH_TRUE, -1); |
693 | const char *force_full_to = switch_channel_get_variable(tech_pvt->channel, "sip_force_full_to")switch_channel_get_variable_dup(tech_pvt->channel, "sip_force_full_to" , SWITCH_TRUE, -1); |
694 | const char *content_encoding = switch_channel_get_variable(tech_pvt->channel, "sip_content_encoding")switch_channel_get_variable_dup(tech_pvt->channel, "sip_content_encoding" , SWITCH_TRUE, -1); |
695 | char *mp = NULL((void*)0), *mp_type = NULL((void*)0); |
696 | char *record_route = NULL((void*)0); |
697 | const char *recover_via = NULL((void*)0); |
698 | int require_timer = 1; |
699 | |
700 | if (switch_channel_test_flag(tech_pvt->channel, CF_RECOVERING)) { |
701 | const char *recover_contact = switch_channel_get_variable(tech_pvt->channel, "sip_recover_contact")switch_channel_get_variable_dup(tech_pvt->channel, "sip_recover_contact" , SWITCH_TRUE, -1); |
702 | recover_via = switch_channel_get_variable(tech_pvt->channel, "sip_recover_via")switch_channel_get_variable_dup(tech_pvt->channel, "sip_recover_via" , SWITCH_TRUE, -1); |
703 | |
704 | if (!zstr(invite_record_route)_zstr(invite_record_route)) { |
705 | record_route = switch_core_session_sprintf(session, "Record-Route: %s", invite_record_route); |
706 | } |
707 | |
708 | if (recover_contact) { |
709 | char *tmp = switch_core_session_strdup(session, recover_contact)switch_core_perform_session_strdup(session, recover_contact, "sofia_glue.c" , (const char *)__func__, 709); |
710 | tech_pvt->redirected = sofia_glue_get_url_from_contact(tmp, 0); |
711 | } |
712 | } |
713 | |
714 | |
715 | if ((rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER)switch_channel_get_variable_dup(channel, "_sofia_replaces_", SWITCH_TRUE , -1))) { |
716 | switch_channel_set_variable(channel, SOFIA_REPLACES_HEADER, NULL)switch_channel_set_variable_var_check(channel, "_sofia_replaces_" , ((void*)0), SWITCH_TRUE); |
717 | } |
718 | |
719 | switch_assert(tech_pvt != NULL)((tech_pvt != ((void*)0)) ? (void) (0) : __assert_fail ("tech_pvt != ((void*)0)" , "sofia_glue.c", 719, __PRETTY_FUNCTION__)); |
720 | |
721 | sofia_clear_flag_locked(tech_pvt, TFLAG_SDP)switch_mutex_lock(tech_pvt->flag_mutex); (tech_pvt)->flags [TFLAG_SDP] = 0; switch_mutex_unlock(tech_pvt->flag_mutex) ;; |
722 | |
723 | caller_profile = switch_channel_get_caller_profile(channel); |
724 | |
725 | if (!caller_profile) { |
726 | switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER)switch_channel_perform_hangup(channel, "sofia_glue.c", (const char *)__func__, 726, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); |
727 | return SWITCH_STATUS_FALSE; |
728 | } |
729 | |
730 | |
731 | if ((val = switch_channel_get_variable_dup(channel, "sip_require_timer", SWITCH_FALSE, -1)) && switch_false(val)) { |
732 | require_timer = 0; |
733 | } |
734 | |
735 | |
736 | cid_name = caller_profile->caller_id_name; |
737 | cid_num = caller_profile->caller_id_number; |
738 | |
739 | if (!tech_pvt->sent_invites && !switch_channel_test_flag(channel, CF_ANSWERED)) { |
740 | switch_core_media_prepare_codecs(tech_pvt->session, SWITCH_FALSE); |
741 | switch_core_media_check_video_codecs(tech_pvt->session); |
742 | } |
743 | |
744 | check_decode(cid_name, session)do { ((session) ? (void) (0) : __assert_fail ("session", "sofia_glue.c" , 744, __PRETTY_FUNCTION__)); if (!_zstr(cid_name)) { int d = 0; char *p; if ((__extension__ (__builtin_constant_p ('%') && !__builtin_constant_p (cid_name) && ('%') == '\0' ? ( char *) __rawmemchr (cid_name, '%') : __builtin_strchr (cid_name , '%')))) { char *tmp = switch_core_perform_session_strdup(session , cid_name, "sofia_glue.c", (const char *)__func__, 744); switch_url_decode (tmp); cid_name = tmp; d++; } if ((p = (__extension__ (__builtin_constant_p ('"') && !__builtin_constant_p (cid_name) && ('"') == '\0' ? (char *) __rawmemchr (cid_name, '"') : __builtin_strchr (cid_name, '"'))))) { if (!d) { char *tmp = switch_core_perform_session_strdup (session, cid_name, "sofia_glue.c", (const char *)__func__, 744 ); cid_name = tmp; } if ((p = (__extension__ (__builtin_constant_p ('"') && !__builtin_constant_p (cid_name) && ('"') == '\0' ? (char *) __rawmemchr (cid_name, '"') : __builtin_strchr (cid_name, '"'))))) { cid_name = p+1; } if ((p = strrchr(cid_name , '"'))) { *p = '\0'; } } } if (session) break; } while(!session ); |
745 | check_decode(cid_num, session)do { ((session) ? (void) (0) : __assert_fail ("session", "sofia_glue.c" , 745, __PRETTY_FUNCTION__)); if (!_zstr(cid_num)) { int d = 0 ; char *p; if ((__extension__ (__builtin_constant_p ('%') && !__builtin_constant_p (cid_num) && ('%') == '\0' ? ( char *) __rawmemchr (cid_num, '%') : __builtin_strchr (cid_num , '%')))) { char *tmp = switch_core_perform_session_strdup(session , cid_num, "sofia_glue.c", (const char *)__func__, 745); switch_url_decode (tmp); cid_num = tmp; d++; } if ((p = (__extension__ (__builtin_constant_p ('"') && !__builtin_constant_p (cid_num) && ( '"') == '\0' ? (char *) __rawmemchr (cid_num, '"') : __builtin_strchr (cid_num, '"'))))) { if (!d) { char *tmp = switch_core_perform_session_strdup (session, cid_num, "sofia_glue.c", (const char *)__func__, 745 ); cid_num = tmp; } if ((p = (__extension__ (__builtin_constant_p ('"') && !__builtin_constant_p (cid_num) && ( '"') == '\0' ? (char *) __rawmemchr (cid_num, '"') : __builtin_strchr (cid_num, '"'))))) { cid_num = p+1; } if ((p = strrchr(cid_num , '"'))) { *p = '\0'; } } } if (session) break; } while(!session ); |
746 | |
747 | |
748 | if ((alertbuf = switch_channel_get_variable(channel, "alert_info")switch_channel_get_variable_dup(channel, "alert_info", SWITCH_TRUE , -1))) { |
749 | alert_info = switch_core_session_sprintf(tech_pvt->session, "Alert-Info: %s", alertbuf); |
750 | } |
751 | |
752 | max_forwards = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE)switch_channel_get_variable_dup(channel, "max_forwards", SWITCH_TRUE , -1); |
753 | |
754 | if ((status = switch_core_media_choose_port(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, 0)) != SWITCH_STATUS_SUCCESS) { |
755 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session)SWITCH_CHANNEL_ID_SESSION, "sofia_glue.c", (const char *)__func__ , 755, (const char*)(tech_pvt->session), SWITCH_LOG_ERROR, "Port Error!\n"); |
756 | return status; |
757 | } |
758 | |
759 | if (!switch_channel_get_private(tech_pvt->channel, "t38_options") || zstr(tech_pvt->mparams.local_sdp_str)_zstr(tech_pvt->mparams.local_sdp_str)) { |
760 | switch_core_media_gen_local_sdp(session, SDP_TYPE_REQUEST, NULL((void*)0), 0, NULL((void*)0), 0); |
761 | } |
762 | |
763 | sofia_set_flag_locked(tech_pvt, TFLAG_READY)((tech_pvt->flag_mutex != ((void*)0)) ? (void) (0) : __assert_fail ("tech_pvt->flag_mutex != ((void*)0)", "sofia_glue.c", 763 , __PRETTY_FUNCTION__));switch_mutex_lock(tech_pvt->flag_mutex );(tech_pvt)->flags[TFLAG_READY] = 1;switch_mutex_unlock(tech_pvt ->flag_mutex);; |
764 | |
765 | if (!tech_pvt->nh) { |
766 | char *d_url = NULL((void*)0), *url = NULL((void*)0), *url_str = NULL((void*)0); |
767 | sofia_private_t *sofia_private; |
768 | char *invite_contact = NULL((void*)0), *to_str, *use_from_str, *from_str; |
769 | const char *t_var; |
770 | char *rpid_domain = NULL((void*)0), *p; |
771 | const char *priv = "off"; |
772 | const char *screen = "no"; |
773 | const char *invite_params = switch_channel_get_variable(tech_pvt->channel, "sip_invite_params")switch_channel_get_variable_dup(tech_pvt->channel, "sip_invite_params" , SWITCH_TRUE, -1); |
774 | const char *invite_to_params = switch_channel_get_variable(tech_pvt->channel, "sip_invite_to_params")switch_channel_get_variable_dup(tech_pvt->channel, "sip_invite_to_params" , SWITCH_TRUE, -1); |
775 | const char *invite_tel_params = switch_channel_get_variable(switch_core_session_get_channel(session), "sip_invite_tel_params")switch_channel_get_variable_dup(switch_core_session_get_channel (session), "sip_invite_tel_params", SWITCH_TRUE, -1); |
776 | const char *invite_to_uri = switch_channel_get_variable(tech_pvt->channel, "sip_invite_to_uri")switch_channel_get_variable_dup(tech_pvt->channel, "sip_invite_to_uri" , SWITCH_TRUE, -1); |
777 | const char *invite_from_uri = switch_channel_get_variable(tech_pvt->channel, "sip_invite_from_uri")switch_channel_get_variable_dup(tech_pvt->channel, "sip_invite_from_uri" , SWITCH_TRUE, -1); |
778 | const char *invite_contact_params = switch_channel_get_variable(tech_pvt->channel, "sip_invite_contact_params")switch_channel_get_variable_dup(tech_pvt->channel, "sip_invite_contact_params" , SWITCH_TRUE, -1); |
779 | const char *invite_from_params = switch_channel_get_variable(tech_pvt->channel, "sip_invite_from_params")switch_channel_get_variable_dup(tech_pvt->channel, "sip_invite_from_params" , SWITCH_TRUE, -1); |
780 | const char *from_var = switch_channel_get_variable(tech_pvt->channel, "sip_from_uri")switch_channel_get_variable_dup(tech_pvt->channel, "sip_from_uri" , SWITCH_TRUE, -1); |
781 | const char *from_display = switch_channel_get_variable(tech_pvt->channel, "sip_from_display")switch_channel_get_variable_dup(tech_pvt->channel, "sip_from_display" , SWITCH_TRUE, -1); |
782 | const char *invite_req_uri = switch_channel_get_variable(tech_pvt->channel, "sip_invite_req_uri")switch_channel_get_variable_dup(tech_pvt->channel, "sip_invite_req_uri" , SWITCH_TRUE, -1); |
783 | const char *invite_domain = switch_channel_get_variable(tech_pvt->channel, "sip_invite_domain")switch_channel_get_variable_dup(tech_pvt->channel, "sip_invite_domain" , SWITCH_TRUE, -1); |
784 | |
785 | const char *use_name, *use_number; |
786 | |
787 | if (zstr(tech_pvt->dest)_zstr(tech_pvt->dest)) { |
788 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session)SWITCH_CHANNEL_ID_SESSION, "sofia_glue.c", (const char *)__func__ , 788, (const char*)(tech_pvt->session), SWITCH_LOG_ERROR, "URL Error!\n"); |
789 | return SWITCH_STATUS_FALSE; |
790 | } |
791 | |
792 | if ((d_url = sofia_glue_get_url_from_contact(tech_pvt->dest, 1))) { |
793 | url = d_url; |
794 | } else { |
795 | url = tech_pvt->dest; |
796 | } |
797 | |
798 | url_str = url; |
Value stored to 'url_str' is never read | |
799 | |
800 | if (!tech_pvt->from_str) { |
801 | const char *sipip; |
802 | const char *format; |
803 | |
804 | sipip = tech_pvt->profile->sipip; |
805 | |
806 | if (!zstr(tech_pvt->mparams.remote_ip)_zstr(tech_pvt->mparams.remote_ip) && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->mparams.remote_ip)) { |
807 | sipip = tech_pvt->profile->extsipip; |
808 | } |
809 | |
810 | if (!zstr(invite_domain)_zstr(invite_domain)) { |
811 | sipip = invite_domain; |
812 | } |
813 | |
814 | format = strchr(sipip, ':')(__extension__ (__builtin_constant_p (':') && !__builtin_constant_p (sipip) && (':') == '\0' ? (char *) __rawmemchr (sipip , ':') : __builtin_strchr (sipip, ':'))) ? "\"%s\" <sip:%s%s[%s]>" : "\"%s\" <sip:%s%s%s>"; |
815 | |
816 | tech_pvt->from_str = switch_core_session_sprintf(tech_pvt->session, format, cid_name, cid_num, !zstr(cid_num)_zstr(cid_num) ? "@" : "", sipip); |
817 | } |
818 | |
819 | if (from_var) { |
820 | if (strncasecmp(from_var, "sip:", 4) || strncasecmp(from_var, "sips:", 5)) { |
821 | use_from_str = switch_core_session_strdup(tech_pvt->session, from_var)switch_core_perform_session_strdup(tech_pvt->session, from_var , "sofia_glue.c", (const char *)__func__, 821); |
822 | } else { |
823 | use_from_str = switch_core_session_sprintf(tech_pvt->session, "sip:%s", from_var); |
824 | } |
825 | } else if (!zstr(tech_pvt->gateway_from_str)_zstr(tech_pvt->gateway_from_str)) { |
826 | use_from_str = tech_pvt->gateway_from_str; |
827 | } else { |
828 | use_from_str = tech_pvt->from_str; |
829 | } |
830 | |
831 | if (!zstr(tech_pvt->gateway_from_str)_zstr(tech_pvt->gateway_from_str)) { |
832 | rpid_domain = switch_core_session_strdup(session, tech_pvt->gateway_from_str)switch_core_perform_session_strdup(session, tech_pvt->gateway_from_str , "sofia_glue.c", (const char *)__func__, 832); |
833 | } else if (!zstr(tech_pvt->from_str)_zstr(tech_pvt->from_str)) { |
834 | rpid_domain = switch_core_session_strdup(session, use_from_str)switch_core_perform_session_strdup(session, use_from_str, "sofia_glue.c" , (const char *)__func__, 834); |
835 | } |
836 | |
837 | sofia_glue_get_url_from_contact(rpid_domain, 0); |
838 | if ((rpid_domain = strrchr(rpid_domain, '@'))) { |
839 | rpid_domain++; |
840 | if ((p = strchr(rpid_domain, ';')(__extension__ (__builtin_constant_p (';') && !__builtin_constant_p (rpid_domain) && (';') == '\0' ? (char *) __rawmemchr (rpid_domain, ';') : __builtin_strchr (rpid_domain, ';'))))) { |
841 | *p = '\0'; |
842 | } |
843 | } |
844 | |
845 | if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT)((tech_pvt->profile)->pflags[PFLAG_AUTO_NAT] ? 1 : 0)) { |
846 | if (!zstr(tech_pvt->mparams.remote_ip)_zstr(tech_pvt->mparams.remote_ip) && !zstr(tech_pvt->profile->extsipip)_zstr(tech_pvt->profile->extsipip) && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->mparams.remote_ip)) { |
847 | rpid_domain = tech_pvt->profile->extsipip; |
848 | } else { |
849 | rpid_domain = tech_pvt->profile->sipip; |
850 | } |
851 | } |
852 | |
853 | if (!zstr(invite_domain)_zstr(invite_domain)) { |
854 | rpid_domain = (char *)invite_domain; |
855 | } |
856 | |
857 | if (zstr(rpid_domain)_zstr(rpid_domain)) { |
858 | rpid_domain = "cluecon.com"; |
859 | } |
860 | |
861 | /* |
862 | * Ignore transport chanvar and uri parameter for gateway connections |
863 | * since all of them have been already taken care of in mod_sofia.c:sofia_outgoing_channel() |
864 | */ |
865 | if (tech_pvt->transport == SOFIA_TRANSPORT_UNKNOWN && zstr(tech_pvt->gateway_name)_zstr(tech_pvt->gateway_name)) { |
866 | if ((p = (char *) switch_stristr("port=", url))) { |
867 | p += 5; |
868 | tech_pvt->transport = sofia_glue_str2transport(p); |
869 | } else { |
870 | if ((t_var = switch_channel_get_variable(channel, "sip_transport")switch_channel_get_variable_dup(channel, "sip_transport", SWITCH_TRUE , -1))) { |
871 | tech_pvt->transport = sofia_glue_str2transport(t_var); |
872 | } |
873 | } |
874 | |
875 | if (tech_pvt->transport == SOFIA_TRANSPORT_UNKNOWN) { |
876 | tech_pvt->transport = SOFIA_TRANSPORT_UDP; |
877 | } |
878 | } |
879 | |
880 | if (!zstr(tech_pvt->mparams.remote_ip)_zstr(tech_pvt->mparams.remote_ip) && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->mparams.remote_ip)) { |
881 | tech_pvt->user_via = sofia_glue_create_external_via(session, tech_pvt->profile, tech_pvt->transport); |
882 | } |
883 | |
884 | if (!sofia_test_pflag(tech_pvt->profile, PFLAG_TLS)((tech_pvt->profile)->pflags[PFLAG_TLS] ? 1 : 0) && sofia_glue_transport_has_tls(tech_pvt->transport)) { |
885 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session)SWITCH_CHANNEL_ID_SESSION, "sofia_glue.c", (const char *)__func__ , 885, (const char*)(tech_pvt->session), SWITCH_LOG_ERROR, "TLS not supported by profile\n"); |
886 | return SWITCH_STATUS_FALSE; |
887 | } |
888 | |
889 | if (zstr(tech_pvt->invite_contact)_zstr(tech_pvt->invite_contact)) { |
890 | const char *contact; |
891 | if ((contact = switch_channel_get_variable(channel, "sip_contact_user")switch_channel_get_variable_dup(channel, "sip_contact_user", SWITCH_TRUE , -1))) { |
892 | char *ip_addr = tech_pvt->profile->sipip; |
893 | char *ipv6; |
894 | |
895 | if ( !zstr(tech_pvt->mparams.remote_ip)_zstr(tech_pvt->mparams.remote_ip) && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->mparams.remote_ip ) ) { |
896 | ip_addr = tech_pvt->profile->extsipip; |
897 | } |
898 | |
899 | ipv6 = strchr(ip_addr, ':')(__extension__ (__builtin_constant_p (':') && !__builtin_constant_p (ip_addr) && (':') == '\0' ? (char *) __rawmemchr (ip_addr , ':') : __builtin_strchr (ip_addr, ':'))); |
900 | |
901 | if (sofia_glue_transport_has_tls(tech_pvt->transport)) { |
902 | tech_pvt->invite_contact = switch_core_session_sprintf(session, "sip:%s@%s%s%s:%d", contact, |
903 | ipv6 ? "[" : "", ip_addr, ipv6 ? "]" : "", tech_pvt->profile->tls_sip_port); |
904 | } else { |
905 | tech_pvt->invite_contact = switch_core_session_sprintf(session, "sip:%s@%s%s%s:%d", contact, |
906 | ipv6 ? "[" : "", ip_addr, ipv6 ? "]" : "", tech_pvt->profile->extsipport); |
907 | } |
908 | } else { |
909 | if (sofia_glue_transport_has_tls(tech_pvt->transport)) { |
910 | tech_pvt->invite_contact = tech_pvt->profile->tls_url; |
911 | } else { |
912 | if (!zstr(tech_pvt->mparams.remote_ip)_zstr(tech_pvt->mparams.remote_ip) && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->mparams.remote_ip)) { |
913 | tech_pvt->invite_contact = tech_pvt->profile->public_url; |
914 | } else { |
915 | tech_pvt->invite_contact = tech_pvt->profile->url; |
916 | } |
917 | } |
918 | } |
919 | } |
920 | |
921 | url_str = sofia_overcome_sip_uri_weakness(session, url, tech_pvt->transport, SWITCH_TRUE, invite_params, invite_tel_params); |
922 | invite_contact = sofia_overcome_sip_uri_weakness(session, tech_pvt->invite_contact, tech_pvt->transport, SWITCH_FALSE, invite_contact_params, NULL((void*)0)); |
923 | from_str = sofia_overcome_sip_uri_weakness(session, invite_from_uri ? invite_from_uri : use_from_str, 0, SWITCH_TRUE, invite_from_params, NULL((void*)0)); |
924 | to_str = sofia_overcome_sip_uri_weakness(session, invite_to_uri ? invite_to_uri : tech_pvt->dest_to, 0, SWITCH_FALSE, invite_to_params, NULL((void*)0)); |
925 | |
926 | switch_channel_set_variable(channel, "sip_outgoing_contact_uri", invite_contact)switch_channel_set_variable_var_check(channel, "sip_outgoing_contact_uri" , invite_contact, SWITCH_TRUE); |
927 | |
928 | /* |
929 | Does the "genius" who wanted SIP to be "text-based" so it was "easier to read" even use it now, |
930 | or did he just suggest it to make our lives miserable? |
931 | */ |
932 | use_from_str = from_str; |
933 | |
934 | if (!switch_stristr("sip:", use_from_str)) { |
935 | use_from_str = switch_core_session_sprintf(session, "sip:%s", use_from_str); |
936 | } |
937 | |
938 | if (!from_display && !strcasecmp(tech_pvt->caller_profile->caller_id_name, "_undef_")) { |
939 | from_str = switch_core_session_sprintf(session, "<%s>", use_from_str); |
940 | } else { |
941 | char *name = switch_core_session_strdup(session, from_display ? from_display : tech_pvt->caller_profile->caller_id_name)switch_core_perform_session_strdup(session, from_display ? from_display : tech_pvt->caller_profile->caller_id_name, "sofia_glue.c" , (const char *)__func__, 941); |
942 | check_decode(name, session)do { ((session) ? (void) (0) : __assert_fail ("session", "sofia_glue.c" , 942, __PRETTY_FUNCTION__)); if (!_zstr(name)) { int d = 0; char *p; if ((__extension__ (__builtin_constant_p ('%') && !__builtin_constant_p (name) && ('%') == '\0' ? (char *) __rawmemchr (name, '%') : __builtin_strchr (name, '%')))) { char *tmp = switch_core_perform_session_strdup(session, name , "sofia_glue.c", (const char *)__func__, 942); switch_url_decode (tmp); name = tmp; d++; } if ((p = (__extension__ (__builtin_constant_p ('"') && !__builtin_constant_p (name) && ('"' ) == '\0' ? (char *) __rawmemchr (name, '"') : __builtin_strchr (name, '"'))))) { if (!d) { char *tmp = switch_core_perform_session_strdup (session, name, "sofia_glue.c", (const char *)__func__, 942); name = tmp; } if ((p = (__extension__ (__builtin_constant_p ( '"') && !__builtin_constant_p (name) && ('"') == '\0' ? (char *) __rawmemchr (name, '"') : __builtin_strchr (name, '"'))))) { name = p+1; } if ((p = strrchr(name, '"')) ) { *p = '\0'; } } } if (session) break; } while(!session); |
943 | from_str = switch_core_session_sprintf(session, "\"%s\" <%s>", name, use_from_str); |
944 | } |
945 | |
946 | if (!(call_id = switch_channel_get_variable(channel, "sip_invite_call_id")switch_channel_get_variable_dup(channel, "sip_invite_call_id" , SWITCH_TRUE, -1))) { |
947 | if (sofia_test_pflag(tech_pvt->profile, PFLAG_UUID_AS_CALLID)((tech_pvt->profile)->pflags[PFLAG_UUID_AS_CALLID] ? 1 : 0)) { |
948 | call_id = switch_core_session_get_uuid(session); |
949 | } |
950 | } |
951 | |
952 | if (handle_full_from) { |
953 | from_str = (char *) handle_full_from; |
954 | } |
955 | |
956 | if (handle_full_to) { |
957 | to_str = (char *) handle_full_to; |
958 | } |
959 | |
960 | |
961 | if (force_full_from) { |
962 | from_str = (char *) force_full_from; |
963 | } |
964 | |
965 | if (force_full_to) { |
966 | to_str = (char *) force_full_to; |
967 | } |
968 | |
969 | |
970 | if (invite_req_uri) { |
971 | url_str = (char *) invite_req_uri; |
972 | } |
973 | |
974 | if (url_str) { |
975 | char *s = NULL((void*)0); |
976 | if (!strncasecmp(url_str, "sip:", 4)) { |
977 | s = url_str + 4; |
978 | } |
979 | if (!strncasecmp(url_str, "sips:", 5)) { |
980 | s = url_str + 5; |
981 | } |
982 | |
983 | /* tel: patch from jaybinks, added by MC |
984 | It compiles but I don't have a way to test it |
985 | */ |
986 | if (!strncasecmp(url_str, "tel:", 4)) { |
987 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session)SWITCH_CHANNEL_ID_SESSION, "sofia_glue.c", (const char *)__func__ , 987, (const char*)(tech_pvt->session), |
988 | SWITCH_LOG_ERROR, "URL Error! tel: uri's not supported at this time\n"); |
989 | return SWITCH_STATUS_FALSE; |
990 | } |
991 | if (!s) { |
992 | s = url_str; |
993 | } |
994 | switch_channel_set_variable(channel, "sip_req_uri", s)switch_channel_set_variable_var_check(channel, "sip_req_uri", s, SWITCH_TRUE); |
995 | } |
996 | |
997 | switch_channel_set_variable(channel, "sip_to_host", sofia_glue_get_host(to_str, switch_core_session_get_pool(session)))switch_channel_set_variable_var_check(channel, "sip_to_host", sofia_glue_get_host(to_str, switch_core_session_get_pool(session )), SWITCH_TRUE); |
998 | switch_channel_set_variable(channel, "sip_from_host", sofia_glue_get_host(from_str, switch_core_session_get_pool(session)))switch_channel_set_variable_var_check(channel, "sip_from_host" , sofia_glue_get_host(from_str, switch_core_session_get_pool( session)), SWITCH_TRUE); |
999 | |
1000 | if (!(tech_pvt->nh = nua_handle(tech_pvt->profile->nua, NULL((void*)0), |
1001 | NUTAG_URL(url_str)nutag_url, urltag_url_v(url_str), |
1002 | TAG_IF(call_id, SIPTAG_CALL_ID_STR(call_id))!(call_id) ? tag_skip : siptag_call_id_str, tag_str_v(call_id ), |
1003 | TAG_IF(!zstr(record_route), SIPTAG_HEADER_STR(record_route))!(!_zstr(record_route)) ? tag_skip : siptag_header_str, tag_str_v ((record_route)), |
1004 | SIPTAG_TO_STR(to_str)siptag_to_str, tag_str_v(to_str), SIPTAG_FROM_STR(from_str)siptag_from_str, tag_str_v(from_str), SIPTAG_CONTACT_STR(invite_contact)siptag_contact_str, tag_str_v(invite_contact), TAG_END()(tag_type_t)0, (tag_value_t)0))) { |
1005 | |
1006 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "sofia_glue.c", (const char *)__func__ , 1006, (const char*)(session), SWITCH_LOG_CRIT, |
1007 | "Error creating HANDLE!\nurl_str=[%s]\ncall_id=[%s]\nto_str=[%s]\nfrom_str=[%s]\ninvite_contact=[%s]\n", |
1008 | url_str, |
1009 | call_id ? call_id : "N/A", |
1010 | to_str, |
1011 | from_str, |
1012 | invite_contact); |
1013 | |
1014 | switch_safe_free(d_url)if (d_url) {free(d_url);d_url=((void*)0);}; |
1015 | return SWITCH_STATUS_FALSE; |
1016 | } |
1017 | |
1018 | if (tech_pvt->dest && (strstr(tech_pvt->dest, ";fs_nat") || strstr(tech_pvt->dest, ";received") |
1019 | || ((val = switch_channel_get_variable(channel, "sip_sticky_contact")switch_channel_get_variable_dup(channel, "sip_sticky_contact" , SWITCH_TRUE, -1)) && switch_true(val)))) { |
1020 | sofia_set_flag(tech_pvt, TFLAG_NAT)(tech_pvt)->flags[TFLAG_NAT] = 1; |
1021 | tech_pvt->record_route = switch_core_session_strdup(tech_pvt->session, url_str)switch_core_perform_session_strdup(tech_pvt->session, url_str , "sofia_glue.c", (const char *)__func__, 1021); |
1022 | route_uri = tech_pvt->record_route; |
1023 | session_timeout = SOFIA_NAT_SESSION_TIMEOUT90; |
1024 | switch_channel_set_variable(channel, "sip_nat_detected", "true")switch_channel_set_variable_var_check(channel, "sip_nat_detected" , "true", SWITCH_TRUE); |
1025 | } |
1026 | |
1027 | if ((val = switch_channel_get_variable(channel, "sip_cid_type")switch_channel_get_variable_dup(channel, "sip_cid_type", SWITCH_TRUE , -1))) { |
1028 | cid_type = sofia_cid_name2type(val); |
1029 | } |
1030 | |
1031 | if (switch_channel_test_flag(tech_pvt->channel, CF_RECOVERING) && switch_channel_direction(tech_pvt->channel) == SWITCH_CALL_DIRECTION_INBOUND) { |
1032 | if (zstr((use_name = switch_channel_get_variable(tech_pvt->channel, "effective_callee_id_name")))_zstr((use_name = switch_channel_get_variable_dup(tech_pvt-> channel, "effective_callee_id_name", SWITCH_TRUE, -1))) && |
1033 | zstr((use_name = switch_channel_get_variable(tech_pvt->channel, "sip_callee_id_name")))_zstr((use_name = switch_channel_get_variable_dup(tech_pvt-> channel, "sip_callee_id_name", SWITCH_TRUE, -1)))) { |
1034 | if (!(use_name = switch_channel_get_variable(tech_pvt->channel, "sip_to_display")switch_channel_get_variable_dup(tech_pvt->channel, "sip_to_display" , SWITCH_TRUE, -1))) { |
1035 | use_name = switch_channel_get_variable(tech_pvt->channel, "sip_to_user")switch_channel_get_variable_dup(tech_pvt->channel, "sip_to_user" , SWITCH_TRUE, -1); |
1036 | } |
1037 | } |
1038 | |
1039 | if (zstr((use_number = switch_channel_get_variable(tech_pvt->channel, "effective_callee_id_number")))_zstr((use_number = switch_channel_get_variable_dup(tech_pvt-> channel, "effective_callee_id_number", SWITCH_TRUE, -1))) && |
1040 | zstr((use_number = switch_channel_get_variable(tech_pvt->channel, "sip_callee_id_number")))_zstr((use_number = switch_channel_get_variable_dup(tech_pvt-> channel, "sip_callee_id_number", SWITCH_TRUE, -1)))) { |
1041 | use_number = switch_channel_get_variable(tech_pvt->channel, "sip_to_user")switch_channel_get_variable_dup(tech_pvt->channel, "sip_to_user" , SWITCH_TRUE, -1); |
1042 | } |
1043 | |
1044 | if (zstr(use_name)_zstr(use_name) && zstr(use_name = tech_pvt->caller_profile->callee_id_name)_zstr(use_name = tech_pvt->caller_profile->callee_id_name )) { |
1045 | use_name = tech_pvt->caller_profile->caller_id_name; |
1046 | } |
1047 | |
1048 | if (zstr(use_number)_zstr(use_number) && zstr(use_number = tech_pvt->caller_profile->callee_id_number)_zstr(use_number = tech_pvt->caller_profile->callee_id_number )) { |
1049 | use_number = tech_pvt->caller_profile->caller_id_number; |
1050 | } |
1051 | } else { |
1052 | use_name = tech_pvt->caller_profile->caller_id_name; |
1053 | use_number = tech_pvt->caller_profile->caller_id_number; |
1054 | } |
1055 | |
1056 | check_decode(use_name, session)do { ((session) ? (void) (0) : __assert_fail ("session", "sofia_glue.c" , 1056, __PRETTY_FUNCTION__)); if (!_zstr(use_name)) { int d = 0; char *p; if ((__extension__ (__builtin_constant_p ('%') && !__builtin_constant_p (use_name) && ('%') == '\0' ? ( char *) __rawmemchr (use_name, '%') : __builtin_strchr (use_name , '%')))) { char *tmp = switch_core_perform_session_strdup(session , use_name, "sofia_glue.c", (const char *)__func__, 1056); switch_url_decode (tmp); use_name = tmp; d++; } if ((p = (__extension__ (__builtin_constant_p ('"') && !__builtin_constant_p (use_name) && ('"') == '\0' ? (char *) __rawmemchr (use_name, '"') : __builtin_strchr (use_name, '"'))))) { if (!d) { char *tmp = switch_core_perform_session_strdup (session, use_name, "sofia_glue.c", (const char *)__func__, 1056 ); use_name = tmp; } if ((p = (__extension__ (__builtin_constant_p ('"') && !__builtin_constant_p (use_name) && ('"') == '\0' ? (char *) __rawmemchr (use_name, '"') : __builtin_strchr (use_name, '"'))))) { use_name = p+1; } if ((p = strrchr(use_name , '"'))) { *p = '\0'; } } } if (session) break; } while(!session ); |
1057 | |
1058 | switch (cid_type) { |
1059 | case CID_TYPE_PID: |
1060 | if (switch_test_flag(caller_profile, SWITCH_CPF_SCREEN)((caller_profile)->flags & SWITCH_CPF_SCREEN)) { |
1061 | if (zstr(tech_pvt->caller_profile->caller_id_name)_zstr(tech_pvt->caller_profile->caller_id_name) || !strcasecmp(tech_pvt->caller_profile->caller_id_name, "_undef_")) { |
1062 | tech_pvt->asserted_id = switch_core_session_sprintf(tech_pvt->session, "<sip:%s@%s>", |
1063 | use_number, rpid_domain); |
1064 | } else { |
1065 | tech_pvt->asserted_id = switch_core_session_sprintf(tech_pvt->session, "\"%s\"<sip:%s@%s>", |
1066 | use_name, use_number, rpid_domain); |
1067 | } |
1068 | } else { |
1069 | if (zstr(tech_pvt->caller_profile->caller_id_name)_zstr(tech_pvt->caller_profile->caller_id_name) || !strcasecmp(tech_pvt->caller_profile->caller_id_name, "_undef_")) { |
1070 | tech_pvt->preferred_id = switch_core_session_sprintf(tech_pvt->session, "<sip:%s@%s>", |
1071 | tech_pvt->caller_profile->caller_id_number, rpid_domain); |
1072 | } else { |
1073 | tech_pvt->preferred_id = switch_core_session_sprintf(tech_pvt->session, "\"%s\"<sip:%s@%s>", |
1074 | tech_pvt->caller_profile->caller_id_name, |
1075 | tech_pvt->caller_profile->caller_id_number, rpid_domain); |
1076 | } |
1077 | } |
1078 | |
1079 | if (switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER)((caller_profile)->flags & SWITCH_CPF_HIDE_NUMBER)) { |
1080 | tech_pvt->privacy = "id"; |
1081 | } else { |
1082 | if (!(val = switch_channel_get_variable(channel, "sip_cid_suppress_privacy_none")switch_channel_get_variable_dup(channel, "sip_cid_suppress_privacy_none" , SWITCH_TRUE, -1)) || !switch_true(val)) { |
1083 | tech_pvt->privacy = "none"; |
1084 | } |
1085 | } |
1086 | |
1087 | break; |
1088 | case CID_TYPE_RPID: |
1089 | { |
1090 | if (switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NAME)((caller_profile)->flags & SWITCH_CPF_HIDE_NAME)) { |
1091 | priv = "name"; |
1092 | if (switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER)((caller_profile)->flags & SWITCH_CPF_HIDE_NUMBER)) { |
1093 | priv = "full"; |
1094 | } |
1095 | } else if (switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER)((caller_profile)->flags & SWITCH_CPF_HIDE_NUMBER)) { |
1096 | priv = "full"; |
1097 | } |
1098 | |
1099 | if (switch_test_flag(caller_profile, SWITCH_CPF_SCREEN)((caller_profile)->flags & SWITCH_CPF_SCREEN)) { |
1100 | screen = "yes"; |
1101 | } |
1102 | |
1103 | if (zstr(tech_pvt->caller_profile->caller_id_name)_zstr(tech_pvt->caller_profile->caller_id_name) || !strcasecmp(tech_pvt->caller_profile->caller_id_name, "_undef_")) { |
1104 | tech_pvt->rpid = switch_core_session_sprintf(tech_pvt->session, "<sip:%s@%s>;party=calling;screen=%s;privacy=%s", |
1105 | use_number, rpid_domain, screen, priv); |
1106 | } else { |
1107 | tech_pvt->rpid = switch_core_session_sprintf(tech_pvt->session, "\"%s\"<sip:%s@%s>;party=calling;screen=%s;privacy=%s", |
1108 | use_name, use_number, rpid_domain, screen, priv); |
1109 | } |
1110 | } |
1111 | break; |
1112 | default: |
1113 | break; |
1114 | } |
1115 | |
1116 | |
1117 | switch_safe_free(d_url)if (d_url) {free(d_url);d_url=((void*)0);}; |
1118 | |
1119 | if (!(sofia_private = su_alloc(tech_pvt->nh->nh_home, sizeof(*sofia_private)))) { |
1120 | abort(); |
1121 | } |
1122 | |
1123 | memset(sofia_private, 0, sizeof(*sofia_private)); |
1124 | sofia_private->is_call = 2; |
1125 | sofia_private->is_static++; |
1126 | |
1127 | if (switch_channel_test_flag(tech_pvt->channel, CF_RECOVERING)) { |
1128 | sofia_private->is_call++; |
1129 | } |
1130 | |
1131 | tech_pvt->sofia_private = sofia_private; |
1132 | switch_copy_string(tech_pvt->sofia_private->uuid, switch_core_session_get_uuid(session), sizeof(tech_pvt->sofia_private->uuid)); |
1133 | nua_handle_bind(tech_pvt->nh, tech_pvt->sofia_private); |
1134 | } |
1135 | |
1136 | if (tech_pvt->e_dest && sofia_test_pflag(tech_pvt->profile, PFLAG_IN_DIALOG_CHAT)((tech_pvt->profile)->pflags[PFLAG_IN_DIALOG_CHAT] ? 1 : 0)) { |
1137 | char *user = NULL((void*)0), *host = NULL((void*)0); |
1138 | char hash_key[256] = ""; |
1139 | |
1140 | e_dest = strdup(tech_pvt->e_dest)(__extension__ (__builtin_constant_p (tech_pvt->e_dest) && ((size_t)(const void *)((tech_pvt->e_dest) + 1) - (size_t )(const void *)(tech_pvt->e_dest) == 1) ? (((const char *) (tech_pvt->e_dest))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (tech_pvt->e_dest ) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, tech_pvt ->e_dest, __len); __retval; })) : __strdup (tech_pvt->e_dest ))); |
1141 | switch_assert(e_dest != NULL)((e_dest != ((void*)0)) ? (void) (0) : __assert_fail ("e_dest != ((void*)0)" , "sofia_glue.c", 1141, __PRETTY_FUNCTION__)); |
1142 | user = e_dest; |
1143 | |
1144 | if ((host = strchr(user, '@')(__extension__ (__builtin_constant_p ('@') && !__builtin_constant_p (user) && ('@') == '\0' ? (char *) __rawmemchr (user , '@') : __builtin_strchr (user, '@'))))) { |
1145 | *host++ = '\0'; |
1146 | } |
1147 | switch_snprintf(hash_key, sizeof(hash_key), "%s%s%s", user, host, cid_num); |
1148 | |
1149 | tech_pvt->chat_from = tech_pvt->from_str; |
1150 | tech_pvt->chat_to = tech_pvt->dest; |
1151 | if (tech_pvt->profile->pres_type) { |
1152 | tech_pvt->hash_key = switch_core_session_strdup(tech_pvt->session, hash_key)switch_core_perform_session_strdup(tech_pvt->session, hash_key , "sofia_glue.c", (const char *)__func__, 1152); |
1153 | switch_mutex_lock(tech_pvt->profile->flag_mutex); |
1154 | switch_core_hash_insert(tech_pvt->profile->chat_hash, tech_pvt->hash_key, tech_pvt)switch_core_hash_insert_destructor(tech_pvt->profile->chat_hash , tech_pvt->hash_key, tech_pvt, ((void*)0)); |
1155 | switch_mutex_unlock(tech_pvt->profile->flag_mutex); |
1156 | } |
1157 | free(e_dest); |
1158 | } |
1159 | |
1160 | holdstr = sofia_test_flag(tech_pvt, TFLAG_SIP_HOLD)((tech_pvt)->flags[TFLAG_SIP_HOLD] ? 1 : 0) ? "*" : ""; |
1161 | |
1162 | if (!switch_channel_get_variable(channel, "sofia_profile_name")switch_channel_get_variable_dup(channel, "sofia_profile_name" , SWITCH_TRUE, -1)) { |
1163 | switch_channel_set_variable(channel, "sofia_profile_name", tech_pvt->profile->name)switch_channel_set_variable_var_check(channel, "sofia_profile_name" , tech_pvt->profile->name, SWITCH_TRUE); |
1164 | switch_channel_set_variable(channel, "recovery_profile_name", tech_pvt->profile->name)switch_channel_set_variable_var_check(channel, "recovery_profile_name" , tech_pvt->profile->name, SWITCH_TRUE); |
1165 | } |
1166 | |
1167 | extra_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_HEADER_PREFIX"sip_h_"); |
1168 | |
1169 | session_timeout = tech_pvt->profile->session_timeout; |
1170 | |
1171 | if ((val = switch_channel_get_variable(channel, SOFIA_SESSION_TIMEOUT)switch_channel_get_variable_dup(channel, "sofia_session_timeout" , SWITCH_TRUE, -1))) { |
1172 | int v_session_timeout = atoi(val); |
1173 | if (v_session_timeout >= 0) { |
1174 | session_timeout = v_session_timeout; |
1175 | } |
1176 | } |
1177 | |
1178 | if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) { |
1179 | if (switch_core_media_ready(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO)) { |
1180 | switch_core_media_proxy_remote_addr(session, NULL((void*)0)); |
1181 | } |
1182 | switch_core_media_patch_sdp(tech_pvt->session); |
1183 | } |
1184 | |
1185 | if (!zstr(tech_pvt->dest)_zstr(tech_pvt->dest)) { |
1186 | dst = sofia_glue_get_destination(tech_pvt->dest); |
1187 | |
1188 | if (dst->route_uri) { |
1189 | route_uri = sofia_overcome_sip_uri_weakness(tech_pvt->session, dst->route_uri, tech_pvt->transport, SWITCH_TRUE, NULL((void*)0), NULL((void*)0)); |
1190 | } |
1191 | |
1192 | if (dst->route) { |
1193 | route = dst->route; |
1194 | } |
1195 | } |
1196 | |
1197 | if ((val = switch_channel_get_variable(channel, "sip_route_uri")switch_channel_get_variable_dup(channel, "sip_route_uri", SWITCH_TRUE , -1))) { |
1198 | route_uri = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "sofia_glue.c" , (const char *)__func__, 1198); |
1199 | route = NULL((void*)0); |
1200 | } |
1201 | |
1202 | if (route_uri) { |
1203 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session)SWITCH_CHANNEL_ID_SESSION, "sofia_glue.c", (const char *)__func__ , 1203, (const char*)(tech_pvt->session), SWITCH_LOG_DEBUG, "%s Setting proxy route to %s\n", route_uri, |
1204 | switch_channel_get_name(channel)); |
1205 | tech_pvt->route_uri = switch_core_session_strdup(tech_pvt->session, route_uri)switch_core_perform_session_strdup(tech_pvt->session, route_uri , "sofia_glue.c", (const char *)__func__, 1205); |
1206 | } |
1207 | |
1208 | |
1209 | if ((val = switch_channel_get_variable(tech_pvt->channel, "sip_invite_cseq")switch_channel_get_variable_dup(tech_pvt->channel, "sip_invite_cseq" , SWITCH_TRUE, -1))) { |
1210 | uint32_t callsequence = (uint32_t) strtoul(val, NULL((void*)0), 10); |
1211 | cseq = sip_cseq_create(tech_pvt->nh->nh_home, callsequence, SIP_METHOD_INVITEsip_method_invite, "INVITE"); |
1212 | } |
1213 | |
1214 | |
1215 | switch_channel_clear_flag(channel, CF_MEDIA_ACK); |
1216 | |
1217 | if (handle_full_from) { |
1218 | tech_pvt->nh->nh_has_invite = 1; |
1219 | } |
1220 | |
1221 | if ((mp = sofia_media_get_multipart(session, "sip_multipart", tech_pvt->mparams.local_sdp_str, &mp_type))) { |
1222 | sofia_clear_flag(tech_pvt, TFLAG_ENABLE_SOA)(tech_pvt)->flags[TFLAG_ENABLE_SOA] = 0; |
1223 | } |
1224 | |
1225 | if ((tech_pvt->session_timeout = session_timeout)) { |
1226 | tech_pvt->session_refresher = switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND ? nua_local_refresher : nua_remote_refresher; |
1227 | } else { |
1228 | tech_pvt->session_refresher = nua_no_refresher; |
1229 | } |
1230 | |
1231 | |
1232 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session)SWITCH_CHANNEL_ID_SESSION, "sofia_glue.c", (const char *)__func__ , 1232, (const char*)(tech_pvt->session), SWITCH_LOG_DEBUG, "%s sending invite version: %s\nLocal SDP:\n%s\n", |
1233 | switch_channel_get_name(tech_pvt->channel), switch_version_full_human(), |
1234 | tech_pvt->mparams.local_sdp_str ? tech_pvt->mparams.local_sdp_str : "NO SDP PRESENT\n"); |
1235 | |
1236 | |
1237 | |
1238 | if (switch_channel_get_private(tech_pvt->channel, "t38_options")) { |
1239 | sofia_clear_flag(tech_pvt, TFLAG_ENABLE_SOA)(tech_pvt)->flags[TFLAG_ENABLE_SOA] = 0; |
1240 | } |
1241 | |
1242 | if (sofia_use_soa(tech_pvt)((tech_pvt)->flags[TFLAG_ENABLE_SOA] ? 1 : 0)) { |
1243 | nua_invite(tech_pvt->nh, |
1244 | NUTAG_AUTOANSWER(0)nutag_autoanswer, tag_bool_v(0), |
1245 | //TAG_IF(zstr(tech_pvt->mparams.local_sdp_str), NUTAG_AUTOACK(0)), |
1246 | //TAG_IF(!zstr(tech_pvt->mparams.local_sdp_str), NUTAG_AUTOACK(1)), |
1247 | // The code above is breaking things...... grrr WE need this because we handle our own acks and there are 3pcc cases in there too |
1248 | NUTAG_AUTOACK(0)nutag_autoack, tag_bool_v(0), |
1249 | NUTAG_SESSION_TIMER(tech_pvt->session_timeout)nutag_session_timer, tag_uint_v((tech_pvt->session_timeout )), |
1250 | NUTAG_SESSION_REFRESHER(tech_pvt->session_refresher)nutag_session_refresher, tag_int_v((tech_pvt->session_refresher )), |
1251 | TAG_IF(sofia_test_flag(tech_pvt, TFLAG_RECOVERED), NUTAG_INVITE_TIMER(UINT_MAX))!(((tech_pvt)->flags[TFLAG_RECOVERED] ? 1 : 0)) ? tag_skip : nutag_invite_timer, tag_uint_v(((2147483647 *2U +1U))), |
1252 | TAG_IF(invite_full_from, SIPTAG_FROM_STR(invite_full_from))!(invite_full_from) ? tag_skip : siptag_from_str, tag_str_v(invite_full_from ), |
1253 | TAG_IF(invite_full_to, SIPTAG_TO_STR(invite_full_to))!(invite_full_to) ? tag_skip : siptag_to_str, tag_str_v(invite_full_to ), |
1254 | TAG_IF(tech_pvt->redirected, NUTAG_URL(tech_pvt->redirected))!(tech_pvt->redirected) ? tag_skip : nutag_url, urltag_url_v (tech_pvt->redirected), |
1255 | TAG_IF(!zstr(recover_via), SIPTAG_VIA_STR(recover_via))!(!_zstr(recover_via)) ? tag_skip : siptag_via_str, tag_str_v (recover_via), |
1256 | TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via))!(!_zstr(tech_pvt->user_via)) ? tag_skip : siptag_via_str, tag_str_v(tech_pvt->user_via), |
1257 | TAG_IF(!zstr(tech_pvt->rpid), SIPTAG_REMOTE_PARTY_ID_STR(tech_pvt->rpid))!(!_zstr(tech_pvt->rpid)) ? tag_skip : siptag_remote_party_id_str , tag_str_v(tech_pvt->rpid), |
1258 | TAG_IF(!zstr(tech_pvt->preferred_id), SIPTAG_P_PREFERRED_IDENTITY_STR(tech_pvt->preferred_id))!(!_zstr(tech_pvt->preferred_id)) ? tag_skip : siptag_p_preferred_identity_str , tag_str_v(tech_pvt->preferred_id), |
1259 | TAG_IF(!zstr(tech_pvt->asserted_id), SIPTAG_P_ASSERTED_IDENTITY_STR(tech_pvt->asserted_id))!(!_zstr(tech_pvt->asserted_id)) ? tag_skip : siptag_p_asserted_identity_str , tag_str_v(tech_pvt->asserted_id), |
1260 | TAG_IF(!zstr(tech_pvt->privacy), SIPTAG_PRIVACY_STR(tech_pvt->privacy))!(!_zstr(tech_pvt->privacy)) ? tag_skip : siptag_privacy_str , tag_str_v(tech_pvt->privacy), |
1261 | TAG_IF(!zstr(alert_info), SIPTAG_HEADER_STR(alert_info))!(!_zstr(alert_info)) ? tag_skip : siptag_header_str, tag_str_v ((alert_info)), |
1262 | TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers))!(!_zstr(extra_headers)) ? tag_skip : siptag_header_str, tag_str_v ((extra_headers)), |
1263 | TAG_IF(sofia_test_pflag(tech_pvt->profile, PFLAG_PASS_CALLEE_ID), SIPTAG_HEADER_STR("X-FS-Support: " FREESWITCH_SUPPORT))!(((tech_pvt->profile)->pflags[PFLAG_PASS_CALLEE_ID] ? 1 : 0)) ? tag_skip : siptag_header_str, tag_str_v(("X-FS-Support: " "update_display,send_info")), |
1264 | TAG_IF(!zstr(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards))!(!_zstr(max_forwards)) ? tag_skip : siptag_max_forwards_str, tag_str_v(max_forwards), |
1265 | TAG_IF(!zstr(route_uri), NUTAG_PROXY(route_uri))!(!_zstr(route_uri)) ? tag_skip : ntatag_default_proxy, urltag_url_v ((route_uri)), |
1266 | TAG_IF(!zstr(invite_route_uri), NUTAG_INITIAL_ROUTE_STR(invite_route_uri))!(!_zstr(invite_route_uri)) ? tag_skip : nutag_initial_route_str , tag_str_v(invite_route_uri), |
1267 | TAG_IF(!zstr(route), SIPTAG_ROUTE_STR(route))!(!_zstr(route)) ? tag_skip : siptag_route_str, tag_str_v(route ), |
1268 | TAG_IF(tech_pvt->profile->minimum_session_expires, NUTAG_MIN_SE(tech_pvt->profile->minimum_session_expires))!(tech_pvt->profile->minimum_session_expires) ? tag_skip : nutag_min_se, tag_uint_v((tech_pvt->profile->minimum_session_expires )), |
1269 | TAG_IF(cseq, SIPTAG_CSEQ(cseq))!(cseq) ? tag_skip : siptag_cseq, siptag_cseq_v(cseq), |
1270 | TAG_IF(content_encoding, SIPTAG_CONTENT_ENCODING_STR(content_encoding))!(content_encoding) ? tag_skip : siptag_content_encoding_str, tag_str_v(content_encoding), |
1271 | TAG_IF(zstr(tech_pvt->mparams.local_sdp_str), SIPTAG_PAYLOAD_STR(""))!(_zstr(tech_pvt->mparams.local_sdp_str)) ? tag_skip : siptag_payload_str , tag_str_v(""), |
1272 | TAG_IF(!zstr(tech_pvt->mparams.local_sdp_str), SOATAG_ADDRESS(tech_pvt->mparams.adv_sdp_audio_ip))!(!_zstr(tech_pvt->mparams.local_sdp_str)) ? tag_skip : soatag_address , tag_str_v(tech_pvt->mparams.adv_sdp_audio_ip), |
1273 | TAG_IF(!zstr(tech_pvt->mparams.local_sdp_str), SOATAG_USER_SDP_STR(tech_pvt->mparams.local_sdp_str))!(!_zstr(tech_pvt->mparams.local_sdp_str)) ? tag_skip : soatag_user_sdp_str , tag_str_v(tech_pvt->mparams.local_sdp_str), |
1274 | TAG_IF(!zstr(tech_pvt->mparams.local_sdp_str), SOATAG_REUSE_REJECTED(1))!(!_zstr(tech_pvt->mparams.local_sdp_str)) ? tag_skip : soatag_reuse_rejected , tag_bool_v(1), |
1275 | TAG_IF(switch_channel_get_private(tech_pvt->channel, "t38_options"), SOATAG_ORDERED_USER(1))!(switch_channel_get_private(tech_pvt->channel, "t38_options" )) ? tag_skip : soatag_ordered_user, tag_bool_v(1), |
1276 | TAG_IF(!zstr(tech_pvt->mparams.local_sdp_str), SOATAG_RTP_SORT(SOA_RTP_SORT_REMOTE))!(!_zstr(tech_pvt->mparams.local_sdp_str)) ? tag_skip : soatag_rtp_sort , tag_int_v(SOA_RTP_SORT_REMOTE), |
1277 | TAG_IF(!zstr(tech_pvt->mparams.local_sdp_str), SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL))!(!_zstr(tech_pvt->mparams.local_sdp_str)) ? tag_skip : soatag_rtp_select , tag_int_v(SOA_RTP_SELECT_ALL), |
1278 | TAG_IF(rep, SIPTAG_REPLACES_STR(rep))!(rep) ? tag_skip : siptag_replaces_str, tag_str_v(rep), |
1279 | TAG_IF(!require_timer, NUTAG_TIMER_AUTOREQUIRE(0))!(!require_timer) ? tag_skip : nutag_timer_autorequire, tag_bool_v (0), |
1280 | TAG_IF(!zstr(tech_pvt->mparams.local_sdp_str), SOATAG_HOLD(holdstr))!(!_zstr(tech_pvt->mparams.local_sdp_str)) ? tag_skip : soatag_hold , tag_str_v(holdstr), TAG_END()(tag_type_t)0, (tag_value_t)0); |
1281 | } else { |
1282 | nua_invite(tech_pvt->nh, |
1283 | NUTAG_AUTOANSWER(0)nutag_autoanswer, tag_bool_v(0), |
1284 | NUTAG_AUTOACK(0)nutag_autoack, tag_bool_v(0), |
1285 | NUTAG_SESSION_TIMER(tech_pvt->session_timeout)nutag_session_timer, tag_uint_v((tech_pvt->session_timeout )), |
1286 | NUTAG_SESSION_REFRESHER(tech_pvt->session_refresher)nutag_session_refresher, tag_int_v((tech_pvt->session_refresher )), |
1287 | TAG_IF(sofia_test_flag(tech_pvt, TFLAG_RECOVERED), NUTAG_INVITE_TIMER(UINT_MAX))!(((tech_pvt)->flags[TFLAG_RECOVERED] ? 1 : 0)) ? tag_skip : nutag_invite_timer, tag_uint_v(((2147483647 *2U +1U))), |
1288 | TAG_IF(invite_full_from, SIPTAG_FROM_STR(invite_full_from))!(invite_full_from) ? tag_skip : siptag_from_str, tag_str_v(invite_full_from ), |
1289 | TAG_IF(invite_full_to, SIPTAG_TO_STR(invite_full_to))!(invite_full_to) ? tag_skip : siptag_to_str, tag_str_v(invite_full_to ), |
1290 | TAG_IF(tech_pvt->redirected, NUTAG_URL(tech_pvt->redirected))!(tech_pvt->redirected) ? tag_skip : nutag_url, urltag_url_v (tech_pvt->redirected), |
1291 | TAG_IF(!zstr(recover_via), SIPTAG_VIA_STR(recover_via))!(!_zstr(recover_via)) ? tag_skip : siptag_via_str, tag_str_v (recover_via), |
1292 | TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via))!(!_zstr(tech_pvt->user_via)) ? tag_skip : siptag_via_str, tag_str_v(tech_pvt->user_via), |
1293 | TAG_IF(!zstr(tech_pvt->rpid), SIPTAG_REMOTE_PARTY_ID_STR(tech_pvt->rpid))!(!_zstr(tech_pvt->rpid)) ? tag_skip : siptag_remote_party_id_str , tag_str_v(tech_pvt->rpid), |
1294 | TAG_IF(!zstr(tech_pvt->preferred_id), SIPTAG_P_PREFERRED_IDENTITY_STR(tech_pvt->preferred_id))!(!_zstr(tech_pvt->preferred_id)) ? tag_skip : siptag_p_preferred_identity_str , tag_str_v(tech_pvt->preferred_id), |
1295 | TAG_IF(!zstr(tech_pvt->asserted_id), SIPTAG_P_ASSERTED_IDENTITY_STR(tech_pvt->asserted_id))!(!_zstr(tech_pvt->asserted_id)) ? tag_skip : siptag_p_asserted_identity_str , tag_str_v(tech_pvt->asserted_id), |
1296 | TAG_IF(!zstr(tech_pvt->privacy), SIPTAG_PRIVACY_STR(tech_pvt->privacy))!(!_zstr(tech_pvt->privacy)) ? tag_skip : siptag_privacy_str , tag_str_v(tech_pvt->privacy), |
1297 | TAG_IF(!zstr(alert_info), SIPTAG_HEADER_STR(alert_info))!(!_zstr(alert_info)) ? tag_skip : siptag_header_str, tag_str_v ((alert_info)), |
1298 | TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers))!(!_zstr(extra_headers)) ? tag_skip : siptag_header_str, tag_str_v ((extra_headers)), |
1299 | TAG_IF(sofia_test_pflag(tech_pvt->profile, PFLAG_PASS_CALLEE_ID), SIPTAG_HEADER_STR("X-FS-Support: " FREESWITCH_SUPPORT))!(((tech_pvt->profile)->pflags[PFLAG_PASS_CALLEE_ID] ? 1 : 0)) ? tag_skip : siptag_header_str, tag_str_v(("X-FS-Support: " "update_display,send_info")), |
1300 | TAG_IF(!zstr(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards))!(!_zstr(max_forwards)) ? tag_skip : siptag_max_forwards_str, tag_str_v(max_forwards), |
1301 | TAG_IF(!zstr(route_uri), NUTAG_PROXY(route_uri))!(!_zstr(route_uri)) ? tag_skip : ntatag_default_proxy, urltag_url_v ((route_uri)), |
1302 | TAG_IF(!zstr(route), SIPTAG_ROUTE_STR(route))!(!_zstr(route)) ? tag_skip : siptag_route_str, tag_str_v(route ), |
1303 | TAG_IF(!zstr(invite_route_uri), NUTAG_INITIAL_ROUTE_STR(invite_route_uri))!(!_zstr(invite_route_uri)) ? tag_skip : nutag_initial_route_str , tag_str_v(invite_route_uri), |
1304 | TAG_IF(tech_pvt->profile->minimum_session_expires, NUTAG_MIN_SE(tech_pvt->profile->minimum_session_expires))!(tech_pvt->profile->minimum_session_expires) ? tag_skip : nutag_min_se, tag_uint_v((tech_pvt->profile->minimum_session_expires )), |
1305 | TAG_IF(!require_timer, NUTAG_TIMER_AUTOREQUIRE(0))!(!require_timer) ? tag_skip : nutag_timer_autorequire, tag_bool_v (0), |
1306 | TAG_IF(cseq, SIPTAG_CSEQ(cseq))!(cseq) ? tag_skip : siptag_cseq, siptag_cseq_v(cseq), |
1307 | TAG_IF(content_encoding, SIPTAG_CONTENT_ENCODING_STR(content_encoding))!(content_encoding) ? tag_skip : siptag_content_encoding_str, tag_str_v(content_encoding), |
1308 | NUTAG_MEDIA_ENABLE(0)nutag_media_enable, tag_bool_v(0), |
1309 | SIPTAG_CONTENT_TYPE_STR(mp_type ? mp_type : "application/sdp")siptag_content_type_str, tag_str_v(mp_type ? mp_type : "application/sdp" ), |
1310 | SIPTAG_PAYLOAD_STR(mp ? mp : tech_pvt->mparams.local_sdp_str)siptag_payload_str, tag_str_v(mp ? mp : tech_pvt->mparams. local_sdp_str), TAG_IF(rep, SIPTAG_REPLACES_STR(rep))!(rep) ? tag_skip : siptag_replaces_str, tag_str_v(rep), SOATAG_HOLD(holdstr)soatag_hold, tag_str_v(holdstr), TAG_END()(tag_type_t)0, (tag_value_t)0); |
1311 | } |
1312 | |
1313 | sofia_glue_free_destination(dst); |
1314 | switch_safe_free(extra_headers)if (extra_headers) {free(extra_headers);extra_headers=((void* )0);}; |
1315 | switch_safe_free(mp)if (mp) {free(mp);mp=((void*)0);}; |
1316 | tech_pvt->redirected = NULL((void*)0); |
1317 | |
1318 | return SWITCH_STATUS_SUCCESS; |
1319 | } |
1320 | |
1321 | void sofia_glue_do_xfer_invite(switch_core_session_t *session) |
1322 | { |
1323 | private_object_t *tech_pvt = switch_core_session_get_private(session)switch_core_session_get_private_class(session, SWITCH_PVT_PRIMARY ); |
1324 | switch_channel_t *channel = switch_core_session_get_channel(session); |
1325 | switch_caller_profile_t *caller_profile; |
1326 | const char *sipip, *format, *contact_url; |
1327 | |
1328 | switch_assert(tech_pvt != NULL)((tech_pvt != ((void*)0)) ? (void) (0) : __assert_fail ("tech_pvt != ((void*)0)" , "sofia_glue.c", 1328, __PRETTY_FUNCTION__)); |
1329 | switch_mutex_lock(tech_pvt->sofia_mutex); |
1330 | caller_profile = switch_channel_get_caller_profile(channel); |
1331 | |
1332 | if (!zstr(tech_pvt->mparams.remote_ip)_zstr(tech_pvt->mparams.remote_ip) && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->mparams.remote_ip)) { |
1333 | sipip = tech_pvt->profile->extsipip; |
1334 | contact_url = tech_pvt->profile->public_url; |
1335 | } else { |
1336 | sipip = tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip; |
1337 | contact_url = tech_pvt->profile->url; |
1338 | } |
1339 | |
1340 | format = strchr(sipip, ':')(__extension__ (__builtin_constant_p (':') && !__builtin_constant_p (sipip) && (':') == '\0' ? (char *) __rawmemchr (sipip , ':') : __builtin_strchr (sipip, ':'))) ? "\"%s\" <sip:%s@[%s]>" : "\"%s\" <sip:%s@%s>"; |
1341 | |
1342 | if ((tech_pvt->from_str = switch_core_session_sprintf(session, format, caller_profile->caller_id_name, caller_profile->caller_id_number, sipip))) { |
1343 | |
1344 | const char *rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER)switch_channel_get_variable_dup(channel, "_sofia_replaces_", SWITCH_TRUE , -1); |
1345 | |
1346 | tech_pvt->nh2 = nua_handle(tech_pvt->profile->nua, NULL((void*)0), |
1347 | SIPTAG_TO_STR(tech_pvt->dest)siptag_to_str, tag_str_v(tech_pvt->dest), SIPTAG_FROM_STR(tech_pvt->from_str)siptag_from_str, tag_str_v(tech_pvt->from_str), SIPTAG_CONTACT_STR(contact_url)siptag_contact_str, tag_str_v(contact_url), TAG_END()(tag_type_t)0, (tag_value_t)0); |
1348 | |
1349 | nua_handle_bind(tech_pvt->nh2, tech_pvt->sofia_private); |
1350 | |
1351 | nua_invite(tech_pvt->nh2, |
1352 | SIPTAG_CONTACT_STR(contact_url)siptag_contact_str, tag_str_v(contact_url), |
1353 | TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via))!(!_zstr(tech_pvt->user_via)) ? tag_skip : siptag_via_str, tag_str_v(tech_pvt->user_via), |
1354 | SOATAG_ADDRESS(tech_pvt->mparams.adv_sdp_audio_ip)soatag_address, tag_str_v(tech_pvt->mparams.adv_sdp_audio_ip ), |
1355 | SOATAG_USER_SDP_STR(tech_pvt->mparams.local_sdp_str)soatag_user_sdp_str, tag_str_v(tech_pvt->mparams.local_sdp_str ), |
1356 | SOATAG_REUSE_REJECTED(1)soatag_reuse_rejected, tag_bool_v(1), |
1357 | SOATAG_RTP_SORT(SOA_RTP_SORT_REMOTE)soatag_rtp_sort, tag_int_v(SOA_RTP_SORT_REMOTE), SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL)soatag_rtp_select, tag_int_v(SOA_RTP_SELECT_ALL), TAG_IF(rep, SIPTAG_REPLACES_STR(rep))!(rep) ? tag_skip : siptag_replaces_str, tag_str_v(rep), TAG_END()(tag_type_t)0, (tag_value_t)0); |
1358 | } else { |
1359 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session)SWITCH_CHANNEL_ID_SESSION, "sofia_glue.c", (const char *)__func__ , 1359, (const char*)(tech_pvt->session), SWITCH_LOG_ERROR, "Memory Error!\n"); |
1360 | } |
1361 | switch_mutex_unlock(tech_pvt->sofia_mutex); |
1362 | } |
1363 | |
1364 | |
1365 | /* map sip responses to QSIG cause codes ala RFC4497 section 8.4.4 */ |
1366 | switch_call_cause_t sofia_glue_sip_cause_to_freeswitch(int status) |
1367 | { |
1368 | switch (status) { |
1369 | case 200: |
1370 | return SWITCH_CAUSE_NORMAL_CLEARING; |
1371 | case 401: |
1372 | case 402: |
1373 | case 403: |
1374 | case 407: |
1375 | case 603: |
1376 | return SWITCH_CAUSE_CALL_REJECTED; |
1377 | case 404: |
1378 | return SWITCH_CAUSE_UNALLOCATED_NUMBER; |
1379 | case 485: |
1380 | case 604: |
1381 | return SWITCH_CAUSE_NO_ROUTE_DESTINATION; |
1382 | case 408: |
1383 | case 504: |
1384 | return SWITCH_CAUSE_RECOVERY_ON_TIMER_EXPIRE; |
1385 | case 410: |
1386 | return SWITCH_CAUSE_NUMBER_CHANGED; |
1387 | case 413: |
1388 | case 414: |
1389 | case 416: |
1390 | case 420: |
1391 | case 421: |
1392 | case 423: |
1393 | case 505: |
1394 | case 513: |
1395 | return SWITCH_CAUSE_INTERWORKING; |
1396 | case 480: |
1397 | return SWITCH_CAUSE_NO_USER_RESPONSE; |
1398 | case 400: |
1399 | case 481: |
1400 | case 500: |
1401 | case 503: |
1402 | return SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE; |
1403 | case 486: |
1404 | case 600: |
1405 | return SWITCH_CAUSE_USER_BUSY; |
1406 | case 484: |
1407 | return SWITCH_CAUSE_INVALID_NUMBER_FORMAT; |
1408 | case 488: |
1409 | case 606: |
1410 | return SWITCH_CAUSE_INCOMPATIBLE_DESTINATION; |
1411 | case 502: |
1412 | return SWITCH_CAUSE_NETWORK_OUT_OF_ORDER; |
1413 | case 405: |
1414 | return SWITCH_CAUSE_SERVICE_UNAVAILABLE; |
1415 | case 406: |
1416 | case 415: |
1417 | case 501: |
1418 | return SWITCH_CAUSE_SERVICE_NOT_IMPLEMENTED; |
1419 | case 482: |
1420 | case 483: |
1421 | return SWITCH_CAUSE_EXCHANGE_ROUTING_ERROR; |
1422 | case 487: |
1423 | return SWITCH_CAUSE_ORIGINATOR_CANCEL; |
1424 | default: |
1425 | return SWITCH_CAUSE_NORMAL_UNSPECIFIED; |
1426 | } |
1427 | } |
1428 | |
1429 | void sofia_glue_pass_sdp(private_object_t *tech_pvt, char *sdp) |
1430 | { |
1431 | const char *val; |
1432 | switch_core_session_t *other_session; |
1433 | switch_channel_t *other_channel; |
1434 | |
1435 | if ((val = switch_channel_get_partner_uuid(tech_pvt->channel)) |
1436 | && (other_session = switch_core_session_locate(val)switch_core_session_perform_locate(val, "sofia_glue.c", (const char *)__func__, 1436))) { |
1437 | other_channel = switch_core_session_get_channel(other_session); |
1438 | switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, sdp)switch_channel_set_variable_var_check(other_channel, "switch_m_sdp" , sdp, SWITCH_TRUE); |
1439 | |
1440 | #if 0 |
1441 | if (!sofia_test_flag(tech_pvt, TFLAG_CHANGE_MEDIA)((tech_pvt)->flags[TFLAG_CHANGE_MEDIA] ? 1 : 0) && !switch_channel_test_flag(tech_pvt->channel, CF_RECOVERING) && |
1442 | (switch_channel_direction(other_channel) == SWITCH_CALL_DIRECTION_OUTBOUND && |
1443 | switch_channel_direction(tech_pvt->channel) == SWITCH_CALL_DIRECTION_OUTBOUND && switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE))) { |
1444 | switch_ivr_nomedia(val, SMF_FORCE); |
1445 | sofia_set_flag_locked(tech_pvt, TFLAG_CHANGE_MEDIA)((tech_pvt->flag_mutex != ((void*)0)) ? (void) (0) : __assert_fail ("tech_pvt->flag_mutex != ((void*)0)", "sofia_glue.c", 1445 , __PRETTY_FUNCTION__));switch_mutex_lock(tech_pvt->flag_mutex );(tech_pvt)->flags[TFLAG_CHANGE_MEDIA] = 1;switch_mutex_unlock (tech_pvt->flag_mutex);; |
1446 | } |
1447 | #endif |
1448 | |
1449 | switch_core_session_rwunlock(other_session); |
1450 | } |
1451 | } |
1452 | |
1453 | char *sofia_glue_get_path_from_contact(char *buf) |
1454 | { |
1455 | char *p, *e, *path = NULL((void*)0), *contact = NULL((void*)0); |
1456 | |
1457 | if (!buf) return NULL((void*)0); |
1458 | |
1459 | contact = sofia_glue_get_url_from_contact(buf, SWITCH_TRUE); |
1460 | |
1461 | if (!contact) return NULL((void*)0); |
1462 | |
1463 | if ((p = strstr(contact, "fs_path="))) { |
1464 | p += 8; |
1465 | |
1466 | if (!zstr(p)_zstr(p)) { |
1467 | path = strdup(p)(__extension__ (__builtin_constant_p (p) && ((size_t) (const void *)((p) + 1) - (size_t)(const void *)(p) == 1) ? ( ((const char *) (p))[0] == '\0' ? (char *) calloc ((size_t) 1 , (size_t) 1) : ({ size_t __len = strlen (p) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, p, __len); __retval; })) : __strdup (p))); |
1468 | } |
1469 | } |
1470 | |
1471 | if (!path) { |
1472 | free(contact); |
1473 | return NULL((void*)0); |
1474 | } |
1475 | |
1476 | if ((e = strrchr(path, ';'))) { |
1477 | *e = '\0'; |
1478 | } |
1479 | |
1480 | switch_url_decode(path); |
1481 | |
1482 | free(contact); |
1483 | |
1484 | return path; |
1485 | } |
1486 | |
1487 | char *sofia_glue_get_url_from_contact(char *buf, uint8_t to_dup) |
1488 | { |
1489 | char *url = NULL((void*)0), *e; |
1490 | |
1491 | switch_assert(buf)((buf) ? (void) (0) : __assert_fail ("buf", "sofia_glue.c", 1491 , __PRETTY_FUNCTION__)); |
1492 | |
1493 | while(*buf == ' ') { |
1494 | buf++; |
1495 | } |
1496 | |
1497 | if (*buf == '"') { |
1498 | buf++; |
1499 | if((e = strchr(buf, '"')(__extension__ (__builtin_constant_p ('"') && !__builtin_constant_p (buf) && ('"') == '\0' ? (char *) __rawmemchr (buf, '"' ) : __builtin_strchr (buf, '"'))))) { |
1500 | buf = e+1; |
1501 | } |
1502 | } |
1503 | |
1504 | while(*buf == ' ') { |
1505 | buf++; |
1506 | } |
1507 | |
1508 | url = strchr(buf, '<')(__extension__ (__builtin_constant_p ('<') && !__builtin_constant_p (buf) && ('<') == '\0' ? (char *) __rawmemchr (buf , '<') : __builtin_strchr (buf, '<'))); |
1509 | |
1510 | if (url && (e = switch_find_end_paren(url, '<', '>'))) { |
1511 | url++; |
1512 | if (to_dup) { |
1513 | url = strdup(url)(__extension__ (__builtin_constant_p (url) && ((size_t )(const void *)((url) + 1) - (size_t)(const void *)(url) == 1 ) ? (((const char *) (url))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (url) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, url, __len); __retval ; })) : __strdup (url))); |
1514 | e = strchr(url, '>')(__extension__ (__builtin_constant_p ('>') && !__builtin_constant_p (url) && ('>') == '\0' ? (char *) __rawmemchr (url , '>') : __builtin_strchr (url, '>'))); |
1515 | } |
1516 | |
1517 | *e = '\0'; |
1518 | } else { |
1519 | if (url) buf++; |
1520 | |
1521 | if (to_dup) { |
1522 | url = strdup(buf)(__extension__ (__builtin_constant_p (buf) && ((size_t )(const void *)((buf) + 1) - (size_t)(const void *)(buf) == 1 ) ? (((const char *) (buf))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (buf) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, buf, __len); __retval ; })) : __strdup (buf))); |
1523 | } else { |
1524 | url = buf; |
1525 | } |
1526 | } |
1527 | return url; |
1528 | } |
1529 | |
1530 | switch_status_t sofia_glue_profile_rdlock__(const char *file, const char *func, int line, sofia_profile_t *profile) |
1531 | { |
1532 | switch_status_t status = switch_thread_rwlock_tryrdlock(profile->rwlock); |
1533 | if (status != SWITCH_STATUS_SUCCESS) { |
1534 | switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL((void*)0), SWITCH_LOG_ERROR, "Profile %s is locked\n", profile->name); |
1535 | return status; |
1536 | } |
1537 | #ifdef SOFIA_DEBUG_RWLOCKS |
1538 | switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL((void*)0), SWITCH_LOG_ERROR, "XXXXXXXXXXXXXX LOCK %s\n", profile->name); |
1539 | #endif |
1540 | return status; |
1541 | } |
1542 | |
1543 | switch_bool_t sofia_glue_profile_exists(const char *key) |
1544 | { |
1545 | switch_bool_t tf = SWITCH_FALSE; |
1546 | |
1547 | switch_mutex_lock(mod_sofia_globals.hash_mutex); |
1548 | if (switch_core_hash_find(mod_sofia_globals.profile_hash, key)) { |
1549 | tf = SWITCH_TRUE; |
1550 | } |
1551 | switch_mutex_unlock(mod_sofia_globals.hash_mutex); |
1552 | |
1553 | return tf; |
1554 | } |
1555 | |
1556 | sofia_profile_t *sofia_glue_find_profile__(const char *file, const char *func, int line, const char *key) |
1557 | { |
1558 | sofia_profile_t *profile; |
1559 | |
1560 | switch_mutex_lock(mod_sofia_globals.hash_mutex); |
1561 | if ((profile = (sofia_profile_t *) switch_core_hash_find(mod_sofia_globals.profile_hash, key))) { |
1562 | if (!sofia_test_pflag(profile, PFLAG_RUNNING)((profile)->pflags[PFLAG_RUNNING] ? 1 : 0)) { |
1563 | #ifdef SOFIA_DEBUG_RWLOCKS |
1564 | switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL((void*)0), SWITCH_LOG_ERROR, "Profile %s is not running\n", profile->name); |
1565 | #endif |
1566 | profile = NULL((void*)0); |
1567 | goto done; |
1568 | } |
1569 | if (sofia_glue_profile_rdlock__(file, func, line, profile) != SWITCH_STATUS_SUCCESS) { |
1570 | profile = NULL((void*)0); |
1571 | } |
1572 | } else { |
1573 | #ifdef SOFIA_DEBUG_RWLOCKS |
1574 | switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL((void*)0), SWITCH_LOG_ERROR, "Profile %s is not in the hash\n", key); |
1575 | #endif |
1576 | } |
1577 | |
1578 | done: |
1579 | switch_mutex_unlock(mod_sofia_globals.hash_mutex); |
1580 | |
1581 | return profile; |
1582 | } |
1583 | |
1584 | void sofia_glue_release_profile__(const char *file, const char *func, int line, sofia_profile_t *profile) |
1585 | { |
1586 | if (profile) { |
1587 | #ifdef SOFIA_DEBUG_RWLOCKS |
1588 | switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL((void*)0), SWITCH_LOG_ERROR, "XXXXXXXXXXXXXX UNLOCK %s\n", profile->name); |
1589 | #endif |
1590 | switch_thread_rwlock_unlock(profile->rwlock); |
1591 | } |
1592 | } |
1593 | |
1594 | switch_status_t sofia_glue_add_profile(char *key, sofia_profile_t *profile) |
1595 | { |
1596 | switch_status_t status = SWITCH_STATUS_FALSE; |
1597 | |
1598 | switch_mutex_lock(mod_sofia_globals.hash_mutex); |
1599 | if (!switch_core_hash_find(mod_sofia_globals.profile_hash, key)) { |
1600 | status = switch_core_hash_insert(mod_sofia_globals.profile_hash, key, profile)switch_core_hash_insert_destructor(mod_sofia_globals.profile_hash , key, profile, ((void*)0)); |
1601 | } |
1602 | switch_mutex_unlock(mod_sofia_globals.hash_mutex); |
1603 | |
1604 | return status; |
1605 | } |
1606 | |
1607 | |
1608 | void sofia_glue_del_every_gateway(sofia_profile_t *profile) |
1609 | { |
1610 | sofia_gateway_t *gp = NULL((void*)0); |
1611 | |
1612 | switch_mutex_lock(mod_sofia_globals.hash_mutex); |
1613 | for (gp = profile->gateways; gp; gp = gp->next) { |
1614 | sofia_glue_del_gateway(gp); |
1615 | } |
1616 | switch_mutex_unlock(mod_sofia_globals.hash_mutex); |
1617 | } |
1618 | |
1619 | |
1620 | void sofia_glue_gateway_list(sofia_profile_t *profile, switch_stream_handle_t *stream, int up) |
1621 | { |
1622 | sofia_gateway_t *gp = NULL((void*)0); |
1623 | char *r = (char *) stream->data; |
1624 | |
1625 | switch_mutex_lock(mod_sofia_globals.hash_mutex); |
1626 | for (gp = profile->gateways; gp; gp = gp->next) { |
1627 | int reged = (gp->status == SOFIA_GATEWAY_UP); |
1628 | |
1629 | if (up ? reged : !reged) { |
1630 | stream->write_function(stream, "%s ", gp->name); |
1631 | } |
1632 | } |
1633 | |
1634 | if (r) { |
1635 | end_of(r)*(*r == '\0' ? r : r + strlen(r) - 1) = '\0'; |
1636 | } |
1637 | |
1638 | switch_mutex_unlock(mod_sofia_globals.hash_mutex); |
1639 | } |
1640 | |
1641 | |
1642 | void sofia_glue_del_gateway(sofia_gateway_t *gp) |
1643 | { |
1644 | if (!gp->deleted) { |
1645 | if (gp->state != REG_STATE_NOREG) { |
1646 | gp->retry = 0; |
1647 | gp->state = REG_STATE_UNREGISTER; |
1648 | } |
1649 | |
1650 | gp->deleted = 1; |
1651 | } |
1652 | } |
1653 | |
1654 | void sofia_glue_restart_all_profiles(void) |
1655 | { |
1656 | switch_hash_index_t *hi; |
1657 | const void *var; |
1658 | void *val; |
1659 | sofia_profile_t *pptr; |
1660 | switch_xml_t xml_root; |
1661 | const char *err; |
1662 | |
1663 | if ((xml_root = switch_xml_open_root(1, &err))) { |
1664 | switch_xml_free(xml_root); |
1665 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 1665, ((void*)0), SWITCH_LOG_NOTICE, "Reload XML [%s]\n", err); |
1666 | } |
1667 | |
1668 | switch_mutex_lock(mod_sofia_globals.hash_mutex); |
1669 | if (mod_sofia_globals.profile_hash) { |
1670 | for (hi = switch_core_hash_first(mod_sofia_globals.profile_hash)switch_core_hash_first_iter(mod_sofia_globals.profile_hash, ( (void*)0)); hi; hi = switch_core_hash_next(&hi)) { |
1671 | switch_core_hash_this(hi, &var, NULL((void*)0), &val); |
1672 | if ((pptr = (sofia_profile_t *) val)) { |
1673 | int rsec = 10; |
1674 | int diff = (int) (switch_epoch_time_now(NULL((void*)0)) - pptr->started); |
1675 | int remain = rsec - diff; |
1676 | if (sofia_test_pflag(pptr, PFLAG_RESPAWN)((pptr)->pflags[PFLAG_RESPAWN] ? 1 : 0) || !sofia_test_pflag(pptr, PFLAG_RUNNING)((pptr)->pflags[PFLAG_RUNNING] ? 1 : 0)) { |
1677 | continue; |
1678 | } |
1679 | |
1680 | if (diff < rsec) { |
1681 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 1681, ((void*)0), SWITCH_LOG_ERROR, |
1682 | "Profile %s must be up for at least %d seconds to stop/restart.\nPlease wait %d second%s\n", |
1683 | pptr->name, rsec, remain, remain == 1 ? "" : "s"); |
1684 | continue; |
1685 | } |
1686 | sofia_set_pflag_locked(pptr, PFLAG_RESPAWN)((pptr->flag_mutex != ((void*)0)) ? (void) (0) : __assert_fail ("pptr->flag_mutex != ((void*)0)", "sofia_glue.c", 1686, __PRETTY_FUNCTION__ ));switch_mutex_lock(pptr->flag_mutex);(pptr)->pflags[PFLAG_RESPAWN ] = 1;switch_mutex_unlock(pptr->flag_mutex);; |
1687 | sofia_clear_pflag_locked(pptr, PFLAG_RUNNING)switch_mutex_lock(pptr->flag_mutex); (pptr)->pflags[PFLAG_RUNNING ] = 0; switch_mutex_unlock(pptr->flag_mutex);; |
1688 | } |
1689 | } |
1690 | } |
1691 | switch_mutex_unlock(mod_sofia_globals.hash_mutex); |
1692 | |
1693 | } |
1694 | |
1695 | |
1696 | void sofia_glue_global_siptrace(switch_bool_t on) |
1697 | { |
1698 | switch_hash_index_t *hi; |
1699 | const void *var; |
1700 | void *val; |
1701 | sofia_profile_t *pptr; |
1702 | |
1703 | switch_mutex_lock(mod_sofia_globals.hash_mutex); |
1704 | if (mod_sofia_globals.profile_hash) { |
1705 | for (hi = switch_core_hash_first(mod_sofia_globals.profile_hash)switch_core_hash_first_iter(mod_sofia_globals.profile_hash, ( (void*)0)); hi; hi = switch_core_hash_next(&hi)) { |
1706 | switch_core_hash_this(hi, &var, NULL((void*)0), &val); |
1707 | if ((pptr = (sofia_profile_t *) val)) { |
1708 | nua_set_params(pptr->nua, TPTAG_LOG(on)tptag_log, tag_bool_v((on)), TAG_END()(tag_type_t)0, (tag_value_t)0); |
1709 | } |
1710 | } |
1711 | } |
1712 | switch_mutex_unlock(mod_sofia_globals.hash_mutex); |
1713 | |
1714 | } |
1715 | |
1716 | void sofia_glue_global_standby(switch_bool_t on) |
1717 | { |
1718 | switch_hash_index_t *hi; |
1719 | const void *var; |
1720 | void *val; |
1721 | sofia_profile_t *pptr; |
1722 | |
1723 | switch_mutex_lock(mod_sofia_globals.hash_mutex); |
1724 | if (mod_sofia_globals.profile_hash) { |
1725 | for (hi = switch_core_hash_first(mod_sofia_globals.profile_hash)switch_core_hash_first_iter(mod_sofia_globals.profile_hash, ( (void*)0)); hi; hi = switch_core_hash_next(&hi)) { |
1726 | switch_core_hash_this(hi, &var, NULL((void*)0), &val); |
1727 | if ((pptr = (sofia_profile_t *) val)) { |
1728 | if (on) { |
1729 | sofia_set_pflag_locked(pptr, PFLAG_STANDBY)((pptr->flag_mutex != ((void*)0)) ? (void) (0) : __assert_fail ("pptr->flag_mutex != ((void*)0)", "sofia_glue.c", 1729, __PRETTY_FUNCTION__ ));switch_mutex_lock(pptr->flag_mutex);(pptr)->pflags[PFLAG_STANDBY ] = 1;switch_mutex_unlock(pptr->flag_mutex);; |
1730 | } else { |
1731 | sofia_clear_pflag_locked(pptr, PFLAG_STANDBY)switch_mutex_lock(pptr->flag_mutex); (pptr)->pflags[PFLAG_STANDBY ] = 0; switch_mutex_unlock(pptr->flag_mutex);; |
1732 | } |
1733 | } |
1734 | } |
1735 | } |
1736 | switch_mutex_unlock(mod_sofia_globals.hash_mutex); |
1737 | |
1738 | } |
1739 | |
1740 | void sofia_glue_global_capture(switch_bool_t on) |
1741 | { |
1742 | switch_hash_index_t *hi; |
1743 | const void *var; |
1744 | void *val; |
1745 | sofia_profile_t *pptr; |
1746 | |
1747 | switch_mutex_lock(mod_sofia_globals.hash_mutex); |
1748 | if (mod_sofia_globals.profile_hash) { |
1749 | for (hi = switch_core_hash_first(mod_sofia_globals.profile_hash)switch_core_hash_first_iter(mod_sofia_globals.profile_hash, ( (void*)0)); hi; hi = switch_core_hash_next(&hi)) { |
1750 | switch_core_hash_this(hi, &var, NULL((void*)0), &val); |
1751 | if ((pptr = (sofia_profile_t *) val)) { |
1752 | nua_set_params(pptr->nua, TPTAG_CAPT(on ? mod_sofia_globals.capture_server : NULL)tptag_capt, tag_str_v((on ? mod_sofia_globals.capture_server : ((void*)0))), TAG_END()(tag_type_t)0, (tag_value_t)0); |
1753 | } |
1754 | } |
1755 | } |
1756 | switch_mutex_unlock(mod_sofia_globals.hash_mutex); |
1757 | |
1758 | } |
1759 | |
1760 | |
1761 | void sofia_glue_global_watchdog(switch_bool_t on) |
1762 | { |
1763 | switch_hash_index_t *hi; |
1764 | const void *var; |
1765 | void *val; |
1766 | sofia_profile_t *pptr; |
1767 | |
1768 | switch_mutex_lock(mod_sofia_globals.hash_mutex); |
1769 | if (mod_sofia_globals.profile_hash) { |
1770 | for (hi = switch_core_hash_first(mod_sofia_globals.profile_hash)switch_core_hash_first_iter(mod_sofia_globals.profile_hash, ( (void*)0)); hi; hi = switch_core_hash_next(&hi)) { |
1771 | switch_core_hash_this(hi, &var, NULL((void*)0), &val); |
1772 | if ((pptr = (sofia_profile_t *) val)) { |
1773 | pptr->watchdog_enabled = (on ? 1 : 0); |
1774 | } |
1775 | } |
1776 | } |
1777 | switch_mutex_unlock(mod_sofia_globals.hash_mutex); |
1778 | |
1779 | } |
1780 | |
1781 | void sofia_glue_del_profile(sofia_profile_t *profile) |
1782 | { |
1783 | sofia_gateway_t *gp; |
1784 | char *aliases[512]; |
1785 | int i = 0, j = 0; |
1786 | switch_hash_index_t *hi; |
1787 | const void *var; |
1788 | void *val; |
1789 | sofia_profile_t *pptr; |
1790 | |
1791 | switch_mutex_lock(mod_sofia_globals.hash_mutex); |
1792 | if (mod_sofia_globals.profile_hash) { |
1793 | for (hi = switch_core_hash_first(mod_sofia_globals.profile_hash)switch_core_hash_first_iter(mod_sofia_globals.profile_hash, ( (void*)0)); hi; hi = switch_core_hash_next(&hi)) { |
1794 | switch_core_hash_this(hi, &var, NULL((void*)0), &val); |
1795 | if ((pptr = (sofia_profile_t *) val) && pptr == profile) { |
1796 | aliases[i++] = strdup((char *) var)(__extension__ (__builtin_constant_p ((char *) var) && ((size_t)(const void *)(((char *) var) + 1) - (size_t)(const void *)((char *) var) == 1) ? (((const char *) ((char *) var ))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ((char *) var) + 1; char *__retval = ( char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, (char *) var, __len); __retval; } )) : __strdup ((char *) var))); |
1797 | if (i == 512) { |
1798 | abort(); |
1799 | } |
1800 | } |
1801 | } |
1802 | |
1803 | for (j = 0; j < i && j < 512; j++) { |
1804 | switch_core_hash_delete(mod_sofia_globals.profile_hash, aliases[j]); |
1805 | free(aliases[j]); |
1806 | } |
1807 | |
1808 | for (gp = profile->gateways; gp; gp = gp->next) { |
1809 | char *pkey = switch_mprintf("%s::%s", profile->name, gp->name); |
1810 | |
1811 | switch_core_hash_delete(mod_sofia_globals.gateway_hash, gp->name); |
1812 | switch_core_hash_delete(mod_sofia_globals.gateway_hash, pkey); |
1813 | switch_safe_free(pkey)if (pkey) {free(pkey);pkey=((void*)0);}; |
1814 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 1814, ((void*)0), SWITCH_LOG_NOTICE, "deleted gateway %s from profile %s\n", gp->name, profile->name); |
1815 | } |
1816 | profile->gateways = NULL((void*)0); |
1817 | } |
1818 | switch_mutex_unlock(mod_sofia_globals.hash_mutex); |
1819 | } |
1820 | |
1821 | int sofia_recover_callback(switch_core_session_t *session) |
1822 | { |
1823 | |
1824 | switch_channel_t *channel = switch_core_session_get_channel(session); |
1825 | private_object_t *tech_pvt = NULL((void*)0); |
1826 | sofia_profile_t *profile = NULL((void*)0); |
1827 | const char *tmp; |
1828 | const char *rr; |
1829 | int r = 0; |
1830 | const char *profile_name = switch_channel_get_variable_dup(channel, "recovery_profile_name", SWITCH_FALSE, -1); |
1831 | |
1832 | |
1833 | if (zstr(profile_name)_zstr(profile_name)) { |
1834 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "sofia_glue.c", (const char *)__func__ , 1834, (const char*)(session), SWITCH_LOG_CRIT, "Missing profile\n"); |
1835 | return 0; |
1836 | } |
1837 | |
1838 | if (!(profile = sofia_glue_find_profile(profile_name)sofia_glue_find_profile__("sofia_glue.c", (const char *)__func__ , 1838, profile_name))) { |
1839 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "sofia_glue.c", (const char *)__func__ , 1839, (const char*)(session), SWITCH_LOG_CRIT, "Invalid profile %s\n", profile_name); |
1840 | return 0; |
1841 | } |
1842 | |
1843 | |
1844 | tech_pvt = (private_object_t *) switch_core_session_alloc(session, sizeof(private_object_t))switch_core_perform_session_alloc(session, sizeof(private_object_t ), "sofia_glue.c", (const char *)__func__, 1844); |
1845 | tech_pvt->channel = channel; |
1846 | |
1847 | switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED0x1, switch_core_session_get_pool(session)); |
1848 | switch_mutex_init(&tech_pvt->sofia_mutex, SWITCH_MUTEX_NESTED0x1, switch_core_session_get_pool(session)); |
1849 | |
1850 | tech_pvt->mparams.remote_ip = (char *) switch_channel_get_variable(channel, "sip_network_ip")switch_channel_get_variable_dup(channel, "sip_network_ip", SWITCH_TRUE , -1); |
1851 | tech_pvt->mparams.remote_port = atoi(switch_str_nil(switch_channel_get_variable(channel, "sip_network_port"))(switch_channel_get_variable_dup(channel, "sip_network_port", SWITCH_TRUE, -1) ? switch_channel_get_variable_dup(channel, "sip_network_port" , SWITCH_TRUE, -1) : "")); |
1852 | tech_pvt->caller_profile = switch_channel_get_caller_profile(channel); |
1853 | |
1854 | if ((tmp = switch_channel_get_variable(tech_pvt->channel, "rtp_2833_send_payload")switch_channel_get_variable_dup(tech_pvt->channel, "rtp_2833_send_payload" , SWITCH_TRUE, -1))) { |
1855 | int te = atoi(tmp); |
1856 | if (te > 64) { |
1857 | tech_pvt->te = (switch_payload_t)te; |
1858 | } |
1859 | } |
1860 | |
1861 | if ((tmp = switch_channel_get_variable(tech_pvt->channel, "rtp_2833_recv_payload")switch_channel_get_variable_dup(tech_pvt->channel, "rtp_2833_recv_payload" , SWITCH_TRUE, -1))) { |
1862 | int te = atoi(tmp); |
1863 | if (te > 64) { |
1864 | tech_pvt->recv_te = (switch_payload_t)te; |
1865 | } |
1866 | } |
1867 | |
1868 | rr = switch_channel_get_variable(channel, "sip_invite_record_route")switch_channel_get_variable_dup(channel, "sip_invite_record_route" , SWITCH_TRUE, -1); |
1869 | |
1870 | if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { |
1871 | int break_rfc = switch_true(switch_channel_get_variable(channel, "sip_recovery_break_rfc")switch_channel_get_variable_dup(channel, "sip_recovery_break_rfc" , SWITCH_TRUE, -1)); |
1872 | tech_pvt->dest = switch_core_session_sprintf(session, "sip:%s", switch_channel_get_variable(channel, "sip_req_uri")switch_channel_get_variable_dup(channel, "sip_req_uri", SWITCH_TRUE , -1)); |
1873 | switch_channel_set_variable(channel, "sip_handle_full_from", switch_channel_get_variable(channel, break_rfc ? "sip_full_to" : "sip_full_from"))switch_channel_set_variable_var_check(channel, "sip_handle_full_from" , switch_channel_get_variable_dup(channel, break_rfc ? "sip_full_to" : "sip_full_from", SWITCH_TRUE, -1), SWITCH_TRUE); |
1874 | switch_channel_set_variable(channel, "sip_handle_full_to", switch_channel_get_variable(channel, break_rfc ? "sip_full_from" : "sip_full_to"))switch_channel_set_variable_var_check(channel, "sip_handle_full_to" , switch_channel_get_variable_dup(channel, break_rfc ? "sip_full_from" : "sip_full_to", SWITCH_TRUE, -1), SWITCH_TRUE); |
1875 | } else { |
1876 | tech_pvt->redirected = switch_core_session_sprintf(session, "sip:%s", switch_channel_get_variable(channel, "sip_contact_uri")switch_channel_get_variable_dup(channel, "sip_contact_uri", SWITCH_TRUE , -1)); |
1877 | |
1878 | if (zstr(rr)_zstr(rr)) { |
1879 | switch_channel_set_variable_printf(channel, "sip_invite_route_uri", "<sip:%s@%s:%s;transport=%s>", |
1880 | switch_channel_get_variable(channel, "sip_from_user")switch_channel_get_variable_dup(channel, "sip_from_user", SWITCH_TRUE , -1), |
1881 | switch_channel_get_variable(channel, "sip_network_ip")switch_channel_get_variable_dup(channel, "sip_network_ip", SWITCH_TRUE , -1), |
1882 | switch_channel_get_variable(channel, "sip_network_port")switch_channel_get_variable_dup(channel, "sip_network_port", SWITCH_TRUE , -1), |
1883 | switch_channel_get_variable(channel,"sip_via_protocol")switch_channel_get_variable_dup(channel, "sip_via_protocol", SWITCH_TRUE , -1) |
1884 | ); |
1885 | |
1886 | } |
1887 | |
1888 | tech_pvt->dest = switch_core_session_sprintf(session, "sip:%s", switch_channel_get_variable(channel, "sip_from_uri")switch_channel_get_variable_dup(channel, "sip_from_uri", SWITCH_TRUE , -1)); |
1889 | |
1890 | if (!switch_channel_get_variable_dup(channel, "sip_handle_full_from", SWITCH_FALSE, -1)) { |
1891 | switch_channel_set_variable(channel, "sip_handle_full_from", switch_channel_get_variable(channel, "sip_full_to"))switch_channel_set_variable_var_check(channel, "sip_handle_full_from" , switch_channel_get_variable_dup(channel, "sip_full_to", SWITCH_TRUE , -1), SWITCH_TRUE); |
1892 | } |
1893 | |
1894 | if (!switch_channel_get_variable_dup(channel, "sip_handle_full_to", SWITCH_FALSE, -1)) { |
1895 | switch_channel_set_variable(channel, "sip_handle_full_to", switch_channel_get_variable(channel, "sip_full_from"))switch_channel_set_variable_var_check(channel, "sip_handle_full_to" , switch_channel_get_variable_dup(channel, "sip_full_from", SWITCH_TRUE , -1), SWITCH_TRUE); |
1896 | } |
1897 | } |
1898 | |
1899 | if (rr) { |
1900 | switch_channel_set_variable(channel, "sip_invite_route_uri", rr)switch_channel_set_variable_var_check(channel, "sip_invite_route_uri" , rr, SWITCH_TRUE); |
1901 | } |
1902 | |
1903 | tech_pvt->dest_to = tech_pvt->dest; |
1904 | |
1905 | sofia_glue_attach_private(session, profile, tech_pvt, NULL((void*)0)); |
1906 | switch_channel_set_name(tech_pvt->channel, switch_channel_get_variable(channel, "channel_name")switch_channel_get_variable_dup(channel, "channel_name", SWITCH_TRUE , -1)); |
1907 | |
1908 | |
1909 | switch_channel_set_variable(channel, "sip_invite_call_id", switch_channel_get_variable(channel, "sip_call_id"))switch_channel_set_variable_var_check(channel, "sip_invite_call_id" , switch_channel_get_variable_dup(channel, "sip_call_id", SWITCH_TRUE , -1), SWITCH_TRUE); |
1910 | |
1911 | if (switch_true(switch_channel_get_variable(channel, "sip_nat_detected")switch_channel_get_variable_dup(channel, "sip_nat_detected", SWITCH_TRUE , -1))) { |
1912 | switch_channel_set_variable_printf(channel, "sip_route_uri", "sip:%s@%s:%s", |
1913 | switch_channel_get_variable(channel, "sip_req_user")switch_channel_get_variable_dup(channel, "sip_req_user", SWITCH_TRUE , -1), |
1914 | switch_channel_get_variable(channel, "sip_network_ip")switch_channel_get_variable_dup(channel, "sip_network_ip", SWITCH_TRUE , -1), switch_channel_get_variable(channel, "sip_network_port")switch_channel_get_variable_dup(channel, "sip_network_port", SWITCH_TRUE , -1) |
1915 | ); |
1916 | } |
1917 | |
1918 | if (session) { |
1919 | const char *use_uuid; |
1920 | |
1921 | if ((use_uuid = switch_channel_get_variable(channel, "origination_uuid")switch_channel_get_variable_dup(channel, "origination_uuid", SWITCH_TRUE , -1))) { |
1922 | if (switch_core_session_set_uuid(session, use_uuid) == SWITCH_STATUS_SUCCESS) { |
1923 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "sofia_glue.c", (const char *)__func__ , 1923, (const char*)(session), SWITCH_LOG_DEBUG, "%s set UUID=%s\n", switch_channel_get_name(channel), |
1924 | use_uuid); |
1925 | } else { |
1926 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "sofia_glue.c", (const char *)__func__ , 1926, (const char*)(session), SWITCH_LOG_CRIT, "%s set UUID=%s FAILED\n", |
1927 | switch_channel_get_name(channel), use_uuid); |
1928 | } |
1929 | } |
1930 | } |
1931 | |
1932 | r++; |
1933 | |
1934 | if (profile) { |
1935 | sofia_glue_release_profile(profile)sofia_glue_release_profile__("sofia_glue.c", (const char *)__func__ , 1935, profile); |
1936 | } |
1937 | |
1938 | |
1939 | return r; |
1940 | |
1941 | } |
1942 | |
1943 | |
1944 | |
1945 | int sofia_glue_recover(switch_bool_t flush) |
1946 | { |
1947 | sofia_profile_t *profile; |
1948 | int r = 0; |
1949 | switch_console_callback_match_t *matches; |
1950 | |
1951 | |
1952 | if (list_profiles_full(NULL((void*)0), NULL((void*)0), &matches, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) { |
1953 | switch_console_callback_match_node_t *m; |
1954 | for (m = matches->head; m; m = m->next) { |
1955 | if ((profile = sofia_glue_find_profile(m->val)sofia_glue_find_profile__("sofia_glue.c", (const char *)__func__ , 1955, m->val))) { |
1956 | r += sofia_glue_profile_recover(profile, flush); |
1957 | sofia_glue_release_profile(profile)sofia_glue_release_profile__("sofia_glue.c", (const char *)__func__ , 1957, profile); |
1958 | } |
1959 | } |
1960 | switch_console_free_matches(&matches); |
1961 | } |
1962 | return r; |
1963 | } |
1964 | |
1965 | int sofia_glue_profile_recover(sofia_profile_t *profile, switch_bool_t flush) |
1966 | { |
1967 | int r = 0; |
1968 | |
1969 | if (profile) { |
1970 | sofia_clear_pflag_locked(profile, PFLAG_STANDBY)switch_mutex_lock(profile->flag_mutex); (profile)->pflags [PFLAG_STANDBY] = 0; switch_mutex_unlock(profile->flag_mutex );; |
1971 | |
1972 | if (flush) { |
1973 | switch_core_recovery_flush(SOFIA_RECOVER"sofia", profile->name); |
1974 | } else { |
1975 | r = switch_core_recovery_recover(SOFIA_RECOVER"sofia", profile->name); |
1976 | } |
1977 | } |
1978 | |
1979 | return r; |
1980 | } |
1981 | |
1982 | |
1983 | int sofia_glue_init_sql(sofia_profile_t *profile) |
1984 | { |
1985 | char *test_sql = NULL((void*)0); |
1986 | |
1987 | char reg_sql[] = |
1988 | "CREATE TABLE sip_registrations (\n" |
1989 | " call_id VARCHAR(255),\n" |
1990 | " sip_user VARCHAR(255),\n" |
1991 | " sip_host VARCHAR(255),\n" |
1992 | " presence_hosts VARCHAR(255),\n" |
1993 | " contact VARCHAR(1024),\n" |
1994 | " status VARCHAR(255),\n" |
1995 | " ping_status VARCHAR(255),\n" |
1996 | " ping_count INTEGER,\n" |
1997 | " rpid VARCHAR(255),\n" |
1998 | " expires BIGINT,\n" |
1999 | " ping_expires INTEGER not null default 0,\n" |
2000 | " user_agent VARCHAR(255),\n" |
2001 | " server_user VARCHAR(255),\n" |
2002 | " server_host VARCHAR(255),\n" |
2003 | " profile_name VARCHAR(255),\n" |
2004 | " hostname VARCHAR(255),\n" |
2005 | " network_ip VARCHAR(255),\n" |
2006 | " network_port VARCHAR(6),\n" |
2007 | " sip_username VARCHAR(255),\n" |
2008 | " sip_realm VARCHAR(255),\n" |
2009 | " mwi_user VARCHAR(255),\n" |
2010 | " mwi_host VARCHAR(255),\n" |
2011 | " orig_server_host VARCHAR(255),\n" |
2012 | " orig_hostname VARCHAR(255),\n" |
2013 | " sub_host VARCHAR(255)\n" |
2014 | ");\n"; |
2015 | |
2016 | char pres_sql[] = |
2017 | "CREATE TABLE sip_presence (\n" |
2018 | " sip_user VARCHAR(255),\n" |
2019 | " sip_host VARCHAR(255),\n" |
2020 | " status VARCHAR(255),\n" |
2021 | " rpid VARCHAR(255),\n" |
2022 | " expires BIGINT,\n" |
2023 | " user_agent VARCHAR(255),\n" |
2024 | " profile_name VARCHAR(255),\n" |
2025 | " hostname VARCHAR(255),\n" |
2026 | " network_ip VARCHAR(255),\n" |
2027 | " network_port VARCHAR(6),\n" |
2028 | " open_closed VARCHAR(255)\n" |
2029 | ");\n"; |
2030 | |
2031 | char dialog_sql[] = |
2032 | "CREATE TABLE sip_dialogs (\n" |
2033 | " call_id VARCHAR(255),\n" |
2034 | " uuid VARCHAR(255),\n" |
2035 | " sip_to_user VARCHAR(255),\n" |
2036 | " sip_to_host VARCHAR(255),\n" |
2037 | " sip_from_user VARCHAR(255),\n" |
2038 | " sip_from_host VARCHAR(255),\n" |
2039 | " contact_user VARCHAR(255),\n" |
2040 | " contact_host VARCHAR(255),\n" |
2041 | " state VARCHAR(255),\n" |
2042 | " direction VARCHAR(255),\n" |
2043 | " user_agent VARCHAR(255),\n" |
2044 | " profile_name VARCHAR(255),\n" |
2045 | " hostname VARCHAR(255),\n" |
2046 | " contact VARCHAR(255),\n" |
2047 | " presence_id VARCHAR(255),\n" |
2048 | " presence_data VARCHAR(255),\n" |
2049 | " call_info VARCHAR(255),\n" |
2050 | " call_info_state VARCHAR(255) default '',\n" |
2051 | " expires BIGINT default 0,\n" |
2052 | " status VARCHAR(255),\n" |
2053 | " rpid VARCHAR(255),\n" |
2054 | " sip_to_tag VARCHAR(255),\n" |
2055 | " sip_from_tag VARCHAR(255),\n" |
2056 | " rcd INTEGER not null default 0\n" |
2057 | ");\n"; |
2058 | |
2059 | char sub_sql[] = |
2060 | "CREATE TABLE sip_subscriptions (\n" |
2061 | " proto VARCHAR(255),\n" |
2062 | " sip_user VARCHAR(255),\n" |
2063 | " sip_host VARCHAR(255),\n" |
2064 | " sub_to_user VARCHAR(255),\n" |
2065 | " sub_to_host VARCHAR(255),\n" |
2066 | " presence_hosts VARCHAR(255),\n" |
2067 | " event VARCHAR(255),\n" |
2068 | " contact VARCHAR(1024),\n" |
2069 | " call_id VARCHAR(255),\n" |
2070 | " full_from VARCHAR(255),\n" |
2071 | " full_via VARCHAR(255),\n" |
2072 | " expires BIGINT,\n" |
2073 | " user_agent VARCHAR(255),\n" |
2074 | " accept VARCHAR(255),\n" |
2075 | " profile_name VARCHAR(255),\n" |
2076 | " hostname VARCHAR(255),\n" |
2077 | " network_port VARCHAR(6),\n" |
2078 | " network_ip VARCHAR(255),\n" |
2079 | " version INTEGER DEFAULT 0 NOT NULL,\n" |
2080 | " orig_proto VARCHAR(255),\n" |
2081 | " full_to VARCHAR(255)\n" |
2082 | ");\n"; |
2083 | |
2084 | char auth_sql[] = |
2085 | "CREATE TABLE sip_authentication (\n" |
2086 | " nonce VARCHAR(255),\n" |
2087 | " expires BIGINT," |
2088 | " profile_name VARCHAR(255),\n" |
2089 | " hostname VARCHAR(255),\n" |
2090 | " last_nc INTEGER\n" |
2091 | ");\n"; |
2092 | |
2093 | /* should we move this glue to sofia_sla or keep it here where all db init happens? XXX MTK */ |
2094 | char shared_appearance_sql[] = |
2095 | "CREATE TABLE sip_shared_appearance_subscriptions (\n" |
2096 | " subscriber VARCHAR(255),\n" |
2097 | " call_id VARCHAR(255),\n" |
2098 | " aor VARCHAR(255),\n" |
2099 | " profile_name VARCHAR(255),\n" |
2100 | " hostname VARCHAR(255),\n" |
2101 | " contact_str VARCHAR(255),\n" |
2102 | " network_ip VARCHAR(255)\n" |
2103 | ");\n"; |
2104 | |
2105 | char shared_appearance_dialogs_sql[] = |
2106 | "CREATE TABLE sip_shared_appearance_dialogs (\n" |
2107 | " profile_name VARCHAR(255),\n" |
2108 | " hostname VARCHAR(255),\n" |
2109 | " contact_str VARCHAR(255),\n" |
2110 | " call_id VARCHAR(255),\n" |
2111 | " network_ip VARCHAR(255),\n" |
2112 | " expires BIGINT\n" |
2113 | ");\n"; |
2114 | |
2115 | |
2116 | int x; |
2117 | char *indexes[] = { |
2118 | "create index sr_call_id on sip_registrations (call_id)", |
2119 | "create index sr_sip_user on sip_registrations (sip_user)", |
2120 | "create index sr_sip_host on sip_registrations (sip_host)", |
2121 | "create index sr_sub_host on sip_registrations (sub_host)", |
2122 | "create index sr_mwi_user on sip_registrations (mwi_user)", |
2123 | "create index sr_mwi_host on sip_registrations (mwi_host)", |
2124 | "create index sr_profile_name on sip_registrations (profile_name)", |
2125 | "create index sr_presence_hosts on sip_registrations (presence_hosts)", |
2126 | "create index sr_contact on sip_registrations (contact)", |
2127 | "create index sr_expires on sip_registrations (expires)", |
2128 | "create index sr_ping_expires on sip_registrations (ping_expires)", |
2129 | "create index sr_hostname on sip_registrations (hostname)", |
2130 | "create index sr_status on sip_registrations (status)", |
2131 | "create index sr_ping_status on sip_registrations (ping_status)", |
2132 | "create index sr_network_ip on sip_registrations (network_ip)", |
2133 | "create index sr_network_port on sip_registrations (network_port)", |
2134 | "create index sr_sip_username on sip_registrations (sip_username)", |
2135 | "create index sr_sip_realm on sip_registrations (sip_realm)", |
2136 | "create index sr_orig_server_host on sip_registrations (orig_server_host)", |
2137 | "create index sr_orig_hostname on sip_registrations (orig_hostname)", |
2138 | "create index ss_call_id on sip_subscriptions (call_id)", |
2139 | "create index ss_multi on sip_subscriptions (call_id, profile_name, hostname)", |
2140 | "create index ss_hostname on sip_subscriptions (hostname)", |
2141 | "create index ss_network_ip on sip_subscriptions (network_ip)", |
2142 | "create index ss_sip_user on sip_subscriptions (sip_user)", |
2143 | "create index ss_sip_host on sip_subscriptions (sip_host)", |
2144 | "create index ss_presence_hosts on sip_subscriptions (presence_hosts)", |
2145 | "create index ss_event on sip_subscriptions (event)", |
2146 | "create index ss_proto on sip_subscriptions (proto)", |
2147 | "create index ss_sub_to_user on sip_subscriptions (sub_to_user)", |
2148 | "create index ss_sub_to_host on sip_subscriptions (sub_to_host)", |
2149 | "create index ss_expires on sip_subscriptions (expires)", |
2150 | "create index ss_orig_proto on sip_subscriptions (orig_proto)", |
2151 | "create index ss_network_port on sip_subscriptions (network_port)", |
2152 | "create index ss_profile_name on sip_subscriptions (profile_name)", |
2153 | "create index ss_version on sip_subscriptions (version)", |
2154 | "create index ss_full_from on sip_subscriptions (full_from)", |
2155 | "create index ss_contact on sip_subscriptions (contact)", |
2156 | "create index sd_uuid on sip_dialogs (uuid)", |
2157 | "create index sd_hostname on sip_dialogs (hostname)", |
2158 | "create index sd_presence_data on sip_dialogs (presence_data)", |
2159 | "create index sd_call_info on sip_dialogs (call_info)", |
2160 | "create index sd_call_info_state on sip_dialogs (call_info_state)", |
2161 | "create index sd_expires on sip_dialogs (expires)", |
2162 | "create index sd_rcd on sip_dialogs (rcd)", |
2163 | "create index sd_sip_to_tag on sip_dialogs (sip_to_tag)", |
2164 | "create index sd_sip_from_user on sip_dialogs (sip_from_user)", |
2165 | "create index sd_sip_from_host on sip_dialogs (sip_from_host)", |
2166 | "create index sd_sip_to_host on sip_dialogs (sip_to_host)", |
2167 | "create index sd_presence_id on sip_dialogs (presence_id)", |
2168 | "create index sd_call_id on sip_dialogs (call_id)", |
2169 | "create index sd_sip_from_tag on sip_dialogs (sip_from_tag)", |
2170 | "create index sp_hostname on sip_presence (hostname)", |
2171 | "create index sp_open_closed on sip_presence (open_closed)", |
2172 | "create index sp_sip_user on sip_presence (sip_user)", |
2173 | "create index sp_sip_host on sip_presence (sip_host)", |
2174 | "create index sp_profile_name on sip_presence (profile_name)", |
2175 | "create index sp_expires on sip_presence (expires)", |
2176 | "create index sa_nonce on sip_authentication (nonce)", |
2177 | "create index sa_hostname on sip_authentication (hostname)", |
2178 | "create index sa_expires on sip_authentication (expires)", |
2179 | "create index sa_last_nc on sip_authentication (last_nc)", |
2180 | "create index ssa_hostname on sip_shared_appearance_subscriptions (hostname)", |
2181 | "create index ssa_network_ip on sip_shared_appearance_subscriptions (network_ip)", |
2182 | "create index ssa_subscriber on sip_shared_appearance_subscriptions (subscriber)", |
2183 | "create index ssa_profile_name on sip_shared_appearance_subscriptions (profile_name)", |
2184 | "create index ssa_aor on sip_shared_appearance_subscriptions (aor)", |
2185 | "create index ssd_profile_name on sip_shared_appearance_dialogs (profile_name)", |
2186 | "create index ssd_hostname on sip_shared_appearance_dialogs (hostname)", |
2187 | "create index ssd_contact_str on sip_shared_appearance_dialogs (contact_str)", |
2188 | "create index ssd_call_id on sip_shared_appearance_dialogs (call_id)", |
2189 | "create index ssd_expires on sip_shared_appearance_dialogs (expires)", |
2190 | NULL((void*)0) |
2191 | }; |
2192 | |
2193 | switch_cache_db_handle_t *dbh = sofia_glue_get_db_handle(profile)_sofia_glue_get_db_handle(profile, "sofia_glue.c", (const char *)__func__, 2193); |
2194 | char *test2; |
2195 | char *err; |
2196 | |
2197 | if (!dbh) { |
2198 | return 0; |
2199 | } |
2200 | |
2201 | |
2202 | test_sql = switch_mprintf("delete from sip_registrations where sub_host is null " |
2203 | "and hostname='%q' " |
2204 | "and network_ip like '%%' and network_port like '%%' and sip_username " |
2205 | "like '%%' and mwi_user like '%%' and mwi_host like '%%' " |
2206 | "and orig_server_host like '%%' and orig_hostname like '%%'", mod_sofia_globals.hostname); |
2207 | |
2208 | |
2209 | switch_cache_db_test_reactive(dbh, test_sql, "drop table sip_registrations", reg_sql); |
2210 | |
2211 | switch_cache_db_test_reactive(dbh, "select ping_count from sip_registrations", NULL((void*)0), "alter table sip_registrations add column ping_count INTEGER default 0"); |
2212 | switch_cache_db_test_reactive(dbh, "select ping_status from sip_registrations", NULL((void*)0), "alter table sip_registrations add column ping_status VARCHAR(255) default \"Reachable\""); |
2213 | switch_cache_db_test_reactive(dbh, "select ping_expires from sip_registrations", NULL((void*)0), "alter table sip_registrations add column ping_expires INTEGER not null default 0"); |
2214 | |
2215 | test2 = switch_mprintf("%s;%s", test_sql, test_sql); |
2216 | |
2217 | if (switch_cache_db_execute_sql(dbh, test2, &err) != SWITCH_STATUS_SUCCESS) { |
2218 | |
2219 | if (switch_stristr("read-only", err)) { |
2220 | free(err); |
2221 | } else { |
2222 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 2222, ((void*)0), SWITCH_LOG_CRIT, "GREAT SCOTT!!! Cannot execute batched statements! [%s]\n" |
2223 | "If you are using mysql, make sure you are using MYODBC 3.51.18 or higher and enable FLAG_MULTI_STATEMENTS\n", err); |
2224 | |
2225 | switch_cache_db_release_db_handle(&dbh); |
2226 | free(test2); |
2227 | free(test_sql); |
2228 | free(err); |
2229 | return 0; |
2230 | } |
2231 | } |
2232 | |
2233 | free(test2); |
2234 | |
2235 | |
2236 | free(test_sql); |
2237 | |
2238 | test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' and full_to='XXX'", mod_sofia_globals.hostname); |
2239 | |
2240 | switch_cache_db_test_reactive(dbh, test_sql, "DROP TABLE sip_subscriptions", sub_sql); |
2241 | |
2242 | free(test_sql); |
2243 | test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and (expires <> -9999 or rpid='' or sip_from_tag='' or rcd > 0)", |
2244 | mod_sofia_globals.hostname); |
2245 | |
2246 | |
2247 | switch_cache_db_test_reactive(dbh, test_sql, "DROP TABLE sip_dialogs", dialog_sql); |
2248 | |
2249 | free(test_sql); |
2250 | test_sql = switch_mprintf("delete from sip_presence where hostname='%q' or open_closed=''", mod_sofia_globals.hostname); |
2251 | |
2252 | switch_cache_db_test_reactive(dbh, test_sql, "DROP TABLE sip_presence", pres_sql); |
2253 | |
2254 | free(test_sql); |
2255 | test_sql = switch_mprintf("delete from sip_authentication where hostname='%q' or last_nc >= 0", mod_sofia_globals.hostname); |
2256 | |
2257 | switch_cache_db_test_reactive(dbh, test_sql, "DROP TABLE sip_authentication", auth_sql); |
2258 | |
2259 | free(test_sql); |
2260 | test_sql = switch_mprintf("delete from sip_shared_appearance_subscriptions where contact_str='' or hostname='%q' and network_ip like '%%'", |
2261 | mod_sofia_globals.hostname); |
2262 | |
2263 | switch_cache_db_test_reactive(dbh, test_sql, "DROP TABLE sip_shared_appearance_subscriptions", shared_appearance_sql); |
2264 | |
2265 | free(test_sql); |
2266 | test_sql = switch_mprintf("delete from sip_shared_appearance_dialogs where contact_str='' or hostname='%q' and network_ip like '%%'", |
2267 | mod_sofia_globals.hostname); |
2268 | |
2269 | switch_cache_db_test_reactive(dbh, test_sql, "DROP TABLE sip_shared_appearance_dialogs", shared_appearance_dialogs_sql); |
2270 | |
2271 | free(test_sql); |
2272 | |
2273 | for (x = 0; indexes[x]; x++) { |
2274 | switch_cache_db_execute_sql(dbh, indexes[x], NULL((void*)0)); |
2275 | } |
2276 | |
2277 | switch_cache_db_release_db_handle(&dbh); |
2278 | |
2279 | return 1; |
2280 | |
2281 | } |
2282 | |
2283 | void sofia_glue_execute_sql(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic) |
2284 | { |
2285 | char *sql; |
2286 | |
2287 | switch_assert(sqlp && *sqlp)((sqlp && *sqlp) ? (void) (0) : __assert_fail ("sqlp && *sqlp" , "sofia_glue.c", 2287, __PRETTY_FUNCTION__)); |
2288 | sql = *sqlp; |
2289 | |
2290 | switch_sql_queue_manager_push(profile->qm, sql, 1, !sql_already_dynamic); |
2291 | |
2292 | if (sql_already_dynamic) { |
2293 | *sqlp = NULL((void*)0); |
2294 | } |
2295 | } |
2296 | |
2297 | |
2298 | void sofia_glue_execute_sql_now(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic) |
2299 | { |
2300 | char *sql; |
2301 | |
2302 | switch_assert(sqlp && *sqlp)((sqlp && *sqlp) ? (void) (0) : __assert_fail ("sqlp && *sqlp" , "sofia_glue.c", 2302, __PRETTY_FUNCTION__)); |
2303 | sql = *sqlp; |
2304 | |
2305 | switch_mutex_lock(profile->dbh_mutex); |
2306 | switch_sql_queue_manager_push_confirm(profile->qm, sql, 0, !sql_already_dynamic); |
2307 | switch_mutex_unlock(profile->dbh_mutex); |
2308 | |
2309 | if (sql_already_dynamic) { |
2310 | *sqlp = NULL((void*)0); |
2311 | } |
2312 | } |
2313 | |
2314 | void sofia_glue_execute_sql_soon(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic) |
2315 | { |
2316 | char *sql; |
2317 | |
2318 | switch_assert(sqlp && *sqlp)((sqlp && *sqlp) ? (void) (0) : __assert_fail ("sqlp && *sqlp" , "sofia_glue.c", 2318, __PRETTY_FUNCTION__)); |
2319 | sql = *sqlp; |
2320 | |
2321 | switch_sql_queue_manager_push(profile->qm, sql, 0, !sql_already_dynamic); |
2322 | |
2323 | if (sql_already_dynamic) { |
2324 | *sqlp = NULL((void*)0); |
2325 | } |
2326 | } |
2327 | |
2328 | |
2329 | switch_cache_db_handle_t *_sofia_glue_get_db_handle(sofia_profile_t *profile, const char *file, const char *func, int line) |
2330 | { |
2331 | switch_cache_db_handle_t *dbh = NULL((void*)0); |
2332 | char *dsn; |
2333 | |
2334 | if (!zstr(profile->odbc_dsn)_zstr(profile->odbc_dsn)) { |
2335 | dsn = profile->odbc_dsn; |
2336 | } else { |
2337 | dsn = profile->dbname; |
2338 | } |
2339 | |
2340 | if (_switch_cache_db_get_db_handle_dsn(&dbh, dsn, file, func, line) != SWITCH_STATUS_SUCCESS) { |
2341 | dbh = NULL((void*)0); |
2342 | } |
2343 | |
2344 | return dbh; |
2345 | } |
2346 | |
2347 | void sofia_glue_actually_execute_sql_trans(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex) |
2348 | { |
2349 | switch_cache_db_handle_t *dbh = NULL((void*)0); |
2350 | |
2351 | if (mutex) { |
2352 | switch_mutex_lock(mutex); |
2353 | } |
2354 | |
2355 | |
2356 | if (!(dbh = sofia_glue_get_db_handle(profile)_sofia_glue_get_db_handle(profile, "sofia_glue.c", (const char *)__func__, 2356))) { |
2357 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 2357, ((void*)0), SWITCH_LOG_ERROR, "Error Opening DB\n"); |
2358 | |
2359 | goto end; |
2360 | } |
2361 | |
2362 | switch_cache_db_persistant_execute_trans_full(dbh, sql, 1, |
2363 | profile->pre_trans_execute, |
2364 | profile->post_trans_execute, |
2365 | profile->inner_pre_trans_execute, |
2366 | profile->inner_post_trans_execute |
2367 | ); |
2368 | |
2369 | switch_cache_db_release_db_handle(&dbh); |
2370 | |
2371 | end: |
2372 | |
2373 | if (mutex) { |
2374 | switch_mutex_unlock(mutex); |
2375 | } |
2376 | } |
2377 | |
2378 | void sofia_glue_actually_execute_sql(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex) |
2379 | { |
2380 | switch_cache_db_handle_t *dbh = NULL((void*)0); |
2381 | char *err = NULL((void*)0); |
2382 | |
2383 | if (mutex) { |
2384 | switch_mutex_lock(mutex); |
2385 | } |
2386 | |
2387 | if (!(dbh = sofia_glue_get_db_handle(profile)_sofia_glue_get_db_handle(profile, "sofia_glue.c", (const char *)__func__, 2387))) { |
2388 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 2388, ((void*)0), SWITCH_LOG_ERROR, "Error Opening DB\n"); |
2389 | |
2390 | if (mutex) { |
2391 | switch_mutex_unlock(mutex); |
2392 | } |
2393 | |
2394 | return; |
2395 | } |
2396 | |
2397 | switch_cache_db_execute_sql(dbh, sql, &err); |
2398 | |
2399 | if (mutex) { |
2400 | switch_mutex_unlock(mutex); |
2401 | } |
2402 | |
2403 | if (err) { |
2404 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 2404, ((void*)0), SWITCH_LOG_ERROR, "SQL ERR: [%s]\n%s\n", err, sql); |
2405 | free(err); |
2406 | } |
2407 | |
2408 | switch_cache_db_release_db_handle(&dbh); |
2409 | } |
2410 | |
2411 | switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile, |
2412 | switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata) |
2413 | { |
2414 | switch_bool_t ret = SWITCH_FALSE; |
2415 | char *errmsg = NULL((void*)0); |
2416 | switch_cache_db_handle_t *dbh = NULL((void*)0); |
2417 | |
2418 | if (mutex) { |
2419 | switch_mutex_lock(mutex); |
2420 | } |
2421 | |
2422 | if (!(dbh = sofia_glue_get_db_handle(profile)_sofia_glue_get_db_handle(profile, "sofia_glue.c", (const char *)__func__, 2422))) { |
2423 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 2423, ((void*)0), SWITCH_LOG_ERROR, "Error Opening DB\n"); |
2424 | |
2425 | if (mutex) { |
2426 | switch_mutex_unlock(mutex); |
2427 | } |
2428 | |
2429 | return ret; |
2430 | } |
2431 | |
2432 | switch_cache_db_execute_sql_callback(dbh, sql, callback, pdata, &errmsg); |
2433 | |
2434 | if (mutex) { |
2435 | switch_mutex_unlock(mutex); |
2436 | } |
2437 | |
2438 | if (errmsg) { |
2439 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 2439, ((void*)0), SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg); |
2440 | free(errmsg); |
2441 | } |
2442 | |
2443 | switch_cache_db_release_db_handle(&dbh); |
2444 | |
2445 | |
2446 | sofia_glue_fire_events(profile); |
2447 | |
2448 | return ret; |
2449 | } |
2450 | |
2451 | char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len) |
2452 | { |
2453 | char *ret = NULL((void*)0); |
2454 | char *err = NULL((void*)0); |
2455 | switch_cache_db_handle_t *dbh = NULL((void*)0); |
2456 | |
2457 | if (mutex) { |
2458 | switch_mutex_lock(mutex); |
2459 | } |
2460 | |
2461 | if (!(dbh = sofia_glue_get_db_handle(profile)_sofia_glue_get_db_handle(profile, "sofia_glue.c", (const char *)__func__, 2461))) { |
2462 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 2462, ((void*)0), SWITCH_LOG_ERROR, "Error Opening DB\n"); |
2463 | |
2464 | if (mutex) { |
2465 | switch_mutex_unlock(mutex); |
2466 | } |
2467 | |
2468 | return NULL((void*)0); |
2469 | } |
2470 | |
2471 | ret = switch_cache_db_execute_sql2str(dbh, sql, resbuf, len, &err); |
2472 | |
2473 | if (mutex) { |
2474 | switch_mutex_unlock(mutex); |
2475 | } |
2476 | |
2477 | if (err) { |
2478 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 2478, ((void*)0), SWITCH_LOG_ERROR, "SQL ERR: [%s]\n%s\n", err, sql); |
2479 | free(err); |
2480 | } |
2481 | |
2482 | switch_cache_db_release_db_handle(&dbh); |
2483 | |
2484 | |
2485 | sofia_glue_fire_events(profile); |
2486 | |
2487 | return ret; |
2488 | } |
2489 | |
2490 | char *sofia_glue_get_register_host(const char *uri) |
2491 | { |
2492 | char *register_host = NULL((void*)0); |
2493 | const char *s; |
2494 | char *p = NULL((void*)0); |
2495 | |
2496 | if (zstr(uri)_zstr(uri)) { |
2497 | return NULL((void*)0); |
2498 | } |
2499 | |
2500 | if ((s = switch_stristr("sip:", uri))) { |
2501 | s += 4; |
2502 | } else if ((s = switch_stristr("sips:", uri))) { |
2503 | s += 5; |
2504 | } |
2505 | |
2506 | if (!s) { |
2507 | return NULL((void*)0); |
2508 | } |
2509 | |
2510 | register_host = strdup(s)(__extension__ (__builtin_constant_p (s) && ((size_t) (const void *)((s) + 1) - (size_t)(const void *)(s) == 1) ? ( ((const char *) (s))[0] == '\0' ? (char *) calloc ((size_t) 1 , (size_t) 1) : ({ size_t __len = strlen (s) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, s, __len); __retval; })) : __strdup (s))); |
2511 | |
2512 | /* remove port for register_host for testing nat acl take into account |
2513 | ipv6 addresses which are required to have brackets around the addr |
2514 | */ |
2515 | |
2516 | if ((p = strchr(register_host, ']')(__extension__ (__builtin_constant_p (']') && !__builtin_constant_p (register_host) && (']') == '\0' ? (char *) __rawmemchr (register_host, ']') : __builtin_strchr (register_host, ']') )))) { |
2517 | if (*(p + 1) == ':') { |
2518 | *(p + 1) = '\0'; |
2519 | } |
2520 | } else { |
2521 | if ((p = strrchr(register_host, ':'))) { |
2522 | *p = '\0'; |
2523 | } |
2524 | } |
2525 | |
2526 | /* register_proxy should always start with "sip:" or "sips:" */ |
2527 | assert(register_host)((register_host) ? (void) (0) : __assert_fail ("register_host" , "sofia_glue.c", 2527, __PRETTY_FUNCTION__)); |
2528 | |
2529 | return register_host; |
2530 | } |
2531 | |
2532 | const char *sofia_glue_strip_proto(const char *uri) |
2533 | { |
2534 | char *p; |
2535 | |
2536 | if ((p = strchr(uri, ':')(__extension__ (__builtin_constant_p (':') && !__builtin_constant_p (uri) && (':') == '\0' ? (char *) __rawmemchr (uri, ':' ) : __builtin_strchr (uri, ':'))))) { |
2537 | return p + 1; |
2538 | } |
2539 | |
2540 | return uri; |
2541 | } |
2542 | |
2543 | sofia_cid_type_t sofia_cid_name2type(const char *name) |
2544 | { |
2545 | if (!strcasecmp(name, "rpid")) { |
2546 | return CID_TYPE_RPID; |
2547 | } |
2548 | |
2549 | if (!strcasecmp(name, "pid")) { |
2550 | return CID_TYPE_PID; |
2551 | } |
2552 | |
2553 | return CID_TYPE_NONE; |
2554 | |
2555 | } |
2556 | |
2557 | /* all the values of the structure are initialized to NULL */ |
2558 | /* in case of failure the function returns NULL */ |
2559 | /* sofia_destination->route can be NULL */ |
2560 | sofia_destination_t *sofia_glue_get_destination(char *data) |
2561 | { |
2562 | sofia_destination_t *dst = NULL((void*)0); |
2563 | char *to = NULL((void*)0); |
2564 | char *contact = NULL((void*)0); |
2565 | char *route = NULL((void*)0); |
2566 | char *route_uri = NULL((void*)0); |
2567 | char *eoc = NULL((void*)0); |
2568 | char *p = NULL((void*)0); |
2569 | |
2570 | if (zstr(data)_zstr(data)) { |
2571 | return NULL((void*)0); |
2572 | } |
2573 | |
2574 | if (!(dst = (sofia_destination_t *) malloc(sizeof(sofia_destination_t)))) { |
2575 | return NULL((void*)0); |
2576 | } |
2577 | |
2578 | /* return a copy of what is in the buffer between the first < and > */ |
2579 | if (!(contact = sofia_glue_get_url_from_contact(data, 1))) { |
2580 | goto mem_fail; |
2581 | } |
2582 | |
2583 | if ((eoc = strstr(contact, ";fs_path="))) { |
2584 | *eoc = '\0'; |
2585 | |
2586 | if (!(route = strdup(eoc + 9)(__extension__ (__builtin_constant_p (eoc + 9) && ((size_t )(const void *)((eoc + 9) + 1) - (size_t)(const void *)(eoc + 9) == 1) ? (((const char *) (eoc + 9))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ( eoc + 9) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, eoc + 9 , __len); __retval; })) : __strdup (eoc + 9))))) { |
2587 | goto mem_fail; |
2588 | } |
2589 | |
2590 | for (p = route; p && *p; p++) { |
2591 | if (*p == '>' || *p == ';') { |
2592 | *p = '\0'; |
2593 | break; |
2594 | } |
2595 | } |
2596 | |
2597 | switch_url_decode(route); |
2598 | |
2599 | if (!(route_uri = strdup(route)(__extension__ (__builtin_constant_p (route) && ((size_t )(const void *)((route) + 1) - (size_t)(const void *)(route) == 1) ? (((const char *) (route))[0] == '\0' ? (char *) calloc ( (size_t) 1, (size_t) 1) : ({ size_t __len = strlen (route) + 1 ; char *__retval = (char *) malloc (__len); if (__retval != ( (void*)0)) __retval = (char *) memcpy (__retval, route, __len ); __retval; })) : __strdup (route))))) { |
2600 | goto mem_fail; |
2601 | } |
2602 | if ((p = strchr(route_uri, ',')(__extension__ (__builtin_constant_p (',') && !__builtin_constant_p (route_uri) && (',') == '\0' ? (char *) __rawmemchr ( route_uri, ',') : __builtin_strchr (route_uri, ','))))) { |
2603 | do { |
2604 | *p = '\0'; |
2605 | } while ((--p > route_uri) && *p == ' '); |
2606 | } |
2607 | } |
2608 | |
2609 | if (!(to = strdup(data)(__extension__ (__builtin_constant_p (data) && ((size_t )(const void *)((data) + 1) - (size_t)(const void *)(data) == 1) ? (((const char *) (data))[0] == '\0' ? (char *) calloc ( (size_t) 1, (size_t) 1) : ({ size_t __len = strlen (data) + 1 ; char *__retval = (char *) malloc (__len); if (__retval != ( (void*)0)) __retval = (char *) memcpy (__retval, data, __len) ; __retval; })) : __strdup (data))))) { |
2610 | goto mem_fail; |
2611 | } |
2612 | |
2613 | if ((eoc = strstr(to, ";fs_path="))) { |
2614 | *eoc++ = '>'; |
2615 | *eoc = '\0'; |
2616 | } |
2617 | |
2618 | if ((p = strstr(contact, ";fs_"))) { |
2619 | *p = '\0'; |
2620 | } |
2621 | |
2622 | dst->contact = contact; |
2623 | dst->to = to; |
2624 | dst->route = route; |
2625 | dst->route_uri = route_uri; |
2626 | return dst; |
2627 | |
2628 | mem_fail: |
2629 | switch_safe_free(contact)if (contact) {free(contact);contact=((void*)0);}; |
2630 | switch_safe_free(to)if (to) {free(to);to=((void*)0);}; |
2631 | switch_safe_free(route)if (route) {free(route);route=((void*)0);}; |
2632 | switch_safe_free(route_uri)if (route_uri) {free(route_uri);route_uri=((void*)0);}; |
2633 | switch_safe_free(dst)if (dst) {free(dst);dst=((void*)0);}; |
2634 | return NULL((void*)0); |
2635 | } |
2636 | |
2637 | void sofia_glue_free_destination(sofia_destination_t *dst) |
2638 | { |
2639 | if (dst) { |
2640 | switch_safe_free(dst->contact)if (dst->contact) {free(dst->contact);dst->contact=( (void*)0);}; |
2641 | switch_safe_free(dst->route)if (dst->route) {free(dst->route);dst->route=((void* )0);}; |
2642 | switch_safe_free(dst->route_uri)if (dst->route_uri) {free(dst->route_uri);dst->route_uri =((void*)0);}; |
2643 | switch_safe_free(dst->to)if (dst->to) {free(dst->to);dst->to=((void*)0);}; |
2644 | switch_safe_free(dst)if (dst) {free(dst);dst=((void*)0);}; |
2645 | } |
2646 | } |
2647 | |
2648 | switch_status_t sofia_glue_send_notify(sofia_profile_t *profile, const char *user, const char *host, const char *event, const char *contenttype, |
2649 | const char *body, const char *o_contact, const char *network_ip, const char *call_id) |
2650 | { |
2651 | char *id = NULL((void*)0); |
2652 | nua_handle_t *nh; |
2653 | sofia_destination_t *dst = NULL((void*)0); |
2654 | char *contact_str, *contact, *user_via = NULL((void*)0); |
2655 | char *route_uri = NULL((void*)0), *p; |
2656 | char *ptr; |
2657 | |
2658 | contact = sofia_glue_get_url_from_contact((char *) o_contact, 1); |
2659 | |
2660 | if ((p = strstr(contact, ";fs_"))) { |
2661 | *p = '\0'; |
2662 | } |
2663 | |
2664 | if (!zstr(network_ip)_zstr(network_ip) && sofia_glue_check_nat(profile, network_ip)) { |
2665 | id = switch_mprintf("sip:%s@%s", user, profile->extsipip); |
2666 | switch_assert(id)((id) ? (void) (0) : __assert_fail ("id", "sofia_glue.c", 2666 , __PRETTY_FUNCTION__)); |
2667 | |
2668 | if ((ptr = sofia_glue_find_parameter(o_contact, "transport="))) { |
2669 | sofia_transport_t transport = sofia_glue_str2transport( ptr + 10 ); |
2670 | |
2671 | switch (transport) { |
2672 | case SOFIA_TRANSPORT_TCP: |
2673 | contact_str = profile->tcp_public_contact; |
2674 | break; |
2675 | case SOFIA_TRANSPORT_TCP_TLS: |
2676 | contact_str = sofia_test_pflag(profile, PFLAG_TLS)((profile)->pflags[PFLAG_TLS] ? 1 : 0) ? |
2677 | profile->tls_public_contact : profile->tcp_public_contact; |
2678 | break; |
2679 | default: |
2680 | contact_str = profile->public_url; |
2681 | break; |
2682 | } |
2683 | user_via = sofia_glue_create_external_via(NULL((void*)0), profile, transport); |
2684 | } else { |
2685 | user_via = sofia_glue_create_external_via(NULL((void*)0), profile, SOFIA_TRANSPORT_UDP); |
2686 | contact_str = profile->public_url; |
2687 | } |
2688 | } else { |
2689 | id = switch_mprintf("sip:%s@%s", user, host); |
2690 | switch_assert(id)((id) ? (void) (0) : __assert_fail ("id", "sofia_glue.c", 2690 , __PRETTY_FUNCTION__)); |
2691 | |
2692 | if ((ptr = sofia_glue_find_parameter(o_contact, "transport="))) { |
2693 | sofia_transport_t transport = sofia_glue_str2transport( ptr + 10 ); |
2694 | |
2695 | switch (transport) { |
2696 | case SOFIA_TRANSPORT_TCP: |
2697 | contact_str = profile->tcp_contact; |
2698 | break; |
2699 | case SOFIA_TRANSPORT_TCP_TLS: |
2700 | contact_str = sofia_test_pflag(profile, PFLAG_TLS)((profile)->pflags[PFLAG_TLS] ? 1 : 0) ? |
2701 | profile->tls_contact : profile->tcp_contact; |
2702 | break; |
2703 | default: |
2704 | contact_str = profile->url; |
2705 | break; |
2706 | } |
2707 | } else { |
2708 | contact_str = profile->url; |
2709 | } |
2710 | } |
2711 | |
2712 | dst = sofia_glue_get_destination((char *) o_contact); |
2713 | switch_assert(dst)((dst) ? (void) (0) : __assert_fail ("dst", "sofia_glue.c", 2713 , __PRETTY_FUNCTION__)); |
2714 | |
2715 | if (dst->route_uri) { |
2716 | route_uri = sofia_glue_strip_uri(dst->route_uri); |
2717 | } |
2718 | |
2719 | nh = nua_handle(profile->nua, NULL((void*)0), NUTAG_URL(contact)nutag_url, urltag_url_v(contact), SIPTAG_FROM_STR(id)siptag_from_str, tag_str_v(id), SIPTAG_TO_STR(id)siptag_to_str, tag_str_v(id), SIPTAG_CONTACT_STR(contact_str)siptag_contact_str, tag_str_v(contact_str), TAG_END()(tag_type_t)0, (tag_value_t)0); |
2720 | nua_handle_bind(nh, &mod_sofia_globals.destroy_private); |
2721 | |
2722 | nua_notify(nh, |
2723 | NUTAG_NEWSUB(1)nutag_newsub, tag_bool_v(1), |
2724 | TAG_IF(dst->route_uri, NUTAG_PROXY(route_uri))!(dst->route_uri) ? tag_skip : ntatag_default_proxy, urltag_url_v ((route_uri)), TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route))!(dst->route) ? tag_skip : siptag_route_str, tag_str_v(dst ->route), |
2725 | TAG_IF(user_via, SIPTAG_VIA_STR(user_via))!(user_via) ? tag_skip : siptag_via_str, tag_str_v(user_via), |
2726 | SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource")siptag_subscription_state_str, tag_str_v("terminated;reason=noresource" ), |
2727 | TAG_IF(event, SIPTAG_EVENT_STR(event))!(event) ? tag_skip : siptag_event_str, tag_str_v(event), |
2728 | TAG_IF(call_id, SIPTAG_CALL_ID_STR(call_id))!(call_id) ? tag_skip : siptag_call_id_str, tag_str_v(call_id ), |
2729 | TAG_IF(contenttype, SIPTAG_CONTENT_TYPE_STR(contenttype))!(contenttype) ? tag_skip : siptag_content_type_str, tag_str_v (contenttype), TAG_IF(body, SIPTAG_PAYLOAD_STR(body))!(body) ? tag_skip : siptag_payload_str, tag_str_v(body), TAG_END()(tag_type_t)0, (tag_value_t)0); |
2730 | |
2731 | switch_safe_free(contact)if (contact) {free(contact);contact=((void*)0);}; |
2732 | switch_safe_free(route_uri)if (route_uri) {free(route_uri);route_uri=((void*)0);}; |
2733 | switch_safe_free(id)if (id) {free(id);id=((void*)0);}; |
2734 | sofia_glue_free_destination(dst); |
2735 | switch_safe_free(user_via)if (user_via) {free(user_via);user_via=((void*)0);}; |
2736 | |
2737 | return SWITCH_STATUS_SUCCESS; |
2738 | } |
2739 | |
2740 | |
2741 | int sofia_glue_tech_simplify(private_object_t *tech_pvt) |
2742 | { |
2743 | const char *uuid, *network_addr_a = NULL((void*)0), *network_addr_b = NULL((void*)0), *simplify, *simplify_other_channel; |
2744 | switch_channel_t *other_channel = NULL((void*)0), *inbound_channel = NULL((void*)0); |
2745 | switch_core_session_t *other_session = NULL((void*)0), *inbound_session = NULL((void*)0); |
2746 | uint8_t did_simplify = 0; |
2747 | int r = 0; |
2748 | |
2749 | if (!switch_channel_test_flag(tech_pvt->channel, CF_ANSWERED) || switch_channel_test_flag(tech_pvt->channel, CF_SIMPLIFY)) { |
2750 | goto end; |
2751 | } |
2752 | |
2753 | if (switch_channel_test_flag(tech_pvt->channel, CF_BRIDGED) && |
2754 | (uuid = switch_channel_get_partner_uuid(tech_pvt->channel)) && (other_session = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "sofia_glue.c", (const char *)__func__, 2754))) { |
2755 | |
2756 | other_channel = switch_core_session_get_channel(other_session); |
2757 | |
2758 | if (switch_channel_test_flag(other_channel, CF_ANSWERED)) { /* Check if the other channel is answered */ |
2759 | simplify = switch_channel_get_variable(tech_pvt->channel, "sip_auto_simplify")switch_channel_get_variable_dup(tech_pvt->channel, "sip_auto_simplify" , SWITCH_TRUE, -1); |
2760 | simplify_other_channel = switch_channel_get_variable(other_channel, "sip_auto_simplify")switch_channel_get_variable_dup(other_channel, "sip_auto_simplify" , SWITCH_TRUE, -1); |
2761 | |
2762 | r = 1; |
2763 | |
2764 | if (switch_true(simplify) && !switch_channel_test_flag(tech_pvt->channel, CF_BRIDGE_ORIGINATOR)) { |
2765 | network_addr_a = switch_channel_get_variable(tech_pvt->channel, "network_addr")switch_channel_get_variable_dup(tech_pvt->channel, "network_addr" , SWITCH_TRUE, -1); |
2766 | network_addr_b = switch_channel_get_variable(other_channel, "network_addr")switch_channel_get_variable_dup(other_channel, "network_addr" , SWITCH_TRUE, -1); |
2767 | inbound_session = other_session; |
2768 | inbound_channel = other_channel; |
2769 | } else if (switch_true(simplify_other_channel) && !switch_channel_test_flag(other_channel, CF_BRIDGE_ORIGINATOR)) { |
2770 | network_addr_a = switch_channel_get_variable(other_channel, "network_addr")switch_channel_get_variable_dup(other_channel, "network_addr" , SWITCH_TRUE, -1); |
2771 | network_addr_b = switch_channel_get_variable(tech_pvt->channel, "network_addr")switch_channel_get_variable_dup(tech_pvt->channel, "network_addr" , SWITCH_TRUE, -1); |
2772 | inbound_session = tech_pvt->session; |
2773 | inbound_channel = tech_pvt->channel; |
2774 | } |
2775 | |
2776 | if (inbound_channel && inbound_session && !zstr(network_addr_a)_zstr(network_addr_a) && !zstr(network_addr_b)_zstr(network_addr_b) && !strcmp(network_addr_a, network_addr_b)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (network_addr_a) && __builtin_constant_p (network_addr_b ) && (__s1_len = __builtin_strlen (network_addr_a), __s2_len = __builtin_strlen (network_addr_b), (!((size_t)(const void * )((network_addr_a) + 1) - (size_t)(const void *)(network_addr_a ) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((network_addr_b) + 1) - (size_t)(const void *)(network_addr_b ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (network_addr_a , network_addr_b) : (__builtin_constant_p (network_addr_a) && ((size_t)(const void *)((network_addr_a) + 1) - (size_t)(const void *)(network_addr_a) == 1) && (__s1_len = __builtin_strlen (network_addr_a), __s1_len < 4) ? (__builtin_constant_p ( network_addr_b) && ((size_t)(const void *)((network_addr_b ) + 1) - (size_t)(const void *)(network_addr_b) == 1) ? __builtin_strcmp (network_addr_a, network_addr_b) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (network_addr_b ); int __result = (((const unsigned char *) (const char *) (network_addr_a ))[0] - __s2[0]); if (__s1_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (network_addr_a ))[1] - __s2[1]); if (__s1_len > 1 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (network_addr_a ))[2] - __s2[2]); if (__s1_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (network_addr_a ))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ( network_addr_b) && ((size_t)(const void *)((network_addr_b ) + 1) - (size_t)(const void *)(network_addr_b) == 1) && (__s2_len = __builtin_strlen (network_addr_b), __s2_len < 4) ? (__builtin_constant_p (network_addr_a) && ((size_t )(const void *)((network_addr_a) + 1) - (size_t)(const void * )(network_addr_a) == 1) ? __builtin_strcmp (network_addr_a, network_addr_b ) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (network_addr_a); int __result = (((const unsigned char *) (const char *) (network_addr_b))[0] - __s2[ 0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (network_addr_b)) [1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (network_addr_b ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (network_addr_b ))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (network_addr_a , network_addr_b)))); })) { |
2777 | if (strcmp(network_addr_a, switch_str_nil(tech_pvt->profile->sipip))__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (network_addr_a) && __builtin_constant_p ((tech_pvt-> profile->sipip ? tech_pvt->profile->sipip : "")) && (__s1_len = __builtin_strlen (network_addr_a), __s2_len = __builtin_strlen ((tech_pvt->profile->sipip ? tech_pvt->profile-> sipip : "")), (!((size_t)(const void *)((network_addr_a) + 1) - (size_t)(const void *)(network_addr_a) == 1) || __s1_len >= 4) && (!((size_t)(const void *)(((tech_pvt->profile ->sipip ? tech_pvt->profile->sipip : "")) + 1) - (size_t )(const void *)((tech_pvt->profile->sipip ? tech_pvt-> profile->sipip : "")) == 1) || __s2_len >= 4)) ? __builtin_strcmp (network_addr_a, (tech_pvt->profile->sipip ? tech_pvt-> profile->sipip : "")) : (__builtin_constant_p (network_addr_a ) && ((size_t)(const void *)((network_addr_a) + 1) - ( size_t)(const void *)(network_addr_a) == 1) && (__s1_len = __builtin_strlen (network_addr_a), __s1_len < 4) ? (__builtin_constant_p ((tech_pvt->profile->sipip ? tech_pvt->profile-> sipip : "")) && ((size_t)(const void *)(((tech_pvt-> profile->sipip ? tech_pvt->profile->sipip : "")) + 1 ) - (size_t)(const void *)((tech_pvt->profile->sipip ? tech_pvt ->profile->sipip : "")) == 1) ? __builtin_strcmp (network_addr_a , (tech_pvt->profile->sipip ? tech_pvt->profile-> sipip : "")) : (__extension__ ({ const unsigned char *__s2 = ( const unsigned char *) (const char *) ((tech_pvt->profile-> sipip ? tech_pvt->profile->sipip : "")); int __result = (((const unsigned char *) (const char *) (network_addr_a))[0 ] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (network_addr_a ))[1] - __s2[1]); if (__s1_len > 1 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (network_addr_a ))[2] - __s2[2]); if (__s1_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (network_addr_a ))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ( (tech_pvt->profile->sipip ? tech_pvt->profile->sipip : "")) && ((size_t)(const void *)(((tech_pvt->profile ->sipip ? tech_pvt->profile->sipip : "")) + 1) - (size_t )(const void *)((tech_pvt->profile->sipip ? tech_pvt-> profile->sipip : "")) == 1) && (__s2_len = __builtin_strlen ((tech_pvt->profile->sipip ? tech_pvt->profile-> sipip : "")), __s2_len < 4) ? (__builtin_constant_p (network_addr_a ) && ((size_t)(const void *)((network_addr_a) + 1) - ( size_t)(const void *)(network_addr_a) == 1) ? __builtin_strcmp (network_addr_a, (tech_pvt->profile->sipip ? tech_pvt-> profile->sipip : "")) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (network_addr_a ); int __result = (((const unsigned char *) (const char *) (( tech_pvt->profile->sipip ? tech_pvt->profile->sipip : "")))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ( (tech_pvt->profile->sipip ? tech_pvt->profile->sipip : "")))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ( (tech_pvt->profile->sipip ? tech_pvt->profile->sipip : "")))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (( tech_pvt->profile->sipip ? tech_pvt->profile->sipip : "")))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (network_addr_a, (tech_pvt->profile->sipip ? tech_pvt-> profile->sipip : ""))))); }) |
2778 | && strcmp(network_addr_a, switch_str_nil(tech_pvt->profile->extsipip))__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (network_addr_a) && __builtin_constant_p ((tech_pvt-> profile->extsipip ? tech_pvt->profile->extsipip : "" )) && (__s1_len = __builtin_strlen (network_addr_a), __s2_len = __builtin_strlen ((tech_pvt->profile->extsipip ? tech_pvt ->profile->extsipip : "")), (!((size_t)(const void *)(( network_addr_a) + 1) - (size_t)(const void *)(network_addr_a) == 1) || __s1_len >= 4) && (!((size_t)(const void *)(((tech_pvt->profile->extsipip ? tech_pvt->profile ->extsipip : "")) + 1) - (size_t)(const void *)((tech_pvt-> profile->extsipip ? tech_pvt->profile->extsipip : "" )) == 1) || __s2_len >= 4)) ? __builtin_strcmp (network_addr_a , (tech_pvt->profile->extsipip ? tech_pvt->profile-> extsipip : "")) : (__builtin_constant_p (network_addr_a) && ((size_t)(const void *)((network_addr_a) + 1) - (size_t)(const void *)(network_addr_a) == 1) && (__s1_len = __builtin_strlen (network_addr_a), __s1_len < 4) ? (__builtin_constant_p ( (tech_pvt->profile->extsipip ? tech_pvt->profile-> extsipip : "")) && ((size_t)(const void *)(((tech_pvt ->profile->extsipip ? tech_pvt->profile->extsipip : "")) + 1) - (size_t)(const void *)((tech_pvt->profile-> extsipip ? tech_pvt->profile->extsipip : "")) == 1) ? __builtin_strcmp (network_addr_a, (tech_pvt->profile->extsipip ? tech_pvt ->profile->extsipip : "")) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ((tech_pvt ->profile->extsipip ? tech_pvt->profile->extsipip : "")); int __result = (((const unsigned char *) (const char *) (network_addr_a))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (network_addr_a))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (network_addr_a))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (network_addr_a))[3] - __s2[3]); } } __result ; }))) : (__builtin_constant_p ((tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : "")) && ((size_t )(const void *)(((tech_pvt->profile->extsipip ? tech_pvt ->profile->extsipip : "")) + 1) - (size_t)(const void * )((tech_pvt->profile->extsipip ? tech_pvt->profile-> extsipip : "")) == 1) && (__s2_len = __builtin_strlen ((tech_pvt->profile->extsipip ? tech_pvt->profile-> extsipip : "")), __s2_len < 4) ? (__builtin_constant_p (network_addr_a ) && ((size_t)(const void *)((network_addr_a) + 1) - ( size_t)(const void *)(network_addr_a) == 1) ? __builtin_strcmp (network_addr_a, (tech_pvt->profile->extsipip ? tech_pvt ->profile->extsipip : "")) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (network_addr_a); int __result = (((const unsigned char *) ( const char *) ((tech_pvt->profile->extsipip ? tech_pvt-> profile->extsipip : "")))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ((tech_pvt->profile->extsipip ? tech_pvt ->profile->extsipip : "")))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ((tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : "")))[2] - __s2[2]); if ( __s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ((tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : "")))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (network_addr_a, (tech_pvt ->profile->extsipip ? tech_pvt->profile->extsipip : ""))))); })) { |
2779 | |
2780 | switch_core_session_message_t *msg; |
2781 | |
2782 | switch_log_printf(SWITCH_CHANNEL_ID_LOG, __FILE__"sofia_glue.c", __SWITCH_FUNC__(const char *)__func__, __LINE__2782, switch_channel_get_uuid(inbound_channel), |
2783 | SWITCH_LOG_NOTICE, "Will simplify channel [%s]\n", switch_channel_get_name(inbound_channel)); |
2784 | |
2785 | msg = switch_core_session_alloc(inbound_session, sizeof(*msg))switch_core_perform_session_alloc(inbound_session, sizeof(*msg ), "sofia_glue.c", (const char *)__func__, 2785); |
2786 | MESSAGE_STAMP_FFL(msg)msg->_file = "sofia_glue.c"; msg->_func = (const char * )__func__; msg->_line = 2786; |
2787 | msg->message_id = SWITCH_MESSAGE_INDICATE_SIMPLIFY; |
2788 | msg->from = __FILE__"sofia_glue.c"; |
2789 | switch_core_session_receive_message(inbound_session, msg)switch_core_session_perform_receive_message(inbound_session, msg , "sofia_glue.c", (const char *)__func__, 2789); |
2790 | |
2791 | did_simplify = 1; |
2792 | |
2793 | switch_core_recovery_track(inbound_session); |
2794 | |
2795 | switch_channel_set_flag(inbound_channel, CF_SIMPLIFY)switch_channel_set_flag_value(inbound_channel, CF_SIMPLIFY, 1 ); |
2796 | |
2797 | } |
2798 | } |
2799 | |
2800 | if (!did_simplify && inbound_channel) { |
2801 | switch_log_printf(SWITCH_CHANNEL_ID_LOG, __FILE__"sofia_glue.c", __SWITCH_FUNC__(const char *)__func__, __LINE__2801, switch_channel_get_uuid(inbound_channel), SWITCH_LOG_NOTICE, |
2802 | "Could not simplify channel [%s]\n", switch_channel_get_name(inbound_channel)); |
2803 | } |
2804 | } |
2805 | |
2806 | switch_core_session_rwunlock(other_session); |
2807 | } |
2808 | |
2809 | |
2810 | end: |
2811 | |
2812 | return r; |
2813 | } |
2814 | |
2815 | void sofia_glue_pause_jitterbuffer(switch_core_session_t *session, switch_bool_t on) |
2816 | { |
2817 | switch_core_session_message_t *msg; |
2818 | msg = switch_core_session_alloc(session, sizeof(*msg))switch_core_perform_session_alloc(session, sizeof(*msg), "sofia_glue.c" , (const char *)__func__, 2818); |
2819 | MESSAGE_STAMP_FFL(msg)msg->_file = "sofia_glue.c"; msg->_func = (const char * )__func__; msg->_line = 2819; |
2820 | msg->message_id = SWITCH_MESSAGE_INDICATE_JITTER_BUFFER; |
2821 | msg->string_arg = switch_core_session_strdup(session, on ? "pause" : "resume")switch_core_perform_session_strdup(session, on ? "pause" : "resume" , "sofia_glue.c", (const char *)__func__, 2821); |
2822 | msg->from = __FILE__"sofia_glue.c"; |
2823 | |
2824 | switch_core_session_queue_message(session, msg); |
2825 | } |
2826 | |
2827 | |
2828 | void sofia_glue_build_vid_refresh_message(switch_core_session_t *session, const char *pl) |
2829 | { |
2830 | switch_core_session_message_t *msg; |
2831 | msg = switch_core_session_alloc(session, sizeof(*msg))switch_core_perform_session_alloc(session, sizeof(*msg), "sofia_glue.c" , (const char *)__func__, 2831); |
2832 | MESSAGE_STAMP_FFL(msg)msg->_file = "sofia_glue.c"; msg->_func = (const char * )__func__; msg->_line = 2832; |
2833 | msg->message_id = SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ; |
2834 | if (pl) { |
2835 | msg->string_arg = switch_core_session_strdup(session, pl)switch_core_perform_session_strdup(session, pl, "sofia_glue.c" , (const char *)__func__, 2835); |
2836 | } |
2837 | msg->from = __FILE__"sofia_glue.c"; |
2838 | |
2839 | switch_core_session_queue_message(session, msg); |
2840 | } |
2841 | |
2842 | |
2843 | char *sofia_glue_gen_contact_str(sofia_profile_t *profile, sip_t const *sip, nua_handle_t *nh, sofia_dispatch_event_t *de, sofia_nat_parse_t *np) |
2844 | { |
2845 | char *contact_str = NULL((void*)0); |
2846 | const char *contact_host;//, *contact_user; |
2847 | sip_contact_t const *contact; |
2848 | char *port; |
2849 | const char *display = "\"user\""; |
2850 | char new_port[25] = ""; |
2851 | sofia_nat_parse_t lnp = { { 0 } }; |
2852 | const char *ipv6; |
2853 | sip_from_t const *from; |
2854 | |
2855 | if (!sip || !sip->sip_contact || !sip->sip_contact->m_url) { |
2856 | return NULL((void*)0); |
2857 | } |
2858 | |
2859 | from = sip->sip_from; |
2860 | contact = sip->sip_contact; |
2861 | |
2862 | if (!np) { |
2863 | np = &lnp; |
2864 | } |
2865 | |
2866 | sofia_glue_get_addr(de->data->e_msg, np->network_ip, sizeof(np->network_ip), &np->network_port); |
2867 | |
2868 | if (sofia_glue_check_nat(profile, np->network_ip)) { |
2869 | np->is_auto_nat = 1; |
2870 | } |
2871 | |
2872 | port = (char *) contact->m_url->url_port; |
2873 | contact_host = sip->sip_contact->m_url->url_host; |
2874 | //contact_user = sip->sip_contact->m_url->url_user; |
2875 | |
2876 | display = contact->m_display; |
2877 | |
2878 | |
2879 | if (zstr(display)_zstr(display)) { |
2880 | if (from) { |
2881 | display = from->a_display; |
2882 | if (zstr(display)_zstr(display)) { |
2883 | display = "\"user\""; |
2884 | } |
2885 | } |
2886 | } else { |
2887 | display = "\"user\""; |
2888 | } |
2889 | |
2890 | if (sofia_test_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION)((profile)->pflags[PFLAG_AGGRESSIVE_NAT_DETECTION] ? 1 : 0 )) { |
2891 | if (sip->sip_via) { |
2892 | const char *v_port = sip->sip_via->v_port; |
2893 | const char *v_host = sip->sip_via->v_host; |
2894 | |
2895 | if (v_host && sip->sip_via->v_received) { |
2896 | np->is_nat = "via received"; |
2897 | } else if (v_host && strcmp(np->network_ip, v_host)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (np->network_ip) && __builtin_constant_p (v_host) && (__s1_len = __builtin_strlen (np->network_ip), __s2_len = __builtin_strlen (v_host), (!((size_t)(const void *)((np->network_ip) + 1) - (size_t)(const void *)(np-> network_ip) == 1) || __s1_len >= 4) && (!((size_t) (const void *)((v_host) + 1) - (size_t)(const void *)(v_host) == 1) || __s2_len >= 4)) ? __builtin_strcmp (np->network_ip , v_host) : (__builtin_constant_p (np->network_ip) && ((size_t)(const void *)((np->network_ip) + 1) - (size_t)( const void *)(np->network_ip) == 1) && (__s1_len = __builtin_strlen (np->network_ip), __s1_len < 4) ? (__builtin_constant_p (v_host) && ((size_t)(const void *)((v_host) + 1) - ( size_t)(const void *)(v_host) == 1) ? __builtin_strcmp (np-> network_ip, v_host) : (__extension__ ({ const unsigned char * __s2 = (const unsigned char *) (const char *) (v_host); int __result = (((const unsigned char *) (const char *) (np->network_ip ))[0] - __s2[0]); if (__s1_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (np-> network_ip))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ( np->network_ip))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (np->network_ip))[3] - __s2[3]); } } __result; }))) : ( __builtin_constant_p (v_host) && ((size_t)(const void *)((v_host) + 1) - (size_t)(const void *)(v_host) == 1) && (__s2_len = __builtin_strlen (v_host), __s2_len < 4) ? (__builtin_constant_p (np->network_ip) && ((size_t)(const void *)((np-> network_ip) + 1) - (size_t)(const void *)(np->network_ip) == 1) ? __builtin_strcmp (np->network_ip, v_host) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (np->network_ip); int __result = (((const unsigned char *) (const char *) (v_host))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (v_host))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (v_host))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (v_host))[3] - __s2[3]); } } __result ; })))) : __builtin_strcmp (np->network_ip, v_host)))); })) { |
2898 | np->is_nat = "via host"; |
2899 | } else if (v_port && atoi(v_port) != np->network_port) { |
2900 | np->is_nat = "via port"; |
2901 | } |
2902 | } |
2903 | } |
2904 | |
2905 | if (!np->is_nat && sip && sip->sip_via && sip->sip_via->v_port && |
2906 | atoi(sip->sip_via->v_port) == 5060 && np->network_port != 5060 ) { |
2907 | np->is_nat = "via port"; |
2908 | } |
2909 | |
2910 | if (!np->is_nat && profile->nat_acl_count) { |
2911 | uint32_t x = 0; |
2912 | int ok = 1; |
2913 | char *last_acl = NULL((void*)0); |
2914 | |
2915 | if (!zstr(contact_host)_zstr(contact_host)) { |
2916 | for (x = 0; x < profile->nat_acl_count; x++) { |
2917 | last_acl = profile->nat_acl[x]; |
2918 | if (!(ok = switch_check_network_list_ip(contact_host, last_acl)switch_check_network_list_ip_token(contact_host, last_acl, (( void*)0)))) { |
2919 | break; |
2920 | } |
2921 | } |
2922 | |
2923 | if (ok) { |
2924 | np->is_nat = last_acl; |
2925 | } |
2926 | } |
2927 | } |
2928 | |
2929 | if (np->is_nat && profile->local_network && switch_check_network_list_ip(np->network_ip, profile->local_network)switch_check_network_list_ip_token(np->network_ip, profile ->local_network, ((void*)0))) { |
2930 | if (profile->debug) { |
2931 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "sofia_glue.c", (const char *)__func__ , 2931, ((void*)0), SWITCH_LOG_DEBUG, "IP %s is on local network, not seting NAT mode.\n", np->network_ip); |
2932 | } |
2933 | np->is_nat = NULL((void*)0); |
2934 | } |
2935 | |
2936 | if (sip->sip_record_route && sip->sip_record_route->r_url) { |
2937 | char *full_contact = sip_header_as_string(nh->nh_home, (void *) contact); |
2938 | char *route = sofia_glue_strip_uri(sip_header_as_string(nh->nh_home, (void *) sip->sip_record_route)); |
2939 | char *full_contact_dup; |
2940 | char *route_encoded; |
2941 | int route_encoded_len; |
2942 | full_contact_dup = sofia_glue_get_url_from_contact(full_contact, 1); |
2943 | route_encoded_len = (int)(strlen(route) * 3) + 1; |
2944 | switch_zmalloc(route_encoded, route_encoded_len)(void)((((route_encoded = calloc(1, (route_encoded_len)))) ? ( void) (0) : __assert_fail ("(route_encoded = calloc(1, (route_encoded_len)))" , "sofia_glue.c", 2944, __PRETTY_FUNCTION__)),route_encoded); |
2945 | switch_url_encode(route, route_encoded, route_encoded_len); |
2946 | contact_str = switch_mprintf("%s <%s;fs_path=%s>", display, full_contact_dup, route_encoded); |
2947 | free(full_contact_dup); |
2948 | free(route_encoded); |
2949 | } |
2950 | else if (np->is_nat && np->fs_path) { |
2951 | char *full_contact = sip_header_as_string(nh->nh_home, (void *) contact); |
2952 | char *full_contact_dup; |
2953 | char *path_encoded; |
2954 | int path_encoded_len; |
2955 | char *path_val; |
2956 | const char *tp; |
2957 | |
2958 | full_contact_dup = sofia_glue_get_url_from_contact(full_contact, 1); |
2959 | |
2960 | if ((tp = switch_stristr("transport=", full_contact_dup))) { |
2961 | tp += 10; |
2962 | } |
2963 | |
2964 | if (zstr(tp)_zstr(tp)) { |
2965 | tp = "udp"; |
2966 | } |
2967 | |
2968 | path_val = switch_mprintf("sip:%s:%d;transport=%s", np->network_ip, np->network_port, tp); |
2969 | path_encoded_len = (int)(strlen(path_val) * 3) + 1; |
2970 | |
2971 | switch_zmalloc(path_encoded, path_encoded_len)(void)((((path_encoded = calloc(1, (path_encoded_len)))) ? (void ) (0) : __assert_fail ("(path_encoded = calloc(1, (path_encoded_len)))" , "sofia_glue.c", 2971, __PRETTY_FUNCTION__)),path_encoded); |
2972 | switch_copy_string(path_encoded, ";fs_path=", 10); |
2973 | switch_url_encode(path_val, path_encoded + 9, path_encoded_len - 9); |
2974 | |
2975 | contact_str = switch_mprintf("%s <%s;fs_nat=yes%s>", display, full_contact_dup, path_encoded); |
2976 | |
2977 | free(full_contact_dup); |
2978 | free(path_encoded); |
2979 | free(path_val); |
2980 | |
2981 | } else { |
2982 | |
2983 | if (zstr(contact_host)_zstr(contact_host)) { |
2984 | np->is_nat = "No contact host"; |
2985 | } |
2986 | |
2987 | if (np->is_nat) { |
2988 | contact_host = np->network_ip; |
2989 | switch_snprintf(new_port, sizeof(new_port), ":%d", np->network_port); |
2990 | port = NULL((void*)0); |
2991 | } |
2992 | |
2993 | |
2994 | if (port) { |
2995 | switch_snprintf(new_port, sizeof(new_port), ":%s", port); |
2996 | } |
2997 | |
2998 | ipv6 = strchr(contact_host, ':')(__extension__ (__builtin_constant_p (':') && !__builtin_constant_p (contact_host) && (':') == '\0' ? (char *) __rawmemchr (contact_host, ':') : __builtin_strchr (contact_host, ':'))); |
2999 | |
3000 | |
3001 | if (contact->m_url->url_params) { |
3002 | contact_str = switch_mprintf("%s <sip:%s%s%s%s%s%s;%s>%s", |
3003 | display, contact->m_url->url_user, |
3004 | contact->m_url->url_user ? "@" : "", |
3005 | ipv6 ? "[" : "", |
3006 | contact_host, ipv6 ? "]" : "", new_port, contact->m_url->url_params, np->is_nat ? ";fs_nat=yes" : ""); |
3007 | } else { |
3008 | contact_str = switch_mprintf("%s <sip:%s%s%s%s%s%s>%s", |
3009 | display, |
3010 | contact->m_url->url_user, |
3011 | contact->m_url->url_user ? "@" : "", |
3012 | ipv6 ? "[" : "", contact_host, ipv6 ? "]" : "", new_port, np->is_nat ? ";fs_nat=yes" : ""); |
3013 | } |
3014 | } |
3015 | |
3016 | return contact_str; |
3017 | } |
3018 | |
3019 | char *sofia_glue_get_host(const char *str, switch_memory_pool_t *pool) |
3020 | { |
3021 | char *s, *p; |
3022 | |
3023 | if ((p = strchr(str, '@')(__extension__ (__builtin_constant_p ('@') && !__builtin_constant_p (str) && ('@') == '\0' ? (char *) __rawmemchr (str, '@' ) : __builtin_strchr (str, '@'))))) { |
3024 | p++; |
3025 | } else { |
3026 | return NULL((void*)0); |
3027 | } |
3028 | |
3029 | if (pool) { |
3030 | s = switch_core_strdup(pool, p)switch_core_perform_strdup(pool, p, "sofia_glue.c", (const char *)__func__, 3030); |
3031 | } else { |
3032 | s = strdup(p)(__extension__ (__builtin_constant_p (p) && ((size_t) (const void *)((p) + 1) - (size_t)(const void *)(p) == 1) ? ( ((const char *) (p))[0] == '\0' ? (char *) calloc ((size_t) 1 , (size_t) 1) : ({ size_t __len = strlen (p) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, p, __len); __retval; })) : __strdup (p))); |
3033 | } |
3034 | |
3035 | for (p = s; p && *p; p++) { |
3036 | if ((*p == ';') || (*p == '>')) { |
3037 | *p = '\0'; |
3038 | break; |
3039 | } |
3040 | } |
3041 | |
3042 | return s; |
3043 | } |
3044 | |
3045 | void sofia_glue_fire_events(sofia_profile_t *profile) |
3046 | { |
3047 | void *pop = NULL((void*)0); |
3048 | |
3049 | while (profile->event_queue && switch_queue_trypop(profile->event_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) { |
3050 | switch_event_t *event = (switch_event_t *) pop; |
3051 | switch_event_fire(&event)switch_event_fire_detailed("sofia_glue.c", (const char * )(const char *)__func__, 3051, &event, ((void*)0)); |
3052 | } |
3053 | |
3054 | } |
3055 | |
3056 | void sofia_event_fire(sofia_profile_t *profile, switch_event_t **event) |
3057 | { |
3058 | switch_queue_push(profile->event_queue, *event); |
3059 | *event = NULL((void*)0); |
3060 | } |
3061 | |
3062 | |
3063 | /* For Emacs: |
3064 | * Local Variables: |
3065 | * mode:c |
3066 | * indent-tabs-mode:t |
3067 | * tab-width:4 |
3068 | * c-basic-offset:4 |
3069 | * End: |
3070 | * For VIM: |
3071 | * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet: |
3072 | */ |