| 154 | } |
| 155 | |
| 156 | static mi_request_t *mi_script_parse_request(str *method, str *params, |
| 157 | pv_spec_p attrs, pv_spec_p vals, int shared) |
| 158 | { |
| 159 | static mi_request_t static_req; |
| 160 | mi_request_t *req = NULL; |
| 161 | struct usr_avp *v_avp = NULL; |
| 162 | struct usr_avp *a_avp = NULL; |
| 163 | int_str avp_val, avp_val_v; |
| 164 | unsigned int tmp; |
| 165 | cJSON *val; |
| 166 | char *p; |
| 167 | |
| 168 | if (shared) { |
| 169 | req = shm_malloc(sizeof *req); |
| 170 | if (!req) { |
| 171 | LM_ERR("oom for new request\n"); |
| 172 | return NULL; |
| 173 | } |
| 174 | _init_mi_shm_mem_hooks(); |
| 175 | } else { |
| 176 | req = &static_req; |
| 177 | _init_mi_sys_mem_hooks(); |
| 178 | } |
| 179 | memset(req, 0, sizeof *req); |
| 180 | |
| 181 | req->req_obj = cJSON_CreateObject(); |
| 182 | if (!req->req_obj) { |
| 183 | LM_ERR("Failed to build temporary json request\n"); |
| 184 | goto error; |
| 185 | } |
| 186 | |
| 187 | /* if no parameters whatso ever */ |
| 188 | if (!attrs && !vals && params->len == 0) |
| 189 | return req; |
| 190 | |
| 191 | /* if they specified only vals, but not attributes |
| 192 | * swap them as a best effort chance to run the command */ |
| 193 | if (!attrs && vals) { |
| 194 | attrs = vals; |
| 195 | vals = NULL; |
| 196 | } |
| 197 | |
| 198 | if (vals) |
| 199 | req->params = cJSON_CreateObject(); |
| 200 | else |
| 201 | req->params = cJSON_CreateArray(); |
| 202 | if (!req->params) { |
| 203 | LM_ERR("Failed to build temporary json params\n"); |
| 204 | goto error; |
| 205 | } |
| 206 | cJSON_AddItemToObject(req->req_obj, JSONRPC_PARAMS_S, req->params); |
| 207 | |
| 208 | if (!attrs) { |
| 209 | /* parameters are in command */ |
| 210 | do { |
| 211 | trim_leading(params); |
| 212 | p = q_memchr(params->s, ' ', params->len); |
| 213 | avp_val.s = *params; |
no test coverage detected