]> jfr.im git - irc/rqf/shadowircd.git/blobdiff - src/cache.c
dlink -> rb_dlink
[irc/rqf/shadowircd.git] / src / cache.c
index 3321e649cd3ea12731a6fcb48933eb8c75ac57a9..6f5efb230f91a1ebfa9fd116d2f0b2f3ed078ee4 100644 (file)
@@ -45,6 +45,7 @@
 #include "cache.h"
 #include "sprintf_irc.h"
 #include "irc_dictionary.h"
+#include "numeric.h"
 
 static BlockHeap *cachefile_heap = NULL;
 static BlockHeap *cacheline_heap = NULL;
@@ -53,7 +54,8 @@ struct cachefile *user_motd = NULL;
 struct cachefile *oper_motd = NULL;
 char user_motd_changed[MAX_DATE_STRING];
 
-struct Dictionary *help_dict = NULL;
+struct Dictionary *help_dict_oper = NULL;
+struct Dictionary *help_dict_user = NULL;
 
 /* init_cache()
  *
@@ -72,7 +74,8 @@ init_cache(void)
        user_motd = cache_file(MPATH, "ircd.motd", 0);
        oper_motd = cache_file(OPATH, "opers.motd", 0);
 
-       help_dict = irc_dictionary_create(strcasecmp);
+       help_dict_oper = irc_dictionary_create(strcasecmp);
+       help_dict_user = irc_dictionary_create(strcasecmp);
 }
 
 /* cache_file()
@@ -104,7 +107,7 @@ cache_file(const char *filename, const char *shortname, int flags)
                local_tm = localtime(&sb.st_mtime);
 
                if(local_tm != NULL)
-                       ircsnprintf(user_motd_changed, sizeof(user_motd_changed),
+                       rb_snprintf(user_motd_changed, sizeof(user_motd_changed),
                                 "%d/%d/%d %d:%d",
                                 local_tm->tm_mday, local_tm->tm_mon + 1,
                                 1900 + local_tm->tm_year, local_tm->tm_hour,
@@ -127,7 +130,7 @@ cache_file(const char *filename, const char *shortname, int flags)
                        strlcpy(lineptr->data, " ", sizeof(lineptr->data));
                else
                        strlcpy(lineptr->data, line, sizeof(lineptr->data));
-               dlinkAddTail(lineptr, &lineptr->linenode, &cacheptr->contents);
+               rb_dlinkAddTail(lineptr, &lineptr->linenode, &cacheptr->contents);
        }
 
        fclose(in);
@@ -143,13 +146,13 @@ cache_file(const char *filename, const char *shortname, int flags)
 void
 free_cachefile(struct cachefile *cacheptr)
 {
-       dlink_node *ptr;
-       dlink_node *next_ptr;
+       rb_dlink_node *ptr;
+       rb_dlink_node *next_ptr;
 
        if(cacheptr == NULL)
                return;
 
-       DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head)
+       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head)
        {
                BlockHeapFree(cacheline_heap, ptr->data);
        }
@@ -161,7 +164,8 @@ free_cachefile(struct cachefile *cacheptr)
  *
  * inputs      -
  * outputs     -
- * side effects - contents of help directories are loaded.
+ * side effects - old help cache deleted
+ *             - contents of help directories are loaded.
  */
 void
 load_help(void)
@@ -170,12 +174,19 @@ load_help(void)
        struct dirent *ldirent= NULL;
        char filename[MAXPATHLEN];
        struct cachefile *cacheptr;
+       struct DictionaryIter iter;
 
-#if defined(S_ISLNK) && defined(HAVE_LSTAT)
-       struct stat sb;
-#endif
+       DICTIONARY_FOREACH(cacheptr, &iter, help_dict_oper)
+       {
+               irc_dictionary_delete(help_dict_oper, cacheptr->name);
+               free_cachefile(cacheptr);
+       }
+       DICTIONARY_FOREACH(cacheptr, &iter, help_dict_user)
+       {
+               irc_dictionary_delete(help_dict_user, cacheptr->name);
+               free_cachefile(cacheptr);
+       }
 
