Răsfoiți Sursa

* Removed HOOKS
* Cleaned up some code for leaf binaries.


svn: 899

Bryan Drewery 22 ani în urmă
părinte
comite
388f964460

+ 1 - 0
doc/UPDATES

@@ -8,6 +8,7 @@ This is a summary of ChangeLog basically.
 4.Segfault fix in cmd_debug.
 5.Fixed a potential bug in share.
 6.Traffic stats are now properly cleared on leaf bots every day.
+7.Removed a bunch of unused code on leaf bots.
 
 1.1.4 (Quickly advanced to 1.1.5)
 

+ 0 - 1
src/Makefile.in

@@ -32,7 +32,6 @@ OBJS = auth.o \
 	egg_timer.o \
 	flags.o \
 	garble.o \
-	hooks.o \
 	log.o \
 	main.o \
 	match.o \

+ 7 - 12
src/chanprog.c

@@ -13,6 +13,12 @@
 #include "chanprog.h"
 #include "settings.h"
 #include "src/mod/channels.mod/channels.h"
+#ifdef LEAF
+#include "src/mod/server.mod/server.h"
+#endif /* LEAF */
+#ifdef HUB
+#include "src/mod/share.mod/share.h"
+#endif /* HUB */
 #include "rfc1459.h"
 #include "net.h"
 #include "misc.h"
@@ -29,7 +35,6 @@
 #endif
 #endif
 #include <sys/utsname.h>
-#include "hooks.h"
 
 struct chanset_t 	*chanset = NULL;	/* Channel list			*/
 char 			admin[121] = "";	/* Admin info			*/
@@ -596,20 +601,10 @@ void reload()
   checkchans(1);
   loading = 0;
   reaffirm_owners();
-  call_hook(HOOK_READ_USERFILE);
+  hook_read_userfile();
 }
 #endif /* HUB */
 
-void rehash()
-{
-  call_hook(HOOK_PRE_REHASH);
-  noshare = 1;
-  clear_userlist(userlist);
-  noshare = 0;
-  userlist = NULL;
-  chanprog();
-}
-
 /* Oddly enough, written by proton (Emech's coder)
  */
 int isowner(char *name)

+ 0 - 1
src/chanprog.h

@@ -16,7 +16,6 @@ void tell_verbose_status(int);
 void tell_settings(int);
 int isowner(char *);
 void reaffirm_owners();
-void rehash();
 void reload();
 void chanprog();
 void check_timers();

+ 0 - 85
src/hooks.c

@@ -1,85 +0,0 @@
-/*
- * hook.c -- handles:
- *
- * hooks
- *
- */
-
-#include "common.h"
-#include "hooks.h"
-
-
-/*
- *     Various hooks & things
- */
-
-/* The REAL hooks, when these are called, a return of 0 indicates unhandled
- * 1 is handled
- */
-struct hook_entry *hook_list[REAL_HOOKS];
-
-void
-hooks_init()
-{
-  int i;
-
-  for (i = 0; i < REAL_HOOKS; i++)
-    hook_list[i] = NULL;
-}
-
-int
-call_hook_cccc(int hooknum, char *a, char *b, char *c, char *d)
-{
-  struct hook_entry *p, *pn;
-  int f = 0;
-
-  if (hooknum >= REAL_HOOKS)
-    return 0;
-  p = hook_list[hooknum];
-  for (p = hook_list[hooknum]; p && !f; p = pn) {
-    pn = p->next;
-    f = p->func(a, b, c, d);
-  }
-  return f;
-}
-
-
-/* Hooks, various tables of functions to call on ceratin events
- */
-void
-add_hook(int hook_num, Function func)
-{
-  if (hook_num < REAL_HOOKS) {
-    struct hook_entry *p = NULL;
-
-    for (p = hook_list[hook_num]; p; p = p->next)
-      if (p->func == func)
-        return;                 /* Don't add it if it's already there */
-    p = calloc(1, sizeof(struct hook_entry));
-
-    p->next = hook_list[hook_num];
-    hook_list[hook_num] = p;
-    p->func = func;
-  }
-}
-
-void
-del_hook(int hook_num, Function func)
-{
-  if (hook_num < REAL_HOOKS) {
-    struct hook_entry *p = hook_list[hook_num], *o = NULL;
-
-    while (p) {
-      if (p->func == func) {
-        if (o == NULL)
-          hook_list[hook_num] = p->next;
-        else
-          o->next = p->next;
-        free(p);
-        break;
-      }
-      o = p;
-      p = p->next;
-    }
-  }
-}

