From 37e7252269c49af4c75d8d4f41ea164a8527154c Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Thu, 19 Nov 2015 22:27:20 +0000 Subject: [PATCH] Add ability to print SIP trace --- include/re_sip.h | 4 ++++ src/sip/sip.c | 9 +++++++++ src/sip/sip.h | 1 + src/sip/transp.c | 10 ++++++++++ 4 files changed, 24 insertions(+) diff --git a/include/re_sip.h b/include/re_sip.h index 9a2af7a..ca71cfc 100644 --- a/include/re_sip.h +++ b/include/re_sip.h @@ -241,6 +241,9 @@ typedef int(sip_auth_h)(char **username, char **password, const char *realm, typedef bool(sip_hdr_h)(const struct sip_hdr *hdr, const struct sip_msg *msg, void *arg); typedef void(sip_keepalive_h)(int err, void *arg); +typedef void(sip_trace_h)(bool tx, enum sip_transp tp, + const struct sa *src, const struct sa *dst, + const uint8_t *pkt, size_t len, void *arg); /* sip */ @@ -253,6 +256,7 @@ int sip_listen(struct sip_lsnr **lsnrp, struct sip *sip, bool req, int sip_debug(struct re_printf *pf, const struct sip *sip); int sip_send(struct sip *sip, void *sock, enum sip_transp tp, const struct sa *dst, struct mbuf *mb); +void sip_set_trace(struct sip *sip, sip_trace_h *traceh); /* transport */ diff --git a/src/sip/sip.c b/src/sip/sip.c index 651628c..d7e9fad 100644 --- a/src/sip/sip.c +++ b/src/sip/sip.c @@ -236,3 +236,12 @@ int sip_debug(struct re_printf *pf, const struct sip *sip) return err; } + + +void sip_set_trace(struct sip *sip, sip_trace_h *traceh) +{ + if (!sip) + return; + + sip->traceh = traceh; +} diff --git a/src/sip/sip.h b/src/sip/sip.h index 912c69b..f9ef7f2 100644 --- a/src/sip/sip.h +++ b/src/sip/sip.h @@ -18,6 +18,7 @@ struct sip { struct stun *stun; char *software; sip_exit_h *exith; + sip_trace_h *traceh; void *arg; bool closing; }; diff --git a/src/sip/transp.c b/src/sip/transp.c index dd3b7c4..acd3927 100644 --- a/src/sip/transp.c +++ b/src/sip/transp.c @@ -236,6 +236,11 @@ static void sip_recv(struct sip *sip, const struct sip_msg *msg) { struct le *le = sip->lsnrl.head; + if (sip->traceh) { + sip->traceh(false, msg->tp, &msg->src, &msg->dst, + msg->mb->buf, msg->mb->end, sip->arg); + } + while (le) { struct sip_lsnr *lsnr = le->data; @@ -724,6 +729,11 @@ int sip_transp_send(struct sip_connqent **qentp, struct sip *sip, void *sock, if (!sip || !dst || !mb) return EINVAL; + if (sip->traceh) { + sip->traceh(true, tp, NULL, dst, + mbuf_buf(mb), mbuf_get_left(mb), sip->arg); + } + switch (tp) { case SIP_TRANSP_UDP: