diff --git a/include/re_fmt.h b/include/re_fmt.h index ff694dea5..bb64be49b 100644 --- a/include/re_fmt.h +++ b/include/re_fmt.h @@ -46,6 +46,7 @@ int pl_strcpy(const struct pl *pl, char *str, size_t size); int pl_strdup(char **dst, const struct pl *src); int pl_dup(struct pl *dst, const struct pl *src); int pl_strcmp(const struct pl *pl, const char *str); +int pl_strncmp(const struct pl *pl, const char *str, size_t n); int pl_strcasecmp(const struct pl *pl, const char *str); int pl_cmp(const struct pl *pl1, const struct pl *pl2); int pl_casecmp(const struct pl *pl1, const struct pl *pl2); diff --git a/include/re_sip.h b/include/re_sip.h index 5e892721a..f9c171765 100644 --- a/include/re_sip.h +++ b/include/re_sip.h @@ -150,6 +150,7 @@ enum { /** SIP Via header */ +#define RE_RFC3261_BRANCH_ID "z9hG4bK" struct sip_via { struct pl sentby; struct sa addr; diff --git a/src/fmt/pl.c b/src/fmt/pl.c index 72ebfa4e8..47057236f 100644 --- a/src/fmt/pl.c +++ b/src/fmt/pl.c @@ -536,6 +536,28 @@ int pl_strcmp(const struct pl *pl, const char *str) } +/** + * Compare n characters of a pointer-length object with a NULL-terminated + * string (case-sensitive) + * + * @param pl Pointer-length object + * @param str NULL-terminated string + * @param n number of characters that should be compared + * + * @return 0 if match, otherwise errorcode + */ +int pl_strncmp(const struct pl *pl, const char *str, size_t n) +{ + if (!pl_isset(pl) || !str || !n) + return EINVAL; + + if (pl->l < n) + return EINVAL; + + return strncmp(pl->p, str, n) == 0 ? 0 : EINVAL; +} + + /** * Compare a pointer-length object with a NULL-terminated string * (case-insensitive)