mirror of git://git.gnupg.org/gnupg.git
common: New function string_to_u64.
* common/stringhelp.c (string_to_u64): New. * dirmngr/http.c (longcounter_t): Remove. (struct cookie_s): Change content_length to uint64_t. (parse_response): Use string_to_u64. -- Meanwhile we allow some C99 features including stdint.h. Thus we can simplify things now. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
72fa314b71
commit
0698324cde
|
@ -36,9 +36,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#ifdef HAVE_STDINT_H
|
#include <stdint.h>
|
||||||
# include <stdint.h>
|
|
||||||
#endif
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
|
|
||||||
#define tohex_lower(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'a'))
|
#define tohex_lower(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'a'))
|
||||||
|
|
||||||
|
|
||||||
/* Sometimes we want to avoid mixing slashes and backslashes on W32
|
/* Sometimes we want to avoid mixing slashes and backslashes on W32
|
||||||
and prefer backslashes. There is usual no problem with mixing
|
and prefer backslashes. There is usual no problem with mixing
|
||||||
them, however a very few W32 API calls can't grok plain slashes.
|
them, however a very few W32 API calls can't grok plain slashes.
|
||||||
|
@ -660,6 +661,25 @@ compare_filenames (const char *a, const char *b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Convert a base-10 number in STRING into a 64 bit unsigned int
|
||||||
|
* value. Leading white spaces are skipped but no error checking is
|
||||||
|
* done. Thus it is similar to atoi(). */
|
||||||
|
uint64_t
|
||||||
|
string_to_u64 (const char *string)
|
||||||
|
{
|
||||||
|
uint64_t val = 0;
|
||||||
|
|
||||||
|
while (spacep (string))
|
||||||
|
string++;
|
||||||
|
for (; digitp (string); string++)
|
||||||
|
{
|
||||||
|
val *= 10;
|
||||||
|
val += *string - '0';
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Convert 2 hex characters at S to a byte value. Return this value
|
/* Convert 2 hex characters at S to a byte value. Return this value
|
||||||
or -1 if there is an error. */
|
or -1 if there is an error. */
|
||||||
int
|
int
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#ifndef GNUPG_COMMON_STRINGHELP_H
|
#ifndef GNUPG_COMMON_STRINGHELP_H
|
||||||
#define GNUPG_COMMON_STRINGHELP_H
|
#define GNUPG_COMMON_STRINGHELP_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
/*-- stringhelp.c --*/
|
/*-- stringhelp.c --*/
|
||||||
|
@ -59,6 +60,7 @@ char *make_absfilename_try (const char *first_part,
|
||||||
...) GPGRT_ATTR_SENTINEL(0);
|
...) GPGRT_ATTR_SENTINEL(0);
|
||||||
int compare_filenames( const char *a, const char *b );
|
int compare_filenames( const char *a, const char *b );
|
||||||
|
|
||||||
|
uint64_t string_to_u64 (const char *string);
|
||||||
int hextobyte (const char *s);
|
int hextobyte (const char *s);
|
||||||
|
|
||||||
size_t utf8_charcount (const char *s, int len);
|
size_t utf8_charcount (const char *s, int len);
|
||||||
|
|
|
@ -130,15 +130,6 @@
|
||||||
"01234567890@" \
|
"01234567890@" \
|
||||||
"!\"#$%&'()*+,-./:;<=>?[\\]^_{|}~"
|
"!\"#$%&'()*+,-./:;<=>?[\\]^_{|}~"
|
||||||
|
|
||||||
/* A long counter type. */
|
|
||||||
#ifdef HAVE_STRTOULL
|
|
||||||
typedef unsigned long long longcounter_t;
|
|
||||||
# define counter_strtoul(a) strtoull ((a), NULL, 10)
|
|
||||||
#else
|
|
||||||
typedef unsigned long longcounter_t;
|
|
||||||
# define counter_strtoul(a) strtoul ((a), NULL, 10)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HTTP_USE_NTBTLS
|
#if HTTP_USE_NTBTLS
|
||||||
typedef ntbtls_t tls_session_t;
|
typedef ntbtls_t tls_session_t;
|
||||||
# define USE_TLS 1
|
# define USE_TLS 1
|
||||||
|
@ -206,7 +197,7 @@ struct cookie_s
|
||||||
|
|
||||||
/* The remaining content length and a flag telling whether to use
|
/* The remaining content length and a flag telling whether to use
|
||||||
the content length. */
|
the content length. */
|
||||||
longcounter_t content_length;
|
uint64_t content_length;
|
||||||
unsigned int content_length_valid:1;
|
unsigned int content_length_valid:1;
|
||||||
};
|
};
|
||||||
typedef struct cookie_s *cookie_t;
|
typedef struct cookie_s *cookie_t;
|
||||||
|
@ -2170,7 +2161,7 @@ parse_response (http_t hd)
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
cookie->content_length_valid = 1;
|
cookie->content_length_valid = 1;
|
||||||
cookie->content_length = counter_strtoul (s);
|
cookie->content_length = string_to_u64 (s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue