Remove ^M.

This commit is contained in:
Jilles Tjoelker 2008-04-02 20:50:20 +02:00
parent 5640a31ea5
commit ae4091d2f9
5 changed files with 448 additions and 448 deletions

View File

@ -1,37 +1,37 @@
/* /*
* ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd). * ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd).
* cache.c - code for caching files * cache.c - code for caching files
* *
* Copyright (C) 2003 Lee Hardy <lee@leeh.co.uk> * Copyright (C) 2003 Lee Hardy <lee@leeh.co.uk>
* Copyright (C) 2003-2005 ircd-ratbox development team * Copyright (C) 2003-2005 ircd-ratbox development team
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
* met: * met:
* *
* 1.Redistributions of source code must retain the above copyright notice, * 1.Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2.Redistributions in binary form must reproduce the above copyright * 2.Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* 3.The name of the author may not be used to endorse or promote products * 3.The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: cache.c 25119 2008-03-13 16:57:05Z androsyn $ * $Id: cache.c 25119 2008-03-13 16:57:05Z androsyn $
*/ */
#include "stdinc.h" #include "stdinc.h"
#include "ircd_defs.h" #include "ircd_defs.h"
#include "common.h" #include "common.h"
@ -41,145 +41,145 @@
#include "cache.h" #include "cache.h"
#include "sprintf_irc.h" #include "sprintf_irc.h"
#include "irc_dictionary.h" #include "irc_dictionary.h"
#include "numeric.h" #include "numeric.h"
struct cachefile *user_motd = NULL; struct cachefile *user_motd = NULL;
struct cachefile *oper_motd = NULL; struct cachefile *oper_motd = NULL;
struct cacheline *emptyline = NULL; struct cacheline *emptyline = NULL;
rb_dlink_list links_cache_list; rb_dlink_list links_cache_list;
char user_motd_changed[MAX_DATE_STRING]; char user_motd_changed[MAX_DATE_STRING];
struct Dictionary *help_dict_oper = NULL; struct Dictionary *help_dict_oper = NULL;
struct Dictionary *help_dict_user = NULL; struct Dictionary *help_dict_user = NULL;
/* init_cache() /* init_cache()
* *
* inputs - * inputs -
* outputs - * outputs -
* side effects - inits the file/line cache blockheaps, loads motds * side effects - inits the file/line cache blockheaps, loads motds
*/ */
void void
init_cache(void) init_cache(void)
{ {
/* allocate the emptyline */ /* allocate the emptyline */
emptyline = rb_malloc(sizeof(struct cacheline)); emptyline = rb_malloc(sizeof(struct cacheline));
emptyline->data[0] = ' '; emptyline->data[0] = ' ';
emptyline->data[1] = '\0'; emptyline->data[1] = '\0';
user_motd_changed[0] = '\0'; user_motd_changed[0] = '\0';
user_motd = cache_file(MPATH, "ircd.motd", 0); user_motd = cache_file(MPATH, "ircd.motd", 0);
oper_motd = cache_file(OPATH, "opers.motd", 0); oper_motd = cache_file(OPATH, "opers.motd", 0);
memset(&links_cache_list, 0, sizeof(links_cache_list)); memset(&links_cache_list, 0, sizeof(links_cache_list));
help_dict_oper = irc_dictionary_create(strcasecmp); help_dict_oper = irc_dictionary_create(strcasecmp);
help_dict_user = irc_dictionary_create(strcasecmp); help_dict_user = irc_dictionary_create(strcasecmp);
} }
/* cache_file() /* cache_file()
* *
* inputs - file to cache, files "shortname", flags to set * inputs - file to cache, files "shortname", flags to set
* outputs - pointer to file cached, else NULL * outputs - pointer to file cached, else NULL
* side effects - * side effects -
*/ */
struct cachefile * struct cachefile *
cache_file(const char *filename, const char *shortname, int flags) cache_file(const char *filename, const char *shortname, int flags)
{ {
FILE *in; FILE *in;
struct cachefile *cacheptr; struct cachefile *cacheptr;
struct cacheline *lineptr; struct cacheline *lineptr;
char line[BUFSIZE]; char line[BUFSIZE];
char *p; char *p;
if((in = fopen(filename, "r")) == NULL) if((in = fopen(filename, "r")) == NULL)
return NULL; return NULL;
cacheptr = rb_malloc(sizeof(struct cachefile)); cacheptr = rb_malloc(sizeof(struct cachefile));
rb_strlcpy(cacheptr->name, shortname, sizeof(cacheptr->name)); rb_strlcpy(cacheptr->name, shortname, sizeof(cacheptr->name));
cacheptr->flags = flags; cacheptr->flags = flags;
/* cache the file... */ /* cache the file... */
while(fgets(line, sizeof(line), in) != NULL) while(fgets(line, sizeof(line), in) != NULL)
{ {
if((p = strpbrk(line, "\r\n")) != NULL) if((p = strpbrk(line, "\r\n")) != NULL)
*p = '\0'; *p = '\0';
if(!EmptyString(line)) if(!EmptyString(line))
{ {
lineptr = rb_malloc(sizeof(struct cacheline)); lineptr = rb_malloc(sizeof(struct cacheline));
rb_strlcpy(lineptr->data, line, sizeof(lineptr->data)); rb_strlcpy(lineptr->data, line, sizeof(lineptr->data));
rb_dlinkAddTail(lineptr, &lineptr->linenode, &cacheptr->contents); rb_dlinkAddTail(lineptr, &lineptr->linenode, &cacheptr->contents);
} }
else else
rb_dlinkAddTailAlloc(emptyline, &cacheptr->contents); rb_dlinkAddTailAlloc(emptyline, &cacheptr->contents);
} }
fclose(in); fclose(in);
return cacheptr; return cacheptr;
} }
void void
cache_links(void *unused) cache_links(void *unused)
{ {
struct Client *target_p; struct Client *target_p;
rb_dlink_node *ptr; rb_dlink_node *ptr;
rb_dlink_node *next_ptr; rb_dlink_node *next_ptr;
char *links_line; char *links_line;
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, links_cache_list.head) RB_DLINK_FOREACH_SAFE(ptr, next_ptr, links_cache_list.head)
{ {
rb_free(ptr->data); rb_free(ptr->data);
rb_free_rb_dlink_node(ptr); rb_free_rb_dlink_node(ptr);
} }
links_cache_list.head = links_cache_list.tail = NULL; links_cache_list.head = links_cache_list.tail = NULL;
links_cache_list.length = 0; links_cache_list.length = 0;
RB_DLINK_FOREACH(ptr, global_serv_list.head) RB_DLINK_FOREACH(ptr, global_serv_list.head)
{ {
target_p = ptr->data; target_p = ptr->data;
/* skip ourselves (done in /links) and hidden servers */ /* skip ourselves (done in /links) and hidden servers */
if(IsMe(target_p) || if(IsMe(target_p) ||
(IsHidden(target_p) && !ConfigServerHide.disable_hidden)) (IsHidden(target_p) && !ConfigServerHide.disable_hidden))
continue; continue;
/* if the below is ever modified, change LINKSLINELEN */ /* if the below is ever modified, change LINKSLINELEN */
links_line = rb_malloc(LINKSLINELEN); links_line = rb_malloc(LINKSLINELEN);
rb_snprintf(links_line, LINKSLINELEN, "%s %s :1 %s", rb_snprintf(links_line, LINKSLINELEN, "%s %s :1 %s",
target_p->name, me.name, target_p->name, me.name,
target_p->info[0] ? target_p->info : target_p->info[0] ? target_p->info :
"(Unknown Location)"); "(Unknown Location)");
rb_dlinkAddTailAlloc(links_line, &links_cache_list); rb_dlinkAddTailAlloc(links_line, &links_cache_list);
} }
} }
/* free_cachefile() /* free_cachefile()
* *
* inputs - cachefile to free * inputs - cachefile to free
* outputs - * outputs -
* side effects - cachefile and its data is free'd * side effects - cachefile and its data is free'd
*/ */
void void
free_cachefile(struct cachefile *cacheptr) free_cachefile(struct cachefile *cacheptr)
{ {
rb_dlink_node *ptr; rb_dlink_node *ptr;
rb_dlink_node *next_ptr; rb_dlink_node *next_ptr;
if(cacheptr == NULL) if(cacheptr == NULL)
return; return;
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head) RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head)
{ {
if(ptr->data != emptyline) if(ptr->data != emptyline)
rb_free(ptr->data); rb_free(ptr->data);
} }
rb_free(cacheptr); rb_free(cacheptr);
} }
/* load_help() /* load_help()
* *
* inputs - * inputs -
@ -234,57 +234,57 @@ load_help(void)
} }
closedir(helpfile_dir); closedir(helpfile_dir);
} }
/* send_user_motd() /* send_user_motd()
* *
* inputs - client to send motd to * inputs - client to send motd to
* outputs - client is sent motd if exists, else ERR_NOMOTD * outputs - client is sent motd if exists, else ERR_NOMOTD
* side effects - * side effects -
*/ */
void void
send_user_motd(struct Client *source_p) send_user_motd(struct Client *source_p)
{ {
struct cacheline *lineptr; struct cacheline *lineptr;
rb_dlink_node *ptr; rb_dlink_node *ptr;
const char *myname = get_id(&me, source_p); const char *myname = get_id(&me, source_p);
const char *nick = get_id(source_p, source_p); const char *nick = get_id(source_p, source_p);
if(user_motd == NULL || rb_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); sendto_one(source_p, form_str(ERR_NOMOTD), myname, nick);
return; return;
} }
sendto_one(source_p, form_str(RPL_MOTDSTART), myname, nick, me.name); sendto_one(source_p, form_str(RPL_MOTDSTART), myname, nick, me.name);
RB_DLINK_FOREACH(ptr, user_motd->contents.head) RB_DLINK_FOREACH(ptr, user_motd->contents.head)
{ {
lineptr = ptr->data; lineptr = ptr->data;
sendto_one(source_p, form_str(RPL_MOTD), myname, nick, lineptr->data); sendto_one(source_p, form_str(RPL_MOTD), myname, nick, lineptr->data);
} }
sendto_one(source_p, form_str(RPL_ENDOFMOTD), myname, nick); sendto_one(source_p, form_str(RPL_ENDOFMOTD), myname, nick);
} }
void void
cache_user_motd(void) cache_user_motd(void)
{ {
struct stat sb; struct stat sb;
struct tm *local_tm; struct tm *local_tm;
if(stat(MPATH, &sb) == 0) if(stat(MPATH, &sb) == 0)
{ {
local_tm = localtime(&sb.st_mtime); local_tm = localtime(&sb.st_mtime);
if(local_tm != NULL) if(local_tm != NULL)
{ {
rb_snprintf(user_motd_changed, sizeof(user_motd_changed), rb_snprintf(user_motd_changed, sizeof(user_motd_changed),
"%d/%d/%d %d:%d", "%d/%d/%d %d:%d",
local_tm->tm_mday, local_tm->tm_mon + 1, local_tm->tm_mday, local_tm->tm_mon + 1,
1900 + local_tm->tm_year, local_tm->tm_hour, 1900 + local_tm->tm_year, local_tm->tm_hour,
local_tm->tm_min); local_tm->tm_min);
} }
} }
free_cachefile(user_motd); free_cachefile(user_motd);
user_motd = cache_file(MPATH, "ircd.motd", 0); user_motd = cache_file(MPATH, "ircd.motd", 0);
} }

