Преглед на файлове

Merge branch 'master' into 39-dynamic-roles

* master:
  Obviously there is a member pointer here
  Use member_getuser here
  do_op: Just pass the member pointer
  Add ASSERT and WARN macros.
  makeset.sh: Allow empty lists
  Really fix 'make clean' in lib/
  lib/Makefile.in: fix make clean exit
Bryan Drewery преди 10 години
родител
ревизия
bc6e0b0c96
променени са 11 файла, в които са добавени 75 реда и са изтрити 27 реда
  1. 7 1
      build/makeset.sh
  2. 6 4
      lib/Makefile.in
  3. 21 0
      src/debug.cc
  4. 18 0
      src/debug.h
  5. 2 0
      src/main.cc
  6. 5 8
      src/mod/irc.mod/chan.cc
  7. 2 2
      src/mod/irc.mod/cmdsirc.cc
  8. 2 2
      src/mod/irc.mod/irc.cc
  9. 1 1
      src/mod/irc.mod/irc.h
  10. 5 7
      src/mod/irc.mod/mode.cc
  11. 6 2
      src/mod/irc.mod/msgcmds.cc

+ 7 - 1
build/makeset.sh

@@ -2,15 +2,21 @@
 
 echo "/* Generated by $0 */"
 needcomma=0
+printedtype=0
 while read -r line; do
 	[ -z "${line%%#*}" ] && continue # skip comments
+	# :type/:end
 	if [ -n "${line}" -a -z "${line%%:*}" ]; then
-		[ ${needcomma} -eq 1 ] && printf "\"\n\n"
+		# Close out the last type.
+		[ ${printedtype} -eq 1 ] && printf "%c\n\n" '"'
 		type="${line#:}"
 		[ "${type}" = "end" ] && break
 		printf "#define DEFAULT_%s \"%c\n" $(echo "${type}" | tr '[:lower:]' '[:upper:]') '\'
 		needcomma=0
+		printedtype=1
 	else
+	# entry
+		# Comma-separate the last entry.
 		[ ${needcomma} -eq 1 ] && printf ",%c\n" '\'
 		printf "%s" "${line}"
 		needcomma=1

+ 6 - 4
lib/Makefile.in

@@ -16,14 +16,16 @@ default: normal
 
 clean:
 	-+@cd bdlib && $(MAKE) clean
-	-+@[ -n "${LIBELF_BUNDLED}" ] && [ -f libelf/Makefile && \
-	    cd libelf && $(MAKE) clean
+	-+@if [ -n "${LIBELF_BUNDLED}" ] && [ -f libelf/Makefile ]; then \
+	    cd libelf && $(MAKE) clean; \
+	   fi
 	@rm -f *.a
 
 distclean: clean
 	-+@cd bdlib && $(MAKE) distclean
-	-+@[ -n "${LIBELF_BUNDLED}" ] && [ -f libelf/Makefile ] && \
-	    cd libelf && $(MAKE) distclean
+	-+@if [ -n "${LIBELF_BUNDLED}" ] && [ -f libelf/Makefile ]; then \
+	    cd libelf && $(MAKE) distclean; \
+	   fi
 
 notice:
 	@echo "[*] Making libraries"

+ 21 - 0
src/debug.cc

@@ -108,6 +108,27 @@ void sdprintf (const char *format, ...)
 #endif
 }
 
+void _assert(int recoverable, const char *file, int line, const char *function,
+    const char *exp, const char *format, ...)
+{
+    char msg[1024], buf[1024];
+    va_list va;
+
+    if (format != NULL) {
+      va_start(va, format);
+      egg_vsnprintf(msg, sizeof(msg), format, va);
+      va_end(va);
+    }
+
+    simple_snprintf(buf, sizeof(buf),
+        STR("Assertion failed%s: (%s:%d:%s) [%s]%s%s"),
+        recoverable == 0 ? "" : " (ignoring)",
+        file, line, function, exp,
+        format != NULL ? ": ": "",
+        format != NULL ? msg : "");
+    fatal(buf, recoverable);
+}
+
 static void write_debug(bool fatal = 1)
 {
   if (fatal) {

+ 18 - 0
src/debug.h

@@ -37,4 +37,22 @@ void setlimits();
 void sdprintf (const char *, ...) __attribute__((format(printf, 1, 2)));
 void init_signals();
 void init_debug();
+
+#ifdef DEBUG
+void _assert(int, const char *, int, const char *, const char *,
+    const char *, ...) __attribute__((format(printf, 6, 7)));
+#define _ASSERT(recoverable, cond, msg...) do { \
+  if (__predict_false(!(cond))) { \
+    _assert(recoverable, __FILE__, __LINE__, __func__, # cond, msg); \
+  } \
+  Context; \
+} while (0)
+#else
+#define _ASSERT(recoverable, cond, msg...) do { \
+} while (0)
+#endif
+#define ASSERT(cond, msg...) _ASSERT(0, cond, msg)
+#define ASSERT0(cond) ASSERT(cond, NULL)
+#define WARN(cond, msg...) _ASSERT(1, cond, msg)
+
 #endif /* !_DEBUG_H */

+ 2 - 0
src/main.cc

@@ -204,6 +204,8 @@ void fatal(const char *s, int recoverable)
 //    if (conf.bot && conf.bot->pid_file)
 //      unlink(conf.bot->pid_file);
     exit(1);
+  } else {
+    ContextNote(__func__, s);
   }
 }
 