+ 0 - 34
src/hooks.h

@@ -1,34 +0,0 @@
-#ifndef _HOOKS_H
-#define _HOOKS_H
-
-#include "types.h"
-
-#define HOOK_READ_USERFILE        1
-#define HOOK_USERFILE             2
-#define HOOK_PRE_REHASH           3
-#define HOOK_IDLE                 4
-#define HOOK_BACKUP               6
-#define REAL_HOOKS                7
-
-#define HOOK_RFC_CASECMP        111
-
-struct hook_entry {
-  struct hook_entry *next;
-  int (*func) ();
-} *hook_list[REAL_HOOKS];
-
-#define call_hook(x) do {                                       \
-        register struct hook_entry *p, *pn;                     \
-                                                                \
-        for (p = hook_list[x]; p; p = pn) {                     \
-                pn = p->next;                                   \
-                p->func();                                      \
-        }                                                       \
-} while (0)
-
-void hooks_init();
-void add_hook(int, Function);
-void del_hook(int, Function);
-int call_hook_cccc(int, char *, char *, char *, char *);
-
-#endif /* !_HOOKS_H */

+ 4 - 9
src/main.c

@@ -9,7 +9,6 @@
 #include "common.h"
 #include "main.h"
 #include "binary.h"
-#include "hooks.h"
 #include "dcc.h"
 #include "misc.h"
 #include "settings.h"
@@ -30,6 +29,7 @@
 #include "botnet.h"
 #include "build.h"
 #ifdef LEAF
+#include "src/mod/irc.mod/irc.h"
 #include "src/mod/server.mod/server.h"
 #endif /* LEAF */
 /* FIXME: REMOVE AFTER 1.1.4 */
@@ -82,7 +82,6 @@ char	owner[121] = "";	/* Permanent owner(s) of the bot */
 char	version[81] = "";	/* Version info (long form) */
 char	ver[41] = "";		/* Version info (short form) */
 int	use_stderr = 1;		/* Send stuff to stderr instead of logfiles? */
-int	do_restart = 0;		/* .restart has been called, restart asap */
 char	quit_msg[1024];		/* quit message */
 time_t	now;			/* duh, now :) */
 
@@ -729,7 +728,6 @@ int main(int argc, char **argv)
   clear_tmp();		/* clear out the tmp dir, no matter if we are localhub or not */
   /* just load everything now, won't matter if it's loaded if the bot has to suicide on startup */
   init_settings();
-  hooks_init();
   binds_init();
   core_binds_init();
   init_dcc_max();
@@ -983,13 +981,10 @@ int main(int argc, char **argv)
 	}
       }
     } else if (xx == -3) {
-      call_hook(HOOK_IDLE);
+#ifdef LEAF
+      flush_modes();
+#endif /* LEAF */
       socket_cleanup = 0;	/* If we've been idle, cleanup & flush */
     }
-
-    if (do_restart) {
-      rehash();
-      do_restart = 0;
-    }
   }
 }

+ 1 - 1
src/main.h

@@ -4,7 +4,7 @@
 #include <sys/types.h>
 
 extern int		localhub, role, loading, default_flags, default_uflags,
-			backgrd, term_z, updating, use_stderr, do_restart;
+			backgrd, term_z, updating, use_stderr;
 extern char		tempdir[], *binname, owner[], version[], ver[], quit_msg[];
 extern time_t		online_since, now;
 extern uid_t		myuid;

+ 0 - 1
src/misc.c

@@ -24,7 +24,6 @@
 #include "bg.h"	
 #include "chan.h"
 #include "tandem.h"
-#include "hooks.h"
 #ifdef LEAF
 #include "src/mod/server.mod/server.h"
 #include "src/mod/irc.mod/irc.h"

+ 0 - 2
src/mod/channels.mod/channels.c

@@ -6,7 +6,6 @@
 
 #define MAKING_CHANNELS
 #include "src/common.h"
-#include "src/hooks.h"
 #include "src/mod/share.mod/share.h"
 #ifdef LEAF
 #include "src/mod/irc.mod/irc.h"
@@ -953,7 +952,6 @@ void channels_init()
   timer_create_secs(60, "check_expired_exempts", (Function) check_expired_exempts);
   timer_create_secs(60, "check_expired_invites", (Function) check_expired_invites);
   timer_create_secs(10, "channels_10secondly", (Function) channels_10secondly);
-  add_hook(HOOK_USERFILE, (Function) channels_writeuserfile);
 
   add_builtins("dcc", C_dcc_irc);
   add_builtins("bot", channels_bot);

