From: Thomas Helvey Date: Sat, 11 Jan 2003 12:49:27 +0000 (+0000) Subject: Cleanup code so it builds with C++ again X-Git-Url: http://git.pk910.de/?p=ircu2.10.12-pk.git;a=commitdiff_plain;h=182404026d6a5dbff5c91c8071ead76e8d43a10b Cleanup code so it builds with C++ again git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@911 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- diff --git a/ChangeLog b/ChangeLog index 0876d1d..9a954dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2003-01-11 Thomas Helvey + * include/channel.h, include/ircd_alloc.h, ircd/channel.c, + ircd/client.c, ircd/gline.c, ircd/ircd_alloc.c, + ircd/ircd_events.c, ircd/ircd_log.c, ircd/ircd_parser.y, + ircd/ircd_snprintf.c, ircd/listener.c, ircd/m_nick.c, + ircd/m_opmode.c, ircd/m_whois.c, ircd/motd.c, + ircd/s_auth.c, ircd/s_bsd.c, ircd/uping.c: Server compiles + with g++ again, type safety, const correctness fixes, + remove C++ keywords again :/ 2003-01-11 Thomas Helvey * ircd/client.c, ircd/ircd_feature.c: Bugfix, the feature table data was in a different order than the feature data diff --git a/include/channel.h b/include/channel.h index 96c878a..a3ae4e8 100644 --- a/include/channel.h +++ b/include/channel.h @@ -348,7 +348,12 @@ extern void remove_user_from_all_channels(struct Client* cptr); extern int is_chan_op(struct Client *cptr, struct Channel *chptr); extern int is_zombie(struct Client *cptr, struct Channel *chptr); extern int has_voice(struct Client *cptr, struct Channel *chptr); -extern int IsInvited(struct Client* cptr, struct Channel* chptr); +/* + NOTE: pointer is compared, and not dereferenced, called by + add_target with a void*, since targets could be anything, + this function can't make any assumptions that it has a channel +*/ +extern int IsInvited(struct Client* cptr, const void* chptr); extern void send_channel_modes(struct Client *cptr, struct Channel *chptr); extern char *pretty_mask(char *mask); extern void del_invite(struct Client *cptr, struct Channel *chptr); diff --git a/include/ircd_alloc.h b/include/ircd_alloc.h index f78ad0d..2bfa018 100644 --- a/include/ircd_alloc.h +++ b/include/ircd_alloc.h @@ -46,7 +46,6 @@ extern void set_nomem_handler(OutOfMemoryHandler handler); * go ahead and write it). */ -extern void *malloc_tmp; /* First version: fast non-debugging macros... */ #ifndef MDEBUG @@ -58,10 +57,19 @@ extern void *malloc_tmp; extern OutOfMemoryHandler noMemHandler; #define DoFree(x, file, line) do { free((x)); (x) = 0; } while(0) +extern void* DoMalloc(size_t len, const char*, const char*, int); +extern void* DoMallocZero(size_t len, const char*, const char*, int); +#if 0 +extern void *malloc_tmp; +/* + Bleah, this is silly, the function call overhead for doing + the RightThing(tm) well worth the cost of avoiding this + non-reentrant mess of this macro, and accompanying global. +*/ #define DoMalloc(size, type, file, line) \ (\ (malloc_tmp = malloc(size), \ - (malloc_tmp == NULL) ? noMemHandler() : 0), \ + (malloc_tmp == NULL) ? (*noMemHandler)() : 0), \ malloc_tmp) #define DoMallocZero(size, type, file, line) \ @@ -69,6 +77,7 @@ extern OutOfMemoryHandler noMemHandler; (DoMalloc(size, type, file, line), \ memset(malloc_tmp, 0, size)), \ malloc_tmp) +#endif /* Second version: slower debugging versions... */ #else /* defined(MDEBUG) */ diff --git a/ircd/channel.c b/ircd/channel.c index 62f21cf..80030bb 100644 --- a/ircd/channel.c +++ b/ircd/channel.c @@ -1462,7 +1462,8 @@ int number_of_zombies(struct Channel *chptr) * of course, str2 is not NULL) */ static void -build_string(char *strptr, int *strptr_i, char *str1, char *str2, char c) +build_string(char *strptr, int *strptr_i, const char *str1, + const char *str2, char c) { if (c) strptr[(*strptr_i)++] = c; @@ -3232,7 +3233,7 @@ joinbuf_flush(struct JoinBuf *jbuf) } /* Returns TRUE (1) if client is invited, FALSE (0) if not */ -int IsInvited(struct Client* cptr, struct Channel* chptr) +int IsInvited(struct Client* cptr, const void* chptr) { struct SLink *lp; diff --git a/ircd/client.c b/ircd/client.c index 670da3a..e125466 100644 --- a/ircd/client.c +++ b/ircd/client.c @@ -101,18 +101,20 @@ void client_add_sendq(struct Connection* con, struct Connection** con_p) } } +enum FeatureFlag { + FEATFLAG_NULL, + FEATFLAG_DISABLES_PRIV, + FEATFLAG_ENABLES_PRIV, + FEATFLAG_GLOBAL_OPERS, + FEATFLAG_LOCAL_OPERS, + FEATFLAG_ALL_OPERS +}; + static struct { enum Priv priv; enum Feature feat; - enum - { - FEATFLAG_DISABLES_PRIV, - FEATFLAG_ENABLES_PRIV, - FEATFLAG_GLOBAL_OPERS, - FEATFLAG_LOCAL_OPERS, - FEATFLAG_ALL_OPERS - } flag; + enum FeatureFlag flag; } feattab[] = { { PRIV_WHOX, FEAT_LAST_F, FEATFLAG_ALL_OPERS }, @@ -166,7 +168,7 @@ static struct { PRIV_SEE_CHAN, FEAT_LOCOP_SEE_IN_SECRET_CHANNELS, FEATFLAG_LOCAL_OPERS }, { PRIV_WIDE_GLINE, FEAT_LOCOP_WIDE_GLINE, FEATFLAG_LOCAL_OPERS }, - { PRIV_LAST_PRIV, FEAT_LAST_F, 0 } + { PRIV_LAST_PRIV, FEAT_LAST_F, FEATFLAG_NULL } }; /* client_set_privs(struct Client* client) @@ -225,6 +227,8 @@ client_set_privs(struct Client *client, struct ConfItem *oper) if (IsLocOp(client)) PrivSet(&cli_privs(client), feattab[i].priv); continue; + default: + continue; /* ?? */ } } diff --git a/ircd/gline.c b/ircd/gline.c index ebbe642..e2672f4 100644 --- a/ircd/gline.c +++ b/ircd/gline.c @@ -132,15 +132,15 @@ make_gline(char *user, char *host, char *reason, time_t expire, time_t lastmod, DupString(gline->gl_host, host); if (check_if_ipmask(host)) { /* mark if it's an IP mask */ - int class; + int c_class; char ipname[16]; int ad[4] = { 0 }; int bits2 = 0; - class = sscanf(host,"%d.%d.%d.%d/%d", + c_class = sscanf(host,"%d.%d.%d.%d/%d", &ad[0],&ad[1],&ad[2],&ad[3], &bits2); - if (class!=5) { - gline->bits=class*8; + if (c_class!=5) { + gline->bits=c_class*8; } else { gline->bits=bits2; diff --git a/ircd/ircd_alloc.c b/ircd/ircd_alloc.c index c46bd98..f77fc0f 100644 --- a/ircd/ircd_alloc.c +++ b/ircd/ircd_alloc.c @@ -28,6 +28,7 @@ #include "s_debug.h" #include +#include static void nomem_handler(void); @@ -51,3 +52,22 @@ set_nomem_handler(OutOfMemoryHandler handler) { noMemHandler = handler; } + +void* DoMalloc(size_t size, const char* x, const char* y, int z) +{ + void* t = malloc(size); + if (!t) + (*noMemHandler)(); + return t; +} + +void* DoMallocZero(size_t size, const char* x, const char* y, int z) +{ + void* t = malloc(size); + if (!t) + (*noMemHandler)(); + memset(t, 0, size); + return t; +} + + diff --git a/ircd/ircd_events.c b/ircd/ircd_events.c index 00616e6..1371f88 100644 --- a/ircd/ircd_events.c +++ b/ircd/ircd_events.c @@ -663,7 +663,7 @@ struct { \ #define NM(name) { #name, name } -#define NE { 0, 0 } +#define NE { 0 } const char* state_to_name(enum SocketState state) diff --git a/ircd/ircd_log.c b/ircd/ircd_log.c index 37e942b..740feb0 100644 --- a/ircd/ircd_log.c +++ b/ircd/ircd_log.c @@ -235,7 +235,7 @@ log_debug_reopen(void) void log_debug_init(int usetty) { - logInfo.dbfile = MyMalloc(sizeof(struct LogFile)); + logInfo.dbfile = (struct LogFile*) MyMalloc(sizeof(struct LogFile)); logInfo.dbfile->next = 0; /* initialize debugging filename */ logInfo.dbfile->prev_p = 0; @@ -418,7 +418,7 @@ log_vwrite(enum LogSys subsys, enum LogLevel severity, unsigned int flags, vector[0].iov_base = timebuf; vector[1].iov_base = buf; - vector[2].iov_base = "\n"; /* terminate lines with a \n */ + vector[2].iov_base = (void*) "\n"; /* terminate lines with a \n */ vector[2].iov_len = 1; /* write it out to the log file */ @@ -469,7 +469,7 @@ log_file_create(const char *file) tmp = logInfo.freelist; logInfo.freelist = tmp->next; } else /* allocate a new one */ - tmp = MyMalloc(sizeof(struct LogFile)); + tmp = (struct LogFile*) MyMalloc(sizeof(struct LogFile)); tmp->fd = -1; /* initialize the structure */ tmp->ref = 1; diff --git a/ircd/ircd_parser.y b/ircd/ircd_parser.y index 4e63ff9..f748f01 100644 --- a/ircd/ircd_parser.y +++ b/ircd/ircd_parser.y @@ -55,6 +55,7 @@ #include "support.h" #include "sys.h" #include +#include #include #include #define MAX_STRINGS 80 /* Maximum number of feature params. */ @@ -71,7 +72,7 @@ int stringno; char *name, *pass, *host; char *stringlist[MAX_STRINGS]; - struct ConnectionClass *class; + struct ConnectionClass *c_class; struct ConfItem *aconf; struct DenyConf *dconf; struct ServerConf *sconf; @@ -352,11 +353,11 @@ classsendq: SENDQ '=' sizespec ';' connectblock: CONNECT { name = pass = host = NULL; - class = NULL; + c_class = NULL; port = 0; } '{' connectitems '}' { - if (name != NULL && pass != NULL && host != NULL && class != NULL && + if (name != NULL && pass != NULL && host != NULL && c_class != NULL && /*ccount < MAXCONFLINKS &&*/ !strchr(host, '*') && !strchr(host, '?')) { @@ -364,7 +365,7 @@ connectblock: CONNECT aconf->status = CONF_SERVER; aconf->name = name; aconf->passwd = pass; - aconf->conn_class = class; + aconf->conn_class = c_class; aconf->port = port; aconf->status = CONF_SERVER; aconf->host = host; @@ -396,7 +397,7 @@ connectpass: PASS '=' QSTRING ';' }; connectclass: CLASS '=' QSTRING ';' { - class = find_class(yylval.text); + c_class = find_class(yylval.text); }; connecthost: HOST '=' QSTRING ';' { @@ -410,7 +411,7 @@ connectport: PORT '=' NUMBER ';' serverblock: SERVER { - aconf = MyMalloc(sizeof(*aconf)); + aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf)); memset(aconf, 0, sizeof(*aconf)); } '{' serveritems '}' { @@ -472,7 +473,7 @@ serveruworld: UWORLD '=' YES ';' operblock: OPER { - aconf = MyMalloc(sizeof(*aconf)); + aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf)); memset(aconf, 0, sizeof(*aconf)); aconf->status = CONF_OPERATOR; } '{' operitems '}' ';' @@ -524,7 +525,7 @@ operhost: HOST '=' QSTRING ';' if (!strchr(yylval.text, '@')) { int uh_len; - char *b = MyMalloc((uh_len = strlen(yylval.text)+3)); + char *b = (char*) MyMalloc((uh_len = strlen(yylval.text)+3)); ircd_snprintf(0, b, uh_len, "*@%s", yylval.text); aconf->host = b; } @@ -640,7 +641,7 @@ porthidden: HIDDEN '=' YES ';' clientblock: CLIENT { - aconf = MyMalloc(sizeof(*aconf)); + aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf)); memset(aconf, 0, sizeof(*aconf)); aconf->status = CONF_CLIENT; } '{' clientitems '}' @@ -692,7 +693,7 @@ clientpass: PASS '=' QSTRING ';' killblock: KILL { - dconf = MyMalloc(sizeof(*dconf)); + dconf = (struct DenyConf*) MyMalloc(sizeof(*dconf)); memset(dconf, 0, sizeof(*dconf)); } '{' killitems '}' { @@ -785,7 +786,7 @@ cruleblock: CRULE struct CRuleNode *node; if (host != NULL && pass != NULL && (node=crule_parse(pass)) != NULL) { - struct CRuleConf *p = MyMalloc(sizeof(*p)); + struct CRuleConf *p = (struct CRuleConf*) MyMalloc(sizeof(*p)); p->hostmask = host; p->rule = pass; p->type = tconn; @@ -875,7 +876,7 @@ extrastring: QSTRING quarantineblock: QUARANTINE '{' { if (qconf != NULL) - qconf = MyMalloc(sizeof(*qconf)); + qconf = (struct qline*) MyMalloc(sizeof(*qconf)); else { if (qconf->chname != NULL) @@ -890,7 +891,7 @@ quarantineblock: QUARANTINE '{' { log_write(LS_CONFIG, L_ERROR, 0, "quarantine blocks need a channel name " "and a reason."); - return; + return 0; } qconf->next = GlobalQuarantineList; GlobalQuarantineList = qconf; diff --git a/ircd/ircd_snprintf.c b/ircd/ircd_snprintf.c index 0a762aa..700aeba 100644 --- a/ircd/ircd_snprintf.c +++ b/ircd/ircd_snprintf.c @@ -2010,7 +2010,7 @@ doprintf(struct Client *dest, struct BufData *buf_p, const char *fmt, vdata->vd_overflow = SNP_MAX(buf_s.buf_overflow, buf_s.overflow); } else if ((fld_s.flags & CONV_MASK) == CONV_CLIENT) { struct Client *cptr = (struct Client*) fld_s.value.v_ptr; - char *str1 = 0, *str2 = 0, *str3 = 0; + const char *str1 = 0, *str2 = 0, *str3 = 0; int slen1 = 0, slen2 = 0, slen3 = 0, elen = 0, plen = 0; /* &me is used if it's not a definite server */ diff --git a/ircd/listener.c b/ircd/listener.c index 7b05e49..42ee4bd 100644 --- a/ircd/listener.c +++ b/ircd/listener.c @@ -432,7 +432,7 @@ static void accept_connection(struct Event* ev) assert(0 != ev_socket(ev)); assert(0 != s_data(ev_socket(ev))); - listener = s_data(ev_socket(ev)); + listener = (struct Listener*) s_data(ev_socket(ev)); if (ev_type(ev) == ET_DESTROY) /* being destroyed */ free_listener(listener); diff --git a/ircd/m_nick.c b/ircd/m_nick.c index e986e2d..ef31e88 100644 --- a/ircd/m_nick.c +++ b/ircd/m_nick.c @@ -284,7 +284,7 @@ int ms_nick(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) char nick[NICKLEN + 2]; time_t lastnick = 0; int differ = 1; - char *type; + const char *type; assert(0 != cptr); assert(0 != sptr); diff --git a/ircd/m_opmode.c b/ircd/m_opmode.c index 0c4bbe1..b7fde9a 100644 --- a/ircd/m_opmode.c +++ b/ircd/m_opmode.c @@ -93,6 +93,7 @@ #include "numeric.h" #include "numnicks.h" #include "send.h" +#include "s_conf.h" #include @@ -138,7 +139,8 @@ int mo_opmode(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { struct Channel *chptr = 0; struct ModeBuf mbuf; - char *chname, *qreason; + char *chname; + const char *qreason; int force = 0; struct Membership *member; diff --git a/ircd/m_whois.c b/ircd/m_whois.c index 5dda1a5..b817e3a 100644 --- a/ircd/m_whois.c +++ b/ircd/m_whois.c @@ -227,7 +227,7 @@ static int do_wilds(struct Client* sptr, char *nick, int count, int parc) { struct Client *acptr; /* Current client we're concidering */ struct User *user; /* the user portion of the client */ - char *name; /* the name of this client */ + const char *name; /* the name of this client */ struct Membership* chan; int invis; /* does +i apply? */ int member; /* Is this user on any channels? */ diff --git a/ircd/motd.c b/ircd/motd.c index a2634b9..76dd87c 100644 --- a/ircd/motd.c +++ b/ircd/motd.c @@ -219,22 +219,22 @@ static struct Motd * motd_lookup(struct Client *cptr) { struct Motd *ptr; - char *class = NULL; + char *c_class = NULL; assert(0 != cptr); if (!MyUser(cptr)) /* not my user, always return remote motd */ return MotdList.remote; - class = get_client_class(cptr); + c_class = get_client_class(cptr); /* check the motd blocks first */ for (ptr = MotdList.other; ptr; ptr = ptr->next) { if (ptr->type == MOTD_CLASS && - !match(ptr->hostmask, class)) + !match(ptr->hostmask, c_class)) return ptr; - else if (ptr->type == MOTD_HOSTMASK && class != NULL && + else if (ptr->type == MOTD_HOSTMASK && c_class != NULL && !match(ptr->hostmask, cli_sockhost(cptr))) return ptr; } diff --git a/ircd/s_auth.c b/ircd/s_auth.c index f00e83f..d399af0 100644 --- a/ircd/s_auth.c +++ b/ircd/s_auth.c @@ -138,7 +138,7 @@ static void auth_timeout_callback(struct Event* ev) assert(0 != ev_timer(ev)); assert(0 != t_data(ev_timer(ev))); - auth = t_data(ev_timer(ev)); + auth = (struct AuthRequest*) t_data(ev_timer(ev)); if (ev_type(ev) == ET_DESTROY) { /* being destroyed */ auth->flags &= ~AM_TIMEOUT; @@ -165,7 +165,7 @@ static void auth_sock_callback(struct Event* ev) assert(0 != ev_socket(ev)); assert(0 != s_data(ev_socket(ev))); - auth = s_data(ev_socket(ev)); + auth = (struct AuthRequest*) s_data(ev_socket(ev)); switch (ev_type(ev)) { case ET_DESTROY: /* being destroyed */ diff --git a/ircd/s_bsd.c b/ircd/s_bsd.c index 5498a0c..1b756a6 100644 --- a/ircd/s_bsd.c +++ b/ircd/s_bsd.c @@ -983,7 +983,7 @@ static void client_sock_callback(struct Event* ev) assert(0 != ev_socket(ev)); assert(0 != s_data(ev_socket(ev))); - con = s_data(ev_socket(ev)); + con = (struct Connection*) s_data(ev_socket(ev)); assert(0 != con_client(con) || ev_type(ev) == ET_DESTROY); @@ -1071,7 +1071,7 @@ static void client_timer_callback(struct Event* ev) assert(0 != t_data(ev_timer(ev))); assert(ET_DESTROY == ev_type(ev) || ET_EXPIRE == ev_type(ev)); - con = t_data(ev_timer(ev)); + con = (struct Connection*) t_data(ev_timer(ev)); assert(0 != con_client(con) || ev_type(ev) == ET_DESTROY); diff --git a/ircd/uping.c b/ircd/uping.c index 8f89653..3e69622 100644 --- a/ircd/uping.c +++ b/ircd/uping.c @@ -193,7 +193,7 @@ static void uping_read_callback(struct Event* ev) assert(0 != ev_socket(ev)); assert(0 != s_data(ev_socket(ev))); - pptr = s_data(ev_socket(ev)); + pptr = (struct UPing*) s_data(ev_socket(ev)); Debug((DEBUG_SEND, "uping_read_callback called, %p (%d)", pptr, ev_type(ev))); @@ -218,7 +218,7 @@ static void uping_sender_callback(struct Event* ev) assert(0 != ev_timer(ev)); assert(0 != t_data(ev_timer(ev))); - pptr = t_data(ev_timer(ev)); + pptr = (struct UPing*) t_data(ev_timer(ev)); Debug((DEBUG_SEND, "uping_sender_callback called, %p (%d)", pptr, ev_type(ev))); @@ -247,7 +247,7 @@ static void uping_killer_callback(struct Event* ev) assert(0 != ev_timer(ev)); assert(0 != t_data(ev_timer(ev))); - pptr = t_data(ev_timer(ev)); + pptr = (struct UPing*) t_data(ev_timer(ev)); Debug((DEBUG_SEND, "uping_killer_callback called, %p (%d)", pptr, ev_type(ev)));