Commit 9b6b3ecb authored by Pekka Pessi's avatar Pekka Pessi

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

Using internally size_t.

darcs-hash:20060906195027-65a35-8ce244cb4b2cd32f0649d48fbebeadfea78eb6ad.gz
parent 4d07e229
...@@ -333,7 +333,7 @@ TPORT_DLL int tport_convert_addr(su_home_t *home, ...@@ -333,7 +333,7 @@ TPORT_DLL int tport_convert_addr(su_home_t *home,
su_sockaddr_t const *su); su_sockaddr_t const *su);
/** Print host and port separated with ':' to a string. */ /** Print host and port separated with ':' to a string. */
TPORT_DLL char *tport_hostport(char buf[], int bufsize, TPORT_DLL char *tport_hostport(char buf[], isize_t bufsize,
su_sockaddr_t const *su, int with_port); su_sockaddr_t const *su, int with_port);
/** Initialize STUN keepalives. */ /** Initialize STUN keepalives. */
......
...@@ -110,7 +110,7 @@ static inline int tp_cmp(tport_t const *a, tport_t const *b) ...@@ -110,7 +110,7 @@ static inline int tp_cmp(tport_t const *a, tport_t const *b)
return 0; return 0;
if (a->tp_addrlen != b->tp_addrlen) if (a->tp_addrlen != b->tp_addrlen)
return a->tp_addrlen - b->tp_addrlen; return (int)(a->tp_addrlen - b->tp_addrlen);
return memcmp(a->tp_addr, b->tp_addr, a->tp_addrlen); return memcmp(a->tp_addr, b->tp_addr, a->tp_addrlen);
} }
...@@ -2102,7 +2102,7 @@ int tport_convert_addr(su_home_t *home, ...@@ -2102,7 +2102,7 @@ int tport_convert_addr(su_home_t *home,
char const *host; char const *host;
char buf[TPORT_HOSTPORTSIZE]; char buf[TPORT_HOSTPORTSIZE];
char port[8]; char port[8];
int canonlen = canon ? strlen(canon) : 0; size_t canonlen = canon ? strlen(canon) : 0;
if (su == NULL) if (su == NULL)
host = "*"; host = "*";
...@@ -2224,7 +2224,8 @@ static ...@@ -2224,7 +2224,8 @@ static
char *localipname(int pf, char *buf, int bufsiz) char *localipname(int pf, char *buf, int bufsiz)
{ {
su_localinfo_t *li = NULL, hints[1] = {{ LI_NUMERIC | LI_CANONNAME }}; su_localinfo_t *li = NULL, hints[1] = {{ LI_NUMERIC | LI_CANONNAME }};
int n, error; size_t n;
int error;
hints->li_family = pf; hints->li_family = pf;
...@@ -3278,17 +3279,17 @@ int tport_send_error(tport_t *self, msg_t *msg, ...@@ -3278,17 +3279,17 @@ int tport_send_error(tport_t *self, msg_t *msg,
else if (self->tp_addrinfo->ai_family == AF_INET6) { else if (self->tp_addrinfo->ai_family == AF_INET6) {
su_sockaddr_t const *su = (su_sockaddr_t const *)ai->ai_addr; su_sockaddr_t const *su = (su_sockaddr_t const *)ai->ai_addr;
SU_DEBUG_3(("tport_vsend(%p): %s with " SU_DEBUG_3(("tport_vsend(%p): %s with "
"(s=%d, IP6=%s/%s:%s%s (scope=%i) addrlen=%zd)\n", "(s=%d, IP6=%s/%s:%s%s (scope=%i) addrlen=%u)\n",
self, su_strerror(error), (int)self->tp_socket, self, su_strerror(error), (int)self->tp_socket,
tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port, comp, tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port, comp,
su->su_scope_id, ai->ai_addrlen)); su->su_scope_id, (unsigned)ai->ai_addrlen));
} }
#endif #endif
else { else {
SU_DEBUG_3(("\ttport_vsend(%p): %s with " SU_DEBUG_3(("\ttport_vsend(%p): %s with "
"(s=%d, AF=%u addrlen=%zd)%s\n", "(s=%d, AF=%u addrlen=%u)%s\n",
self, su_strerror(error), self, su_strerror(error),
(int)self->tp_socket, ai->ai_family, ai->ai_addrlen, comp)); (int)self->tp_socket, ai->ai_family, (unsigned)ai->ai_addrlen, comp));
} }
#if 0 #if 0
...@@ -4304,7 +4305,7 @@ int tport_name_by_url(su_home_t *home, ...@@ -4304,7 +4305,7 @@ int tport_name_by_url(su_home_t *home,
tp_name_t *tpn, tp_name_t *tpn,
url_string_t const *us) url_string_t const *us)
{ {
int n; size_t n;
url_t url[1]; url_t url[1];
char *b; char *b;
...@@ -4347,7 +4348,7 @@ int tport_name_by_url(su_home_t *home, ...@@ -4347,7 +4348,7 @@ int tport_name_by_url(su_home_t *home,
/** Check if transport named is already resolved */ /** Check if transport named is already resolved */
int tport_name_is_resolved(tp_name_t const *tpn) int tport_name_is_resolved(tp_name_t const *tpn)
{ {
int n; size_t n;
if (!tpn->tpn_host) if (!tpn->tpn_host)
return 0; return 0;
...@@ -4386,7 +4387,7 @@ int tport_name_dup(su_home_t *home, ...@@ -4386,7 +4387,7 @@ int tport_name_dup(su_home_t *home,
tp_name_t *dst, tp_name_t *dst,
tp_name_t const *src) tp_name_t const *src)
{ {
int n_proto, n_host, n_port, n_canon, n_comp = 0; size_t n_proto, n_host, n_port, n_canon, n_comp = 0;
char *s; char *s;
if (strcmp(src->tpn_proto, tpn_any)) if (strcmp(src->tpn_proto, tpn_any))
...@@ -4431,12 +4432,12 @@ int tport_name_dup(su_home_t *home, ...@@ -4431,12 +4432,12 @@ int tport_name_dup(su_home_t *home,
} }
/** Convert a sockaddr structure into printable form. */ /** Convert a sockaddr structure into printable form. */
char *tport_hostport(char buf[], int bufsize, char *tport_hostport(char buf[], isize_t bufsize,
su_sockaddr_t const *su, su_sockaddr_t const *su,
int with_port_and_brackets) int with_port_and_brackets)
{ {
char *b = buf; char *b = buf;
int n; size_t n;
#if SU_HAVE_IN6 #if SU_HAVE_IN6
if (with_port_and_brackets > 1 || su->su_family == AF_INET6) { if (with_port_and_brackets > 1 || su->su_family == AF_INET6) {
...@@ -4446,10 +4447,12 @@ char *tport_hostport(char buf[], int bufsize, ...@@ -4446,10 +4447,12 @@ char *tport_hostport(char buf[], int bufsize,
if (inet_ntop(su->su_family, SU_ADDR(su), b, bufsize) == NULL) if (inet_ntop(su->su_family, SU_ADDR(su), b, bufsize) == NULL)
return NULL; return NULL;
n = strlen(b); bufsize -= n; b += n; n = strlen(b);
if (bufsize < 2) if (bufsize < n + 2)
return NULL; return NULL;
bufsize -= n; b += n;
#if SU_HAVE_IN6 #if SU_HAVE_IN6
if (with_port_and_brackets > 1 || su->su_family == AF_INET6) { if (with_port_and_brackets > 1 || su->su_family == AF_INET6) {
*b++ = ']'; bufsize--; *b++ = ']'; bufsize--;
......
...@@ -422,7 +422,7 @@ void tport_open_log(tport_master_t *mr, tagi_t *tags); ...@@ -422,7 +422,7 @@ void tport_open_log(tport_master_t *mr, tagi_t *tags);
void tport_log_msg(tport_t *tp, msg_t *msg, char const *what, void tport_log_msg(tport_t *tp, msg_t *msg, char const *what,
char const *via, su_time_t now); char const *via, su_time_t now);
void tport_dump_iovec(tport_t const *self, msg_t *msg, void tport_dump_iovec(tport_t const *self, msg_t *msg,
int n, su_iovec_t const iov[], int iovused, isize_t n, su_iovec_t const iov[], isize_t iovused,
char const *what, char const *how); char const *what, char const *how);
extern tport_vtable_t const tport_udp_vtable; extern tport_vtable_t const tport_udp_vtable;
......
...@@ -115,7 +115,7 @@ void tport_open_log(tport_master_t *mr, tagi_t *tags) ...@@ -115,7 +115,7 @@ void tport_open_log(tport_master_t *mr, tagi_t *tags)
/** Create log stamp */ /** Create log stamp */
void tport_stamp(tport_t const *self, msg_t *msg, void tport_stamp(tport_t const *self, msg_t *msg,
char stamp[128], char const *what, char stamp[128], char const *what,
int n, char const *via, isize_t n, char const *via,
su_time_t now) su_time_t now)
{ {
char label[24] = ""; char label[24] = "";
...@@ -150,12 +150,12 @@ void tport_stamp(tport_t const *self, msg_t *msg, ...@@ -150,12 +150,12 @@ void tport_stamp(tport_t const *self, msg_t *msg,
/** Dump the data from the iovec */ /** Dump the data from the iovec */
void tport_dump_iovec(tport_t const *self, msg_t *msg, void tport_dump_iovec(tport_t const *self, msg_t *msg,
int n, su_iovec_t const iov[], int iovused, isize_t n, su_iovec_t const iov[], isize_t iovused,
char const *what, char const *how) char const *what, char const *how)
{ {
tport_master_t *mr = self->tp_master; tport_master_t *mr = self->tp_master;
char stamp[128]; char stamp[128];
int i; size_t i;
if (!mr->mr_dump_file) if (!mr->mr_dump_file)
return; return;
...@@ -182,9 +182,9 @@ void tport_log_msg(tport_t *self, msg_t *msg, ...@@ -182,9 +182,9 @@ void tport_log_msg(tport_t *self, msg_t *msg,
{ {
char stamp[128]; char stamp[128];
msg_iovec_t iov[80]; msg_iovec_t iov[80];
int i, iovlen = msg_iovec(msg, iov, 80); size_t i, iovlen = msg_iovec(msg, iov, 80);
int skip_lf = 0, linelen = 0; size_t linelen = 0, n, logged = 0, truncated = 0;
size_t n, logged = 0, truncated = 0; int skip_lf = 0;
#define MSG_SEPARATOR \ #define MSG_SEPARATOR \
"------------------------------------------------------------------------\n" "------------------------------------------------------------------------\n"
...@@ -217,7 +217,7 @@ void tport_log_msg(tport_t *self, msg_t *msg, ...@@ -217,7 +217,7 @@ void tport_log_msg(tport_t *self, msg_t *msg,
truncated = logged + n; truncated = logged + n;
} }
su_log("%s%.*s", linelen > n ? "" : " ", n, s); su_log("%s%.*s", linelen > n ? "" : " ", (int)n, s);
s += n, linelen += n, logged += n; s += n, linelen += n, logged += n;
if (truncated) if (truncated)
...@@ -247,5 +247,5 @@ void tport_log_msg(tport_t *self, msg_t *msg, ...@@ -247,5 +247,5 @@ void tport_log_msg(tport_t *self, msg_t *msg,
truncated = logged; truncated = logged;
if (truncated) if (truncated)
su_log(" *** message truncated at %d ***\n", truncated); su_log(" *** message truncated at %zu ***\n", truncated);
} }
...@@ -155,7 +155,7 @@ int tport_recv_stun_dgram(tport_t const *self, ...@@ -155,7 +155,7 @@ int tport_recv_stun_dgram(tport_t const *self,
} }
else else
SU_DEBUG_7(("tport(%p): recv_stun_dgram(): " SU_DEBUG_7(("tport(%p): recv_stun_dgram(): "
"ignoring request with %u bytes\n", self, n)); "ignoring request with %zu bytes\n", self, n));
} }
else if (request[0] == 0 && self->tp_master->mr_stun_server) { else if (request[0] == 0 && self->tp_master->mr_stun_server) {
tport_stun_server_vtable_t const *vst = tport_stun_server_vtable; tport_stun_server_vtable_t const *vst = tport_stun_server_vtable;
...@@ -167,9 +167,16 @@ int tport_recv_stun_dgram(tport_t const *self, ...@@ -167,9 +167,16 @@ int tport_recv_stun_dgram(tport_t const *self,
/* Respond to stun request with a simple error message. */ /* Respond to stun request with a simple error message. */
int const status = 600; int const status = 600;
char const *error = "Not Implemented"; char const *error = "Not Implemented";
uint16_t elen = strlen(error); size_t unpadded = strlen(error);
uint16_t elen;
uint8_t dgram[128]; uint8_t dgram[128];
if (unpadded > sizeof(dgram) - 28)
unpadded = sizeof(dgram) - 28;
elen = (uint16_t)unpadded;
elen = (elen + 3) & -4; /* Round up to 4 */
SU_DEBUG_7(("tport(%p): recv_stun_dgram(): " SU_DEBUG_7(("tport(%p): recv_stun_dgram(): "
"responding %u %s\n", self, status, error)); "responding %u %s\n", self, status, error));
/* /*
...@@ -222,10 +229,11 @@ int tport_recv_stun_dgram(tport_t const *self, ...@@ -222,10 +229,11 @@ int tport_recv_stun_dgram(tport_t const *self,
*/ */
dgram[24] = 0, dgram[25] = 0; dgram[24] = 0, dgram[25] = 0;
dgram[26] = status / 100, dgram[27] = status % 100; dgram[26] = status / 100, dgram[27] = status % 100;
memcpy(dgram + 28, error, elen); memcpy(dgram + 28, error, unpadded);
n = 28 + elen; memset(dgram + 28 + unpadded, 0, elen - unpadded);
sendto(self->tp_socket, (void *)dgram, n, 0, (void *)from, fromlen); sendto(self->tp_socket, (void *)dgram, 28 + elen, 0,
(void *)from, fromlen);
#undef set16 #undef set16
} }
else { else {
......
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