+ 5 - 8
src/mod/irc.mod/chan.cc

@@ -1224,7 +1224,7 @@ static void check_this_member(struct chanset_t *chan, char *nick, struct flag_re
     /* if (target_priority(chan, m, 1)) */
       add_mode(chan, '-', 'o', m->nick);
   } else if (!chan_hasop(m) && (chan->role & ROLE_OP) && chk_autoop(m->user, *fr, chan)) {
-    do_op(m->nick, chan, 1, 0);
+    do_op(m, chan, 1, 0);
   }
   if (dovoice(chan)) {
     if (chan_hasvoice(m) && !chan_hasop(m)) {
@@ -2742,10 +2742,8 @@ static int gotjoin(char *from, char *chname)
 //	m->flags |= STOPWHO;
         irc_log(chan, "%s returned from netsplit", m->nick);
 
-
-        if (m && !m->user) {
-          m->user = get_user_by_host(from);
-          m->tried_getuser = 1;
+        if (!m->user) {
+          member_getuser(m);
  
           if (!m->user && !m->userip[0] && doresolv(chan)) {
             if (is_dotted_ip(host)) {
@@ -2769,8 +2767,7 @@ static int gotjoin(char *from, char *chname)
           strlcpy(m->userip, uhost, sizeof(m->userip));
           simple_snprintf(m->fromip, sizeof(m->fromip), "%s!%s", m->nick, m->userip);
         }
-        m->user = get_user_by_host(from);
-        m->tried_getuser = 1;
+        member_getuser(m);
 
         if (!m->userip[0] && doresolv(chan))
           resolve_to_member(chan, nick, host);
@@ -2891,7 +2888,7 @@ static int gotjoin(char *from, char *chname)
           if (!chan_hasop(m) && 
                (op || 
                ((chan->role & ROLE_OP) && chk_autoop(m->user, fr, chan)))) {
-            do_op(m->nick, chan, 1, 0);
+            do_op(m, chan, 1, 0);
           }
 
           /* +v or +voice */

+ 2 - 2
src/mod/irc.mod/cmdsirc.cc

@@ -543,7 +543,7 @@ static void cmd_op(int idx, char *par)
     return;
   }
 
-  if (do_op(nick, chan, 0, 1)) {
+  if (do_op(m, chan, 0, 1)) {
     dprintf(idx, "Gave op to %s on %s.\n", nick, chan->dname);
     stats_add(u, 0, 1);
   }
@@ -1235,7 +1235,7 @@ static void cmd_mop(int idx, char *par)
         if (!chan_hasop(m) && !glob_bot(victim) && chk_op(victim, chan)) {
           found = 1;
           dprintf(idx, "Gave op to '%s' as '%s' on %s\n", m->user->handle, m->nick, chan->dname);
-          do_op(m->nick, chan, 0, 0);
+          do_op(m, chan, 0, 0);
         }
       }
     } else {

+ 2 - 2
src/mod/irc.mod/irc.cc

@@ -784,7 +784,7 @@ getin_request(char *botnick, char *code, char *par)
       else
         chan->channel.no_op = 0;
     }
-    do_op(nick, chan, 0, 1);
+    do_op(mem, chan, 0, 1);
 
     putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - Opped", botnick, nick, chan->dname);
   } else if (what[0] == 'i') {
@@ -1694,7 +1694,7 @@ flush_modes()
         m->flags &= ~FULL_DELAY;
         if (chan_sentop(m)) {
           m->flags &= ~SENTOP;
-          do_op(m->nick, chan, 0, 0);
+          do_op(m, chan, 0, 0);
         }
         if (chan_sentvoice(m)) {
           m->flags &= ~SENTVOICE;

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

@@ -86,7 +86,7 @@ static void rebalance_roles_chan(struct chanset_t* chan);
 
 static int detect_offense(memberlist*, struct chanset_t *, char *);
 /* static int target_priority(struct chanset_t *, memberlist *, int); */
-static bool do_op(char *, struct chanset_t *, bool, bool);
+static bool do_op(memberlist *, struct chanset_t *, bool, bool);
 static void request_op(struct chanset_t *);
 static void request_in(struct chanset_t *);
 static bool detect_chan_flood(memberlist *m, const char* from, struct chanset_t *chan, flood_t which, const char *msg = NULL);

+ 5 - 7
src/mod/irc.mod/mode.cc

@@ -93,10 +93,8 @@ static size_t egg_strcatn(char *dst, const char *src, size_t max)
 }
 
 static bool
-do_op(char *nick, struct chanset_t *chan, bool delay, bool force)
+do_op(memberlist *m, struct chanset_t *chan, bool delay, bool force)
 {
-  memberlist *m = ismember(chan, nick);
-
   if (!me_op(chan) || !m || (!force && (chan_hasop(m) || chan_sentop(m))))
     return 0;
 
@@ -106,9 +104,9 @@ do_op(char *nick, struct chanset_t *chan, bool delay, bool force)
   }
 
   if (channel_fastop(chan) || channel_take(chan) || cookies_disabled) {
-    add_mode(chan, '+', 'o', nick);
+    add_mode(chan, '+', 'o', m->nick);
   } else if (!connect_bursting) {
-    add_cookie(chan, nick);
+    add_cookie(chan, m->nick);
   }
   return 1;
 }
@@ -682,7 +680,7 @@ got_deop(struct chanset_t *chan, memberlist *m, memberlist *mv, char *isserver)
         )
        ) {
       /* Then we'll bless the victim */
-      do_op(mv->nick, chan, 0, 0);
+      do_op(mv, chan, 0, 0);
     }
   }
 
