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

Function parse_extra_token

modules/acc/acc_extra.c:234–291  ·  view source on GitHub ↗

* from a token in form of * tag->value extract the tag and the value * @param token * @param tag reference * @param value reference * @return 0 (success) / < 0 (error) * * tag and value must be allocated beforehand */

Source from the content-addressed store, hash-verified

232 * tag and value must be allocated beforehand
233 */
234static int parse_extra_token(str* token, str* tag, str* value)
235{
236
237 /* insanity checks */
238 if (token == NULL || token->len == 0 || token->s == NULL
239 || tag == NULL || value == NULL) {
240 LM_ERR("bad input!\n");
241 return -1;
242 }
243
244 /* remove tabs, newlines etc */
245 while ( token->s[0] == '\n' || token->s[0] == '\t' || token->s[0] == ' ') {
246 token->s++;
247 token->len--;
248 }
249
250 /* value will not point exactly where the value is
251 * will point where the - character from the '->' delimiter will be */
252 if ((value->s = str_strstr(token, &tag_delim)) == NULL) {
253 /* if not found then the value is the same as the token */
254 str_trim_spaces_lr(*token);
255
256 /**
257 * FIXME null terminate the string
258 * quite insane to do this but it should be safe because after the token
259 * it's either a delimiter for another token or a '\0' that
260 * terminates the string
261 */
262 token->s[token->len] = 0;
263 *value = *tag = *token;
264 } else {
265 tag->s = token->s;
266 tag->len = value->s - token->s;
267
268 /* jump over '->' delimiter */
269 value->s += tag_delim.len;
270 value->len = token->len - (value->s - token->s);
271
272 str_trim_spaces_lr(*tag);
273 str_trim_spaces_lr(*value);
274
275 /**
276 * FIXME null terminate the string
277 * safe because after the tag it's the tag-value delimiter
278 */
279 tag->s[tag->len] = 0;
280
281 /**
282 * FIXME null terminate the string
283 * quite insane to do this but it should be safe because after the token
284 * it's either a delimiter for another token or a '\0' that
285 * terminates the string
286 */
287 value->s[value->len] = 0;
288 }
289
290 return 0;
291}

Callers 1

parse_acc_list_genericFunction · 0.85

Calls 1

str_strstrFunction · 0.85

Tested by

no test coverage detected