| 957 | |
| 958 | |
| 959 | mi_response_t *w_mi_raise_event(const mi_params_t *params, |
| 960 | struct mi_handler *async_hdl) |
| 961 | { |
| 962 | int no; |
| 963 | str event_s; |
| 964 | str tparams; |
| 965 | event_id_t id; |
| 966 | mi_item_t *values; |
| 967 | evi_params_p eparams = NULL; |
| 968 | |
| 969 | if (get_mi_string_param(params, "event", &event_s.s, &event_s.len) < 0) |
| 970 | return init_mi_param_error(); |
| 971 | |
| 972 | id = evi_get_id(&event_s); |
| 973 | if (id == EVI_ERROR) |
| 974 | return init_mi_error(404, MI_SSTR("Event not registered")); |
| 975 | |
| 976 | /* check if there are any subscribers */ |
| 977 | if (!evi_probe_event(id)) |
| 978 | return init_mi_error(480, MI_SSTR("Temporarily Unavailable")); |
| 979 | |
| 980 | /* check to see if we have an array params, or key-value one */ |
| 981 | switch (try_get_mi_array_param(params, "params", &values, &no)) { |
| 982 | case -1: |
| 983 | case -3: |
| 984 | /* no params used */ |
| 985 | break; |
| 986 | case -2: |
| 987 | /* not an array - most likely it's a string */ |
| 988 | if (get_mi_string_param(params, "params", &tparams.s, &tparams.len) < 0) |
| 989 | return init_mi_error(400, MI_SSTR("No Params")); |
| 990 | eparams = mi_raise_event_json_params(&tparams); |
| 991 | if (!eparams) |
| 992 | return init_mi_error(400, MI_SSTR("Bad Params")); |
| 993 | break; |
| 994 | case 0: |
| 995 | /* this is an array - push it like this */ |
| 996 | eparams = mi_raise_event_array_params(values, no); |
| 997 | if (!eparams) |
| 998 | return init_mi_error(400, MI_SSTR("Bad Params")); |
| 999 | break; |
| 1000 | } |
| 1001 | |
| 1002 | if (evi_dispatch_event( id, eparams)<0) { |
| 1003 | LM_ERR("could not dispatch raise event job!\n"); |
| 1004 | goto error; |
| 1005 | } |
| 1006 | |
| 1007 | return init_mi_result_ok(); |
| 1008 | error: |
| 1009 | if (eparams) |
| 1010 | evi_free_params(eparams); |
| 1011 | return init_mi_error(500, MI_SSTR("Cannot Raise Event")); |
| 1012 | } |
nothing calls this directly
no test coverage detected