@@ -1298,7 +1296,7 @@ gotmode(char *from, char *msg)
         } else if (!chan_hasop(m) && !channel_nodesynch(chan)) {
           if (u && u->bot && chk_op(user, chan)) {
             putlog(LOG_MODES, ch, "Mode change by friendly non-chanop on %s!  Opping...", ch);
-            do_op(m->nick, chan, 0, 0);
+            do_op(m, chan, 0, 0);
           } else {
             putlog(LOG_MODES, ch, "Mode change by non-chanop on %s!  Reversing...", ch);
             dprintf(DP_MODE, "KICK %s %s :%sAbusing desync\n", ch, m->nick, kickprefix);

+ 6 - 2
src/mod/irc.mod/msgcmds.cc

@@ -157,12 +157,15 @@ static int msg_op(char *nick, char *host, struct userrec *u, char *par)
 
   if (u_pass_match(u, pass)) {
     if (!u_pass_match(u, "-")) {
+      memberlist *m = NULL;
+
       if (par[0]) {
         chan = findchan_by_dname(par);
         if (chan && channel_active(chan)) {
+          m = ismember(chan, nick);
           get_user_flagrec(u, &fr, par, chan);
           if (chk_op(fr, chan)) {
-            if (do_op(nick, chan, 0, 1)) {
+            if (do_op(m, chan, 0, 1)) {
               stats_add(u, 0, 1);
               putlog(LOG_CMDS, "*", "(%s!%s) !%s! OP %s", nick, host, u->handle, par);
               if (manop_warn && chan->manop) {
@@ -176,9 +179,10 @@ static int msg_op(char *nick, char *host, struct userrec *u, char *par)
       } else {
         int stats = 0;
         for (chan = chanset; chan; chan = chan->next) {
+          m = ismember(chan, nick);
           get_user_flagrec(u, &fr, chan->dname, chan);
           if (chk_op(fr, chan)) {
-            if (do_op(nick, chan, 0, 1)) {
+            if (do_op(m, chan, 0, 1)) {
               stats++;
               if (manop_warn && chan->manop) {
                 msg = bd::String::printf("%s is currently set to punish for manual op.", chan->dname);