Cleanup code so it builds with C++ again
authorThomas Helvey <tom.helvey@cox.net>
Sat, 11 Jan 2003 12:49:27 +0000 (12:49 +0000)
committerThomas Helvey <tom.helvey@cox.net>
Sat, 11 Jan 2003 12:49:27 +0000 (12:49 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@911 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

19 files changed:
ChangeLog
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

index 0876d1def0f1dd000326d27d4317ac17c4d4284f..9a954dd865d2b397cbf5866701f1ef17da4319a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2003-01-11  Thomas Helvey <tom.helvey@cox.net>
+       * 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 <tom.helvey@cox.net>
        * ircd/client.c, ircd/ircd_feature.c: Bugfix, the feature
        table data was in a different order than the feature data
index 96c878aeeceb78092ce1a380135eccbb949f6fd8..a3ae4e8a233e330912ca573fc9757d2199635bf3 100644 (file)
@@ -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);
index f78ad0df9793ae0edc78ca1b1a977f7e59b1d8dd..2bfa0186b80dff29bc93702a2b2231f55aad71c7 100644 (file)
@@ -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) */
index 62f21cfda22a1dcccbcfa4bdf3b2e3b368725da7..80030bbdd7b8f7ee40de8d1d3728dd764d86a725 100644 (file)
@@ -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;
 
index 670da3a291609f03494974f734aaba72ae69a535..e12546651a6caf0b185355bb27729456e9117906 100644 (file)
@@ -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;  /* ?? */
     }
   }
 
index ebbe6424e91cd930f3d52f66c1442e2f3d05509d..e2672f457a4fbdec703ee8881c7bbf91ec1d5157 100644 (file)
@@ -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;
index c46bd987d6783a5f028ac1a0a0be813a22f1f5de..f77fc0f41a4e9d5b0d11325374dc470ceeafbc07 100644 (file)
@@ -28,6 +28,7 @@
 #include "s_debug.h"
 
 #include <assert.h>
+#include <string.h>
 
 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;
+}
+
+
index 00616e64904ecf9d8fdaef166d809ee5285e2b23..1371f88f84d841c1e71c23d03ee12486cbdb8733 100644 (file)
@@ -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)
index 37e942bc8e77eb6b76203153393f7c540cdb5faa..740feb0e67d2b30540207131fd38c7b7dea57fc0 100644 (file)
@@ -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;
index 4e63ff98f3f3c06e6dc6a8a24c77daaa6f76f38b..f748f015713a8b7150d9a32faed029dbf94e936b 100644 (file)
@@ -55,6 +55,7 @@
 #include "support.h"
 #include "sys.h"
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <arpa/inet.h>
 #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;
index 0a762aad3a71bea4f67a2ffc7573bbcc5cccd58f..700aeba9dc637a88a149edff8554081f50bfdaec 100644 (file)
@@ -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 */
index 7b05e49eecb8af7c07c89bc464297c155c2d4b97..42ee4bdca21d53288edbd1d3d649b2d9af7e4379 100644 (file)
@@ -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);
index e986e2db34859fac978d3bcc386a112804b179e4..ef31e88c7f486784a8f63088b222f8e6c6e790ee 100644 (file)
@@ -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);
index 0c4bbe19651bbe0e77c09799b0260494d012e8b3..b7fde9a196e0957afcb17d79b0a566ffa6e15648 100644 (file)
@@ -93,6 +93,7 @@
 #include "numeric.h"
 #include "numnicks.h"
 #include "send.h"
+#include "s_conf.h"
 
 #include <assert.h>
 
@@ -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;
 
index 5dda1a572a2edd3279c7e48ad4967595eb739e58..b817e3a26a6c79b48aedb2747ce64a35c37ede22 100644 (file)
@@ -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? */
index a2634b966c4ca1482e0ed25330adf70039c9a820..76dd87c7fb45fe7bfbfea3d5483a5fa6fcc43605 100644 (file)
@@ -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;
   }
index f00e83f8043e534dbc30d4709bfaac6fb72255d2..d399af0f3f25246132c1cb23c24ebd5a2d4ca35a 100644 (file)
@@ -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 */
index 5498a0c7154c96669fe58d6521faae9282ab8f15..1b756a61d838b3f9ef4b26cebcde3e549b32b2d5 100644 (file)
@@ -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);
 
index 8f8965365d227a5b9646f3bcbcc4f1247c130477..3e69622b052d5ace3607ae7b8b25c592a48fe4be 100644 (file)
@@ -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)));