View File

@ -44,31 +44,31 @@
rb_dlink_list class_list; rb_dlink_list class_list;
struct Class *default_class; struct Class *default_class;
struct Class * struct Class *
make_class(void) make_class(void)
{ {
struct Class *tmp; struct Class *tmp;
tmp = rb_malloc(sizeof(struct Class)); tmp = rb_malloc(sizeof(struct Class));
ConFreq(tmp) = DEFAULT_CONNECTFREQUENCY; ConFreq(tmp) = DEFAULT_CONNECTFREQUENCY;
PingFreq(tmp) = DEFAULT_PINGFREQUENCY; PingFreq(tmp) = DEFAULT_PINGFREQUENCY;
MaxUsers(tmp) = 1; MaxUsers(tmp) = 1;
MaxSendq(tmp) = DEFAULT_SENDQ; MaxSendq(tmp) = DEFAULT_SENDQ;
tmp->ip_limits = rb_new_patricia(PATRICIA_BITS); tmp->ip_limits = rb_new_patricia(PATRICIA_BITS);
return tmp; return tmp;
} }
void void
free_class(struct Class *tmp) free_class(struct Class *tmp)
{ {
if(tmp->ip_limits) if(tmp->ip_limits)
rb_destroy_patricia(tmp->ip_limits, NULL); rb_destroy_patricia(tmp->ip_limits, NULL);
rb_free(tmp->class_name); rb_free(tmp->class_name);
rb_free(tmp); rb_free(tmp);
} }
/* /*

View File

@ -118,7 +118,7 @@ init_client(void)
* start off the check ping event .. -- adrian * start off the check ping event .. -- adrian
* Every 30 seconds is plenty -- db * Every 30 seconds is plenty -- db
*/ */
client_heap = rb_bh_create(sizeof(struct Client), CLIENT_HEAP_SIZE, "client_heap"); 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"); 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"); pclient_heap = rb_bh_create(sizeof(struct PreClient), PCLIENT_HEAP_SIZE, "pclient_heap");
away_heap = rb_bh_create(AWAYLEN, AWAY_HEAP_SIZE, "away_heap"); away_heap = rb_bh_create(AWAYLEN, AWAY_HEAP_SIZE, "away_heap");
@ -1711,8 +1711,8 @@ exit_client(struct Client *client_p, /* The local client originating the
void void
count_local_client_memory(size_t * count, size_t * local_client_memory_used) count_local_client_memory(size_t * count, size_t * local_client_memory_used)
{ {
size_t lusage; size_t lusage;
rb_bh_usage(lclient_heap, count, NULL, &lusage, NULL); rb_bh_usage(lclient_heap, count, NULL, &lusage, NULL);
*local_client_memory_used = lusage + (*count * (sizeof(void *) + sizeof(struct Client))); *local_client_memory_used = lusage + (*count * (sizeof(void *) + sizeof(struct Client)));
} }
@ -1722,10 +1722,10 @@ count_local_client_memory(size_t * count, size_t * local_client_memory_used)
void void
count_remote_client_memory(size_t * count, size_t * remote_client_memory_used) count_remote_client_memory(size_t * count, size_t * remote_client_memory_used)
{ {
size_t lcount, rcount; size_t lcount, rcount;
rb_bh_usage(lclient_heap, &lcount, NULL, NULL, NULL); rb_bh_usage(lclient_heap, &lcount, NULL, NULL, NULL);
rb_bh_usage(client_heap, &rcount, NULL, NULL, NULL); rb_bh_usage(client_heap, &rcount, NULL, NULL, NULL);
*count = rcount - lcount; *count = rcount - lcount;
*remote_client_memory_used = *count * (sizeof(void *) + sizeof(struct Client)); *remote_client_memory_used = *count * (sizeof(void *) + sizeof(struct Client));
} }

View File

@ -52,7 +52,7 @@ static const struct in6_addr in6addr_any =
#endif #endif
static listener_t *ListenerPollList = NULL; static listener_t *ListenerPollList = NULL;
static int accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data); 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 void accept_callback(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t addrlen, void *data);
static listener_t * static listener_t *
@ -195,60 +195,60 @@ inetport(listener_t *listener)
} }
} }
if(F == NULL) if(F == NULL)
{ {
report_error("opening listener socket %s:%s", report_error("opening listener socket %s:%s",
get_listener_name(listener), get_listener_name(listener),
get_listener_name(listener), errno); get_listener_name(listener), errno);
return 0; return 0;
} }
else if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus*/ else if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus*/
{ {
report_error("no more connections left for listener %s:%s", report_error("no more connections left for listener %s:%s",
get_listener_name(listener), get_listener_name(listener),
get_listener_name(listener), errno); get_listener_name(listener), errno);
rb_close(F); rb_close(F);
return 0; return 0;
} }
/* /*
* XXX - we don't want to do all this crap for a listener * XXX - we don't want to do all this crap for a listener
* set_sock_opts(listener); * set_sock_opts(listener);
*/ */
if(setsockopt(rb_get_fd(F), SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt))) if(setsockopt(rb_get_fd(F), SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt)))
{ {
report_error("setting SO_REUSEADDR for listener %s:%s", report_error("setting SO_REUSEADDR for listener %s:%s",
get_listener_name(listener), get_listener_name(listener),
get_listener_name(listener), errno); get_listener_name(listener), errno);
rb_close(F); rb_close(F);
return 0; return 0;
} }
/* /*
* Bind a port to listen for new connections if port is non-null, * 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. * 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))) if(bind(rb_get_fd(F), (struct sockaddr *) &listener->addr, GET_SS_LEN(&listener->addr)))
{ {
report_error("binding listener socket %s:%s", report_error("binding listener socket %s:%s",
get_listener_name(listener), get_listener_name(listener),
get_listener_name(listener), errno); get_listener_name(listener), errno);
rb_close(F); rb_close(F);
return 0; return 0;
} }
if((ret = rb_listen(F, RATBOX_SOMAXCONN))) if((ret = rb_listen(F, RATBOX_SOMAXCONN)))
{ {
report_error("listen failed for %s:%s", report_error("listen failed for %s:%s",
get_listener_name(listener), get_listener_name(listener),
get_listener_name(listener), errno); get_listener_name(listener), errno);
rb_close(F); rb_close(F);
return 0; return 0;
} }
listener->F = F; listener->F = F;
rb_accept_tcp(listener->F, accept_precallback, accept_callback, listener); rb_accept_tcp(listener->F, accept_precallback, accept_callback, listener);
return 1; return 1;
} }
@ -273,9 +273,9 @@ find_listener(struct rb_sockaddr_storage *addr)
if(in4->sin_addr.s_addr == lin4->sin_addr.s_addr && if(in4->sin_addr.s_addr == lin4->sin_addr.s_addr &&
in4->sin_port == lin4->sin_port ) in4->sin_port == lin4->sin_port )
{ {
if(listener->F == NULL) if(listener->F == NULL)
last_closed = listener; last_closed = listener;
else else
return(listener); return(listener);
} }
break; break;
@ -288,9 +288,9 @@ find_listener(struct rb_sockaddr_storage *addr)
if(IN6_ARE_ADDR_EQUAL(&in6->sin6_addr, &lin6->sin6_addr) && if(IN6_ARE_ADDR_EQUAL(&in6->sin6_addr, &lin6->sin6_addr) &&
in6->sin6_port == lin6->sin6_port) in6->sin6_port == lin6->sin6_port)
{ {
if(listener->F == NULL) if(listener->F == NULL)
last_closed = listener; last_closed = listener;
else else
return(listener); return(listener);
} }
break; break;
@ -374,7 +374,7 @@ add_listener(int port, const char *vhost_ip, int family)
} }
if((listener = find_listener(&vaddr))) if((listener = find_listener(&vaddr)))
{ {
if(listener->F != NULL) if(listener->F != NULL)
return; return;
} }
else else
@ -401,10 +401,10 @@ close_listener(listener_t *listener)
s_assert(listener != NULL); s_assert(listener != NULL);
if(listener == NULL) if(listener == NULL)
return; return;
if(listener->F != NULL) if(listener->F != NULL)
{ {
rb_close(listener->F); rb_close(listener->F);
listener->F = NULL; listener->F = NULL;
} }
listener->active = 0; listener->active = 0;
@ -441,7 +441,7 @@ close_listeners()
* The client is sent to the auth module for verification, and not put in * The client is sent to the auth module for verification, and not put in
* any client list yet. * any client list yet.
*/ */
static void static void
add_connection(struct Listener *listener, rb_fde_t *F, struct sockaddr *sai, int exempt) add_connection(struct Listener *listener, rb_fde_t *F, struct sockaddr *sai, int exempt)
{ {
struct Client *new_client; struct Client *new_client;
@ -481,79 +481,79 @@ add_connection(struct Listener *listener, rb_fde_t *F, struct sockaddr *sai, int
start_auth(new_client); start_auth(new_client);
} }
static int static int
accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data) accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data)
{ {
struct Listener *listener = (struct Listener *)data; struct Listener *listener = (struct Listener *)data;
char buf[BUFSIZE]; char buf[BUFSIZE];
struct ConfItem *aconf; struct ConfItem *aconf;
static time_t last_oper_notice = 0; static time_t last_oper_notice = 0;
if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus */ if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus */
{ {
++ServerStats->is_ref; ++ServerStats->is_ref;
/* /*
* slow down the whining to opers bit * slow down the whining to opers bit
*/ */
if((last_oper_notice + 20) <= rb_current_time()) if((last_oper_notice + 20) <= rb_current_time())
{ {
sendto_realops_flags(SNO_GENERAL, L_ALL, sendto_realops_flags(SNO_GENERAL, L_ALL,
"All connections in use. (%s)", "All connections in use. (%s)",
get_listener_name(listener)); get_listener_name(listener));
last_oper_notice = rb_current_time(); last_oper_notice = rb_current_time();
} }
rb_write(F, "ERROR :All connections in use\r\n", 32); rb_write(F, "ERROR :All connections in use\r\n", 32);
rb_close(F); rb_close(F);
/* Re-register a new IO request for the next accept .. */ /* Re-register a new IO request for the next accept .. */
return 0; return 0;
} }
aconf = find_dline(addr, AF_INET); aconf = find_dline(addr, AF_INET);
if(aconf != NULL && (aconf->status & CONF_EXEMPTDLINE)) if(aconf != NULL && (aconf->status & CONF_EXEMPTDLINE))
return 1; return 1;
/* Do an initial check we aren't connecting too fast or with too many /* Do an initial check we aren't connecting too fast or with too many
* from this IP... */ * from this IP... */
if(aconf != NULL) if(aconf != NULL)
{ {
ServerStats->is_ref++; ServerStats->is_ref++;
if(ConfigFileEntry.dline_with_reason) if(ConfigFileEntry.dline_with_reason)
{ {
if (rb_snprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", aconf->passwd) >= (int)(sizeof(buf)-1)) 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) - 3] = '\r';
buf[sizeof(buf) - 2] = '\n'; buf[sizeof(buf) - 2] = '\n';
buf[sizeof(buf) - 1] = '\0'; buf[sizeof(buf) - 1] = '\0';
} }
} }
else else
strcpy(buf, "ERROR :You have been D-lined.\r\n"); strcpy(buf, "ERROR :You have been D-lined.\r\n");
rb_write(F, buf, strlen(buf)); rb_write(F, buf, strlen(buf));
rb_close(F); rb_close(F);
return 0; return 0;
} }
return 1; return 1;
} }
static void static void
accept_callback(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t addrlen, void *data) accept_callback(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t addrlen, void *data)
{ {
struct Listener *listener = data; struct Listener *listener = data;
struct rb_sockaddr_storage lip; struct rb_sockaddr_storage lip;
unsigned int locallen = sizeof(struct rb_sockaddr_storage); unsigned int locallen = sizeof(struct rb_sockaddr_storage);
ServerStats->is_ac++; ServerStats->is_ac++;
if(getsockname(rb_get_fd(F), (struct sockaddr *) &lip, &locallen) < 0) if(getsockname(rb_get_fd(F), (struct sockaddr *) &lip, &locallen) < 0)
{ {
/* this shouldn't fail so... */ /* this shouldn't fail so... */
/* XXX add logging of this */ /* XXX add logging of this */
rb_close(F); rb_close(F);
} }
add_connection(listener, F, addr, 1); add_connection(listener, F, addr, 1);
} }

