Commit e20e140f authored by Pekka Pessi's avatar Pekka Pessi

bnf module: using isize_t and issize_t in API.

darcs-hash:20060906215314-65a35-6f4915046f8c54040db275eba1a56d5c96455d6a.gz
parent 78627370
......@@ -172,7 +172,8 @@ int span_ip4_address(char const *host)
int scan_ip4_address(char **inout_host)
{
char *src = *inout_host, *dst = src;
int n, canonize = 0;
issize_t n;
int canonize = 0;
n = span_canonic_ip4_address(src, &canonize);
if (n == 0)
......@@ -528,11 +529,11 @@ int scan_ip_address(char **inout_host)
/** Return length of a valid domain label */
static inline
int span_domain_label(char const *label)
size_t span_domain_label(char const *label)
{
/* domainlabel = alphanum / alphanum *( alphanum / "-" ) alphanum */
if (IS_ALPHANUM(*label)) {
int n;
size_t n;
for (n = 1; IS_ALPHANUM(label[n]) || label[n] == '-'; n++)
;
if (IS_ALPHANUM(label[n - 1]))
......@@ -544,9 +545,10 @@ int span_domain_label(char const *label)
/** Scan valid domain name and count number of labels in it. */
static inline
int span_domain_labels(char const *host, int *return_labels)
size_t span_domain_labels(char const *host, size_t *return_labels)
{
int len, n, labels, c;
size_t len, n, labels;
int c;
if (!host || !host[0])
return 0;
......@@ -588,16 +590,16 @@ int span_domain_labels(char const *host, int *return_labels)
* toplabel = ALPHA / ALPHA *( alphanum / "-" ) alphanum
* @endcode
*/
int span_domain(char const *host)
isize_t span_domain(char const *host)
{
return span_domain_labels(host, NULL);
}
/** Scan valid domain name. */
int scan_domain(char **inout_host)
issize_t scan_domain(char **inout_host)
{
char *host;
int n, labels;
size_t n, labels;
n = span_domain_labels(host = *inout_host, &labels);
if (n == 0)
......@@ -613,7 +615,7 @@ int scan_domain(char **inout_host)
}
/** Return length of a valid domain name or IP address. */
int span_host(char const *host)
isize_t span_host(char const *host)
{
if (!host || !host[0])
return 0;
......@@ -624,14 +626,14 @@ int span_host(char const *host)
if (IS_DIGIT(host[0])) {
int n = span_ip4_address(host);
if (n)
return n;
return (isize_t)n;
}
return span_domain(host);
}
/** Scan valid domain name or IP address. */
int scan_host(char **inout_host)
issize_t scan_host(char **inout_host)
{
char *host = *inout_host;
......@@ -645,7 +647,7 @@ int scan_host(char **inout_host)
if (IS_DIGIT(host[0])) {
int n = scan_ip4_address(inout_host);
if (n > 0)
return n;
return (issize_t)n;
}
return scan_domain(inout_host);
......@@ -716,7 +718,7 @@ int host_is_ip_address(char const *string)
*/
int host_is_domain(char const *string)
{
int n = string ? span_domain(string) : 0;
size_t n = string ? span_domain(string) : 0;
return string && n > 0 && string[n] == '\0';
}
......@@ -726,7 +728,7 @@ int host_is_domain(char const *string)
*/
int host_is_valid(char const *string)
{
int n = span_host(string);
size_t n = span_host(string);
return n > 0 && string[n] == '\0';
}
......@@ -744,8 +746,8 @@ int host_is_local(char const *host)
else if (host_is_ip4_address(host))
return (strncmp(host, "127.", 4) == 0);
else
return (strcmp(host, "localhost") == 0 ||
strcmp(host, "localhost.localdomain") == 0);
return (strcasecmp(host, "localhost") == 0 ||
strcasecmp(host, "localhost.localdomain") == 0);
}
/** Return true if @a string has domain name in "invalid." domain.
......@@ -753,7 +755,7 @@ int host_is_local(char const *host)
*/
int host_has_domain_invalid(char const *string)
{
int n = span_domain(string);
size_t n = span_domain(string);
if (n >= 7 && string[n] == '\0') {
static char const invalid[] = ".invalid";
......
......@@ -35,7 +35,7 @@
*
*/
#include <sofia-sip/su_config.h>
#include <sofia-sip/su_types.h>
#include <string.h>
......@@ -174,7 +174,7 @@ SOFIAPUBVAR unsigned char const _bnf_table[256];
/** Calculate span of a linear whitespace.
* LWS = [*WSP CRLF] 1*WSP
*/
static inline int span_lws(char const *s)
static inline isize_t span_lws(char const *s)
{
char const *e = s;
int i = 0;
......@@ -187,7 +187,7 @@ static inline int span_lws(char const *s)
}
/** Calculate span of a token or linear whitespace characters. */
static inline int span_token_lws(char const *s)
static inline isize_t span_token_lws(char const *s)
{
char const *e = s;
while (_bnf_table[(unsigned char)(*e)] & (bnf_token | bnf_lws))
......@@ -196,7 +196,7 @@ static inline int span_token_lws(char const *s)
}
/** Calculate span of a token characters. */
static inline int span_token(char const *s)
static inline isize_t span_token(char const *s)
{
char const *e = s;
while (_bnf_table[(unsigned char)(*e)] & bnf_token)
......@@ -205,7 +205,7 @@ static inline int span_token(char const *s)
}
/** Calculate span of a alphabetic characters. */
static inline int span_alpha(char const *s)
static inline isize_t span_alpha(char const *s)
{
char const *e = s;
while (_bnf_table[(unsigned char)(*e)] & bnf_alpha)
......@@ -214,7 +214,7 @@ static inline int span_alpha(char const *s)
}
/** Calculate span of a digits. */
static inline int span_digit(char const *s)
static inline isize_t span_digit(char const *s)
{
char const *e = s;
while (*e >= '0' && *e <= '9')
......@@ -223,7 +223,7 @@ static inline int span_digit(char const *s)
}
/** Calculate span of a hex. */
static inline int span_hexdigit(char const *s)
static inline isize_t span_hexdigit(char const *s)
{
char const *e = s;
while (IS_HEX(*e))
......@@ -232,7 +232,7 @@ static inline int span_hexdigit(char const *s)
}
/** Calculate span of characters belonging to an RTSP token */
static inline int span_alpha_digit_safe(char const *s)
static inline isize_t span_alpha_digit_safe(char const *s)
{
char const *e = s;
while (_bnf_table[(unsigned char)(*e)] & (bnf_alpha | bnf_safe))
......@@ -241,7 +241,7 @@ static inline int span_alpha_digit_safe(char const *s)
}
/** Calculate span of a characters valid in parameters. */
static inline int span_param(char const *s)
static inline isize_t span_param(char const *s)
{
char const *e = s;
while (IS_PARAM(*e))
......@@ -250,7 +250,7 @@ static inline int span_param(char const *s)
}
/** Calculate span of a SIP word. */
static inline int span_word(char const *s)
static inline isize_t span_word(char const *s)
{
char const *e = s;
while (*e && (IS_TOKEN(*e) || strchr(SIP_WORD, *e)))
......@@ -259,7 +259,7 @@ static inline int span_word(char const *s)
}
/** Calculate span of a unreserved characters. */
static inline int span_unreserved(char const *s)
static inline isize_t span_unreserved(char const *s)
{
char const *e = s;
while (IS_UNRESERVED(*e))
......@@ -268,7 +268,7 @@ static inline int span_unreserved(char const *s)
}
/** Calculate span of a double quoted string (with escaped chars inside) */
static inline int span_quoted(char const *s)
static inline isize_t span_quoted(char const *s)
{
char const *b = s;
......@@ -309,15 +309,15 @@ SOFIAPUBFUN int span_ip4_address(char const *host);
SOFIAPUBFUN int span_ip6_address(char const *host);
SOFIAPUBFUN int span_ip6_reference(char const *host);
SOFIAPUBFUN int span_ip_address(char const *host);
SOFIAPUBFUN int span_domain(char const *host);
SOFIAPUBFUN int span_host(char const *host);
SOFIAPUBFUN isize_t span_domain(char const *host);
SOFIAPUBFUN isize_t span_host(char const *host);
SOFIAPUBFUN int scan_ip4_address(char **inout_host);
SOFIAPUBFUN int scan_ip6_address(char **inout_host);
SOFIAPUBFUN int scan_ip6_reference(char **inout_host);
SOFIAPUBFUN int scan_ip_address(char **inout_host);
SOFIAPUBFUN int scan_domain(char **inout_host);
SOFIAPUBFUN int scan_host(char **inout_host);
SOFIAPUBFUN issize_t scan_domain(char **inout_host);
SOFIAPUBFUN issize_t scan_host(char **inout_host);
SOFIA_END_DECLS
......
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