diff --git a/include/re_sip.h b/include/re_sip.h index e6dd358..8d946a3 100644 --- a/include/re_sip.h +++ b/include/re_sip.h @@ -136,12 +136,12 @@ enum { struct sip_via { - struct pl transp; struct pl sentby; struct sa addr; struct pl params; struct pl branch; struct pl val; + enum sip_transp tp; }; struct sip_addr { @@ -231,19 +231,23 @@ typedef void(sip_keepalive_h)(int err, void *arg); int sip_alloc(struct sip **sipp, struct dnsc *dnsc, uint32_t ctsz, uint32_t stsz, uint32_t tcsz, const char *software, sip_exit_h *exith, void *arg); -int sip_transp_add(struct sip *sip, enum sip_transp tp, - const struct sa *laddr, ...); -void sip_transp_flush(struct sip *sip); -bool sip_transp_isladdr(const struct sip *sip, enum sip_transp tp, - const struct sa *laddr); void sip_close(struct sip *sip, bool force); int sip_listen(struct sip_lsnr **lsnrp, struct sip *sip, bool req, sip_msg_h *msgh, void *arg); 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); + + +/* transport */ +int sip_transp_add(struct sip *sip, enum sip_transp tp, + const struct sa *laddr, ...); +void sip_transp_flush(struct sip *sip); +bool sip_transp_isladdr(const struct sip *sip, enum sip_transp tp, + const struct sa *laddr); const char *sip_transp_name(enum sip_transp tp); const char *sip_transp_param(enum sip_transp tp); +uint16_t sip_transp_port(enum sip_transp tp, uint16_t port); /* request */ diff --git a/src/sip/sip.h b/src/sip/sip.h index bbe8397..1551539 100644 --- a/src/sip/sip.h +++ b/src/sip/sip.h @@ -74,7 +74,6 @@ int sip_transp_laddr(struct sip *sip, struct sa *laddr, enum sip_transp tp, bool sip_transp_supported(struct sip *sip, enum sip_transp tp, int af); const char *sip_transp_srvid(enum sip_transp tp); bool sip_transp_reliable(enum sip_transp tp); -uint16_t sip_transp_port(enum sip_transp tp, uint16_t port); int sip_transp_debug(struct re_printf *pf, const struct sip *sip); diff --git a/src/sip/via.c b/src/sip/via.c index a57b103..c99cd1d 100644 --- a/src/sip/via.c +++ b/src/sip/via.c @@ -28,7 +28,7 @@ static int decode_hostport(const struct pl *hostport, struct pl *host, int sip_via_decode(struct sip_via *via, const struct pl *pl) { - struct pl host, port; + struct pl transp, host, port; int err; if (!via || !pl) @@ -37,11 +37,20 @@ int sip_via_decode(struct sip_via *via, const struct pl *pl) err = re_regex(pl->p, pl->l, "SIP[ \t\r\n]*/[ \t\r\n]*2.0[ \t\r\n]*/[ \t\r\n]*" "[A-Z]+[ \t\r\n]*[^; \t\r\n]+[ \t\r\b]*[^]*", - NULL, NULL, NULL, NULL, &via->transp, + NULL, NULL, NULL, NULL, &transp, NULL, &via->sentby, NULL, &via->params); if (err) return err; + if (!pl_strcmp(&transp, "TCP")) + via->tp = SIP_TRANSP_TCP; + else if (!pl_strcmp(&transp, "TLS")) + via->tp = SIP_TRANSP_TLS; + else if (!pl_strcmp(&transp, "UDP")) + via->tp = SIP_TRANSP_UDP; + else + via->tp = SIP_TRANSP_NONE; + err = decode_hostport(&via->sentby, &host, &port); if (err) return err;