modules/server/uhost_cache.c File Reference

#include "server.h"

Go to the source code of this file.

Defines

#define UHOST_CACHE_SIZE   47

Functions

static int uhost_cache_delete (const void *key, void *data, void *param)
void uhost_cache_init ()
void uhost_cache_reset ()
void uhost_cache_destroy ()
static uhost_cache_entry_tcache_lookup (const char *nick)
char * uhost_cache_lookup (const char *nick)
void uhost_cache_addref (const char *nick, const char *uhost)
void uhost_cache_decref (const char *nick)
void uhost_cache_swap (const char *old_nick, const char *new_nick)

Variables

static hash_table_tuhost_cache_ht = NULL


Define Documentation

#define UHOST_CACHE_SIZE   47

Definition at line 3 of file uhost_cache.c.

Referenced by uhost_cache_init().


Function Documentation

static uhost_cache_entry_t* cache_lookup ( const char *  nick  )  [static]

Definition at line 38 of file uhost_cache.c.

References cache, egg_msprintf(), hash_table_find(), NULL, and str_tolower().

Referenced by uhost_cache_decref(), and uhost_cache_lookup().

00039 {
00040   char buf[64], *lnick;
00041   uhost_cache_entry_t *cache = NULL;
00042 
00043   lnick = egg_msprintf(buf, sizeof(buf), NULL, "%s", nick);
00044   str_tolower(lnick);
00045   hash_table_find(uhost_cache_ht, lnick, &cache);
00046   if (lnick != buf) free(lnick);
00047   return(cache);
00048 }

void uhost_cache_addref ( const char *  nick,
const char *  uhost 
)

Definition at line 59 of file uhost_cache.c.

References cache, egg_msprintf(), hash_table_find(), hash_table_insert(), uhost_cache_entry_t::nick, NULL, uhost_cache_entry_t::ref_count, str_tolower(), and uhost_cache_entry_t::uhost.

00060 {
00061   char buf[64], *lnick;
00062   uhost_cache_entry_t *cache = NULL;
00063 
00064   lnick = egg_msprintf(buf, sizeof(buf), NULL, "%s", nick);
00065   str_tolower(lnick);
00066   hash_table_find(uhost_cache_ht, lnick, &cache);
00067   if (!cache) {
00068     cache = calloc(1, sizeof(*cache));
00069     cache->nick = strdup(nick);
00070     str_tolower(cache->nick);
00071     if (uhost) cache->uhost = strdup(uhost);
00072     hash_table_insert(uhost_cache_ht, cache->nick, cache);
00073   }
00074   cache->ref_count++;
00075   if (lnick != buf) free(lnick);
00076 }

void uhost_cache_decref ( const char *  nick  ) 

Definition at line 78 of file uhost_cache.c.

References cache, cache_lookup(), hash_table_remove(), match_my_nick, uhost_cache_entry_t::nick, NULL, uhost_cache_entry_t::ref_count, and uhost_cache_delete().

00079 {
00080   uhost_cache_entry_t *cache;
00081 
00082   /* We don't decrement ourselves.. we always know our own host. */
00083   if (match_my_nick(nick)) return;
00084 
00085   cache = cache_lookup(nick);
00086   if (!cache) return;
00087 
00088   cache->ref_count--;
00089   if (cache->ref_count <= 0) {
00090     hash_table_remove(uhost_cache_ht, cache->nick, NULL);
00091     uhost_cache_delete(NULL, &cache, NULL);
00092   }
00093 }

static int uhost_cache_delete ( const void *  key,
void *  data,
void *  param 
) [static]

Definition at line 28 of file uhost_cache.c.

References cache, uhost_cache_entry_t::nick, and uhost_cache_entry_t::uhost.

Referenced by uhost_cache_decref(), and uhost_cache_destroy().

00029 {
00030   uhost_cache_entry_t *cache = *(void **)dataptr;
00031 
00032   if (cache->nick) free(cache->nick);
00033   if (cache->uhost) free(cache->uhost);
00034   free(cache);
00035   return(0);
00036 }

void uhost_cache_destroy (  ) 

void uhost_cache_init (  ) 

char* uhost_cache_lookup ( const char *  nick  ) 

Definition at line 50 of file uhost_cache.c.

References cache, cache_lookup(), NULL, and uhost_cache_entry_t::uhost.

00051 {
00052   uhost_cache_entry_t *cache;
00053 
00054   cache = cache_lookup(nick);
00055   if (cache) return(cache->uhost);
00056   return(NULL);
00057 }

void uhost_cache_reset (  ) 

Definition at line 16 of file uhost_cache.c.

References uhost_cache_destroy, and uhost_cache_init.

00017 {
00018   uhost_cache_destroy();
00019   uhost_cache_init();
00020 }

void uhost_cache_swap ( const char *  old_nick,
const char *  new_nick 
)

Definition at line 95 of file uhost_cache.c.

References cache, egg_msprintf(), hash_table_insert(), hash_table_remove(), uhost_cache_entry_t::nick, NULL, str_redup(), and str_tolower().

00096 {
00097   uhost_cache_entry_t *cache;
00098   char buf[64], *lnick;
00099 
00100   lnick = egg_msprintf(buf, sizeof(buf), NULL, "%s", old_nick);
00101   str_tolower(lnick);
00102   hash_table_remove(uhost_cache_ht, lnick, &cache);
00103   if (lnick != buf) free(lnick);
00104 
00105   if (cache) {
00106     str_redup(&cache->nick, new_nick);
00107     str_tolower(cache->nick);
00108     hash_table_insert(uhost_cache_ht, cache->nick, cache);
00109   }
00110 }


Variable Documentation

hash_table_t* uhost_cache_ht = NULL [static]

Definition at line 5 of file uhost_cache.c.


Generated on Sun Nov 30 18:43:36 2008 for eggdrop1.9 by  doxygen 1.5.6