-/*\r
- * ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd).\r
- * cache.c - code for caching files\r
- *\r
- * Copyright (C) 2003 Lee Hardy <lee@leeh.co.uk>\r
- * Copyright (C) 2003-2005 ircd-ratbox development team\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions are\r
- * met:\r
- *\r
- * 1.Redistributions of source code must retain the above copyright notice,\r
- * this list of conditions and the following disclaimer.\r
- * 2.Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * 3.The name of the author may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,\r
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\r
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
- * POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * $Id: cache.c 25119 2008-03-13 16:57:05Z androsyn $\r
- */\r
-\r
+/*
+ * ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd).
+ * cache.c - code for caching files
+ *
+ * Copyright (C) 2003 Lee Hardy <lee@leeh.co.uk>
+ * Copyright (C) 2003-2005 ircd-ratbox development team
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1.Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2.Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3.The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF 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.
+ *
+ * $Id: cache.c 25119 2008-03-13 16:57:05Z androsyn $
+ */
+
#include "stdinc.h"
#include "ircd_defs.h"
#include "common.h"
#include "cache.h"
#include "sprintf_irc.h"
#include "irc_dictionary.h"
-#include "numeric.h"\r
-\r
-struct cachefile *user_motd = NULL;\r
-struct cachefile *oper_motd = NULL;\r
-struct cacheline *emptyline = NULL;\r
-rb_dlink_list links_cache_list;\r
-char user_motd_changed[MAX_DATE_STRING];\r
-\r
+#include "numeric.h"
+
+struct cachefile *user_motd = NULL;
+struct cachefile *oper_motd = NULL;
+struct cacheline *emptyline = NULL;
+rb_dlink_list links_cache_list;
+char user_motd_changed[MAX_DATE_STRING];
+
struct Dictionary *help_dict_oper = NULL;
-struct Dictionary *help_dict_user = NULL;\r
-\r
-/* init_cache()\r
- *\r
- * inputs -\r
- * outputs -\r
- * side effects - inits the file/line cache blockheaps, loads motds\r
- */\r
-void\r
-init_cache(void)\r
-{\r
- /* allocate the emptyline */\r
- emptyline = rb_malloc(sizeof(struct cacheline));\r
- emptyline->data[0] = ' ';\r
- emptyline->data[1] = '\0';\r
- user_motd_changed[0] = '\0';\r
-\r
- user_motd = cache_file(MPATH, "ircd.motd", 0);\r
- oper_motd = cache_file(OPATH, "opers.motd", 0);\r
- memset(&links_cache_list, 0, sizeof(links_cache_list));\r
-\r
+struct Dictionary *help_dict_user = NULL;
+
+/* init_cache()
+ *
+ * inputs -
+ * outputs -
+ * side effects - inits the file/line cache blockheaps, loads motds
+ */
+void
+init_cache(void)
+{
+ /* allocate the emptyline */
+ emptyline = rb_malloc(sizeof(struct cacheline));
+ emptyline->data[0] = ' ';
+ emptyline->data[1] = '\0';
+ user_motd_changed[0] = '\0';
+
+ user_motd = cache_file(MPATH, "ircd.motd", 0);
+ oper_motd = cache_file(OPATH, "opers.motd", 0);
+ memset(&links_cache_list, 0, sizeof(links_cache_list));
+
help_dict_oper = irc_dictionary_create(strcasecmp);
- 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
+ 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;
+
+
+ cacheptr = rb_malloc(sizeof(struct cachefile));
+
+ rb_strlcpy(cacheptr->name, shortname, sizeof(cacheptr->name));
+ cacheptr->flags = flags;
+
+ /* cache the file... */
+ while(fgets(line, sizeof(line), in) != NULL)
+ {
+ if((p = strpbrk(line, "\r\n")) != NULL)
+ *p = '\0';
+
+ if(!EmptyString(line))
+ {
+ lineptr = rb_malloc(sizeof(struct cacheline));
+ rb_strlcpy(lineptr->data, line, sizeof(lineptr->data));
+ rb_dlinkAddTail(lineptr, &lineptr->linenode, &cacheptr->contents);
+ }
+ else
+ rb_dlinkAddTailAlloc(emptyline, &cacheptr->contents);
+ }
+
+ fclose(in);
+ return cacheptr;
+}
+
+void
+cache_links(void *unused)
+{
+ struct Client *target_p;
+ rb_dlink_node *ptr;
+ rb_dlink_node *next_ptr;
+ char *links_line;
+
+ RB_DLINK_FOREACH_SAFE(ptr, next_ptr, links_cache_list.head)
+ {
+ rb_free(ptr->data);
+ rb_free_rb_dlink_node(ptr);
+ }
+
+ links_cache_list.head = links_cache_list.tail = NULL;
+ links_cache_list.length = 0;
+
+ RB_DLINK_FOREACH(ptr, global_serv_list.head)
+ {
+ target_p = ptr->data;
+
+ /* skip ourselves (done in /links) and hidden servers */
+ if(IsMe(target_p) ||
+ (IsHidden(target_p) && !ConfigServerHide.disable_hidden))
+ continue;
+
+ /* if the below is ever modified, change LINKSLINELEN */
+ links_line = rb_malloc(LINKSLINELEN);
+ rb_snprintf(links_line, LINKSLINELEN, "%s %s :1 %s",
+ target_p->name, me.name,
+ target_p->info[0] ? target_p->info :
+ "(Unknown Location)");
+
+ rb_dlinkAddTailAlloc(links_line, &links_cache_list);
+ }
+}
+
+/* free_cachefile()
+ *
+ * inputs - cachefile to free
+ * outputs -
+ * side effects - cachefile and its data is free'd
+ */
+void
+free_cachefile(struct cachefile *cacheptr)
+{
+ rb_dlink_node *ptr;
+ rb_dlink_node *next_ptr;
+
+ if(cacheptr == NULL)
+ return;
+
+ RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head)
+ {
+ if(ptr->data != emptyline)
+ rb_free(ptr->data);
+ }
+
+ rb_free(cacheptr);
+}
+
/* load_help()
*
* inputs -
}
closedir(helpfile_dir);
-}\r
-\r
-/* send_user_motd()\r
- *\r
- * inputs - client to send motd to\r
- * outputs - client is sent motd if exists, else ERR_NOMOTD\r
- * side effects -\r
- */\r
-void\r
-send_user_motd(struct Client *source_p)\r
-{\r
- struct cacheline *lineptr;\r
- rb_dlink_node *ptr;\r
- const char *myname = get_id(&me, source_p);\r
- const char *nick = get_id(source_p, source_p);\r
- if(user_motd == NULL || rb_dlink_list_length(&user_motd->contents) == 0)\r
- {\r
- sendto_one(source_p, form_str(ERR_NOMOTD), myname, nick);\r
- return;\r
- }\r
-\r
- sendto_one(source_p, form_str(RPL_MOTDSTART), myname, nick, me.name);\r
-\r
- RB_DLINK_FOREACH(ptr, user_motd->contents.head)\r
- {\r
- lineptr = ptr->data;\r
- sendto_one(source_p, form_str(RPL_MOTD), myname, nick, lineptr->data);\r
- }\r
-\r
- sendto_one(source_p, form_str(RPL_ENDOFMOTD), myname, nick);\r
-}\r
-\r
-void\r
-cache_user_motd(void)\r
-{\r
- struct stat sb;\r
- struct tm *local_tm;\r
- \r
- if(stat(MPATH, &sb) == 0) \r
- {\r
- local_tm = localtime(&sb.st_mtime);\r
-\r
- if(local_tm != NULL) \r
- {\r
- rb_snprintf(user_motd_changed, sizeof(user_motd_changed),\r
- "%d/%d/%d %d:%d",\r
- local_tm->tm_mday, local_tm->tm_mon + 1,\r
- 1900 + local_tm->tm_year, local_tm->tm_hour,\r
- local_tm->tm_min);\r
- }\r
- } \r
- free_cachefile(user_motd);\r
- user_motd = cache_file(MPATH, "ircd.motd", 0);\r
-}\r
+}
+
+/* send_user_motd()
+ *
+ * inputs - client to send motd to
+ * outputs - client is sent motd if exists, else ERR_NOMOTD
+ * side effects -
+ */
+void
+send_user_motd(struct Client *source_p)
+{
+ struct cacheline *lineptr;
+ 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 || rb_dlink_list_length(&user_motd->contents) == 0)
+ {
+ sendto_one(source_p, form_str(ERR_NOMOTD), myname, nick);
+ return;
+ }
+
+ sendto_one(source_p, form_str(RPL_MOTDSTART), myname, nick, me.name);
+
+ RB_DLINK_FOREACH(ptr, user_motd->contents.head)
+ {
+ lineptr = ptr->data;
+ sendto_one(source_p, form_str(RPL_MOTD), myname, nick, lineptr->data);
+ }
+
+ sendto_one(source_p, form_str(RPL_ENDOFMOTD), myname, nick);
+}
+
+void
+cache_user_motd(void)
+{
+ struct stat sb;
+ struct tm *local_tm;
+
+ if(stat(MPATH, &sb) == 0)
+ {
+ 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);
+ }
+ }
+ free_cachefile(user_motd);
+ user_motd = cache_file(MPATH, "ircd.motd", 0);
+}
rb_dlink_list class_list;
struct Class *default_class;
-struct Class *\r
-make_class(void)\r
-{\r
- struct Class *tmp;\r
-\r
- tmp = rb_malloc(sizeof(struct Class));\r
-\r
- ConFreq(tmp) = DEFAULT_CONNECTFREQUENCY;\r
- PingFreq(tmp) = DEFAULT_PINGFREQUENCY;\r
- MaxUsers(tmp) = 1;\r
- MaxSendq(tmp) = DEFAULT_SENDQ;\r
-\r
- tmp->ip_limits = rb_new_patricia(PATRICIA_BITS);\r
- return tmp;\r
-}\r
-\r
-void\r
-free_class(struct Class *tmp)\r
-{\r
- if(tmp->ip_limits)\r
- rb_destroy_patricia(tmp->ip_limits, NULL);\r
-\r
- rb_free(tmp->class_name);\r
- rb_free(tmp);\r
-\r
+struct Class *
+make_class(void)
+{
+ struct Class *tmp;
+
+ tmp = rb_malloc(sizeof(struct Class));
+
+ ConFreq(tmp) = DEFAULT_CONNECTFREQUENCY;
+ PingFreq(tmp) = DEFAULT_PINGFREQUENCY;
+ MaxUsers(tmp) = 1;
+ MaxSendq(tmp) = DEFAULT_SENDQ;
+
+ tmp->ip_limits = rb_new_patricia(PATRICIA_BITS);
+ return tmp;
+}
+
+void
+free_class(struct Class *tmp)
+{
+ if(tmp->ip_limits)
+ rb_destroy_patricia(tmp->ip_limits, NULL);
+
+ rb_free(tmp->class_name);
+ rb_free(tmp);
+
}
/*
* start off the check ping event .. -- adrian
* Every 30 seconds is plenty -- db
*/
- client_heap = rb_bh_create(sizeof(struct Client), CLIENT_HEAP_SIZE, "client_heap");\r
+ client_heap = rb_bh_create(sizeof(struct Client), CLIENT_HEAP_SIZE, "client_heap");
lclient_heap = rb_bh_create(sizeof(struct LocalUser), LCLIENT_HEAP_SIZE, "lclient_heap");
pclient_heap = rb_bh_create(sizeof(struct PreClient), PCLIENT_HEAP_SIZE, "pclient_heap");
away_heap = rb_bh_create(AWAYLEN, AWAY_HEAP_SIZE, "away_heap");
void
count_local_client_memory(size_t * count, size_t * local_client_memory_used)
{
- size_t lusage;\r
- rb_bh_usage(lclient_heap, count, NULL, &lusage, NULL);\r
+ size_t lusage;
+ rb_bh_usage(lclient_heap, count, NULL, &lusage, NULL);
*local_client_memory_used = lusage + (*count * (sizeof(void *) + sizeof(struct Client)));
}
void
count_remote_client_memory(size_t * count, size_t * remote_client_memory_used)
{
- size_t lcount, rcount;\r
- rb_bh_usage(lclient_heap, &lcount, NULL, NULL, NULL);\r
- rb_bh_usage(client_heap, &rcount, NULL, NULL, NULL);\r
- *count = rcount - lcount;\r
+ size_t lcount, rcount;
+ rb_bh_usage(lclient_heap, &lcount, NULL, NULL, NULL);
+ rb_bh_usage(client_heap, &rcount, NULL, NULL, NULL);
+ *count = rcount - lcount;
*remote_client_memory_used = *count * (sizeof(void *) + sizeof(struct Client));
}
#endif
static listener_t *ListenerPollList = NULL;
-static int accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data);\r
+static int accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data);
static void accept_callback(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t addrlen, void *data);
static listener_t *
}
}
- if(F == NULL)\r
- {\r
- report_error("opening listener socket %s:%s",\r
- get_listener_name(listener), \r
- get_listener_name(listener), errno);\r
- return 0;\r
- }\r
- else if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus*/\r
- {\r
- report_error("no more connections left for listener %s:%s",\r
- get_listener_name(listener), \r
- get_listener_name(listener), errno);\r
- rb_close(F);\r
- return 0;\r
+ if(F == NULL)
+ {
+ report_error("opening listener socket %s:%s",
+ get_listener_name(listener),
+ get_listener_name(listener), errno);
+ return 0;
+ }
+ else if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus*/
+ {
+ report_error("no more connections left for listener %s:%s",
+ get_listener_name(listener),
+ get_listener_name(listener), errno);
+ rb_close(F);
+ return 0;
}
- /*\r
- * XXX - we don't want to do all this crap for a listener\r
- * set_sock_opts(listener);\r
- */\r
- if(setsockopt(rb_get_fd(F), SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt)))\r
- {\r
- report_error("setting SO_REUSEADDR for listener %s:%s",\r
- get_listener_name(listener), \r
- get_listener_name(listener), errno);\r
- rb_close(F);\r
- return 0;\r
+ /*
+ * XXX - we don't want to do all this crap for a listener
+ * set_sock_opts(listener);
+ */
+ if(setsockopt(rb_get_fd(F), SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt)))
+ {
+ report_error("setting SO_REUSEADDR for listener %s:%s",
+ get_listener_name(listener),
+ get_listener_name(listener), errno);
+ rb_close(F);
+ return 0;
}
- /*\r
- * Bind a port to listen for new connections if port is non-null,\r
- * else assume it is already open and try get something from it.\r
- */\r
-\r
- if(bind(rb_get_fd(F), (struct sockaddr *) &listener->addr, GET_SS_LEN(&listener->addr)))\r
- {\r
- report_error("binding listener socket %s:%s",\r
- get_listener_name(listener), \r
- get_listener_name(listener), errno);\r
- rb_close(F);\r
- return 0;\r
+ /*
+ * Bind a port to listen for new connections if port is non-null,
+ * else assume it is already open and try get something from it.
+ */
+
+ if(bind(rb_get_fd(F), (struct sockaddr *) &listener->addr, GET_SS_LEN(&listener->addr)))
+ {
+ report_error("binding listener socket %s:%s",
+ get_listener_name(listener),
+ get_listener_name(listener), errno);
+ rb_close(F);
+ return 0;
}
- if((ret = rb_listen(F, RATBOX_SOMAXCONN)))\r
- {\r
- report_error("listen failed for %s:%s", \r
- get_listener_name(listener), \r
- get_listener_name(listener), errno);\r
- rb_close(F);\r
- return 0;\r
+ if((ret = rb_listen(F, RATBOX_SOMAXCONN)))
+ {
+ report_error("listen failed for %s:%s",
+ get_listener_name(listener),
+ get_listener_name(listener), errno);
+ rb_close(F);
+ return 0;
}
- listener->F = F;\r
-\r
+ listener->F = F;
+
rb_accept_tcp(listener->F, accept_precallback, accept_callback, listener);
return 1;
}
if(in4->sin_addr.s_addr == lin4->sin_addr.s_addr &&
in4->sin_port == lin4->sin_port )
{
- if(listener->F == NULL)\r
- last_closed = listener;\r
- else\r
+ if(listener->F == NULL)
+ last_closed = listener;
+ else
return(listener);
}
break;
if(IN6_ARE_ADDR_EQUAL(&in6->sin6_addr, &lin6->sin6_addr) &&
in6->sin6_port == lin6->sin6_port)
{
- if(listener->F == NULL)\r
- last_closed = listener;\r
- else\r
+ if(listener->F == NULL)
+ last_closed = listener;
+ else
return(listener);
}
break;
}
if((listener = find_listener(&vaddr)))
{
- if(listener->F != NULL)\r
+ if(listener->F != NULL)
return;
}
else
s_assert(listener != NULL);
if(listener == NULL)
return;
- if(listener->F != NULL)\r
- {\r
- rb_close(listener->F);\r
- listener->F = NULL;\r
+ if(listener->F != NULL)
+ {
+ rb_close(listener->F);
+ listener->F = NULL;
}
listener->active = 0;
* The client is sent to the auth module for verification, and not put in
* any client list yet.
*/
-static void\r
+static void
add_connection(struct Listener *listener, rb_fde_t *F, struct sockaddr *sai, int exempt)
{
struct Client *new_client;
start_auth(new_client);
}
-static int\r
-accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data)\r
-{\r
- struct Listener *listener = (struct Listener *)data;\r
- char buf[BUFSIZE];\r
- struct ConfItem *aconf;\r
- static time_t last_oper_notice = 0;\r
-\r
- if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus */\r
- {\r
- ++ServerStats->is_ref;\r
- /*\r
- * slow down the whining to opers bit\r
- */\r
- if((last_oper_notice + 20) <= rb_current_time())\r
- {\r
- sendto_realops_flags(SNO_GENERAL, L_ALL,\r
- "All connections in use. (%s)",\r
- get_listener_name(listener));\r
- last_oper_notice = rb_current_time();\r
- }\r
- \r
- rb_write(F, "ERROR :All connections in use\r\n", 32);\r
- rb_close(F);\r
- /* Re-register a new IO request for the next accept .. */\r
- return 0;\r
- }\r
-\r
- aconf = find_dline(addr, AF_INET);\r
- if(aconf != NULL && (aconf->status & CONF_EXEMPTDLINE))\r
- return 1;\r
- \r
- /* Do an initial check we aren't connecting too fast or with too many\r
- * from this IP... */\r
- if(aconf != NULL)\r
- {\r
- ServerStats->is_ref++;\r
- \r
- if(ConfigFileEntry.dline_with_reason)\r
- {\r
- if (rb_snprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", aconf->passwd) >= (int)(sizeof(buf)-1))\r
- {\r
- buf[sizeof(buf) - 3] = '\r';\r
- buf[sizeof(buf) - 2] = '\n';\r
- buf[sizeof(buf) - 1] = '\0';\r
- }\r
- }\r
- else\r
- strcpy(buf, "ERROR :You have been D-lined.\r\n");\r
- \r
- rb_write(F, buf, strlen(buf));\r
- rb_close(F);\r
- return 0;\r
- }\r
-\r
- return 1;\r
-}\r
-\r
-static void\r
-accept_callback(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t addrlen, void *data)\r
-{\r
- struct Listener *listener = data;\r
- struct rb_sockaddr_storage lip;\r
- unsigned int locallen = sizeof(struct rb_sockaddr_storage);\r
- \r
- ServerStats->is_ac++;\r
-\r
- if(getsockname(rb_get_fd(F), (struct sockaddr *) &lip, &locallen) < 0)\r
- {\r
- /* this shouldn't fail so... */\r
- /* XXX add logging of this */\r
- rb_close(F);\r
- }\r
- \r
- add_connection(listener, F, addr, 1);\r
+static int
+accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data)
+{
+ struct Listener *listener = (struct Listener *)data;
+ char buf[BUFSIZE];
+ struct ConfItem *aconf;
+ static time_t last_oper_notice = 0;
+
+ if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus */
+ {
+ ++ServerStats->is_ref;
+ /*
+ * slow down the whining to opers bit
+ */
+ if((last_oper_notice + 20) <= rb_current_time())
+ {
+ sendto_realops_flags(SNO_GENERAL, L_ALL,
+ "All connections in use. (%s)",
+ get_listener_name(listener));
+ last_oper_notice = rb_current_time();
+ }
+
+ rb_write(F, "ERROR :All connections in use\r\n", 32);
+ rb_close(F);
+ /* Re-register a new IO request for the next accept .. */
+ return 0;
+ }
+
+ aconf = find_dline(addr, AF_INET);
+ if(aconf != NULL && (aconf->status & CONF_EXEMPTDLINE))
+ return 1;
+
+ /* Do an initial check we aren't connecting too fast or with too many
+ * from this IP... */
+ if(aconf != NULL)
+ {
+ ServerStats->is_ref++;
+
+ if(ConfigFileEntry.dline_with_reason)
+ {
+ if (rb_snprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", aconf->passwd) >= (int)(sizeof(buf)-1))
+ {
+ buf[sizeof(buf) - 3] = '\r';
+ buf[sizeof(buf) - 2] = '\n';
+ buf[sizeof(buf) - 1] = '\0';
+ }
+ }
+ else
+ strcpy(buf, "ERROR :You have been D-lined.\r\n");
+
+ rb_write(F, buf, strlen(buf));
+ rb_close(F);
+ return 0;
+ }
+
+ return 1;
+}
+
+static void
+accept_callback(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t addrlen, void *data)
+{
+ struct Listener *listener = data;
+ struct rb_sockaddr_storage lip;
+ unsigned int locallen = sizeof(struct rb_sockaddr_storage);
+
+ ServerStats->is_ac++;
+
+ if(getsockname(rb_get_fd(F), (struct sockaddr *) &lip, &locallen) < 0)
+ {
+ /* this shouldn't fail so... */
+ /* XXX add logging of this */
+ rb_close(F);
+ }
+
+ add_connection(listener, F, addr, 1);
}
client_p->localClient->sent_parsed = 0;
}
-/*\r
- * flood_recalc\r
- *\r
- * recalculate the number of allowed flood lines. this should be called\r
- * once a second on any given client. We then attempt to flush some data.\r
- */\r
-void\r
-flood_recalc(void *unused)\r
-{\r
- rb_dlink_node *ptr, *next;\r
- struct Client *client_p;\r
-\r
- RB_DLINK_FOREACH_SAFE(ptr, next, lclient_list.head)\r
- {\r
- client_p = ptr->data;\r
-\r
- if(unlikely(IsMe(client_p)))\r
- continue;\r
- \r
- if(unlikely(client_p->localClient == NULL))\r
- continue;\r
- \r
- if(IsFloodDone(client_p))\r
- client_p->localClient->sent_parsed -= 2;\r
- else\r
- client_p->localClient->sent_parsed = 0;\r
- \r
- if(client_p->localClient->sent_parsed < 0)\r
- client_p->localClient->sent_parsed = 0;\r
-\r
- if(--client_p->localClient->actually_read < 0)\r
- client_p->localClient->actually_read = 0;\r
-\r
- parse_client_queued(client_p);\r
- \r
- if(unlikely(IsAnyDead(client_p)))\r
- continue;\r
-\r
- }\r
-\r
- RB_DLINK_FOREACH_SAFE(ptr, next, unknown_list.head)\r
- {\r
- client_p = ptr->data;\r
-\r
- if(client_p->localClient == NULL)\r
- continue;\r
-\r
- client_p->localClient->sent_parsed--;\r
-\r
- if(client_p->localClient->sent_parsed < 0)\r
- client_p->localClient->sent_parsed = 0;\r
-\r
- if(--client_p->localClient->actually_read < 0)\r
- client_p->localClient->actually_read = 0;\r
-\r
- parse_client_queued(client_p);\r
- }\r
+/*
+ * flood_recalc
+ *
+ * recalculate the number of allowed flood lines. this should be called
+ * once a second on any given client. We then attempt to flush some data.
+ */
+void
+flood_recalc(void *unused)
+{
+ rb_dlink_node *ptr, *next;
+ struct Client *client_p;
+
+ RB_DLINK_FOREACH_SAFE(ptr, next, lclient_list.head)
+ {
+ client_p = ptr->data;
+
+ if(unlikely(IsMe(client_p)))
+ continue;
+
+ if(unlikely(client_p->localClient == NULL))
+ continue;
+
+ if(IsFloodDone(client_p))
+ client_p->localClient->sent_parsed -= 2;
+ else
+ client_p->localClient->sent_parsed = 0;
+
+ if(client_p->localClient->sent_parsed < 0)
+ client_p->localClient->sent_parsed = 0;
+
+ if(--client_p->localClient->actually_read < 0)
+ client_p->localClient->actually_read = 0;
+
+ parse_client_queued(client_p);
+
+ if(unlikely(IsAnyDead(client_p)))
+ continue;
+
+ }
+
+ RB_DLINK_FOREACH_SAFE(ptr, next, unknown_list.head)
+ {
+ client_p = ptr->data;
+
+ if(client_p->localClient == NULL)
+ continue;
+
+ client_p->localClient->sent_parsed--;
+
+ if(client_p->localClient->sent_parsed < 0)
+ client_p->localClient->sent_parsed = 0;
+
+ if(--client_p->localClient->actually_read < 0)
+ client_p->localClient->actually_read = 0;
+
+ parse_client_queued(client_p);
+ }
}
/*