Commit 32f8d5eb authored by Pekka Pessi's avatar Pekka Pessi
Browse files

Using SOFIAPUBFUN in msg_header.h. Avoiding use of msg_param_t where possible.

API CHANGE:
Allowing NULL as message public pointer (using default) in calls to
msg_serialize(), msg_header_add(), msg_header_prepend(),
msg_header_add_dup(), msg_header_add_dup_as(), msg_header_add_make(),
msg_header_add_str(), msg_header_insert(), msg_header_remove(),
msg_header_remove_all(), and msg_header_replace().

darcs-hash:20060317124545-65a35-7fb9a54b61290db26d445feebbbc8ecb26b96479.gz
parent 72a20157
......@@ -1411,9 +1411,12 @@ static int msg_header_prepare(msg_mclass_t const *, int flags,
* @relates msg_s
*
* The function msg_prepare() prepares a message for sending. It encodes all
* serialized fragments in the message. In each fragment, the
* msg_common_s::h_data field will point to the encoding result of size
* msg_common_s::h_len bytes.
* serialized fragments in the message. You have to call msg_serialize()
* before calling msg_headers_prepare() in order to make sure that all the
* heades and other message fragments are included in the chain.
*
* After encoding, the msg_common_s::h_data field will point to the encoding
* result of size msg_common_s::h_len bytes in in each fragment.
*
* When multiple header fields are represented as a comma-separated list
* within a single header line, the first fragment in the header will
......@@ -1422,6 +1425,8 @@ static int msg_header_prepare(msg_mclass_t const *, int flags,
* points to the end of the line.
*
* @return Total size of the encoded message in bytes, or -1 upon an error.
*
* @sa msg_extract(), msg_serialize()
*/
int msg_prepare(msg_t *msg)
{
......@@ -1696,8 +1701,12 @@ int msg_serialize(msg_t *msg, msg_pub_t *pub)
msg_mclass_t const *mc = msg->m_class;
msg_header_t **tail, ***ptail;
if (!msg || !pub)
if (!msg)
return errno = EINVAL, -1;
if (pub == NULL)
pub = msg->m_object;
/* There must be a first line */
if (pub->msg_request)
h = pub->msg_request;
else if (pub->msg_status)
......@@ -1894,19 +1903,25 @@ int msg_iovec(msg_t *msg, msg_iovec_t vec[], int veclen)
*
* @param msg message object [IN]
* @param pub public message structure [IN/OUT]
* @param prepend if true, add before same type of headers (instead after them)
* @param head head of chain
* @param h header to insert
*
*/
static
void msg_insert_chain(msg_t *msg, msg_pub_t *pub, int prepend,
msg_header_t **head, msg_header_t *h)
void msg_insert_chain(msg_t *msg,
msg_pub_t *pub,
int prepend,
msg_header_t **head,
msg_header_t *h)
{
msg_mclass_t const *mc = msg->m_class;
msg_header_t **hh;
msg_header_t **separator;
msg_header_t **payload;
assert(msg && pub && head && h);
separator = (msg_header_t **)((char *)pub + mc->mc_separator->hr_offset);
payload = (msg_header_t **)((char *)pub + mc->mc_payload->hr_offset);
......@@ -2116,11 +2131,10 @@ int msg_header_add(msg_t *msg,
{
msg_header_t **head, *old = NULL, *end;
assert(msg && pub);
if (msg == NULL || pub == NULL ||
h == NULL || h == MSG_HEADER_NONE || hh == NULL)
if (msg == NULL || h == NULL || h == MSG_HEADER_NONE || hh == NULL)
return -1;
if (pub == NULL)
pub = msg->m_object;
head = _msg_chain_head(msg);
......@@ -2190,9 +2204,10 @@ int msg_header_prepend(msg_t *msg,
assert(msg && pub);
if (msg == NULL || pub == NULL ||
h == NULL || h == MSG_HEADER_NONE || hh == NULL)
if (msg == NULL || h == NULL || h == MSG_HEADER_NONE || hh == NULL)
return -1;
if (pub == NULL)
pub = msg->m_object;
head = _msg_chain_head(msg);
......@@ -2310,11 +2325,12 @@ int msg_header_add_dup(msg_t *msg,
msg_header_t *h, **hh = NULL;
msg_hclass_t *hc = NULL;
if (msg == NULL || msg == NULL)
if (msg == NULL)
return -1;
if (src == (msg_header_t *)-1)
if (src == NULL || src == MSG_HEADER_NONE)
return 0;
if (pub == NULL)
pub = msg->m_object;
for ( ;src; src = src->sh_next) {
assert(src->sh_class);
......@@ -2398,11 +2414,12 @@ int msg_header_add_dup_as(msg_t *msg,
msg_hclass_t *hc,
msg_header_t const *src)
{
if (src == (msg_header_t *)-1)
return 0;
if (msg == NULL || msg == NULL || src == NULL)
if (msg == NULL || hc == NULL)
return -1;
if (src == NULL || src == MSG_HEADER_NONE)
return 0;
if (pub == NULL)
pub = msg->m_object;
return _msg_header_add_dup_as(msg, pub, hc, src);
}
......@@ -2457,6 +2474,8 @@ int msg_header_add_make(msg_t *msg,
if (msg == NULL)
return -1;
if (pub == NULL)
pub = msg->m_object;
hh = msg_hclass_offset(msg->m_class, pub, hc);
......@@ -2507,9 +2526,11 @@ int msg_header_add_str(msg_t *msg,
{
char *s;
if (!msg || !pub)
if (!msg)
return -1;
if (!str || !str[0])
if (pub == NULL)
pub = msg->m_object;
if (!str)
return 0;
s = su_strdup(msg_home(msg), str);
......@@ -2565,9 +2586,11 @@ int msg_header_insert(msg_t *msg, msg_pub_t *pub, msg_header_t *h)
assert(msg);
if (h == NULL || h == MSG_HEADER_NONE || h->sh_class == NULL ||
msg == NULL || pub == NULL)
if (msg == NULL || h == NULL || h == MSG_HEADER_NONE ||
h->sh_class == NULL)
return -1;
if (pub == NULL)
pub = msg->m_object;
hh = msg_hclass_offset(msg->m_class, pub, h->sh_class);
......@@ -2589,9 +2612,11 @@ int msg_header_remove(msg_t *msg, msg_pub_t *pub, msg_header_t *h)
{
msg_header_t **hh, **hh0;
if (h == NULL || h == MSG_HEADER_NONE ||
msg == NULL || h->sh_class == NULL)
if (msg == NULL || h == NULL || h == MSG_HEADER_NONE ||
h->sh_class == NULL)
return -1;
if (pub == NULL)
pub = msg->m_object;
/* First, remove from public structure (msg_pub_t) */
hh0 = msg_hclass_offset(msg->m_class, pub, h->sh_class);
......@@ -2635,9 +2660,12 @@ int msg_header_remove_all(msg_t *msg, msg_pub_t *pub, msg_header_t *h)
{
msg_header_t **hh, **hh0;
void const *data;
if (h == NULL || h == MSG_HEADER_NONE ||
msg == NULL || h->sh_class == NULL)
if (msg == NULL || h == NULL || h == MSG_HEADER_NONE ||
h->sh_class == NULL)
return -1;
if (pub == NULL)
pub = msg->m_object;
hh0 = msg_hclass_offset(msg->m_class, pub, h->sh_class);
if (!hh0)
......@@ -2687,13 +2715,12 @@ int msg_header_replace(msg_t *msg,
{
msg_header_t *h0, *last, **hh, **hh0;
assert(msg);
if (msg == NULL || pub == NULL || replaced == NULL)
if (msg == NULL || replaced == NULL)
return -1;
if (h == NULL || h == MSG_HEADER_NONE || h->sh_class == NULL)
return msg_header_remove(msg, pub, replaced);
if (pub == NULL)
pub = msg->m_object;
hh = hh0 = msg_hclass_offset(msg->m_class, pub, h->sh_class);
if (hh == NULL)
......
......@@ -1093,8 +1093,8 @@ int msg_params_remove(msg_param_t *params, msg_param_t param)
return 0;
}
/** Calculate lenght of a parameter list */
size_t msg_params_length(msg_param_t const params[])
/** Calculate number of parameters in a parameter list */
size_t msg_params_length(char const * const * params)
{
size_t len;
......@@ -1273,7 +1273,7 @@ int msg_params_join(su_home_t *home,
* @retval an integer zero if @a match with @a b
* @retval an integer greater than zero if @a is greater than @a b
*/
int msg_params_cmp(msg_param_t const a[], msg_param_t const b[])
int msg_params_cmp(char const * const a[], char const * const b[])
{
int c;
int nlen;
......
......@@ -47,100 +47,133 @@
#ifndef MSG_H
#include <sofia-sip/msg.h>
#endif
#ifndef URL_H
#include <sofia-sip/url.h>
#endif
SOFIA_BEGIN_DECLS
msg_header_t *msg_header_alloc(su_home_t *, msg_hclass_t *hc, int extra)
SOFIAPUBFUN msg_header_t *msg_header_alloc(su_home_t *,
msg_hclass_t *hc,
int extra)
__attribute__((__malloc__));
int msg_header_size(msg_header_t const *h);
msg_header_t **msg_header_offset(msg_t const *, msg_pub_t const *, msg_header_t const *);
msg_header_t **msg_hclass_offset(msg_mclass_t const *,
msg_pub_t const *, msg_hclass_t *);
msg_header_t *msg_header_access(msg_pub_t const *pub, msg_hclass_t *hc);
SOFIAPUBFUN int msg_header_size(msg_header_t const *h);
SOFIAPUBFUN msg_header_t **msg_header_offset(msg_t const *,
msg_pub_t const *,
msg_header_t const *);
SOFIAPUBFUN msg_header_t **msg_hclass_offset(msg_mclass_t const *,
msg_pub_t const *,
msg_hclass_t *);
SOFIAPUBFUN msg_header_t *msg_header_access(msg_pub_t const *pub,
msg_hclass_t *hc);
msg_header_t *msg_header_copy_as(su_home_t *home,
SOFIAPUBFUN msg_header_t *msg_header_copy_as(su_home_t *home,
msg_hclass_t *hc,
msg_header_t const *o)
__attribute__((__malloc__));
msg_header_t *msg_header_copy(su_home_t *home, msg_header_t const *o)
SOFIAPUBFUN msg_header_t *msg_header_copy(su_home_t *home,
msg_header_t const *o)
__attribute__((__malloc__));
msg_header_t *msg_header_copy_one(su_home_t *home, msg_header_t const *o)
SOFIAPUBFUN msg_header_t *msg_header_copy_one(su_home_t *home,
msg_header_t const *o)
__attribute__((__malloc__));
msg_header_t *msg_header_dup_as(su_home_t *home, msg_hclass_t *hc,
SOFIAPUBFUN msg_header_t *msg_header_dup_as(su_home_t *home,
msg_hclass_t *hc,
msg_header_t const *o)
__attribute__((__malloc__));
msg_header_t *msg_header_dup(su_home_t *home, msg_header_t const *h)
SOFIAPUBFUN msg_header_t *msg_header_dup(su_home_t *home,
msg_header_t const *h)
__attribute__((__malloc__));
msg_header_t *msg_header_dup_one(su_home_t *home, msg_header_t const *h)
SOFIAPUBFUN msg_header_t *msg_header_dup_one(su_home_t *home,
msg_header_t const *h)
__attribute__((__malloc__));
msg_header_t *msg_header_d(su_home_t *home, msg_t const *msg, char const *b);
int msg_header_e(char b[], int bsiz, msg_header_t const *h, int flags);
int msg_object_e(char b[], int size, msg_pub_t const *mo, int flags);
int msg_header_field_e(char b[], int bsiz, msg_header_t const *h, int flags);
int msg_copy_all(msg_t *msg, msg_pub_t *dst, msg_pub_t const *src);
int msg_header_remove(msg_t *msg, msg_pub_t *mo, msg_header_t *h);
int msg_header_remove_all(msg_t *msg, msg_pub_t *mo, msg_header_t *h);
SOFIAPUBFUN msg_header_t *msg_header_d(su_home_t *home,
msg_t const *msg,
char const *b);
SOFIAPUBFUN int msg_header_e(char b[], int bsiz,
msg_header_t const *h,
int flags);
SOFIAPUBFUN int msg_object_e(char b[], int size,
msg_pub_t const *mo,
int flags);
SOFIAPUBFUN int msg_header_field_e(char b[], int bsiz,
msg_header_t const *h,
int flags);
SOFIAPUBFUN int msg_copy_all(msg_t *msg,
msg_pub_t *dst,
msg_pub_t const *src);
SOFIAPUBFUN int msg_header_remove(msg_t *msg,
msg_pub_t *mo,
msg_header_t *h);
SOFIAPUBFUN int msg_header_remove_all(msg_t *msg,
msg_pub_t *mo,
msg_header_t *h);
int msg_header_insert(msg_t *msg, msg_pub_t *mo, msg_header_t *h);
SOFIAPUBFUN int msg_header_insert(msg_t *msg, msg_pub_t *mo,
msg_header_t *h);
int msg_header_replace(msg_t *msg, msg_pub_t *mo,
SOFIAPUBFUN int msg_header_replace(msg_t *msg, msg_pub_t *mo,
msg_header_t *old_header,
msg_header_t *new_header);
int msg_header_add_dup(msg_t *msg,
SOFIAPUBFUN int msg_header_add_dup(msg_t *msg,
msg_pub_t *pub,
msg_header_t const *o);
int msg_header_add_str(msg_t *msg,
SOFIAPUBFUN int msg_header_add_str(msg_t *msg,
msg_pub_t *pub,
char const *str);
int msg_header_add_dup_as(msg_t *msg,
SOFIAPUBFUN int msg_header_add_dup_as(msg_t *msg,
msg_pub_t *pub,
msg_hclass_t *hc,
msg_header_t const *o);
int msg_header_add_make(msg_t *msg,
SOFIAPUBFUN int msg_header_add_make(msg_t *msg,
msg_pub_t *pub,
msg_hclass_t *hc,
char const *s);
int msg_header_prepend(msg_t *msg,
SOFIAPUBFUN int msg_header_prepend(msg_t *msg,
msg_pub_t *pub,
msg_header_t **hh,
msg_header_t *h);
msg_header_t *msg_header_make(su_home_t *home,
SOFIAPUBFUN msg_header_t *msg_header_make(su_home_t *home,
msg_hclass_t *hc,
char const *s)
__attribute__((__malloc__));
msg_header_t *msg_header_format(su_home_t *home,
SOFIAPUBFUN msg_header_t *msg_header_format(su_home_t *home,
msg_hclass_t *hc,
char const *fmt,
...)
char const *fmt, ...)
__attribute__ ((__malloc__, __format__ (printf, 3, 4)));
msg_header_t *msg_header_vformat(su_home_t *home,
SOFIAPUBFUN msg_header_t *msg_header_vformat(su_home_t *home,
msg_hclass_t *hc,
char const *fmt,
va_list ap)
__attribute__((__malloc__));
void msg_header_free(su_home_t *home, msg_header_t *h);
SOFIAPUBFUN void msg_header_free(su_home_t *home,
msg_header_t *h);
void msg_header_free_all(su_home_t *home, msg_header_t *h);
SOFIAPUBFUN void msg_header_free_all(su_home_t *home,
msg_header_t *h);
msg_payload_t *msg_payload_create(su_home_t *home, void const *data, int len)
SOFIAPUBFUN msg_payload_t *msg_payload_create(su_home_t *home,
void const *data,
int len)
__attribute__((__malloc__));
msg_separator_t *msg_separator_create(su_home_t *home)
SOFIAPUBFUN msg_separator_t *msg_separator_create(su_home_t *home)
__attribute__((__malloc__));
/* Chunk handling macros */
......@@ -156,7 +189,9 @@ msg_separator_t *msg_separator_create(su_home_t *home)
#define MSG_CHUNK_NEXT(pl) \
((pl)->pl_next)
int msg_headers_prepare(msg_t *msg, msg_header_t *headers, int flags);
SOFIAPUBFUN int msg_headers_prepare(msg_t *,
msg_header_t *headers,
int flags);
#ifdef SU_HAVE_INLINE
/** Clear encoded data from header structure. */
......@@ -164,6 +199,7 @@ static inline void msg_fragment_clear(msg_common_t *h)
{
h->h_data = NULL, h->h_len = 0;
}
/** Pointer to header parameters. */
static inline
msg_param_t **msg_header_params(msg_common_t const *h)
......@@ -180,37 +216,50 @@ msg_param_t **msg_header_params(msg_common_t const *h)
(msg_param_t **)((char *)(h) + ((msg_common_t *)h)->h_class->hc_params) : NULL)
#endif
char const *msg_header_find_param(msg_common_t const *h, char const *name);
int msg_header_add_param(su_home_t *, msg_common_t *h, char const *param);
int msg_header_replace_param(su_home_t *, msg_common_t *h, char const *param);
int msg_header_remove_param(msg_common_t *h, char const *name);
int msg_random_token(char token[], int tlen, void const *data, int dlen);
msg_param_t msg_params_find(msg_param_t const pp[], msg_param_t);
msg_param_t *msg_params_find_slot(msg_param_t params[], msg_param_t token);
int msg_params_add(su_home_t *sh, msg_param_t **pp, msg_param_t);
int msg_params_cmp(msg_param_t const a[], msg_param_t const b[]);
int msg_params_replace(su_home_t *, msg_param_t **pp, msg_param_t);
int msg_params_remove(msg_param_t *pparams, msg_param_t param);
size_t msg_params_length(msg_param_t const params[]);
SOFIAPUBFUN char const *msg_header_find_param(msg_common_t const *,
char const *name);
SOFIAPUBFUN int msg_header_add_param(su_home_t *, msg_common_t *h,
char const *param);
SOFIAPUBFUN int msg_header_replace_param(su_home_t *, msg_common_t *h,
char const *param);
SOFIAPUBFUN int msg_header_remove_param(msg_common_t *h, char const *name);
/** Append a list of constant items to a list. */
MSG_DLL int msg_list_append_items(su_home_t *home, msg_list_t *k,
SOFIAPUBFUN int msg_list_append_items(su_home_t *home, msg_list_t *k,
msg_param_t const items[]);
/** Replace a list of constant items on a list */
MSG_DLL int msg_list_replace_items(su_home_t *home, msg_list_t *k,
SOFIAPUBFUN int msg_list_replace_items(su_home_t *home,
msg_list_t *k,
msg_param_t const items[]);
SOFIAPUBFUN int msg_random_token(char token[], int tlen,
void const *d, int dlen);
SOFIAPUBFUN msg_param_t msg_params_find(msg_param_t const pp[],
char const *name);
SOFIAPUBFUN msg_param_t *msg_params_find_slot(msg_param_t [],
char const *name);
SOFIAPUBFUN int msg_params_add(su_home_t *sh,
msg_param_t **pp,
char const *param);
SOFIAPUBFUN int msg_params_cmp(char const * const a[],
char const * const b[]);
SOFIAPUBFUN int msg_params_replace(su_home_t *,
char const * **inout_paramlist,
char const *);
SOFIAPUBFUN int msg_params_remove(char const **paramlist,
char const *name);
SOFIAPUBFUN size_t msg_params_length(char const * const * params);
/** Unquote a string, return a duplicate. */
MSG_DLL char *msg_unquote_dup(su_home_t *home, char const *q)
SOFIAPUBFUN char *msg_unquote_dup(su_home_t *home, char const *q)
__attribute__((__malloc__));
MSG_DLL char *msg_unquote(char *dst, char const *s);
SOFIAPUBFUN char *msg_unquote(char *dst, char const *s);
/** Calculate a hash over a string. */
MSG_DLL unsigned long msg_hash_string(char const *id);
SOFIAPUBFUN unsigned long msg_hash_string(char const *id);
/* Align pointer p for multiple of t (which must be a power of 2) */
#define MSG_ALIGN(p, t) (((t) - 1 + (long)(p))&-(long)(t))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment