Commit 15330e4f authored by Mark Andrews's avatar Mark Andrews
Browse files

isc_strtouq()

parent 54c26ab2
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: rdata.c,v 1.26 1999/02/05 00:05:44 marka Exp $ */
/* $Id: rdata.c,v 1.27 1999/02/05 04:57:19 marka Exp $ */
#include <config.h>
......@@ -55,12 +55,12 @@ static isc_boolean_t buffer_empty(isc_buffer_t *source);
static void buffer_fromregion(isc_buffer_t *buffer,
isc_region_t *region,
unsigned int type);
static dns_result_t uint32_tobuffer(unsigned long value,
static dns_result_t uint32_tobuffer(isc_uint32_t,
isc_buffer_t *target);
static dns_result_t uint16_tobuffer(unsigned long value,
static dns_result_t uint16_tobuffer(isc_uint32_t,
isc_buffer_t *target);
static unsigned long uint32_fromregion(isc_region_t *region);
static unsigned short uint16_fromregion(isc_region_t *region);
static isc_uint32_t uint32_fromregion(isc_region_t *region);
static isc_uint16_t uint16_fromregion(isc_region_t *region);
static dns_result_t gettoken(isc_lex_t *lexer, isc_token_t *token,
isc_tokentype_t expect, isc_boolean_t eol);
static dns_result_t mem_tobuffer(isc_buffer_t *target, void *base,
......@@ -708,7 +708,7 @@ buffer_fromregion(isc_buffer_t *buffer, isc_region_t *region,
}
static dns_result_t
uint32_tobuffer(unsigned long value, isc_buffer_t *target) {
uint32_tobuffer(isc_uint32_t value, isc_buffer_t *target) {
isc_region_t region;
isc_buffer_available(target, &region);
......@@ -723,7 +723,7 @@ uint32_tobuffer(unsigned long value, isc_buffer_t *target) {
}
static dns_result_t
uint16_tobuffer(unsigned long value, isc_buffer_t *target) {
uint16_tobuffer(isc_uint32_t value, isc_buffer_t *target) {
isc_region_t region;
if (value > 0xffff)
......@@ -737,7 +737,7 @@ uint16_tobuffer(unsigned long value, isc_buffer_t *target) {
return (DNS_R_SUCCESS);
}
static unsigned long
static isc_uint32_t
uint32_fromregion(isc_region_t *region) {
unsigned long value;
......@@ -749,7 +749,7 @@ uint32_fromregion(isc_region_t *region) {
return(value);
}
static unsigned short
static isc_uint16_t
uint16_fromregion(isc_region_t *region) {
INSIST(region->length >= 2);
......@@ -943,9 +943,9 @@ static int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static dns_result_t
time_totext(unsigned long value, isc_buffer_t *target) {
long long start;
long long base;
long long t;
isc_int64_t start;
isc_int64_t base;
isc_int64_t t;
struct tm tm;
char buf[sizeof "YYYYMMDDHHMMSS"];
int secs;
......@@ -1056,11 +1056,11 @@ static const char atob_digits[86] =
struct state {
int32_t Ceor;
int32_t Csum;
int32_t Crot;
int32_t word;
int32_t bcount;
isc_int32_t Ceor;
isc_int32_t Csum;
isc_int32_t Crot;
isc_int32_t word;
isc_int32_t bcount;
};
#define Ceor state->Ceor
......@@ -1150,7 +1150,7 @@ putbyte(int c, isc_buffer_t *target, struct state *state) {
static dns_result_t
atob_tobuffer(isc_lex_t *lexer, isc_buffer_t *target) {
int32_t oeor, osum, orot;
isc_int32_t oeor, osum, orot;
struct state statebuf, *state= &statebuf;
isc_token_t token;
char c;
......@@ -1223,7 +1223,7 @@ byte_btoa(int c, isc_buffer_t *target, struct state *state) {
isc_buffer_add(target, 1);
} else {
register int tmp = 0;
register int32_t tmpword = word;
register isc_int32_t tmpword = word;
if (tmpword < 0) {
/* Because some don't support u_long */
......
......@@ -15,12 +15,13 @@
* SOFTWARE.
*/
/* $Id: tsig_250.c,v 1.1 1999/02/04 01:06:40 marka Exp $ */
/* $Id: tsig_250.c,v 1.2 1999/02/05 04:57:19 marka Exp $ */
/* draft-ietf-dnsind-tsig-07.txt */
#ifndef RDATA_ANY_255_TSIG_250_H
#define RDATA_ANY_255_TSIG_250_H
#include <isc/str.h>
static dns_result_t
fromtext_any_tsig(dns_rdataclass_t class, dns_rdatatype_t type,
......@@ -29,7 +30,7 @@ fromtext_any_tsig(dns_rdataclass_t class, dns_rdatatype_t type,
{
isc_token_t token;
dns_name_t name;
unsigned long long sigtime;
isc_uint64_t sigtime;
isc_buffer_t buffer;
char *e;
......@@ -46,7 +47,7 @@ fromtext_any_tsig(dns_rdataclass_t class, dns_rdatatype_t type,
/* Time Signed: 48 bits */
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
sigtime = strtouq(token.value.as_pointer, &e, 10);
sigtime = isc_strtouq(token.value.as_pointer, &e, 10);
if (*e != 0)
return (DNS_R_SYNTAX);
if ((sigtime >> 48) != 0)
......@@ -99,7 +100,7 @@ totext_any_tsig(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
dns_name_t name;
dns_name_t prefix;
isc_boolean_t sub;
unsigned long long sigtime;
isc_uint64_t sigtime;
unsigned short n;
REQUIRE(rdata->type == 250);
......@@ -116,8 +117,8 @@ totext_any_tsig(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
isc_region_consume(&sr, name_length(&name));
/* Time Signed */
sigtime = ((unsigned long long)sr.base[0] << 40) |
((unsigned long long)sr.base[1] << 32) |
sigtime = ((isc_uint64_t)sr.base[0] << 40) |
((isc_uint64_t)sr.base[1] << 32) |
(sr.base[2] << 24) | (sr.base[3] << 16) |
(sr.base[4] << 8) | sr.base[5];
isc_region_consume(&sr, 6);
......
......@@ -15,12 +15,13 @@
* SOFTWARE.
*/
/* $Id: tsig_250.h,v 1.1 1999/02/04 01:06:40 marka Exp $ */
/* $Id: tsig_250.h,v 1.2 1999/02/05 04:57:19 marka Exp $ */
/* draft-ietf-dnsind-tsig-07.txt */
#ifndef RDATA_ANY_255_TSIG_250_H
#define RDATA_ANY_255_TSIG_250_H
#include <isc/str.h>
static dns_result_t
fromtext_any_tsig(dns_rdataclass_t class, dns_rdatatype_t type,
......@@ -29,7 +30,7 @@ fromtext_any_tsig(dns_rdataclass_t class, dns_rdatatype_t type,
{
isc_token_t token;
dns_name_t name;
unsigned long long sigtime;
isc_uint64_t sigtime;
isc_buffer_t buffer;
char *e;
......@@ -46,7 +47,7 @@ fromtext_any_tsig(dns_rdataclass_t class, dns_rdatatype_t type,
/* Time Signed: 48 bits */
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
sigtime = strtouq(token.value.as_pointer, &e, 10);
sigtime = isc_strtouq(token.value.as_pointer, &e, 10);
if (*e != 0)
return (DNS_R_SYNTAX);
if ((sigtime >> 48) != 0)
......@@ -99,7 +100,7 @@ totext_any_tsig(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
dns_name_t name;
dns_name_t prefix;
isc_boolean_t sub;
unsigned long long sigtime;
isc_uint64_t sigtime;
unsigned short n;
REQUIRE(rdata->type == 250);
......@@ -116,8 +117,8 @@ totext_any_tsig(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
isc_region_consume(&sr, name_length(&name));
/* Time Signed */
sigtime = ((unsigned long long)sr.base[0] << 40) |
((unsigned long long)sr.base[1] << 32) |
sigtime = ((isc_uint64_t)sr.base[0] << 40) |
((isc_uint64_t)sr.base[1] << 32) |
(sr.base[2] << 24) | (sr.base[3] << 16) |
(sr.base[4] << 8) | sr.base[5];
isc_region_consume(&sr, 6);
......
......@@ -24,5 +24,7 @@ typedef short isc_int16_t;
typedef unsigned short isc_uint16_t;
typedef int isc_int32_t;
typedef unsigned int isc_uint32_t;
typedef long long isc_int64_t;
typedef unsigned long long isc_uint64_t;
#endif /* ISC_INT_H */
/*
* Copyright (C) 1999 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/* $Id: str.h,v 1.1 1999/02/05 04:57:20 marka Exp $ */
#ifndef ISC_STR_H
#define ISC_STR_H 1
#include <isc/types.h>
isc_uint64_t isc_strtouq(char *source, char **endp, int base);
/*
* Convert the string pointed to by 'source' to isc_uint64_t.
*
* On successful conversion 'endp' points to the first character
* after conversion is complete.
*
* 'base': 0 or 2..36
*
* If base is 0 the base is computed from the string type.
*
* On error 'endp' points to 'source'.
*/
#endif /* ISC_INT_H */
/*
* Copyright (C) 1999 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#include <ctype.h>
#include <string.h>
#include <isc/str.h>
static char digits[] = "0123456789abcdefghijklmnoprstuvwxyz";
isc_uint64_t
isc_strtouq(char *source, char **end, int base) {
isc_uint64_t tmp;
isc_uint64_t overflow;
char *s = source;
char *o;
char c;
if ((base < 0) || (base == 1) || (base > 36)) {
*end = source;
return (0);
}
while (*s != 0 && isascii(*s&0xff) && isspace(*s&0xff))
s++;
if (*s == '+' /* || *s == '-' */)
s++;
if (base == 0) {
if (*s == '0' && (*(s+1) == 'X' || *(s+1) == 'x')) {
s += 2;
base = 16;
} else if (*s == '0')
base = 8;
else
base = 10;
}
if (*s == 0) {
*end = source;
return (0);
}
overflow = ~0;
overflow /= base;
tmp = 0;
while ((c = *s) != 0) {
c = tolower(c);
/* end ? */
if ((o = strchr(digits, c)) == NULL) {
*end = s;
return (tmp);
}
/* end ? */
if ((o - digits) >= base) {
*end = s;
return (tmp);
}
/* overflow ? */
if (tmp > overflow) {
*end = source;
return (0);
}
tmp *= base;
/* overflow ? */
if ((tmp + (o - digits)) < tmp) {
*end = source;
return (0);
}
tmp += o - digits;
s++;
}
*end = s;
return (tmp);
}
......@@ -24,5 +24,7 @@ typedef short isc_int16_t;
typedef unsigned short isc_uint16_t;
typedef int isc_int32_t;
typedef unsigned int isc_uint32_t;
typedef long long isc_int64_t;
typedef unsigned long long isc_uint64_t;
#endif /* ISC_INT_H */
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