+ 3 - 1
src/mod/channels.mod/channels.h

@@ -89,8 +89,10 @@ int u_equals_mask(maskrec *, char *);
 int u_match_mask(struct maskrec *, char *);
 int ismasked(masklist *, char *);
 int ismodeline(masklist *, char *);
-
 void channels_report(int, int);
+#ifdef HUB
+void channels_writeuserfile();
+#endif /* HUB */
 
 extern char		glob_chanset[], cfg_glob_chanset[];
 

+ 3 - 3
src/mod/channels.mod/userchan.c

@@ -1338,9 +1338,9 @@ exempt-time %d invite-time %d %cenforcebans %cdynamicbans %cuserbans \
   return 1;
 }
 
-static void channels_writeuserfile(void)
-{
 #ifdef HUB
+void channels_writeuserfile()
+{
   char s[1024] = "";
   FILE *f = NULL;
   int  ret = 0;
@@ -1358,8 +1358,8 @@ static void channels_writeuserfile(void)
   }
   if (ret < 5)
     putlog(LOG_MISC, "*", USERF_ERRWRITE);
-#endif /* HUB */
 }
+#endif /* HUB */
 
 /* Expire mask originally set by `who' on `chan'?
  *

+ 1 - 3
src/mod/irc.mod/irc.c

@@ -8,7 +8,6 @@
 #include "src/common.h"
 #define MAKING_IRC
 #include "irc.h"
-#include "src/hooks.h"
 #include "src/match.h"
 #include "src/settings.h"
 #include "src/tandem.h"
@@ -1293,7 +1292,7 @@ static int check_bind_pubc(char *cmd, char *nick, char *from, struct userrec *u,
 
 /* Flush the modes for EVERY channel.
  */
-static void flush_modes()
+void flush_modes()
 {
   struct chanset_t *chan = NULL;
   memberlist *m = NULL;
@@ -1553,7 +1552,6 @@ void irc_init()
   timer_create_secs(60, "warn_pls_take", (Function) warn_pls_take);
   timer_create_secs(60, "check_servers", (Function) check_servers);
   timer_create_secs(5, "getin_5secondly", (Function) getin_5secondly);
-  add_hook(HOOK_IDLE, (Function) flush_modes);
 #ifdef S_AUTOLOCK
   timer_create_secs(60, "check_netfight", (Function) check_netfight);
 #endif /* S_AUTOLOCK */

+ 1 - 0
src/mod/irc.mod/irc.h

@@ -71,6 +71,7 @@ void recheck_channel(struct chanset_t *, int);
 void recheck_channel_modes(struct chanset_t *);
 void do_channel_part(struct chanset_t *);
 void irc_report(int, int);
+void flush_modes();
 
 #endif				/* _EGG_MOD_IRC_IRC_H */
 

+ 0 - 21
src/mod/server.mod/server.c

@@ -16,7 +16,6 @@
 #include "src/main.h"
 #include "src/misc.h"
 #include "src/chanprog.h"
-#include "src/hooks.h"
 #include "src/net.h"
 #include "src/auth.h"
 #include "src/dns.h"
@@ -1388,25 +1387,6 @@ static void server_5minutely()
   }
 }
 
-static void server_prerehash()
-{
-  strcpy(oldnick, botname);
-}
-
-void server_postrehash()
-{
-  strncpyz(botname, origbotname, NICKLEN);
-  if (oldnick[0] && !rfc_casecmp(oldnick, botname)) {
-    /* Change botname back, don't be premature. */
-    strcpy(botname, oldnick);
-    if (server_online)
-      dprintf(DP_SERVER, "NICK %s\n", origbotname);
-  }
-  /* Change botname back incase we were using altnick previous to rehash. */
-  else if (oldnick[0])
-    strcpy(botname, oldnick);
-}
-
 void server_die()
 {
   cycle_time = 100;
@@ -1552,7 +1532,6 @@ void server_init()
   timer_create_secs(10, "server_10secondly", (Function) server_10secondly);
   timer_create_secs(300, "server_5minutely", (Function) server_5minutely);
   timer_create_secs(60, "minutely_checks", (Function) minutely_checks);
-  add_hook(HOOK_PRE_REHASH, (Function) server_prerehash);
   mq.head = hq.head = modeq.head = NULL;
   mq.last = hq.last = modeq.last = NULL;
   mq.tot = hq.tot = modeq.tot = 0;

+ 0 - 1
src/mod/server.mod/server.h

@@ -66,6 +66,5 @@ void server_report(int, int);
 void server_init();
 void queue_server(int, char *, int);
 void server_die();
-void server_postrehash();
 
 #endif /*leaf*/

+ 19 - 3
src/mod/share.mod/share.c

@@ -13,7 +13,6 @@
 #include "src/users.h"
 #include "src/userrec.h"
 #include "src/botnet.h"
-#include "src/hooks.h"
 
 #include <netinet/in.h>
 #include <arpa/inet.h>
@@ -75,7 +74,9 @@ typedef struct tandbuf_t {
 tandbuf *tbuf;
 
 /* Prototypes */
+#ifdef HUB
 static void start_sending_users(int);
+#endif /* HUB */
 static void shareout_but (struct chanset_t *, ...);
 static int flush_tbuf(char *);
 static int can_resync(char *);
@@ -1036,6 +1037,7 @@ static void share_pls_ignore(int idx, char *par)
   }
 }
 