-       /* opers must be done first */
        helpfile_dir = opendir(HPATH);
 
        if(helpfile_dir == NULL)
@@ -183,9 +194,9 @@ load_help(void)
 
        while((ldirent = readdir(helpfile_dir)) != NULL)
        {
-               ircsnprintf(filename, sizeof(filename), "%s/%s", HPATH, ldirent->d_name);
+               rb_snprintf(filename, sizeof(filename), "%s/%s", HPATH, ldirent->d_name);
                cacheptr = cache_file(filename, ldirent->d_name, HELP_OPER);
-               irc_dictionary_add(help_dict, cacheptr->name, cacheptr);
+               irc_dictionary_add(help_dict_oper, cacheptr->name, cacheptr);
        }
 
        closedir(helpfile_dir);
@@ -196,29 +207,10 @@ load_help(void)
 
        while((ldirent = readdir(helpfile_dir)) != NULL)
        {
-               ircsnprintf(filename, sizeof(filename), "%s/%s", UHPATH, ldirent->d_name);
-
-#if defined(S_ISLNK) && defined(HAVE_LSTAT)
-               if(lstat(filename, &sb) < 0)
-                       continue;
-
-               /* ok, if its a symlink, we work on the presumption if an
-                * oper help exists of that name, its a symlink to that --fl
-                */
-               if(S_ISLNK(sb.st_mode))
-               {
-                       cacheptr = irc_dictionary_retrieve(help_dict, ldirent->d_name);
-
-                       if(cacheptr != NULL && cacheptr->flags & HELP_OPER)  /* is this really needed? --nenolod */
-                       {
-                               cacheptr->flags |= HELP_USER;
-                               continue;
-                       }
-               }
-#endif
+               rb_snprintf(filename, sizeof(filename), "%s/%s", UHPATH, ldirent->d_name);
 
                cacheptr = cache_file(filename, ldirent->d_name, HELP_USER);
-               irc_dictionary_add(help_dict, cacheptr->name, cacheptr);
+               irc_dictionary_add(help_dict_user, cacheptr->name, cacheptr);
        }
 
        closedir(helpfile_dir);
@@ -234,11 +226,11 @@ void
 send_user_motd(struct Client *source_p)
 {
        struct cacheline *lineptr;
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
        const char *myname = get_id(&me, source_p);
        const char *nick = get_id(source_p, source_p);
 
-       if(user_motd == NULL || dlink_list_length(&user_motd->contents) == 0)
+       if(user_motd == NULL || rb_dlink_list_length(&user_motd->contents) == 0)
        {
                sendto_one(source_p, form_str(ERR_NOMOTD), myname, nick);
                return;
@@ -246,7 +238,7 @@ send_user_motd(struct Client *source_p)
 
        sendto_one(source_p, form_str(RPL_MOTDSTART), myname, nick, me.name);
 
-       DLINK_FOREACH(ptr, user_motd->contents.head)
+       RB_DLINK_FOREACH(ptr, user_motd->contents.head)
        {
                lineptr = ptr->data;
                sendto_one(source_p, form_str(RPL_MOTD), myname, nick, lineptr->data);
@@ -265,15 +257,15 @@ void
 send_oper_motd(struct Client *source_p)
 {
        struct cacheline *lineptr;
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
 
-       if(oper_motd == NULL || dlink_list_length(&oper_motd->contents) == 0)
+       if(oper_motd == NULL || rb_dlink_list_length(&oper_motd->contents) == 0)
                return;
 
        sendto_one(source_p, form_str(RPL_OMOTDSTART), 
                   me.name, source_p->name);
 
-       DLINK_FOREACH(ptr, oper_motd->contents.head)
+       RB_DLINK_FOREACH(ptr, oper_motd->contents.head)
        {
                lineptr = ptr->data;
                sendto_one(source_p, form_str(RPL_OMOTD),