View File

@ -165,63 +165,63 @@ flood_endgrace(struct Client *client_p)
client_p->localClient->sent_parsed = 0; client_p->localClient->sent_parsed = 0;
} }
/* /*
* flood_recalc * flood_recalc
* *
* recalculate the number of allowed flood lines. this should be called * 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. * once a second on any given client. We then attempt to flush some data.
*/ */
void void
flood_recalc(void *unused) flood_recalc(void *unused)
{ {
rb_dlink_node *ptr, *next; rb_dlink_node *ptr, *next;
struct Client *client_p; struct Client *client_p;
RB_DLINK_FOREACH_SAFE(ptr, next, lclient_list.head) RB_DLINK_FOREACH_SAFE(ptr, next, lclient_list.head)
{ {
client_p = ptr->data; client_p = ptr->data;
if(unlikely(IsMe(client_p))) if(unlikely(IsMe(client_p)))
continue; continue;
if(unlikely(client_p->localClient == NULL)) if(unlikely(client_p->localClient == NULL))
continue; continue;
if(IsFloodDone(client_p)) if(IsFloodDone(client_p))
client_p->localClient->sent_parsed -= 2; client_p->localClient->sent_parsed -= 2;
else else
client_p->localClient->sent_parsed = 0; client_p->localClient->sent_parsed = 0;
if(client_p->localClient->sent_parsed < 0) if(client_p->localClient->sent_parsed < 0)
client_p->localClient->sent_parsed = 0; client_p->localClient->sent_parsed = 0;
if(--client_p->localClient->actually_read < 0) if(--client_p->localClient->actually_read < 0)
client_p->localClient->actually_read = 0; client_p->localClient->actually_read = 0;
parse_client_queued(client_p); parse_client_queued(client_p);
if(unlikely(IsAnyDead(client_p))) if(unlikely(IsAnyDead(client_p)))
continue; continue;
} }
RB_DLINK_FOREACH_SAFE(ptr, next, unknown_list.head) RB_DLINK_FOREACH_SAFE(ptr, next, unknown_list.head)
{ {
client_p = ptr->data; client_p = ptr->data;
if(client_p->localClient == NULL) if(client_p->localClient == NULL)
continue; continue;
client_p->localClient->sent_parsed--; client_p->localClient->sent_parsed--;
if(client_p->localClient->sent_parsed < 0) if(client_p->localClient->sent_parsed < 0)
client_p->localClient->sent_parsed = 0; client_p->localClient->sent_parsed = 0;
if(--client_p->localClient->actually_read < 0) if(--client_p->localClient->actually_read < 0)
client_p->localClient->actually_read = 0; client_p->localClient->actually_read = 0;
parse_client_queued(client_p); parse_client_queued(client_p);
} }
} }
/* /*