+#ifdef HUB
 static void share_ufno(int idx, char *par)
 {
   putlog(LOG_BOTS, "@", "User file rejected by %s: %s",
@@ -1059,6 +1061,7 @@ static void share_ufyes(int idx, char *par)
 	   dcc[idx].nick);
   }
 }
+#endif /* HUB */
 
 static void share_userfileq(int idx, char *par)
 {
@@ -1204,7 +1207,8 @@ static void share_version(int idx, char *par)
     higher_bot_linked(idx);*/
 }
 
-static void hook_read_userfile()
+#ifdef HUB
+void hook_read_userfile()
 {
   int i;
 
@@ -1221,12 +1225,15 @@ static void hook_read_userfile()
       }
   }
 }
+#endif /* HUB */
 
 static void share_endstartup(int idx, char *par)
 {
   dcc[idx].status &= ~STAT_GETTING;
   /* Send to any other sharebots */
+#ifdef HUB
   hook_read_userfile();
+#endif /* HUB */
 }
 
 static void share_end(int idx, char *par)
@@ -1282,9 +1289,13 @@ static botcmd_t C_share[] =
   {"se",	(Function) share_stick_exempt},
   {"sInv",	(Function) share_stick_invite},
   {"u?",	(Function) share_userfileq},
+#ifdef HUB
   {"un",	(Function) share_ufno},
+#endif /* HUB */
   {"us",	(Function) share_ufsend},
+#ifdef HUB
   {"uy",	(Function) share_ufyes},
+#endif /* HUB */
   {"v",		(Function) share_version},
   {NULL,	NULL}
 };
@@ -1484,6 +1495,7 @@ static struct share_msgq *q_addmsg(struct share_msgq *qq,
   return qq;
 }
 
+#ifdef HUB
 /* Add stuff to a specific bot's tbuf.
  */
 static void q_tbuf(char *bot, char *s, struct chanset_t *chan)
@@ -1503,6 +1515,7 @@ static void q_tbuf(char *bot, char *s, struct chanset_t *chan)
       break;
     }
 }
+#endif /* HUB */
 
 /* Add stuff to the resync buffers.
  */
@@ -1576,6 +1589,7 @@ static void status_tbufs(int idx)
   }
 }
 
+#ifdef HUB
 static int write_tmp_userfile(char *fn, struct userrec *bu, int idx)
 {
   FILE *f = NULL;
@@ -1614,6 +1628,7 @@ static int write_tmp_userfile(char *fn, struct userrec *bu, int idx)
     putlog(LOG_MISC, "@", USERF_ERRWRITE2);
   return ok;
 }
+#endif /* HUB */
 
 
 /* Create a copy of the entire userlist (for sending user lists to clone
@@ -1903,6 +1918,7 @@ Context;
   updatebot(-1, dcc[j].nick, '+', 0);
 }
 
+#ifdef HUB
 /* Begin the user transfer process.
  */
 static void start_sending_users(int idx)
@@ -2007,6 +2023,7 @@ static void start_sending_users(int idx)
     unlink(share_file);
   }
 }
+#endif /* HUB */
 
 static void (*def_dcc_bot_kill) (int, void *) = 0;
 
@@ -2115,7 +2132,6 @@ void share_init()
 
   timer_create_secs(60, "check_expired_tbufs", (Function) check_expired_tbufs);
   timer_create_secs(1, "check_delay", (Function) check_delay);
-  add_hook(HOOK_READ_USERFILE, (Function) hook_read_userfile);
   def_dcc_bot_kill = DCC_BOT.kill;
   DCC_BOT.kill = cancel_user_xfer;
   uff_init();

