forgot to add msg module
This commit is contained in:
parent
a2e9dbdad1
commit
ce8c9bf266
4 changed files with 161 additions and 0 deletions
21
include/re_msg.h
Normal file
21
include/re_msg.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* @file re_msg.h Interface to generic message components
|
||||
*
|
||||
* Copyright (C) 2010 Creytiv.com
|
||||
*/
|
||||
|
||||
|
||||
/** Content-Type */
|
||||
struct msg_ctype {
|
||||
struct pl type;
|
||||
struct pl subtype;
|
||||
struct pl params;
|
||||
};
|
||||
|
||||
|
||||
int msg_ctype_decode(struct msg_ctype *ctype, const struct pl *pl);
|
||||
bool msg_ctype_cmp(const struct msg_ctype *ctype,
|
||||
const char *type, const char *subtype);
|
||||
|
||||
int msg_param_decode(const struct pl *pl, const char *name, struct pl *val);
|
||||
int msg_param_exists(const struct pl *pl, const char *name, struct pl *end);
|
62
src/msg/ctype.c
Normal file
62
src/msg/ctype.c
Normal file
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* @file ctype.c Content-Type decode
|
||||
*
|
||||
* Copyright (C) 2010 Creytiv.com
|
||||
*/
|
||||
#include <re_types.h>
|
||||
#include <re_fmt.h>
|
||||
#include <re_msg.h>
|
||||
|
||||
|
||||
/**
|
||||
* Decode a pointer-length string into Content-Type header
|
||||
*
|
||||
* @param ctype Content-Type header
|
||||
* @param pl Pointer-length string
|
||||
*
|
||||
* @return 0 for success, otherwise errorcode
|
||||
*/
|
||||
int msg_ctype_decode(struct msg_ctype *ctype, const struct pl *pl)
|
||||
{
|
||||
struct pl ws;
|
||||
|
||||
if (!ctype || !pl)
|
||||
return EINVAL;
|
||||
|
||||
if (re_regex(pl->p, pl->l,
|
||||
"[ \t\r\n]*[^ \t\r\n;/]+[ \t\r\n]*/[ \t\r\n]*[^ \t\r\n;]+"
|
||||
"[^]*",
|
||||
&ws, &ctype->type, NULL, NULL, &ctype->subtype,
|
||||
&ctype->params))
|
||||
return EBADMSG;
|
||||
|
||||
if (ws.p != pl->p)
|
||||
return EBADMSG;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compare Content-Type
|
||||
*
|
||||
* @param ctype Content-Type header
|
||||
* @param type Media type
|
||||
* @param subtype Media sub-type
|
||||
*
|
||||
* @return true if match, false if no match
|
||||
*/
|
||||
bool msg_ctype_cmp(const struct msg_ctype *ctype,
|
||||
const char *type, const char *subtype)
|
||||
{
|
||||
if (!ctype || !type || !subtype)
|
||||
return false;
|
||||
|
||||
if (pl_strcasecmp(&ctype->type, type))
|
||||
return false;
|
||||
|
||||
if (pl_strcasecmp(&ctype->subtype, subtype))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
8
src/msg/mod.mk
Normal file
8
src/msg/mod.mk
Normal file
|
@ -0,0 +1,8 @@
|
|||
#
|
||||
# mod.mk
|
||||
#
|
||||
# Copyright (C) 2010 Creytiv.com
|
||||
#
|
||||
|
||||
SRCS += msg/ctype.c
|
||||
SRCS += msg/param.c
|
70
src/msg/param.c
Normal file
70
src/msg/param.c
Normal file
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* @file param.c SIP Parameter decode
|
||||
*
|
||||
* Copyright (C) 2010 Creytiv.com
|
||||
*/
|
||||
#include <re_types.h>
|
||||
#include <re_fmt.h>
|
||||
#include <re_msg.h>
|
||||
|
||||
|
||||
/**
|
||||
* Check if a parameter exists
|
||||
*
|
||||
* @param pl Pointer-length string
|
||||
* @param name Parameter name
|
||||
* @param val Returned parameter value
|
||||
*
|
||||
* @return 0 for success, otherwise errorcode
|
||||
*/
|
||||
int msg_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 Parameter
|
||||
*
|
||||
* @param pl Pointer-length string
|
||||
* @param name Parameter name
|
||||
* @param val Returned parameter value
|
||||
*
|
||||
* @return 0 for success, otherwise errorcode
|
||||
*/
|
||||
int msg_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;
|
||||
}
|
Loading…
Add table
Reference in a new issue