79 #define NUMHASH_AUTO_HASH -1 84 101, 503, 1009, 2003, 3001, 5003, 7001,
85 10007, 20011, 30011, 40009, 50021, 60013, 70001, 80021, 90001,
86 100003, 150001, 200003, 300007, 400009, 500009, 600011, 700001,
87 800011, 900001, 1000003, 1100009, 1200007, 1300021, 1400017, 1500007,
88 1600033, 1700021, 1800017, 1900009, 2000003, 3000017, 4000037, 5000111,
89 6000101, 7000127, 8000051, -1
142 warning(0,
"Duplicate number %lld!", nro->
key);
153 if (
table->number_total ==
table->table_size) {
154 error(0,
"Table limit %ld reached, cannot add %s!",
155 table->table_size, nro);
175 ntable = gw_malloc(
sizeof(
Numhash));
181 for(i=0 ;
primes[i] > 0; i++) {
202 if (
sizeof(
long long) >= 16)
204 else if (
sizeof(
long long) >= 8)
234 if (ptr->
key ==
key)
return 1;
267 key = strtoll(nro + len -
precision, (
char**) NULL, 10);
269 key = strtoll(nro, (
char**) NULL, 10);
280 gw_free(
table->hash);
287 int i, l, max = 0, tot = 0;
290 for (i=0; i <
table->hash_size; i++)
291 if (
table->hash[i]) {
293 ptr =
table->hash[i];
294 for (l=0; ptr->
next; ptr = ptr->
next)
303 return (
double)(tot*100.0/(
table->hash_size));
309 return table->number_total;
316 List *request_headers, *reply_headers;
320 char *data, *ptr, numbuf[100];
327 &reply_headers, &reply_body);
335 error(0,
"Cannot load numhash!");
344 error(0,
"Strange content type <%s> for numhash - expecting 'text/plain'" 353 if (*ptr ==
'\n')
lines++;
356 debug(
"numhash", 0,
"Total %d lines in %s",
lines, seek_url);
364 while((ptr = strchr(data,
'\n'))) {
366 while(*data !=
'\0' && isspace(*data))
370 while (*data !=
'\0') {
372 numbuf[loc++] = *data;
373 else if (*data ==
' ' || *data ==
'+' || *data ==
'-')
384 warning(0,
"Corrupted line '%s'", data);
390 info(0,
"Read from <%s> total of %ld numbers", seek_url,
table->number_total);
static Numhash * numhash_init(int max_numbers, int hash_size)
void error(int err, const char *fmt,...)
void info(int err, const char *fmt,...)
void http_header_get_content_type(List *headers, Octstr **type, Octstr **charset)
struct numhash_number * next
void numhash_destroy(Numhash *table)
#define octstr_get_cstr(ostr)
Numhash * numhash_create(const char *seek_url)
void http_destroy_headers(List *headers)
double numhash_hash_fill(Numhash *table, int *longest)
int numhash_find_number(Numhash *table, Octstr *nro)
int numhash_find_key(Numhash *table, long long key)
long long numhash_get_char_key(char *nro)
List * http_create_empty_headers(void)
void warning(int err, const char *fmt,...)
void octstr_destroy(Octstr *ostr)
struct numhash_number * numbers
#define octstr_create(cstr)
static int add_item(Numhash *table, struct numhash_number *nro)
long octstr_len(const Octstr *ostr)
#define NUMHASH_AUTO_HASH
int http_get_real(int method, Octstr *url, List *request_headers, Octstr **final_url, List **reply_headers, Octstr **reply_body)
void debug(const char *place, int err, const char *fmt,...)
int octstr_str_compare(const Octstr *ostr, const char *str)
long long numhash_get_key(Octstr *nro)
int numhash_size(Numhash *table)
static int numhash_add_number(Numhash *table, char *nro)
struct numhash_number ** hash