diff --git a/src/aprsc.c b/src/aprsc.c index cdd2da8..28ec73b 100644 --- a/src/aprsc.c +++ b/src/aprsc.c @@ -257,31 +257,6 @@ int main(int argc, char **argv) dupecheck_init(); historydb_init(); -#if 0 - /* - * As a general rule, loading of databases is not a Good Idea in - * operational system. Development time debugging on other hand.. - */ - sprintf(path, "%s/historydb.dump", rundir); - fp = fopen(path,"r"); - if (fp) { - historydb_load(fp); - fclose(fp); - } - sprintf(path, "%s/filter.wx.dump", rundir); - fp = fopen(path,"r"); - if (fp) { - filter_wx_load(fp); - fclose(fp); - } - sprintf(path, "%s/filter.entry.dump", rundir); - fp = fopen(path,"r"); - if (fp) { - filter_entrycall_load(fp); - fclose(fp); - } -#endif - time(&cleanup_tick); /* start the accept thread, which will start server threads */ diff --git a/src/filter.c b/src/filter.c index e476be5..306072f 100644 --- a/src/filter.c +++ b/src/filter.c @@ -480,63 +480,6 @@ void filter_entrycall_dump(FILE *fp) } } -void filter_entrycall_load(FILE *fp) -{ - char buf[500]; - struct filter_entrycall_t *f, *f2, **fpp; - int idx, i, len; - long t; - uint32_t hash; - char call[20]; - char *p; - - /* No need to have locks -- yet.. */ - - while (!feof(fp)) { - p = fgets(buf, sizeof(buf), fp); - if (!p) break; /* EOF? */ - i = sscanf( buf, "%ld\t%18[^\n]\n", &t, call ); - if (i != 2) { - hlog(LOG_INFO, "Filter_entrycall_load: sscanf->%d, bad input: %s", i, buf); - continue; - } - - if (t < now) - continue; /* Too old */ - - len = strlen(call); - hash = keyhash(call, len, 0); - idx = ( hash ^ /* Fold the hashbits.. */ - (hash >> 11) ^ - (hash >> 22) - ) % FILTER_ENTRYCALL_HASHSIZE; - - fpp = &filter_entrycall_hash[idx]; - f2 = NULL; - - /* There should not be key collisions.. - .. nor it exactly matters if reload gets - items in reverse order. */ - -#ifndef _FOR_VALGRIND_ - f = cellmalloc(filter_entrycall_cells); -#else - f = hmalloc(sizeof(*f)); -#endif - if (!f) break; - - f->next = *fpp; - f->expirytime = t; - f->hash = hash; - f->len = len; - - memcpy(f->callsign, call, len); - memset(f->callsign+len, 0, sizeof(f->callsign)-len); - - *fpp = f; - } -} - /* ================================================================ */ @@ -735,62 +678,6 @@ void filter_wx_dump(FILE *fp) } } -void filter_wx_load(FILE *fp) -{ - char buf[500]; - struct filter_wx_t *f, *f2, **fpp; - int idx, i, len; - long t; - uint32_t hash; - char call[20]; - char *p; - - /* No need to have locks -- yet.. */ - - while (!feof(fp)) { - p = fgets(buf, sizeof(buf), fp); - if (!p) break; /* EOF? */ - i = sscanf( buf, "%ld\t%18[^\n]\n", &t, call ); - if (i != 2) { - hlog(LOG_INFO, "Filter_wx_load: sscanf->%d, bad input: %s", i, buf); - continue; - } - - if (t < now) - continue; /* Too old */ - - len = strlen(call); - hash = keyhash(call, len, 0); - idx = ( hash ^ /* Fold the hashbits.. */ - (hash >> 11) ^ - (hash >> 22) - ) % FILTER_WX_HASHSIZE; - - fpp = &filter_wx_hash[idx]; - f2 = NULL; - - /* There should not be key collisions.. - .. nor it exactly matters if reload gets - items in reverse order. */ - -#ifndef _FOR_VALGRIND_ - f = cellmalloc(filter_wx_cells); -#else - f = hmalloc(sizeof(*f)); -#endif - if (!f) break; - - f->next = *fpp; - f->expirytime = t; - f->hash = hash; - f->len = len; - - memcpy(f->callsign, call, len); - memset(f->callsign+len, 0, sizeof(f->callsign)-len); - - *fpp = f; - } -} /* ================================================================ */ diff --git a/src/historydb.c b/src/historydb.c index a618592..f4a1ec4 100644 --- a/src/historydb.c +++ b/src/historydb.c @@ -116,7 +116,6 @@ void historydb_atend(void) } } - void historydb_dump_entry(FILE *fp, struct history_cell_t *hp) { fprintf(fp, "%ld\t", hp->arrivaltime); @@ -148,96 +147,6 @@ void historydb_dump(FILE *fp) rwl_rdunlock(&historydb_rwlock); } -int historydb_load(FILE *fp) -{ - // load the historydb in text format, ignore too old positions - int i; - time_t expirytime = now - lastposition_storetime; - time_t t; - char bufline[2000]; - char keybuf[20]; - int packettype, flags; - float lat, lon; - int packetlen = 0; - int h1, h2, keylen; - struct history_cell_t *hp; - int linecount = 0; - - - // multiple locks ? one for each bucket, or for a subset of buckets ? - rwl_wrlock(&historydb_rwlock); - - // discard previous content - for ( i = 0; i < HISTORYDB_HASH_MODULO; ++i ) { - struct history_cell_t *hp, *nhp; - - hp = historydb_hash[i]; - nhp = NULL; - for ( ; hp ; hp = nhp ) { - // the 'next' will get freed from underneath of us.. - nhp = hp->next; - historydb_free(hp); - } - historydb_hash[i] = NULL; - } - - // now the loading... - while (!feof(fp)) { - ++linecount; - - i = fscanf(fp, "%ld\t%9[^\t]\t%d\t%d\t%f\t%f\t%d\t", - &t, keybuf, &packettype, &flags, - &lat, &lon, &packetlen ); - - if (i != 7) { /* verify correct scan */ - if (feof(fp)) break; /* errors on EOF */ - - hlog(LOG_ERR, "historybuf load, wrong parse on line %d, ret=%d", linecount, i); - break; - } - // FIXME: now several parameters may be invalid for us, like: - // if packetlen >= sizeof(bufline) ?? - - i = fread( bufline, packetlen, 1, fp); - - // i == packetlen ?? - - if (t <= expirytime) - continue; // Too old, forget it. - - keylen = strlen(keybuf); - h1 = keyhash(keybuf, keylen, 0); - h2 = h1; - h2 ^= (h2 >> 16); /* Fold hash bits.. */ - i = h2 % HISTORYDB_HASH_MODULO; - - // Not found on this chain, insert it! - hp = historydb_alloc(packetlen); - hp->next = historydb_hash[i]; - historydb_hash[i] = hp; - - hp->hash1 = h1; - strcpy(hp->key, keybuf); - hp->lat = lat; - hp->coslat = cosf(lat); - hp->lon = lon; - hp->arrivaltime = t; - hp->packettype = packettype; - hp->flags = flags; - hp->packetlen = packetlen; - if (packetlen > 300) packetlen = 300; // max to 300.. - - memcpy(hp->packet, bufline, packetlen); - - } // .. while !feof .. - - // Free the lock - rwl_wrunlock(&historydb_rwlock); - - return 0; -} - - /* insert... */ int historydb_insert(struct pbuf_t *pb)