Commit 3ee17105 authored by Pekka Pessi's avatar Pekka Pessi

msg module: using isize_t, usize_t, issize_t in API.

darcs-hash:20060906223842-65a35-b09275217b51097b4725b616a5beea20ec7cbca0.gz
parent 56c7fb39
......@@ -251,9 +251,9 @@ su_sockaddr_t *msg_addr(msg_t *msg)
int msg_get_address(msg_t *msg, su_sockaddr_t *su, socklen_t *return_len)
{
if (msg && return_len && *return_len >= msg->m_addrinfo.ai_addrlen) {
*return_len = msg->m_addrinfo.ai_addrlen;
*return_len = (socklen_t)msg->m_addrinfo.ai_addrlen;
if (su)
memcpy(su, msg->m_addr, *return_len = msg->m_addrinfo.ai_addrlen);
memcpy(su, msg->m_addr, msg->m_addrinfo.ai_addrlen);
return 0;
}
if (msg)
......
......@@ -88,10 +88,10 @@ static int msg_auth_item_scan(char *start)
*/
/** Parse security headers. */
int msg_auth_d(su_home_t *home,
msg_header_t *h,
char *s,
int slen)
issize_t msg_auth_d(su_home_t *home,
msg_header_t *h,
char *s,
isize_t slen)
{
msg_auth_t *au = (msg_auth_t *)h;
......@@ -105,7 +105,7 @@ int msg_auth_d(su_home_t *home,
NULL /* msg_auth_item_scan */);
}
int msg_auth_e(char b[], int bsiz, msg_header_t const *h, int f)
issize_t msg_auth_e(char b[], isize_t bsiz, msg_header_t const *h, int f)
{
msg_auth_t const *au = (msg_auth_t *)h;
int compact = MSG_IS_COMPACT(f);
......@@ -131,22 +131,21 @@ int msg_auth_e(char b[], int bsiz, msg_header_t const *h, int f)
* @return
* Size of strings related to msg_auth_t object.
*/
int msg_auth_dup_xtra(msg_header_t const *h, int offset)
isize_t msg_auth_dup_xtra(msg_header_t const *h, isize_t offset)
{
int rv = offset;
msg_auth_t const *au = h->sh_auth;
MSG_PARAMS_SIZE(rv, au->au_params);
rv += MSG_STRING_SIZE(au->au_scheme);
MSG_PARAMS_SIZE(offset, au->au_params);
offset += MSG_STRING_SIZE(au->au_scheme);
return rv;
return offset;
}
/**Duplicate one msg_auth_t object. */
char *msg_auth_dup_one(msg_header_t *dst,
msg_header_t const *src,
char *b,
int xtra)
isize_t xtra)
{
msg_auth_t *au = dst->sh_auth;
msg_auth_t const *o = src->sh_auth;
......
......@@ -38,13 +38,6 @@
#include "config.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <stdarg.h>
#include <sofia-sip/su_alloc.h>
#include <sofia-sip/msg.h>
......@@ -52,6 +45,14 @@
#include <sofia-sip/msg_parser.h>
#include <sofia-sip/msg_header.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
#define msg_generic_update NULL
/* ====================================================================== */
......@@ -72,32 +73,32 @@
* Type for erroneous headers.
*/
int msg_error_dup_xtra(msg_header_t const *h, int offset);
isize_t msg_error_dup_xtra(msg_header_t const *h, isize_t offset);
char *msg_error_dup_one(msg_header_t *dst, msg_header_t const *src,
char *b, int xtra);
char *b, isize_t xtra);
msg_hclass_t msg_error_class[] =
MSG_HEADER_CLASS(msg_, error, "", "", er_common, append,
msg_error, msg_generic);
int msg_error_d(su_home_t *home, msg_header_t *h, char *s, int slen)
issize_t msg_error_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen)
{
return 0;
}
int msg_error_e(char b[], int bsiz, msg_header_t const *h, int flags)
issize_t msg_error_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
{
/* There is no way to encode an erroneous header */
return 0;
}
int msg_error_dup_xtra(msg_header_t const *h, int offset)
isize_t msg_error_dup_xtra(msg_header_t const *h, isize_t offset)
{
return msg_default_dup_xtra(h, offset);
}
char *msg_error_dup_one(msg_header_t *dst, msg_header_t const *src,
char *b, int xtra)
char *b, isize_t xtra)
{
return msg_default_dup_one(dst, src, b, xtra);
}
......@@ -127,7 +128,7 @@ msg_hclass_t msg_unknown_class[] =
MSG_HEADER_CLASS(msg_, unknown, "", "", un_common, append,
msg_unknown, msg_generic);
int msg_unknown_d(su_home_t *home, msg_header_t *h, char *s, int slen)
issize_t msg_unknown_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen)
{
msg_unknown_t *un = (msg_unknown_t *)h;
......@@ -142,7 +143,7 @@ int msg_unknown_d(su_home_t *home, msg_header_t *h, char *s, int slen)
return 0;
}
int msg_unknown_e(char b[], int bsiz, msg_header_t const *h, int flags)
issize_t msg_unknown_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
{
char *b0 = b, *end = b + bsiz;
msg_unknown_t *un = (msg_unknown_t *)h;
......@@ -156,14 +157,14 @@ int msg_unknown_e(char b[], int bsiz, msg_header_t const *h, int flags)
return b - b0;
}
int msg_unknown_dup_xtra(msg_header_t const *h, int offset)
isize_t msg_unknown_dup_xtra(msg_header_t const *h, isize_t offset)
{
msg_unknown_t const *un = (msg_unknown_t *)h;
return offset + MSG_STRING_SIZE(un->un_name) + MSG_STRING_SIZE(un->un_value);
}
char *msg_unknown_dup_one(msg_header_t *dst, msg_header_t const *src,
char *b, int xtra)
char *b, isize_t xtra)
{
msg_unknown_t *un = (msg_unknown_t *)dst;
msg_unknown_t const *o = (msg_unknown_t *)src;
......@@ -208,7 +209,7 @@ MSG_HEADER_CLASS(msg_, payload, NULL, "", pl_common, append,
msg_payload, msg_generic);
/** Create a MIME payload */
msg_payload_t *msg_payload_create(su_home_t *home, void const *data, int len)
msg_payload_t *msg_payload_create(su_home_t *home, void const *data, usize_t len)
{
msg_header_t *h = msg_header_alloc(home, msg_payload_class, len + 1);
msg_payload_t *pl = h->sh_payload;
......@@ -230,7 +231,7 @@ msg_payload_t *msg_payload_create(su_home_t *home, void const *data, int len)
}
/** Parse payload. */
int msg_payload_d(su_home_t *home, msg_header_t *h, char *s, int slen)
issize_t msg_payload_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen)
{
h->sh_payload->pl_len = slen;
h->sh_payload->pl_data = s;
......@@ -241,9 +242,9 @@ int msg_payload_d(su_home_t *home, msg_header_t *h, char *s, int slen)
return 0;
}
int msg_payload_e(char b[], int bsiz, msg_header_t const *h, int flags)
issize_t msg_payload_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
{
int len = h->sh_payload->pl_len;
size_t len = h->sh_payload->pl_len;
if (bsiz > 0) {
memcpy(b, h->sh_payload->pl_data, bsiz > len ? len : bsiz);
......@@ -253,7 +254,7 @@ int msg_payload_e(char b[], int bsiz, msg_header_t const *h, int flags)
return len;
}
int msg_payload_dup_xtra(msg_header_t const *h, int offset)
isize_t msg_payload_dup_xtra(msg_header_t const *h, isize_t offset)
{
return offset + h->sh_payload->pl_len + 1;
}
......@@ -261,7 +262,7 @@ int msg_payload_dup_xtra(msg_header_t const *h, int offset)
char *msg_payload_dup_one(msg_header_t *dst,
msg_header_t const *src,
char *b,
int xtra)
isize_t xtra)
{
msg_payload_t *pl = dst->sh_payload;
msg_payload_t const *o = src->sh_payload;
......@@ -316,7 +317,7 @@ MSG_HEADER_CLASS(msg_, separator, NULL, "", sep_common, single,
#define CRLF_TEST(s) ((s[0]) == '\r' ? ((s[1]) == '\n') + 1 : (s[0])=='\n')
/** Parse a separator line. */
int msg_separator_d(su_home_t *home, msg_header_t *h, char *s, int slen)
issize_t msg_separator_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen)
{
int len = CRLF_TEST(s);
......@@ -330,14 +331,14 @@ int msg_separator_d(su_home_t *home, msg_header_t *h, char *s, int slen)
}
/** Encode a separator line. */
int msg_separator_e(char b[], int bsiz, msg_header_t const *h, int flags)
issize_t msg_separator_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
{
int n = strlen(h->sh_separator->sep_data);
size_t n = strlen(h->sh_separator->sep_data);
if (bsiz > n)
strcpy(b, h->sh_separator->sep_data);
return n;
return (issize_t)n;
}
msg_separator_t *msg_separator_create(su_home_t *home)
......
......@@ -175,7 +175,7 @@ int time_d(char const **ss,
* | "Sep" | "Oct" | "Nov" | "Dec"
* @endverbatim
*/
int msg_date_d(char const **ss, msg_time_t *date)
issize_t msg_date_d(char const **ss, msg_time_t *date)
{
char const *s = *ss;
char const *wkday;
......@@ -321,7 +321,7 @@ int msg_date_d(char const **ss, msg_time_t *date)
*
* @return The function msg_date_e() returns the size of the formatted date.
*/
int msg_date_e(char b[], int bsiz, msg_time_t http_date)
issize_t msg_date_e(char b[], isize_t bsiz, msg_time_t http_date)
{
msg_time_t sec, min, hour, wkday, day, month, year;
msg_time_t days_per_month, leap_year;
......@@ -363,19 +363,22 @@ int msg_date_e(char b[], int bsiz, msg_time_t http_date)
*
* The function msg_delta_d() decodes a http-delta field.
*/
int msg_delta_d(char const **ss, msg_time_t *delta)
issize_t msg_delta_d(char const **ss, msg_time_t *delta)
{
if (!is_digit(**ss))
char const *s = *ss;
if (!is_digit(*s))
return -1;
*delta = strtoul(*ss, (char **)ss, 10);
skip_lws(ss);
return 0;
return *ss - s;
}
/**Encode http-delta
*/
int msg_delta_e(char b[], int bsiz, msg_time_t delta)
issize_t msg_delta_e(char b[], isize_t bsiz, msg_time_t delta)
{
return snprintf(b, bsiz, "%lu", (unsigned long)delta);
}
......@@ -384,7 +387,7 @@ int msg_delta_e(char b[], int bsiz, msg_time_t delta)
*
* The function msg_date_delta_d() decodes a http-date or http-delta field.
*/
int msg_date_delta_d(char const **ss,
issize_t msg_date_delta_d(char const **ss,
msg_time_t *date,
msg_time_t *delta)
{
......
......@@ -34,13 +34,6 @@
#include "config.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <stdarg.h>
#include <sofia-sip/su_alloc.h>
#include "sofia-sip/msg.h"
......@@ -48,6 +41,14 @@
#include "sofia-sip/msg_parser.h"
#include "sofia-sip/msg_header.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
/**
* Parse a generic header.
*
......@@ -61,10 +62,10 @@
* @retval 0 when successful,
* @retval -1 upon an error.
*/
int msg_generic_d(su_home_t *home,
msg_header_t *h,
char *s,
int slen)
issize_t msg_generic_d(su_home_t *home,
msg_header_t *h,
char *s,
isize_t slen)
{
h->sh_generic->g_string = s;
return 0;
......@@ -76,19 +77,19 @@ int msg_generic_d(su_home_t *home,
* The function @c msg_generic_e encodes a generic header.
*
*/
int msg_generic_e(char b[], int bsiz, msg_header_t const *h, int flags)
issize_t msg_generic_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
{
msg_generic_t const *g = h->sh_generic;
int n = strlen(g->g_string);
size_t n = strlen(g->g_string);
if (bsiz > n)
strcpy(b, g->g_string);
return n;
return (issize_t)n;
}
/** Calculate the size of strings associated with a @c msg_generic_t object. */
int msg_generic_dup_xtra(msg_header_t const *h, int offset)
isize_t msg_generic_dup_xtra(msg_header_t const *h, isize_t offset)
{
msg_generic_t const *g = h->sh_generic;
return offset + MSG_STRING_SIZE(g->g_string);
......@@ -98,7 +99,7 @@ int msg_generic_dup_xtra(msg_header_t const *h, int offset)
char *msg_generic_dup_one(msg_header_t *dst,
msg_header_t const *src,
char *b,
int xtra)
isize_t xtra)
{
char *end = b + xtra;
MSG_STRING_DUP(b, dst->sh_generic->g_string, src->sh_generic->g_string);
......@@ -106,14 +107,15 @@ char *msg_generic_dup_one(msg_header_t *dst,
return b;
}
int msg_numeric_d(su_home_t *home,
msg_header_t *h,
char *s,
int slen)
issize_t msg_numeric_d(su_home_t *home,
msg_header_t *h,
char *s,
isize_t slen)
{
int retval;
uint32_t value = 0;
issize_t retval = msg_uint32_d(&s, &value);
retval = msg_uint32_d(&s, (uint32_t *)&h->sh_numeric->x_value);
h->sh_numeric->x_value = value;
if (*s)
return -1;
......@@ -121,20 +123,25 @@ int msg_numeric_d(su_home_t *home,
return retval;
}
int msg_numeric_e(char b[], int bsiz, msg_header_t const *h, int flags)
issize_t msg_numeric_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
{
return snprintf(b, bsiz, "%lu", h->sh_numeric->x_value);
uint32_t value = h->sh_numeric->x_value;
if (h->sh_numeric->x_value > 0xffffffff)
return -1;
return snprintf(b, bsiz, "%lu", (unsigned long)value);
}
/* ====================================================================== */
/* Comma-separated list */
int msg_list_d(su_home_t *home, msg_header_t *h, char *s, int slen)
issize_t msg_list_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen)
{
return msg_commalist_d(home, &s, &h->sh_list->k_items, NULL);
}
int msg_list_e(char b[], int bsiz, msg_header_t const *h, int flags)
issize_t msg_list_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
{
int compact = MSG_IS_COMPACT(flags);
char *b0 = b, *end = b + bsiz;
......@@ -155,7 +162,7 @@ int msg_list_e(char b[], int bsiz, msg_header_t const *h, int flags)
* @return
* Size of strings related to msg_auth_t object.
*/
int msg_list_dup_xtra(msg_header_t const *h, int offset)
isize_t msg_list_dup_xtra(msg_header_t const *h, isize_t offset)
{
MSG_PARAMS_SIZE(offset, h->sh_list->k_items);
return offset;
......@@ -164,7 +171,7 @@ int msg_list_dup_xtra(msg_header_t const *h, int offset)
char *msg_list_dup_one(msg_header_t *dst,
msg_header_t const *src,
char *b,
int xtra)
isize_t xtra)
{
char *end = b + xtra;
msg_param_t const ** items = (msg_param_t const **)&dst->sh_list->k_items;
......@@ -176,7 +183,11 @@ char *msg_list_dup_one(msg_header_t *dst,
return b;
}
/** Append a list of constant items to a list. */
/** Append a list of constant items to a list.
*
* @retval 0 when successful
* @retval -1 upon an error
*/
int msg_list_append_items(su_home_t *home,
msg_list_t *k,
msg_param_t const items[])
......@@ -197,7 +208,11 @@ int msg_list_append_items(su_home_t *home,
return 0;
}
/** Replace a list of constant items */
/** Replace a list of constant items.
*
* @retval 0 when successful
* @retval -1 upon an error
*/
int msg_list_replace_items(su_home_t *home, msg_list_t *k,
msg_param_t const items[])
{
......
......@@ -52,7 +52,7 @@
/** Calculate size of a parameter vector */
static inline
int msg_params_copy_xtra(msg_param_t const pp[], int offset)
size_t msg_params_copy_xtra(msg_param_t const pp[], size_t offset)
{
int n = msg_params_count(pp);
if (n) {
......@@ -64,7 +64,7 @@ int msg_params_copy_xtra(msg_param_t const pp[], int offset)
/** Copy a vector of parameters */
static inline
char *msg_params_copy(char *b, int size,
char *msg_params_copy(char *b, size_t size,
msg_param_t **dst,
msg_param_t const src[])
{
......@@ -99,7 +99,7 @@ static msg_header_t *msg_header_copy_one_as(su_home_t *home,
msg_header_t const *src)
{
msg_header_t *h;
int size = hc->hc_size, xtra;
size_t size = hc->hc_size, xtra;
msg_param_t const *params;
char *end;
......@@ -112,7 +112,7 @@ static msg_header_t *msg_header_copy_one_as(su_home_t *home,
xtra = 0;
}
if (!(h = msg_header_alloc(home, hc, xtra)))
if (!(h = msg_header_alloc(home, hc, (isize_t)xtra)))
return NULL; /* error */
memcpy(&h->sh_data, &src->sh_data, size - offsetof(msg_common_t, h_data));
......@@ -214,7 +214,7 @@ msg_header_t *msg_header_dup_one(su_home_t *home,
msg_header_t const *src)
{
msg_hclass_t *hc;
int size, xtra;
size_t size, xtra;
msg_header_t *h;
char *end;
......@@ -270,11 +270,11 @@ msg_header_t *msg_header_dup_as(su_home_t *home, msg_hclass_t *hc,
assert(hc);
for (prev = &rv; src; src = src->sh_next, prev = &h->sh_next) {
int size = hc->hc_size;
int xtra = hc->hc_dxtra(src, size) - size;
size_t size = hc->hc_size;
size_t xtra = hc->hc_dxtra(src, size) - size;
char *end;
if (!(h = msg_header_alloc(home, hc, xtra)))
if (!(h = msg_header_alloc(home, hc, (isize_t)xtra)))
break; /* error */
if (!rv)
......@@ -322,7 +322,7 @@ msg_header_t *msg_header_dup(su_home_t *home, msg_header_t const *h)
}
/** Calculate extra size of a plain header. */
int msg_default_dup_xtra(msg_header_t const *header, int offset)
isize_t msg_default_dup_xtra(msg_header_t const *header, isize_t offset)
{
return offset;
}
......@@ -344,7 +344,7 @@ int msg_default_dup_xtra(msg_header_t const *header, int offset)
char *msg_default_dup_one(msg_header_t *h,
msg_header_t const *src,
char *b,
int xtra)
isize_t xtra)
{
memcpy(&h->sh_header_next[1],
&src->sh_header_next[1],
......
......@@ -35,11 +35,20 @@
#include "config.h"
#include <sofia-sip/su_alloc.h>
#include "sofia-sip/msg.h"
#include "sofia-sip/bnf.h"
#include "sofia-sip/msg_parser.h"
#include "sofia-sip/msg_header.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
#include <errno.h>
#if defined(va_copy)
/* Xyzzy */
......@@ -51,19 +60,12 @@
#include <assert.h>
#include <sofia-sip/su_alloc.h>
#include "sofia-sip/msg.h"
#include "sofia-sip/bnf.h"
#include "sofia-sip/msg_parser.h"
#include "sofia-sip/msg_header.h"
/** Make a header from a value string. */
msg_header_t *msg_header_make(su_home_t *home,
msg_hclass_t *hc,
char const *s)
{
int xtra;
size_t xtra;
msg_header_t *h;
int normal = hc->hc_name ||
(hc->hc_hash != msg_payload_hash &&
......@@ -107,8 +109,8 @@ msg_header_t *msg_header_vformat(su_home_t *home,
{
msg_header_t *h;
int n, xtra = 64; /* reasonable default */
int n;
size_t xtra = 64; /* reasonable default */
/* Quick path */
if (!fmt || !strchr(fmt, '%'))
......@@ -130,22 +132,28 @@ msg_header_t *msg_header_vformat(su_home_t *home,
n = vsnprintf(MSG_HEADER_DATA(h), xtra, fmt, aq);
va_end(aq);
if (n >= 0 && n < xtra)
if (n >= 0 && (size_t)n < xtra)
break;
/* Try again with more space */
su_free(home, h);
if (xtra >= INT_MAX)
return NULL;
if (n >= 0)
xtra = n + 1; /* precisely what is needed */
else
xtra *= 2; /* glibc 2.0 - twice the old size */
if (xtra > INT_MAX)
xtra = INT_MAX;
if (!(h = msg_header_alloc(home, hc, xtra)))
return NULL;
}