Skip to content

Commit

Permalink
Add ability to print SIP trace
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredh authored and traviscross committed Jul 12, 2016
1 parent c71d858 commit 37e7252
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/re_sip.h
Expand Up @@ -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 */
Expand All @@ -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 */
Expand Down
9 changes: 9 additions & 0 deletions src/sip/sip.c
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/sip/sip.h
Expand Up @@ -18,6 +18,7 @@ struct sip {
struct stun *stun;
char *software;
sip_exit_h *exith;
sip_trace_h *traceh;
void *arg;
bool closing;
};
Expand Down
10 changes: 10 additions & 0 deletions src/sip/transp.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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:
Expand Down

1 comment on commit 37e7252

@garun2536
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

37r7252

Please sign in to comment.