Simplify the user-provided string so that it contains valid names without any duplicates. * It also sets the "saw" flags to a 1-relative count of which name was seen first. */
| 281 | /* Simplify the user-provided string so that it contains valid names without any duplicates. |
| 282 | * It also sets the "saw" flags to a 1-relative count of which name was seen first. */ |
| 283 | static int parse_nni_str(struct name_num_obj *nno, const char *from, char *tobuf, int tobuf_len) |
| 284 | { |
| 285 | char *to = tobuf, *tok = NULL; |
| 286 | int saw_tok = 0, cnt = 0; |
| 287 | |
| 288 | while (1) { |
| 289 | int at_space = isSpace(from); |
| 290 | char ch = *from++; |
| 291 | if (ch == '&') |
| 292 | ch = '\0'; |
| 293 | if (!ch || at_space) { |
| 294 | if (tok) { |
| 295 | struct name_num_item *nni = get_nni_by_name(nno, tok, to - tok); |
| 296 | if (nni && !nno->saw[nni->num]) { |
| 297 | nno->saw[nni->num] = ++cnt; |
| 298 | if (nni->main_nni) { |
| 299 | to = tok + strlcpy(tok, nni->main_nni->name, tobuf_len - (tok - tobuf)); |
| 300 | if (to - tobuf >= tobuf_len) { |
| 301 | to = tok - 1; |
| 302 | break; |
| 303 | } |
| 304 | } |
| 305 | } else |
| 306 | to = tok - (tok != tobuf); |
| 307 | saw_tok = 1; |
| 308 | tok = NULL; |
| 309 | } |
| 310 | if (!ch) |
| 311 | break; |
| 312 | continue; |
| 313 | } |
| 314 | if (!tok) { |
| 315 | if (to != tobuf) |
| 316 | *to++ = ' '; |
| 317 | tok = to; |
| 318 | } |
| 319 | if (to - tobuf >= tobuf_len - 1) { |
| 320 | to = tok - (tok != tobuf); |
| 321 | break; |
| 322 | } |
| 323 | *to++ = ch; |
| 324 | } |
| 325 | *to = '\0'; |
| 326 | |
| 327 | if (saw_tok && to == tobuf) |
| 328 | return strlcpy(tobuf, "INVALID", MAX_NSTR_STRLEN); |
| 329 | |
| 330 | return to - tobuf; |
| 331 | } |
| 332 | |
| 333 | static int parse_negotiate_str(struct name_num_obj *nno, char *tmpbuf) |
| 334 | { |
no test coverage detected