MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / mi_fs_subscribe

Function mi_fs_subscribe

modules/freeswitch_scripting/fss_mod.c:248–329  ·  view source on GitHub ↗

fs_subscribe 10.0.0.10 DTMF HEARTBEAT CHANNEL_STATE FOO ... */

Source from the content-addressed store, hash-verified

246
247/* fs_subscribe 10.0.0.10 DTMF HEARTBEAT CHANNEL_STATE FOO ... */
248mi_response_t *mi_fs_subscribe(const mi_params_t *params,
249 struct mi_handler *async_hdl)
250{
251 mi_response_t *resp = NULL;
252 mi_item_t *events;
253 str event_str;
254 int i, no_events;
255 str_list *evlist = NULL, *li, **last = &evlist;
256 fs_evs *sock;
257 str url;
258
259 if (get_mi_string_param(params, "freeswitch_url", &url.s, &url.len) < 0)
260 return init_mi_param_error();
261
262 sock = fs_api.get_evs_by_url(&url);
263 if (!sock) {
264 LM_ERR("failed to get a socket for FS URL %.*s\n", url.len, url.s);
265 return init_mi_error(500, MI_SSTR("Internal Error"));
266 }
267
268 lock_start_write(db_reload_lk);
269
270 if (find_evs(sock) != 0) {
271 if (add_evs(sock) != 0) {
272 lock_stop_write(db_reload_lk);
273 fs_api.put_evs(sock);
274 LM_ERR("failed to ref socket\n");
275 return init_mi_error(501, MI_SSTR("Internal Error"));
276 }
277 } else {
278 /* we're already referencing this socket */
279 fs_api.put_evs(sock);
280 }
281
282 LM_DBG("found socket %s:%d for URL '%.*s'\n", sock->host.s, sock->port,
283 url.len, url.s);
284
285 if (get_mi_array_param(params, "events", &events, &no_events) < 0) {
286 lock_stop_write(db_reload_lk);
287 return init_mi_param_error();
288 }
289
290 for (i = 0; i < no_events; i++) {
291 if (get_mi_arr_param_string(events, i, &event_str.s, &event_str.len) < 0) {
292 resp = init_mi_param_error();
293 goto out_free;
294 }
295
296 if (ZSTR(event_str) || add_to_fss_sockets(sock, &event_str) <= 0)
297 continue;
298
299 li = pkg_malloc(sizeof *li);
300 if (!li) {
301 LM_ERR("oom\n");
302 resp = init_mi_error(502, MI_SSTR("Internal Error"));
303 goto out_free;
304 }
305 memset(li, 0, sizeof *li);

Callers

nothing calls this directly

Calls 9

get_mi_string_paramFunction · 0.85
init_mi_param_errorFunction · 0.85
init_mi_errorFunction · 0.85
find_evsFunction · 0.85
add_evsFunction · 0.85
get_mi_array_paramFunction · 0.85
get_mi_arr_param_stringFunction · 0.85
add_to_fss_socketsFunction · 0.85
_free_str_listFunction · 0.85

Tested by

no test coverage detected