diff options
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/Makefile.am | 6 | ||||
| -rw-r--r-- | runtime/hashtable.c (renamed from runtime/hashtable/hashtable.c) | 42 | ||||
| -rw-r--r-- | runtime/hashtable.h | 7 | ||||
| -rw-r--r-- | runtime/hashtable_itr.c (renamed from runtime/hashtable/hashtable_itr.c) | 2 | ||||
| -rw-r--r-- | runtime/hashtable_itr.h (renamed from runtime/hashtable/hashtable_itr.h) | 4 | ||||
| -rw-r--r-- | runtime/hashtable_private.h (renamed from runtime/hashtable/hashtable_private.h) | 1 | ||||
| -rw-r--r-- | runtime/rsyslog.h | 3 |
7 files changed, 57 insertions, 8 deletions
diff --git a/runtime/Makefile.am b/runtime/Makefile.am index 5a0c4437..93817e75 100644 --- a/runtime/Makefile.am +++ b/runtime/Makefile.am @@ -95,9 +95,11 @@ librsyslog_la_SOURCES = \ ../parse.c \ ../parse.h \ \ - hashtable/hashtable.c \ + hashtable.c \ hashtable.h \ - hashtable/hashtable_private.h \ + hashtable_itr.c \ + hashtable_itr.h \ + hashtable_private.h \ \ ../outchannel.c \ ../outchannel.h \ diff --git a/runtime/hashtable/hashtable.c b/runtime/hashtable.c index a10e3bc6..41fc60fe 100644 --- a/runtime/hashtable/hashtable.c +++ b/runtime/hashtable.c @@ -29,7 +29,7 @@ const float max_load_factor = 0.65; struct hashtable * create_hashtable(unsigned int minsize, unsigned int (*hashf) (void*), - int (*eqf) (void*,void*)) + int (*eqf) (void*,void*), void (*dest)(void*)) { struct hashtable *h; unsigned int pindex, size = primes[0]; @@ -49,6 +49,7 @@ create_hashtable(unsigned int minsize, h->entrycount = 0; h->hashfn = hashf; h->eqfn = eqf; + h->dest = dest; h->loadlimit = (unsigned int) ceil(size * max_load_factor); return h; } @@ -225,7 +226,16 @@ hashtable_destroy(struct hashtable *h, int free_values) { e = table[i]; while (NULL != e) - { f = e; e = e->next; freekey(f->k); free(f->v); free(f); } + { + f = e; + e = e->next; + freekey(f->k); + if(h->dest == NULL) + free(f->v); + else + h->dest(f->v); + free(f); + } } } else @@ -241,6 +251,34 @@ hashtable_destroy(struct hashtable *h, int free_values) free(h); } +/* some generic hash functions */ + +/* one provided by Aaaron Wiebe based on perl's hashng algorithm + * (so probably pretty generic). Not for excessively large strings! + */ +unsigned int +hash_from_string(void *k) +{ + int len; + char *rkey = (char*) k; + unsigned hashval = 1; + + len = (int) strlen(rkey); + while (len--) + hashval = hashval * 33 + *rkey++; + + return hashval; +} + + +int +key_equals_string(void *key1, void *key2) +{ + /* we must return true IF the keys are equal! */ + return !strcmp(key1, key2); +} + + /* * Copyright (c) 2002, Christopher Clark * All rights reserved. diff --git a/runtime/hashtable.h b/runtime/hashtable.h index b90781ab..f777ad0b 100644 --- a/runtime/hashtable.h +++ b/runtime/hashtable.h @@ -68,13 +68,14 @@ struct hashtable; * @param minsize minimum initial size of hashtable * @param hashfunction function for hashing keys * @param key_eq_fn function for determining key equality + * @param dest destructor for value entries (NULL -> use free()) * @return newly created hashtable or NULL on failure */ struct hashtable * create_hashtable(unsigned int minsize, unsigned int (*hashfunction) (void*), - int (*key_eq_fn) (void*,void*)); + int (*key_eq_fn) (void*,void*), void (*dest) (void*)); /***************************************************************************** * hashtable_insert @@ -196,4 +197,6 @@ hashtable_destroy(struct hashtable *h, int free_values); * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ +unsigned int hash_from_string(void *k) ; +int key_equals_string(void *key1, void *key2); diff --git a/runtime/hashtable/hashtable_itr.c b/runtime/hashtable_itr.c index 5dced841..967287f1 100644 --- a/runtime/hashtable/hashtable_itr.c +++ b/runtime/hashtable_itr.c @@ -38,6 +38,7 @@ hashtable_iterator(struct hashtable *h) /* key - return the key of the (key,value) pair at the current position */ /* value - return the value of the (key,value) pair at the current position */ +#if 0 /* these are now inline functions! */ void * hashtable_iterator_key(struct hashtable_itr *i) { return i->e->k; } @@ -45,6 +46,7 @@ hashtable_iterator_key(struct hashtable_itr *i) void * hashtable_iterator_value(struct hashtable_itr *i) { return i->e->v; } +#endif /*****************************************************************************/ /* advance - advance the iterator to the next element diff --git a/runtime/hashtable/hashtable_itr.h b/runtime/hashtable_itr.h index eea699a7..1c206b6e 100644 --- a/runtime/hashtable/hashtable_itr.h +++ b/runtime/hashtable_itr.h @@ -28,7 +28,7 @@ hashtable_iterator(struct hashtable *h); /* hashtable_iterator_key * - return the value of the (key,value) pair at the current position */ -extern inline void * +static inline void * hashtable_iterator_key(struct hashtable_itr *i) { return i->e->k; @@ -37,7 +37,7 @@ hashtable_iterator_key(struct hashtable_itr *i) /*****************************************************************************/ /* value - return the value of the (key,value) pair at the current position */ -extern inline void * +static inline void * hashtable_iterator_value(struct hashtable_itr *i) { return i->e->v; diff --git a/runtime/hashtable/hashtable_private.h b/runtime/hashtable_private.h index 3e95f600..10b82da4 100644 --- a/runtime/hashtable/hashtable_private.h +++ b/runtime/hashtable_private.h @@ -21,6 +21,7 @@ struct hashtable { unsigned int primeindex; unsigned int (*hashfn) (void *k); int (*eqfn) (void *k1, void *k2); + void (*dest) (void *v); /* destructor for values, if NULL use free() */ }; /*****************************************************************************/ diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h index 43203378..7ccc9cb8 100644 --- a/runtime/rsyslog.h +++ b/runtime/rsyslog.h @@ -458,6 +458,9 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth RS_RET_INTERNAL_ERROR = -2175, /**< rsyslogd internal error, unexpected code path reached */ RS_RET_ERR_CRE_AFUX = -2176, /**< error creating AF_UNIX socket (and binding it) */ RS_RET_RATE_LIMITED = -2177, /**< some messages discarded due to exceeding a rate limit */ + RS_RET_ERR_HDFS_WRITE = -2178, /**< error writing to HDFS */ + RS_RET_ERR_HDFS_OPEN = -2179, /**< error during hdfsOpen (e.g. file does not exist) */ + RS_RET_FILE_NOT_SPECIFIED = -2180, /**< file name not configured where this was required */ /* RainerScript error messages (range 1000.. 1999) */ RS_RET_SYSVAR_NOT_FOUND = 1001, /**< system variable could not be found (maybe misspelled) */ |
