MCPcopy Create free account
hub / github.com/SIPp/sipp / internal_find_header

Function internal_find_header

src/sip_parser.cpp:417–469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

415}
416
417static const char* internal_find_header(const char* msg, const char* name, const char* shortname,
418 bool content)
419{
420 const char *ptr = msg;
421 int namelen = strlen(name);
422 int shortnamelen = shortname ? strlen(shortname) : 0;
423
424 while (1) {
425 int is_short = 0;
426 /* RFC3261, 7.3.1: When comparing header fields, field names
427 * are always case-insensitive. Unless otherwise stated in
428 * the definition of a particular header field, field values,
429 * parameter names, and parameter values are case-insensitive.
430 * Tokens are always case-insensitive. Unless specified
431 * otherwise, values expressed as quoted strings are case-
432 * sensitive.
433 *
434 * Ergo, strcasecmp, because:
435 * To:...;tag=bla == TO:...;TAG=BLA
436 * But:
437 * Warning: "something" != Warning: "SoMeThInG"
438 */
439 if (strncasecmp(ptr, name, namelen) == 0 ||
440 (shortname && (is_short = 1) &&
441 strncasecmp(ptr, shortname, shortnamelen) == 0)) {
442 const char *tmp = ptr + (is_short ? strlen(shortname) : strlen(name));
443 while (*tmp == ' ' || *tmp == '\t') {
444 ++tmp;
445 }
446 if (*tmp == ':') {
447 /* Found */
448 if (content) {
449 /* We just want the content */
450 ptr = internal_skip_lws(tmp + 1);
451 }
452 break;
453 }
454 }
455
456 /* Seek to next line, but not past EOH */
457 ptr = strchr(ptr, '\n');
458 if (!ptr || ptr[-1] != '\r' || (ptr[1] == '\r' && ptr[2] == '\n')) {
459 if (ptr && ptr[-1] != '\r') {
460 WARNING("Missing CR during header scan at pos %d", int(ptr - msg));
461 /* continue? */
462 }
463 return nullptr;
464 }
465 ++ptr;
466 }
467
468 return ptr;
469}
470
471static const char* internal_hdrchr(const char* ptr, const char needle)
472{

Callers 3

get_peer_tagFunction · 0.85
get_call_idFunction · 0.85
TESTFunction · 0.85

Calls 2

internal_skip_lwsFunction · 0.85
WARNINGFunction · 0.85

Tested by

no test coverage detected