Browse Source

* More c++ leaf fixes, now for hub :)

svn: 1317
Bryan Drewery 22 năm trước cách đây
mục cha
commit
b83928cdf0

+ 12 - 13
src/botmsg.c

@@ -102,21 +102,20 @@ char *unsigned_int_to_base10(unsigned int val)
   return buf_base10 + i;
 }
 
-size_t simple_sprintf (char *buf, ...)
+size_t simple_sprintf (char *buf, const char *format, ...)
 {
-  char *format = NULL;
-  unsigned char *s = NULL;
+  char *s = NULL;
+  char *fp = (char *) format;
   size_t c = 0;
   unsigned int i;
   va_list va;
   
-  va_start(va, buf);
-  format = va_arg(va, char *);
+  va_start(va, format);
 
-  while (*format && c < 1023) {
-    if (*format == '%') {
-      format++;
-      switch (*format) {
+  while (*fp && c < 1023) {
+    if (*fp == '%') {
+      fp++;
+      switch (*fp) {
       case 's':
 	s = va_arg(va, char *);
 	break;
@@ -134,11 +133,11 @@ size_t simple_sprintf (char *buf, ...)
         s = unsigned_int_to_base10(i);
 	break;
       case '%':
-	buf[c++] = *format++;
+	buf[c++] = *fp++;
 	continue;
       case 'c':
 	buf[c++] = (char) va_arg(va, int);
-	format++;
+	fp++;
 	continue;
       default:
 	continue;
@@ -146,9 +145,9 @@ size_t simple_sprintf (char *buf, ...)
       if (s)
 	while (*s && c < 1023)
 	  buf[c++] = *s++;
-      format++;
+      fp++;
     } else
-      buf[c++] = *format++;
+      buf[c++] = *fp++;
   }
   va_end(va);
   buf[c] = 0;

+ 1 - 1
src/botmsg.h

@@ -18,7 +18,7 @@ void botnet_send_cfg_broad(int idx, struct cfg_entry *entry);
 void putbot(char *, char *);
 void putallbots(char *);
 int add_note(char *, char *, char *, int, int);
-size_t simple_sprintf (char *, ...);
+size_t simple_sprintf (char *, const char *, ...);
 char *int_to_base10(int);
 char *unsigned_int_to_base10(unsigned int);
 char *int_to_base64(unsigned int);

+ 1 - 1
src/cmds.c

@@ -3297,7 +3297,7 @@ static void cmd_pls_ignore(int idx, char *par)
     dprintf(idx, "That already matches an existing ignore.\n");
   else {
     dprintf(idx, "Now ignoring: %s (%s)\n", s, par);
-    addignore(s, dcc[idx].nick, par, expire_time ? now + expire_time : 0L);
+    addignore(s, dcc[idx].nick, (const char *) par, expire_time ? now + expire_time : 0L);
     putlog(LOG_CMDS, "*", "#%s# +ignore %s %s", dcc[idx].nick, s, par);
 #ifdef HUB
     write_userfile(idx);

+ 4 - 2
src/compat/memutil.c

@@ -3,6 +3,7 @@
 #include "memcpy.h"
 #include "src/main.h"
 
+/*
 extern void * __real_malloc(size_t);
 extern void * __real_realloc(void *, size_t);
 
@@ -44,11 +45,12 @@ __wrap_calloc(size_t nmemb, size_t size)
 
   return x;
 }
+*/
 
 void 
-__wrap_str_redup(char **str, const char *newstr)
+str_redup(char **str, const char *newstr)
 {
-        int len;
+        size_t len;
 
         if (!newstr) {
                 if (*str) free(*str);

+ 8 - 3
src/compat/memutil.h

@@ -1,15 +1,20 @@
 #ifndef _MEMUTIL_H
 #define _MEMUTIL_H
 
+/*
 #undef malloc
 #undef realloc
 #undef calloc
-#undef str_redup
-#undef strdup
-
 void *malloc(size_t);
 void *realloc(void *, size_t);
 void *calloc(size_t, size_t);
+*/
+
+#ifdef str_redup
+#undef str_redup
+#endif /* str_redup */
+#undef strdup
+
 void str_redup(char **, const char *);
 char *strdup(const char *);
 

+ 4 - 4
src/crypt.c

@@ -87,13 +87,13 @@ char *encrypt_string(const char *keydata, char *in)
   char *res = NULL;
 
   len = strlen(in) + 1;
-  bdata = encrypt_binary(keydata, in, &len);
+  bdata = encrypt_binary(keydata, (unsigned char *) in, &len);
   if (keydata && *keydata) {
     res = b64enc(bdata, len);
     free(bdata);
     return res;
   } else {
-    return bdata;
+    return (char *) bdata;
   }
 }
 
@@ -104,8 +104,8 @@ char *decrypt_string(const char *keydata, char *in)
 
   len = strlen(in);
   if (keydata && *keydata) {
-    buf = b64dec(in, &len);
-    res = decrypt_binary(keydata, buf, len);
+    buf = b64dec((const unsigned char *) in, &len);
+    res = (char *) decrypt_binary(keydata, (unsigned char *) buf, len);
     free(buf);
     return res;
   } else {

+ 6 - 4
src/egg_timer.c

@@ -4,6 +4,8 @@
 
 #include "egg_timer.h"
 
+typedef int (*TimerFunc) (void *);
+
 /* From main.c */
 static egg_timeval_t now;
 
@@ -12,7 +14,7 @@ typedef struct egg_timer_b {
 	struct egg_timer_b *next;
 	int id;
 	char *name;
-	int (*callback) (void *);
+        TimerFunc callback;
 	void *client_data;
 	egg_timeval_t howlong;
 	egg_timeval_t trigger_time;
@@ -113,7 +115,7 @@ int timer_create_secs(int secs, const char *name, Function callback)
 	howlong.sec = secs;
 	howlong.usec = 0;
 
-	return timer_create_repeater(&howlong, name, (Function) callback);
+	return timer_create_repeater(&howlong, name, callback);
 }
 
 int timer_create_complex(egg_timeval_t *howlong, const char *name, Function callback, void *client_data, int flags)
@@ -125,7 +127,7 @@ int timer_create_complex(egg_timeval_t *howlong, const char *name, Function call
 	timer->id = timer_next_id++;
 	if (name) timer->name = strdup(name);
 	else timer->name = NULL;
-	timer->callback = callback;
+	timer->callback = (TimerFunc) callback;
 	timer->client_data = client_data;
 	timer->flags = flags;
 	timer->howlong.sec = howlong->sec;
@@ -186,7 +188,7 @@ int timer_get_shortest(egg_timeval_t *howlong)
 int timer_run()
 {
 	egg_timer_t *timer = NULL;
-	int (*callback) (void *);
+        TimerFunc callback;
 	void *client_data = NULL;
 
 	while (timer_list_head) {

+ 1 - 1
src/log.h

@@ -29,7 +29,7 @@
 #define LOG_ALL      0xfffffff   /* (dump to all logfiles)               */
 
 void logidx(int, const char *, ...) __attribute__((format(printf, 2, 3)));
-void putlog (int, const char *, const char *, ...) __attribute((format(printf, 3, 4)));
+void putlog (int, const char *, const char *, ...) __attribute__((format(printf, 3, 4)));
 int logmodes(const char *);
 char *masktype(int);
 char *maskname(int);

+ 1 - 1
src/main.c

@@ -871,7 +871,7 @@ printf("out: %s\n", out);
 #if defined(LEAF) && defined(__linux__)
   if (conf.pscloak) {
     int argi;
-    char *p = response(RES_PSCLOAK);
+    const char *p = response(RES_PSCLOAK);
 
     for (argi = 0; argi < argc; argi++)
       egg_memset(argv[argi], 0, strlen(argv[argi]));

+ 4 - 3
src/makeres.c

@@ -136,7 +136,8 @@ int parse_res(char *in, char *out, char *outs) {
 #ifndef _RESPONSE_H\n\
 #define _RESPONSE_H\n\
 \n\
-typedef enum {\n");
+typedef unsigned int response_t;\n\n\
+enum {\n");
 
   fprintf(outsf, "/* DO NOT EDIT THIS FILE. */\n\
 #ifndef _RESPONSES_H\n\
@@ -172,8 +173,8 @@ typedef char * res_t;\n\n");
           fprintf(outsf, "static res_t res_%s[] = {\n", cmd);
           sprintf(lower_resps, "%s,\n\tres_%s", lower_resps, cmd);
         } else {			/* END */
-          fprintf(outf, "\tRES_END\n} Response;\n\n#define RES_TYPES %d\n", total_responses);
-          fprintf(outf, "char *response(Response);\nvoid init_responses();\n\n#endif /* !_RESPONSE_H */\n");
+          fprintf(outf, "\tRES_END\n};\n\n#define RES_TYPES %d\n", total_responses);
+          fprintf(outf, "const char *response(response_t);\nvoid init_responses();\n\n#endif /* !_RESPONSE_H */\n");
           fprintf(outsf, "static res_t *res[] = {\n\tNULL%s\n};\n#endif /* !_RESPONSES_H */\n", lower_resps);
         }
       } else {				/* NEXT RES TEXT */

+ 1 - 1
src/misc.c

@@ -773,7 +773,7 @@ int updatebin(int idx, char *par, int secs)
       egg_timeval_t howlong;
       howlong.sec = secs;
       howlong.usec = 0;
-      timer_create_complex(&howlong, "restarting for update", (int (*)(int)) restart, (void *) idx, 0);
+      timer_create_complex(&howlong, "restarting for update", (Function) restart, (void *) idx, 0);
     } else
       restart(idx);
     return 0;

+ 2 - 2
src/mod/irc.mod/chan.c

@@ -550,7 +550,7 @@ static char *quickban(struct chanset_t *chan, char *uhost)
 /* Kick any user (except friends/masters) with certain mask from channel
  * with a specified comment.  Ernst 18/3/1998
  */
-static void kick_all(struct chanset_t *chan, char *hostmask, char *comment, int bantype)
+static void kick_all(struct chanset_t *chan, char *hostmask, const char *comment, int bantype)
 {
   memberlist *m = NULL;
   int flushed;
@@ -615,7 +615,7 @@ static void refresh_ban_kick(struct chanset_t *chan, char *user, char *nick)
 	else
 	  c[0] = 0;
         if (role == 2)
-  	  kick_all(chan, b->mask, c[0] ? c : IRC_YOUREBANNED, 0);
+  	  kick_all(chan, b->mask, c[0] ? (const char *) c : IRC_YOUREBANNED, 0);
         return;					/* Drop out on 1st ban.	*/
       } 
     }

+ 2 - 2
src/mod/irc.mod/mode.c

@@ -674,7 +674,7 @@ got_ban(struct chanset_t *chan, char *nick, char *from, char *who)
   refresh_exempt(chan, who);
   /* This looks for bans added through bot and tacks on banned: if a description is found */
   if (nick[0] && channel_enforcebans(chan)) {
-    register maskrec *b;
+    register maskrec *b = NULL;
     int cycle;
     char resn[512] = "";
 
@@ -689,7 +689,7 @@ got_ban(struct chanset_t *chan, char *nick, char *from, char *who)
         }
       }
     }
-    kick_all(chan, who, resn[0] ? resn : response(RES_BANNED), match_my_nick(nick) ? 0 : 1);
+    kick_all(chan, who, resn[0] ? (const char *) resn : response(RES_BANNED), match_my_nick(nick) ? 0 : 1);
   }
   if (!nick[0] && (bounce_bans || bounce_modes) &&
       (!u_equals_mask(global_bans, who) || !u_equals_mask(chan->bans, who)))

+ 1 - 1
src/mod/share.mod/share.c

@@ -980,7 +980,7 @@ share_pls_ignore(int idx, char *par)
       from[HANDLEN + 1] = 0;
     par[65] = 0;
     putlog(LOG_CMDS, "@", "%s: ignore %s (%s: %s)", dcc[idx].nick, ign, from, par);
-    addignore(ign, from, par, expire_time);
+    addignore(ign, from, (const char *) par, expire_time);
     noshare = 0;
   }
 }

+ 1 - 1
src/mod/transfer.mod/transfer.c

@@ -353,7 +353,7 @@ static void eof_dcc_send(int idx)
 	   dcc[idx].u.xfer->origname, dcc[idx].nick, dcc[idx].host);
     egg_snprintf(s, sizeof s, "%s!%s", dcc[idx].nick, dcc[idx].host);
     u = get_user_by_host(s);
-    hand = u ? u->handle : "*";
+    hand = u ? u->handle : (char *) "*";
 
     l = strlen(dcc[idx].u.xfer->filename);
     if (l > NAME_MAX) {

+ 6 - 6
src/response.c

@@ -10,21 +10,21 @@
 #include "main.h"
 #include "responses.h"
 
-static Response response_totals[RES_TYPES + 1];
+static response_t response_totals[RES_TYPES + 1];
 
 void
 init_responses()
 {
-  unsigned int i = 0;
+  response_t i = 0;
   
   for (i = 0; i <= RES_TYPES; i++)
     response_totals[i] = 0;
 }
 
 static void
-count_responses(Response type)
+count_responses(response_t type)
 {
-  unsigned int total = 0;
+  response_t total = 0;
 
   for (total = 0; res[type][total]; total++) 
     ;
@@ -33,8 +33,8 @@ count_responses(Response type)
   /* printf("Type: %d has %d total responses!\n", type, response_totals[type]); */
 }
 
-char *
-response(Response type)
+const char *
+response(response_t type)
 {
   if (!type)
     type = randint(RES_TYPES) + 1;

+ 1 - 1
src/tclhash.c

@@ -411,7 +411,7 @@ static int bind_vcheck_hits (bind_table_t *table, const char *match, struct flag
 
 
 		if (table->match_type & MATCH_MASK) {
-			cmp = !wild_match_per(entry->mask, match);
+			cmp = !wild_match_per(entry->mask, (char *) match);
 		}
 		else if (table->match_type & MATCH_NONE) {
 			cmp = 0;

+ 3 - 3
src/userent.c

@@ -235,7 +235,7 @@ int config_set(struct userrec *u, struct user_entry *e, void *buf)
   }
   if (old != mynew && mynew->data) {
     if (mynew->data[0]) {
-      list_insert((&e->u.extra), mynew);
+      list_insert((struct xtra_key **) (&e->u.extra), mynew);
     } else {
       if (mynew->data)
         free(mynew->data);
@@ -262,7 +262,7 @@ int config_unpack(struct userrec *u, struct user_entry *e)
     if (data[0]) {
       t->key = strdup(key);
       t->data = strdup(data);
-      list_insert((&e->u.extra), t);
+      list_insert((struct xtra_key **) (&e->u.extra), t);
     }
     curr = curr->next;
   }
@@ -1014,7 +1014,7 @@ int add_entry_type(struct user_entry_type *type)
 {
   struct userrec *u = NULL;
 
-  list_insert(&entry_type_list, type);
+  list_insert((&entry_type_list), type);
   for (u = userlist; u; u = u->next) {
     struct user_entry *e = find_user_entry(type, u);
 

+ 1 - 1
src/users.c

@@ -109,7 +109,7 @@ int delignore(char *ign)
   return i;
 }
 
-void addignore(char *ign, char *from, char *mnote, time_t expire_time)
+void addignore(char *ign, char *from, const char *mnote, time_t expire_time)
 {
   struct igrec *p = NULL, *l = NULL;
 

+ 1 - 1
src/users.h

@@ -163,7 +163,7 @@ void def_display(int idx, struct user_entry *e, struct userrec *u);
 #ifdef HUB
 void backup_userfile();
 #endif /* HUB */
-void addignore(char *, char *, char *, time_t);
+void addignore(char *, char *, const char *, time_t);
 int delignore(char *);
 void tell_ignores(int, char *);
 int match_ignore(char *);