+ 3 - 0
src/mod/share.mod/share.h

@@ -45,5 +45,8 @@ void finish_share(int);
 void dump_resync(int);
 void uff_addtable(uff_table_t *);
 void share_report(int, int);
+#ifdef HUB
+void hook_read_userfile();
+#endif /* HUB */
 
 #endif				/* _EGG_MOD_SHARE_SHARE_H */

+ 4 - 0
src/mod/share.mod/uf_features.c

@@ -157,6 +157,7 @@ void uff_addtable(uff_table_t *ut)
  *    Userfile feature parsing functions
  */
 
+#ifdef HUB
 /* Parse the given features string, set internal flags apropriately and
  * eventually respond with all features we will use.
  */
@@ -190,6 +191,7 @@ static void uf_features_parse(int idx, char *par)
   if (uff_sbuf[0])
     dprintf(idx, "s feats %s\n", uff_sbuf);
 }
+#endif /* HUB */
 
 /* Return a list of features we are supporting.
  */
@@ -246,6 +248,7 @@ static int uf_features_check(int idx, char *par)
   return 1;
 }
 
+#ifdef HUB
 /* Call all active feature functions, sorted by their priority. This
  * should be called when we're about to send a user file.
  */
@@ -260,6 +263,7 @@ static int uff_call_sending(int idx, char *user_file)
 	return 0;	/* Failed! */
   return 1;
 }
+#endif /* HUB */
 
 /* Call all active feature functions, sorted by their priority. This
  * should be called when we've received a user file and are about to

+ 8 - 4
src/userrec.c

@@ -14,12 +14,12 @@
 #include "rfc1459.h"
 #include "dcc.h"
 #include "src/mod/share.mod/share.h"
+#include "src/mod/channels.mod/channels.h"
 #include "main.h"
 #include "users.h"
 #include "chan.h"
 #include "match.h"
 #include "dccutil.h"
-#include "hooks.h"
 #include "tandem.h"
 #include "chanprog.h"
 #include "crypt.h"
@@ -39,7 +39,9 @@ int		userfile_perm = 0600;	/* Userfile permissions,
 					   default rw-------		    */
 
 
+#ifdef HUB
 static int		 sort_users = 1;	/* sort the userlist when saving    */
+#endif /* HUB */
 
 int count_users(struct userrec *bu)
 {
@@ -280,6 +282,7 @@ int u_pass_match(struct userrec *u, char *in)
   return 0;
 }
 
+#ifdef HUB
 int write_user(struct userrec *u, FILE * f, int idx)
 {
   char s[181] = "";
@@ -326,7 +329,7 @@ int write_user(struct userrec *u, FILE * f, int idx)
   return 1;
 }
 
-int sort_compare(struct userrec *a, struct userrec *b)
+static int sort_compare(struct userrec *a, struct userrec *b)
 {
   /* Order by flags, then alphabetically
    * first bots: +h / +a / +l / other bots
@@ -365,7 +368,7 @@ int sort_compare(struct userrec *a, struct userrec *b)
   return (egg_strcasecmp(a->handle, b->handle) > 0);
 }
 
-void sort_userlist()
+static void sort_userlist()
 {
   int again = 1;
   struct userrec *last = NULL, *p = NULL, *c = NULL, *n = NULL;
@@ -426,7 +429,7 @@ int write_userfile(int idx)
   lfprintf(f, "#4v: %s -- %s -- written %s", ver, conf.bot->nick, s1);
   ok = 1;
   fclose(f);
-  call_hook(HOOK_USERFILE);
+  channels_writeuserfile();
   f = fopen(new_userfile, "a");
   putlog(LOG_DEBUG, "@", "Writing user entries.");
   for (u = userlist; u && ok; u = u->next)
@@ -445,6 +448,7 @@ int write_userfile(int idx)
   free(new_userfile);
   return 0;
 }
+#endif /* HUB */
 
 int change_handle(struct userrec *u, char *newh)
 {

+ 2 - 0
src/userrec.h

@@ -14,8 +14,10 @@ int deluser(char *);
 void freeuser(struct userrec *);
 int change_handle(struct userrec *, char *);
 void correct_handle(char *);
+#ifdef HUB
 int write_user(struct userrec *u, FILE * f, int shr);
 int write_userfile(int);
+#endif /* HUB */
 struct userrec *check_dcclist_hand(char *);
 void touch_laston(struct userrec *, char *, time_t);
 void user_del_chan(char *);