patch: content-type parsing

- new module 'msg' for generic message handling (SIP, HTTP)
- decode content-type field in HTTP and SIP
This commit is contained in:
Alfred E. Heggestad 2014-02-21 20:37:46 +00:00
parent adb4dcf659
commit a2e9dbdad1
39 changed files with 56 additions and 95 deletions

View file

@ -18,7 +18,7 @@ include $(MK)
# List of modules
MODULES += sip sipevent sipreg sipsess
MODULES += uri http httpauth
MODULES += uri http httpauth msg
MODULES += stun turn ice
MODULES += natbd
MODULES += rtp sdp jbuf telev

View file

@ -40,6 +40,7 @@ Modules:
* mem stable Memory referencing
* mod testing Run-time module loading
* mqueue testing Thread-safe message queue
* msg unstable Generic message component library
* natbd unstable NAT Behavior Discovery using STUN
* net unstable Networking routines
* rtp testing Real-time Transport Protocol

View file

@ -15,6 +15,7 @@ extern "C" {
#include "re_types.h"
#include "re_fmt.h"
#include "re_mbuf.h"
#include "re_msg.h"
#include "re_list.h"
#include "re_sa.h"

View file

@ -81,7 +81,7 @@ struct http_msg {
uint16_t scode;
struct pl reason;
struct list hdrl;
struct pl ctype;
struct msg_ctype ctyp;
struct mbuf *mb;
uint32_t clen;
};

View file

@ -195,10 +195,10 @@ struct sip_msg {
struct sip_taddr to;
struct sip_taddr from;
struct sip_cseq cseq;
struct msg_ctype ctyp;
struct pl callid;
struct pl maxfwd;
struct pl expires;
struct pl ctype;
struct pl clen;
struct hash *hdrht;
struct mbuf *mb;
@ -346,8 +346,6 @@ void sip_msg_dump(const struct sip_msg *msg);
int sip_addr_decode(struct sip_addr *addr, const struct pl *pl);
int sip_via_decode(struct sip_via *via, const struct pl *pl);
int sip_cseq_decode(struct sip_cseq *cseq, const struct pl *pl);
int sip_param_decode(const struct pl *pl, const char *name, struct pl *val);
int sip_param_exists(const struct pl *pl, const char *name, struct pl *end);
/* keepalive */

View file

@ -12,6 +12,7 @@
#include <re_sa.h>
#include <re_list.h>
#include <re_fmt.h>
#include <re_msg.h>
#include <re_httpauth.h>
#include <re_http.h>

View file

@ -10,6 +10,7 @@
#include <re_list.h>
#include <re_hash.h>
#include <re_fmt.h>
#include <re_msg.h>
#include <re_http.h>
@ -94,6 +95,7 @@ static inline int hdr_add(struct http_msg *msg, const struct pl *name,
enum http_hdrid id, const char *p, ssize_t l)
{
struct http_hdr *hdr;
int err = 0;
hdr = mem_zalloc(sizeof(*hdr), hdr_destructor);
if (!hdr)
@ -110,7 +112,7 @@ static inline int hdr_add(struct http_msg *msg, const struct pl *name,
switch (id) {
case HTTP_HDR_CONTENT_TYPE:
msg->ctype = hdr->val;
err = msg_ctype_decode(&msg->ctyp, &hdr->val);
break;
case HTTP_HDR_CONTENT_LENGTH:
@ -121,7 +123,10 @@ static inline int hdr_add(struct http_msg *msg, const struct pl *name,
break;
}
return 0;
if (err)
mem_deref(hdr);
return err;
}

View file

@ -13,6 +13,7 @@
#include <re_tmr.h>
#include <re_tcp.h>
#include <re_tls.h>
#include <re_msg.h>
#include <re_http.h>

View file

@ -10,6 +10,7 @@
#include <re_uri.h>
#include <re_list.h>
#include <re_sa.h>
#include <re_msg.h>
#include <re_sip.h>

View file

@ -15,6 +15,7 @@
#include <re_md5.h>
#include <re_httpauth.h>
#include <re_udp.h>
#include <re_msg.h>
#include <re_sip.h>
#include "sip.h"

View file

@ -9,6 +9,7 @@
#include <re_uri.h>
#include <re_list.h>
#include <re_sa.h>
#include <re_msg.h>
#include <re_sip.h>

View file

@ -15,6 +15,7 @@
#include <re_sys.h>
#include <re_tmr.h>
#include <re_udp.h>
#include <re_msg.h>
#include <re_sip.h>
#include "sip.h"

View file

@ -15,6 +15,7 @@
#include <re_sys.h>
#include <re_tmr.h>
#include <re_udp.h>
#include <re_msg.h>
#include <re_sip.h>
#include "sip.h"

View file

@ -14,6 +14,7 @@
#include <re_sys.h>
#include <re_uri.h>
#include <re_udp.h>
#include <re_msg.h>
#include <re_sip.h>
#include "sip.h"

View file

@ -17,6 +17,7 @@
#include <re_tmr.h>
#include <re_udp.h>
#include <re_stun.h>
#include <re_msg.h>
#include <re_sip.h>
#include "sip.h"

View file

@ -12,7 +12,6 @@ SRCS += sip/dialog.c
SRCS += sip/keepalive.c
SRCS += sip/keepalive_udp.c
SRCS += sip/msg.c
SRCS += sip/param.c
SRCS += sip/reply.c
SRCS += sip/request.c
SRCS += sip/sip.c

View file

@ -14,6 +14,7 @@
#include <re_fmt.h>
#include <re_uri.h>
#include <re_udp.h>
#include <re_msg.h>
#include <re_sip.h>
#include "sip.h"
@ -198,7 +199,7 @@ static inline int hdr_add(struct sip_msg *msg, const struct pl *name,
if (err)
break;
(void)sip_param_decode(&msg->to.params, "tag", &msg->to.tag);
(void)msg_param_decode(&msg->to.params, "tag", &msg->to.tag);
msg->to.val = hdr->val;
break;
@ -208,7 +209,7 @@ static inline int hdr_add(struct sip_msg *msg, const struct pl *name,
if (err)
break;
(void)sip_param_decode(&msg->from.params, "tag",
(void)msg_param_decode(&msg->from.params, "tag",
&msg->from.tag);
msg->from.val = hdr->val;
break;
@ -226,7 +227,7 @@ static inline int hdr_add(struct sip_msg *msg, const struct pl *name,
break;
case SIP_HDR_CONTENT_TYPE:
msg->ctype = hdr->val;
err = msg_ctype_decode(&msg->ctyp, &hdr->val);
break;
case SIP_HDR_CONTENT_LENGTH:

View file

@ -1,74 +0,0 @@
/**
* @file param.c SIP Parameter decode
*
* Copyright (C) 2010 Creytiv.com
*/
#include <re_types.h>
#include <re_fmt.h>
#include <re_mbuf.h>
#include <re_list.h>
#include <re_uri.h>
#include <re_sa.h>
#include <re_sip.h>
/**
* Check if a SIP parameter exists
*
* @param pl Pointer-length string
* @param name SIP Parameter name
* @param val Returned parameter value
*
* @return 0 for success, otherwise errorcode
*/
int sip_param_exists(const struct pl *pl, const char *name, struct pl *val)
{
struct pl v1, v2;
char xpr[128];
if (!pl || !name || !val)
return EINVAL;
(void)re_snprintf(xpr, sizeof(xpr), ";[ \t\r\n]*%s[ \t\r\n;=]*", name);
if (re_regex(pl->p, pl->l, xpr, &v1, &v2))
return ENOENT;
if (!v2.l && v2.p < pl->p + pl->l)
return ENOENT;
val->p = v1.p - 1;
val->l = v2.p - val->p;
return 0;
}
/**
* Decode a SIP Parameter
*
* @param pl Pointer-length string
* @param name SIP Parameter name
* @param val Returned parameter value
*
* @return 0 for success, otherwise errorcode
*/
int sip_param_decode(const struct pl *pl, const char *name, struct pl *val)
{
char expr[128];
struct pl v;
if (!pl || !name || !val)
return EINVAL;
(void)re_snprintf(expr, sizeof(expr),
";[ \t\r\n]*%s[ \t\r\n]*=[ \t\r\n]*[~ \t\r\n;]+",
name);
if (re_regex(pl->p, pl->l, expr, NULL, NULL, NULL, &v))
return ENOENT;
*val = v;
return 0;
}

View file

@ -11,6 +11,7 @@
#include <re_fmt.h>
#include <re_uri.h>
#include <re_udp.h>
#include <re_msg.h>
#include <re_sip.h>
#include "sip.h"
@ -55,7 +56,7 @@ static int vreplyf(struct sip_strans **stp, struct mbuf **mbp, bool trans,
break;
}
if (!sip_param_exists(&msg->via.params, "rport", &rp)){
if (!msg_param_exists(&msg->via.params, "rport", &rp)){
err |= mbuf_write_pl_skip(mb, &hdr->val, &rp);
err |= mbuf_printf(mb, ";rport=%u",
sa_port(&msg->src));
@ -246,7 +247,7 @@ void sip_reply_addr(struct sa *addr, const struct sip_msg *msg, bool rport)
switch (msg->tp) {
case SIP_TRANSP_UDP:
if (!sip_param_decode(&msg->via.params, "maddr", &pl)) {
if (!msg_param_decode(&msg->via.params, "maddr", &pl)) {
(void)sa_set(addr, &pl,sip_transp_port(msg->tp, port));
break;
}

View file

@ -13,6 +13,7 @@
#include <re_uri.h>
#include <re_sys.h>
#include <re_udp.h>
#include <re_msg.h>
#include <re_sip.h>
#include "sip.h"
@ -607,7 +608,7 @@ int sip_request(struct sip_request **reqp, struct sip *sip, bool stateful,
if (err)
goto out;
if (sip_param_decode(&route->params, "maddr", &pl))
if (msg_param_decode(&route->params, "maddr", &pl))
pl = route->host;
err = pl_strdup(&req->host, &pl);
@ -621,7 +622,7 @@ int sip_request(struct sip_request **reqp, struct sip *sip, bool stateful,
req->resph = resph;
req->arg = arg;
if (!sip_param_decode(&route->params, "transport", &pl)) {
if (!msg_param_decode(&route->params, "transport", &pl)) {
if (!pl_strcasecmp(&pl, "udp"))
req->tp = SIP_TRANSP_UDP;

View file

@ -15,6 +15,7 @@
#include <re_tmr.h>
#include <re_udp.h>
#include <re_stun.h>
#include <re_msg.h>
#include <re_sip.h>
#include "sip.h"

View file

@ -14,6 +14,7 @@
#include <re_sys.h>
#include <re_tmr.h>
#include <re_udp.h>
#include <re_msg.h>
#include <re_sip.h>
#include "sip.h"

View file

@ -18,6 +18,7 @@
#include <re_stun.h>
#include <re_tcp.h>
#include <re_tls.h>
#include <re_msg.h>
#include <re_sip.h>
#include "sip.h"

View file

@ -9,6 +9,7 @@
#include <re_uri.h>
#include <re_list.h>
#include <re_sa.h>
#include <re_msg.h>
#include <re_sip.h>
@ -72,5 +73,5 @@ int sip_via_decode(struct sip_via *via, const struct pl *pl)
via->val = *pl;
return sip_param_decode(&via->params, "branch", &via->branch);
return msg_param_decode(&via->params, "branch", &via->branch);
}

View file

@ -12,6 +12,7 @@
#include <re_fmt.h>
#include <re_uri.h>
#include <re_tmr.h>
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipevent.h>
#include "sipevent.h"

View file

@ -9,6 +9,7 @@
#include <re_uri.h>
#include <re_list.h>
#include <re_sa.h>
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipevent.h>
@ -26,7 +27,7 @@ int sipevent_event_decode(struct sipevent_event *se, const struct pl *pl)
if (err)
return EBADMSG;
if (!sip_param_decode(&se->params, "id", &param))
if (!msg_param_decode(&se->params, "id", &param))
se->id = param;
else
se->id = pl_null;
@ -57,7 +58,7 @@ int sipevent_substate_decode(struct sipevent_substate *ss, const struct pl *pl)
else
ss->state = -1;
if (!sip_param_decode(&ss->params, "reason", &param)) {
if (!msg_param_decode(&ss->params, "reason", &param)) {
if (!pl_strcasecmp(&param, "deactivated"))
ss->reason = SIPEVENT_DEACTIVATED;
@ -78,12 +79,12 @@ int sipevent_substate_decode(struct sipevent_substate *ss, const struct pl *pl)
ss->reason = -1;
}
if (!sip_param_decode(&ss->params, "expires", &param))
if (!msg_param_decode(&ss->params, "expires", &param))
ss->expires = param;
else
ss->expires = pl_null;
if (!sip_param_decode(&ss->params, "retry-after", &param))
if (!msg_param_decode(&ss->params, "retry-after", &param))
ss->retry_after = param;
else
ss->retry_after = pl_null;

View file

@ -13,6 +13,7 @@
#include <re_uri.h>
#include <re_sys.h>
#include <re_tmr.h>
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipevent.h>
#include "sipevent.h"

View file

@ -13,6 +13,7 @@
#include <re_uri.h>
#include <re_sys.h>
#include <re_tmr.h>
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipevent.h>
#include "sipevent.h"

View file

@ -13,6 +13,7 @@
#include <re_uri.h>
#include <re_sys.h>
#include <re_tmr.h>
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipreg.h>
@ -155,7 +156,7 @@ static bool contact_handler(const struct sip_hdr *hdr,
if (pl_strcmp(&c.auri, uri))
return false;
if (!sip_param_decode(&c.params, "expires", &pval)) {
if (!msg_param_decode(&c.params, "expires", &pval)) {
reg->wait = pl_u32(&pval);
}
else if (pl_isset(&msg->expires))

View file

@ -12,6 +12,7 @@
#include <re_fmt.h>
#include <re_uri.h>
#include <re_tmr.h>
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipsess.h>
#include "sipsess.h"

View file

@ -12,6 +12,7 @@
#include <re_fmt.h>
#include <re_uri.h>
#include <re_tmr.h>
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipsess.h>
#include "sipsess.h"

View file

@ -12,6 +12,7 @@
#include <re_fmt.h>
#include <re_uri.h>
#include <re_tmr.h>
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipsess.h>
#include "sipsess.h"

View file

@ -13,6 +13,7 @@
#include <re_fmt.h>
#include <re_uri.h>
#include <re_tmr.h>
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipsess.h>
#include "sipsess.h"

View file

@ -12,6 +12,7 @@
#include <re_fmt.h>
#include <re_uri.h>
#include <re_tmr.h>
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipsess.h>
#include "sipsess.h"

View file

@ -12,6 +12,7 @@
#include <re_fmt.h>
#include <re_uri.h>
#include <re_tmr.h>
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipsess.h>
#include "sipsess.h"

View file

@ -12,6 +12,7 @@
#include <re_fmt.h>
#include <re_uri.h>
#include <re_tmr.h>
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipsess.h>
#include "sipsess.h"

View file

@ -12,6 +12,7 @@
#include <re_fmt.h>
#include <re_uri.h>
#include <re_tmr.h>
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipsess.h>
#include "sipsess.h"

View file

@ -12,6 +12,7 @@
#include <re_fmt.h>
#include <re_uri.h>
#include <re_tmr.h>
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipsess.h>
#include "sipsess.h"

View file

@ -12,6 +12,7 @@
#include <re_fmt.h>
#include <re_uri.h>
#include <re_tmr.h>
#include <re_msg.h>
#include <re_sip.h>
#include <re_sipsess.h>
#include "sipsess.h"