diff --git a/include/re_sip.h b/include/re_sip.h index 5e78a5e..f4fce22 100644 --- a/include/re_sip.h +++ b/include/re_sip.h @@ -309,6 +309,8 @@ const struct sip_hdr *sip_msg_xhdr(const struct sip_msg *msg, const struct sip_hdr *sip_msg_xhdr_apply(const struct sip_msg *msg, bool fwd, const char *name, sip_hdr_h *h, void *arg); +uint32_t sip_msg_hdr_count(const struct sip_msg *msg, enum sip_hdrid id); +uint32_t sip_msg_xhdr_count(const struct sip_msg *msg, const char *name); struct tcp_conn *sip_msg_tcpconn(const struct sip_msg *msg); void sip_msg_dump(const struct sip_msg *msg); diff --git a/src/sip/msg.c b/src/sip/msg.c index fa3b876..ae2dd9a 100644 --- a/src/sip/msg.c +++ b/src/sip/msg.c @@ -501,6 +501,39 @@ const struct sip_hdr *sip_msg_xhdr_apply(const struct sip_msg *msg, } +static bool count_handler(const struct sip_hdr *hdr, const struct sip_msg *msg, + void *arg) +{ + uint32_t *n = arg; + (void)hdr; + (void)msg; + + ++(*n); + + return false; +} + + +uint32_t sip_msg_hdr_count(const struct sip_msg *msg, enum sip_hdrid id) +{ + uint32_t n = 0; + + sip_msg_hdr_apply(msg, true, id, count_handler, &n); + + return n; +} + + +uint32_t sip_msg_xhdr_count(const struct sip_msg *msg, const char *name) +{ + uint32_t n = 0; + + sip_msg_xhdr_apply(msg, true, name, count_handler, &n); + + return n; +} + + void sip_msg_dump(const struct sip_msg *msg) { struct le *le;