- help_dict_user = irc_dictionary_create(strcasecmp);
-}
-
-/* cache_file()
- *
- * inputs - file to cache, files "shortname", flags to set
- * outputs - pointer to file cached, else NULL
- * side effects -
- */
-struct cachefile *
-cache_file(const char *filename, const char *shortname, int flags)
-{
- FILE *in;
- struct cachefile *cacheptr;
- struct cacheline *lineptr;
- char line[BUFSIZE];
- char *p;
-
- if((in = fopen(filename, "r")) == NULL)
- return NULL;
-
- if(strcmp(shortname, "ircd.motd") == 0)
- {
- struct stat sb;
- struct tm *local_tm;
-
- if(fstat(fileno(in), &sb) < 0)
- return NULL;
-
- local_tm = localtime(&sb.st_mtime);
-
- if(local_tm != NULL)
- 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,
- local_tm->tm_min);
- }
-
- cacheptr = BlockHeapAlloc(cachefile_heap);
-
- strlcpy(cacheptr->name, shortname, sizeof(cacheptr->name));
- cacheptr->flags = flags;
-
- /* cache the file... */
- while(fgets(line, sizeof(line), in) != NULL)
- {
- if((p = strchr(line, '\n')) != NULL)
- *p = '\0';
-
- lineptr = BlockHeapAlloc(cacheline_heap);
- if(EmptyString(line))
- strlcpy(lineptr->data, " ", sizeof(lineptr->data));
- else
- strlcpy(lineptr->data, line, sizeof(lineptr->data));
- dlinkAddTail(lineptr, &lineptr->linenode, &cacheptr->contents);
- }
-
- fclose(in);
- return cacheptr;
-}
-
-/* free_cachefile()
- *
- * inputs - cachefile to free
- * outputs -
- * side effects - cachefile and its data is free'd
- */
-void
-free_cachefile(struct cachefile *cacheptr)
-{
- dlink_node *ptr;
- dlink_node *next_ptr;
-
- if(cacheptr == NULL)
- return;
-
- DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head)
- {
- BlockHeapFree(cacheline_heap, ptr->data);
- }
-
- BlockHeapFree(cachefile_heap, cacheptr);
-}
-
+ help_dict_user = irc_dictionary_create(strcasecmp);\r
+}\r
+\r
+/* cache_file()\r
+ *\r
+ * inputs - file to cache, files "shortname", flags to set\r
+ * outputs - pointer to file cached, else NULL\r
+ * side effects -\r
+ */\r
+struct cachefile *\r
+cache_file(const char *filename, const char *shortname, int flags)\r
+{\r
+ FILE *in;\r
+ struct cachefile *cacheptr;\r
+ struct cacheline *lineptr;\r
+ char line[BUFSIZE];\r
+ char *p;\r
+\r
+ if((in = fopen(filename, "r")) == NULL)\r
+ return NULL;\r
+\r
+\r
+ cacheptr = rb_malloc(sizeof(struct cachefile));\r
+\r
+ rb_strlcpy(cacheptr->name, shortname, sizeof(cacheptr->name));\r
+ cacheptr->flags = flags;\r
+\r
+ /* cache the file... */\r
+ while(fgets(line, sizeof(line), in) != NULL)\r
+ {\r
+ if((p = strpbrk(line, "\r\n")) != NULL)\r
+ *p = '\0';\r
+\r
+ if(!EmptyString(line))\r
+ {\r
+ lineptr = rb_malloc(sizeof(struct cacheline));\r
+ rb_strlcpy(lineptr->data, line, sizeof(lineptr->data));\r
+ rb_dlinkAddTail(lineptr, &lineptr->linenode, &cacheptr->contents);\r
+ }\r
+ else\r
+ rb_dlinkAddTailAlloc(emptyline, &cacheptr->contents);\r
+ }\r
+\r
+ fclose(in);\r
+ return cacheptr;\r
+}\r
+\r
+void\r
+cache_links(void *unused)\r
+{\r
+ struct Client *target_p;\r
+ rb_dlink_node *ptr;\r
+ rb_dlink_node *next_ptr;\r
+ char *links_line;\r
+\r
+ RB_DLINK_FOREACH_SAFE(ptr, next_ptr, links_cache_list.head)\r
+ {\r
+ rb_free(ptr->data);\r
+ rb_free_rb_dlink_node(ptr);\r
+ }\r
+\r
+ links_cache_list.head = links_cache_list.tail = NULL;\r
+ links_cache_list.length = 0;\r
+\r
+ RB_DLINK_FOREACH(ptr, global_serv_list.head)\r
+ {\r
+ target_p = ptr->data;\r
+\r
+ /* skip ourselves (done in /links) and hidden servers */\r
+ if(IsMe(target_p) ||\r
+ (IsHidden(target_p) && !ConfigServerHide.disable_hidden))\r
+ continue;\r
+\r
+ /* if the below is ever modified, change LINKSLINELEN */\r
+ links_line = rb_malloc(LINKSLINELEN);\r
+ rb_snprintf(links_line, LINKSLINELEN, "%s %s :1 %s",\r
+ target_p->name, me.name, \r
+ target_p->info[0] ? target_p->info : \r
+ "(Unknown Location)");\r
+\r
+ rb_dlinkAddTailAlloc(links_line, &links_cache_list);\r
+ }\r
+}\r
+\r
+/* free_cachefile()\r
+ *\r
+ * inputs - cachefile to free\r
+ * outputs -\r
+ * side effects - cachefile and its data is free'd\r
+ */\r
+void\r
+free_cachefile(struct cachefile *cacheptr)\r
+{\r
+ rb_dlink_node *ptr;\r
+ rb_dlink_node *next_ptr;\r
+\r
+ if(cacheptr == NULL)\r
+ return;\r
+\r
+ RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head)\r
+ {\r
+ if(ptr->data != emptyline)\r
+ rb_free(ptr->data);\r
+ }\r
+\r
+ rb_free(cacheptr);\r
+}\r
+\r