sip: struct sip_via: change transport type to enum sip_transp

sip: export sip_transp_port()
This commit is contained in:
Alfred E. Heggestad 2011-11-14 20:15:35 +00:00
parent 1838b1c844
commit 618eff733f
3 changed files with 21 additions and 9 deletions

View file

@ -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 */

View file

@ -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);

View file

@ -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;