Sfoglia il codice sorgente

Add more pure functions

Bryan Drewery 7 anni fa
parent
commit
ba46d5c58f

+ 10 - 5
src/adns.cc

@@ -169,7 +169,7 @@ static int read_resolv(char *fname);
 static void read_hosts(char *fname);
 static int get_dns_idx();
 //static void dns_resend_queries();
-static int cache_find(const char *);
+static int cache_find(const char *) __attribute__((pure));
 //static int dns_on_read(void *client_data, int idx, char *buf, int len);
 //static int dns_on_eof(void *client_data, int idx, int err, const char *errmsg);
 static void dns_read(int idx, char*, int&, bool blocking = 0);
@@ -418,7 +418,9 @@ static void egg_dns_send(char *query, int len, bool blocking)
 //	sockbuf_write(dns_idx, query, len);
 }
 
-dns_query_t *find_query(const char *host)
+static dns_query_t *
+__attribute__((pure))
+find_query(const char *host)
 {
 	dns_query_t *q = NULL;
 
@@ -892,7 +894,8 @@ static void cache_add(const char *query, bd::Array<bd::String> answer, int ttl)
 	ncache++;
 }
 
-static int cache_find(const char *query)
+static int
+cache_find(const char *query)
 {
 	int i;
 
@@ -1053,10 +1056,12 @@ int egg_dns_cancel(int id, int issue_callback)
 	return(0);
 }
 
-static int skip_name(unsigned char *ptr)
+static int
+__attribute__((pure))
+skip_name(const unsigned char *ptr)
 {
 	int len;
-	unsigned char *start = ptr;
+	const unsigned char *start = ptr;
 
 	while ((len = *ptr++) > 0) {
 		if (len > 63) {

+ 6 - 2
src/binds.cc

@@ -156,7 +156,8 @@ static void bind_table_really_del(bind_table_t *table)
 	free(table);
 }
 
-bind_table_t *bind_table_lookup(const char *name)
+bind_table_t *
+bind_table_lookup(const char *name)
 {
 	bind_table_t *table = NULL;
 
@@ -177,7 +178,10 @@ bind_table_t *bind_table_lookup_or_fake(const char *name)
 
 
 /* Look up a bind entry based on either function name or id. */
-static bind_entry_t *bind_entry_lookup(bind_table_t *table, int id, const char *mask, const char *function_name, Function callback)
+static bind_entry_t *
+__attribute__((pure))
+bind_entry_lookup(bind_table_t *table, int id, const char *mask,
+		const char *function_name, Function callback)
 {
 	bind_entry_t *entry = NULL;
 	int hit;

+ 1 - 1
src/binds.h

@@ -71,7 +71,7 @@ int check_bind_hits(bind_table_t *table, const char *match, struct flag_record *
 
 bind_table_t *bind_table_add(const char *name, int nargs, const char *syntax, int match_type, int flags);
 void bind_table_del(bind_table_t *table);
-bind_table_t *bind_table_lookup(const char *name);
+bind_table_t *bind_table_lookup(const char *name) __attribute__((pure));
 bind_table_t *bind_table_lookup_or_fake(const char *name);
 //int bind_entry_add(bind_table_t *table, const char *flags, const char *mask, const char *function_name, int bind_flags, Function callback, void *client_data);
 //int bind_entry_del(bind_table_t *table, int id, const char *mask, const char *function_name, Function callback);

+ 1 - 1
src/enclink.h

@@ -40,7 +40,7 @@ struct enc_link_dcc {
 extern struct enc_link enclink[];
 
 
-extern int link_find_by_type(int);
+extern int link_find_by_type(int) __attribute__((pure));
 
 extern void link_link(int, int, int, direction_t);
 extern const char *link_write(int, const char *, size_t *);

+ 4 - 2
src/mod/channels.mod/channels.cc

@@ -577,7 +577,8 @@ static void get_mode_protect(struct chanset_t *chan, char *s, size_t ssiz)
 
 /* Returns true if this is one of the channel masks
  */
-bool ismodeline(masklist *m, const char *username)
+bool
+ismodeline(const masklist *m, const char *username)
 {
   for (; m && m->mask[0]; m = m->next)  
     if (!rfc_casecmp(m->mask, username))
@@ -587,7 +588,8 @@ bool ismodeline(masklist *m, const char *username)
 
 /* Returns true if user matches one of the masklist -- drummer
  */
-bool ismasked(masklist *m, const char *username)
+bool
+ismasked(const masklist *m, const char *username)
 {
   for (; m && m->mask[0]; m = m->next)
     if (wild_match(m->mask, (char *) username))

+ 5 - 5
src/mod/channels.mod/channels.h

@@ -46,16 +46,16 @@ bool expired_mask(struct chanset_t *, char *);
 void set_handle_laston(char *, struct userrec *, time_t);
 int u_delmask(char type, struct chanset_t *c, char *who, int doit);
 bool u_addmask(char type, struct chanset_t *, char *, const char *, const char *, time_t, int);
-int u_sticky_mask(maskrec *, char *);
+int u_sticky_mask(const maskrec *, const char *) __attribute__((pure));
 int u_setsticky_mask(struct chanset_t *, maskrec *, char *, int, const char);
 int SplitList(char *, const char *, int *, const char ***);
 int channel_modify(char *, struct chanset_t *, int, char **, bool);
 int channel_add(char *, const char *, char *, bool = 0);
 void clear_channel(struct chanset_t *, bool);
-int u_equals_mask(maskrec *, char *);
-bool u_match_mask(struct maskrec *, const char *);
-bool ismasked(masklist *, const char *);
-bool ismodeline(masklist *, const char *);
+int u_equals_mask(const maskrec *, const char *) __attribute__((pure));
+bool u_match_mask(const maskrec *, const char *) __attribute__((pure));
+bool ismasked(const masklist *, const char *) __attribute__((pure));
+bool ismodeline(const masklist *, const char *) __attribute__((pure));
 void channels_report(int, int);
 void channels_writeuserfile(bd::Stream&, int = 0);
 void rcmd_chans(char *, char *, char *);

+ 12 - 4
src/mod/channels.mod/userchan.cc

@@ -152,7 +152,9 @@ void set_handle_laston(char *chan, struct userrec *u, time_t n)
 
 /* Is this mask sticky?
  */
-int u_sticky_mask(maskrec *u, char *uhost)
+int
+__attribute__((pure))
+u_sticky_mask(const maskrec *u, const char *uhost)
 {
   for (; u; u = u->next)
     if (!rfc_casecmp(u->mask, uhost))
@@ -205,7 +207,9 @@ int u_setsticky_mask(struct chanset_t *chan, maskrec *u, char *uhost, int sticky
  *   1       temporary ban
  *   2       perm ban
  */
-int u_equals_mask(maskrec *u, char *mask)
+int
+__attribute__((pure))
+u_equals_mask(const maskrec *u, const char *mask)
 {
   for (; u; u = u->next)
     if (!rfc_casecmp(u->mask, mask)) {
@@ -217,7 +221,9 @@ int u_equals_mask(maskrec *u, char *mask)
   return 0;
 }
 
-bool u_match_mask(maskrec *rec, const char *mask)
+bool
+__attribute__((pure))
+u_match_mask(const maskrec *rec, const char *mask)
 {
   for (; rec; rec = rec->next)
     if (wild_match(rec->mask, mask) || match_cidr(rec->mask, mask))
@@ -225,7 +231,9 @@ bool u_match_mask(maskrec *rec, const char *mask)
   return 0;
 }
 
-static int count_mask(maskrec *rec)
+static int
+__attribute__((pure))
+count_mask(maskrec *rec)
 {
   int ret = 0;
 

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

@@ -1250,6 +1250,7 @@ me_voice(const struct chanset_t *chan)
 /* Check if there are any ops on the channel. Returns boolean 1 or 0.
  */
 static bool
+__attribute__((pure))
 any_ops(struct chanset_t *chan)
 {
   memberlist *x = NULL;

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

@@ -71,7 +71,6 @@ static void cache_invite(struct chanset_t *, char *, char *, char *, bool, bool)
 void makecookie(char*, size_t, const char *, const memberlist*, const memberlist*, const memberlist* = NULL, const memberlist* = NULL);
 static int checkcookie(const char*, const memberlist*, const memberlist*, const char*, int);
 extern void counter_clear(const char*);
-static bool any_ops(struct chanset_t *);
 static char *getchanmode(struct chanset_t *);
 static void flush_mode(struct chanset_t *, int);
 static bool member_getuser(memberlist* m, bool act_on_lookup = 0);

+ 9 - 4
src/mod/server.mod/server.cc

@@ -171,7 +171,9 @@ static const struct {
 /*
  *     Bot server queues
  */
-static bool burst_mode_ok(const char *msg, size_t len) {
+static bool
+__attribute__((pure))
+burst_mode_ok(const char *msg, size_t len) {
   const bd::String mode(msg, len);
   const auto list(mode.split(' '));
   if (list.length() == 2) return 1;
@@ -205,7 +207,9 @@ static bool burst_mode_ok(const char *msg, size_t len) {
      WHO #Chan
      WHO NICK
 */
-static bool burst_ok(const char* msg, size_t len) {
+static inline bool
+__attribute__((pure))
+burst_ok(const char* msg, size_t len) {
   if (strstr(msg, "JOIN 0") ||
       (strstr(msg, "MODE") && !burst_mode_ok(msg, len)) ||
       strstr(msg, "NICK") ||
@@ -215,7 +219,6 @@ static bool burst_ok(const char* msg, size_t len) {
       strstr(msg, "KICK") ||
       strstr(msg, "INVITE") ||
       strstr(msg, "AWAY")) {
-    sdprintf("BURST MODE VIOLATION!!!: %s\n", msg);
     return 0;
   }
   return 1;
@@ -645,8 +648,10 @@ void queue_server(int which, char *buf, int len)
 
   // If connect bursting, hold off any commands which would end the gracetime (flood_endgrace)
   if (connect_bursting && (which == DP_MODE || which == DP_MODE_NEXT || which == DP_SERVER || which == DP_SERVER_NEXT)) {
-    if (!burst_ok(buf, len))
+    if (!burst_ok(buf, len)) {
+      sdprintf("BURST MODE VIOLATION!!!: %s\n", buf);
       which = DP_HELP;
+    }
   }
 
   int qnext = 0;

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

@@ -74,7 +74,7 @@ void release_nick(const char* = NULL);
 #define check_bind_ctcp(a, b, c, d, e, f) check_bind_ctcpr(a, b, c, d, e, f, BT_ctcp)
 #define check_bind_ctcr(a, b, c, d, e, f) check_bind_ctcpr(a, b, c, d, e, f, BT_ctcr)
 
-bool detect_avalanche(char *);
+bool detect_avalanche(const char *) __attribute__((pure));
 void server_report(int, int);
 void server_init();
 void queue_server(int, char *, int);

+ 3 - 2
src/mod/server.mod/servmsg.cc

@@ -618,11 +618,12 @@ static bool detect_flood(char *floodnick, char *floodhost, char *from, int which
 /* Check for more than 8 control characters in a line.
  * This could indicate: beep flood CTCP avalanche.
  */
-bool detect_avalanche(char *msg)
+bool
+detect_avalanche(const char *msg)
 {
   int count = 0;
 
-  for (unsigned char *p = (unsigned char *) msg; (*p) && (count < 8); p++)
+  for (const unsigned char *p = (const unsigned char *) msg; (*p) && (count < 8); p++)
     if ((*p == 7) || (*p == 1))
       count++;
   if (count >= 8)

+ 7 - 4
src/set.cc

@@ -143,7 +143,7 @@ static variable_t vars[] = {
 };
 
 
-static inline variable_t *var_get_var_by_name(const char *name);
+static inline variable_t *var_get_var_by_name(const char *name) __attribute__((pure));
 
 static const char* get_server_type()
 {
@@ -525,7 +525,7 @@ static int comp_variable_t(const void *m1, const void *m2) {
   return strcasecmp(mi1->name, mi2->name);
 }
 
-static inline variable_t * __attribute__((pure))
+static inline variable_t *
 var_get_var_by_name(const char *name)
 {
   variable_t key;
@@ -533,7 +533,7 @@ var_get_var_by_name(const char *name)
   return (variable_t*) bsearch(&key, &vars, lengthof(vars) - 1, sizeof(variable_t), comp_variable_t);
 }
 
-const char * __attribute__((pure))
+const char *
 var_get_gdata(const char *name) {
   variable_t* var = var_get_var_by_name(name);
   return var && var->gdata ? var->gdata : NULL;
@@ -673,7 +673,9 @@ const char *var_get_str_by_name(const char *name)
   return NULL;
 }
 
-void *var_get_by_name(const char *name)
+#if 0
+void *
+var_get_by_name(const char *name)
 {
   variable_t *var = NULL;
 
@@ -682,6 +684,7 @@ void *var_get_by_name(const char *name)
 
   return NULL;
 }
+#endif
 
 void init_vars()
 {

+ 3 - 1
src/userent.cc

@@ -107,7 +107,9 @@ void def_write_userfile(bd::Stream& stream, const struct userrec *u, const struc
   stream << bd::String::printf("--%s %s\n", e->type->name, e->u.string);
 }
 
-void *def_get(struct userrec *u, struct user_entry *e)
+void *
+__attribute__((pure))
+def_get(struct userrec *u, struct user_entry *e)
 {
   return e->u.string;
 }

+ 7 - 4
src/userrec.cc

@@ -70,16 +70,19 @@ int		userfile_perm = 0600;	/* Userfile permissions,
 
 static bool		 sort_users = 1;	/* sort the userlist when saving    */
 
-int count_users(struct userrec *bu)
+int
+count_users(const struct userrec *bu)
 {
   int tot = 0;
 
-  for (struct userrec *u = bu; u; u = u->next)
+  for (const struct userrec *u = bu; u; u = u->next)
     tot++;
   return tot;
 }
 
-static struct userrec *check_dcclist_hand(const char *handle)
+static struct userrec *
+__attribute__((pure))
+check_dcclist_hand(const char *handle)
 {
   for (int i = 0; i < dcc_total; i++)
     if (dcc[i].type && !strcasecmp(dcc[i].nick, handle))
@@ -87,7 +90,7 @@ static struct userrec *check_dcclist_hand(const char *handle)
   return NULL;
 }
 
-struct userrec *host_conflicts(char *host)
+struct userrec *host_conflicts(const char *host)
 {
   struct userrec *u = NULL;
   struct list_type *q = NULL;

+ 2 - 2
src/userrec.h

@@ -13,7 +13,7 @@ void cache_users();
 void clear_userlist(struct userrec *);
 int u_pass_match(struct userrec *, const char *);
 int delhost_by_handle(char *, char *);
-int count_users(struct userrec *);
+int count_users(const struct userrec *) __attribute__((pure));
 int deluser(char *);
 int change_handle(struct userrec *, char *);
 void correct_handle(char *);
@@ -22,7 +22,7 @@ int real_write_userfile(int);
 int write_userfile(int);
 void touch_laston(struct userrec *, char *, time_t);
 void user_del_chan(char *);
-struct userrec *host_conflicts(char *);
+struct userrec *host_conflicts(const char *);
 struct userrec *get_user_by_handle(struct userrec *, const char *);
 struct userrec *get_user_by_host(char *);
 

+ 2 - 1
src/users.cc

@@ -62,7 +62,8 @@ interval_t ignore_time = 10;		/* how many minutes will ignores last? */
 bool	dont_restructure = 0;		/* set when we botlink() to a hub with +U, only stops bot from restructuring */
 
 /* is this nick!user@host being ignored? */
-bool match_ignore(char *uhost)
+bool
+match_ignore(const char *uhost)
 {
   for (struct igrec *ir = global_ign; ir; ir = ir->next)
     if (wild_match(ir->igmask, uhost))

+ 2 - 2
src/users.h

@@ -182,7 +182,7 @@ extern struct igrec *global_ign;
 bool def_unpack(struct userrec *u, struct user_entry *e);
 bool def_kill(struct user_entry *e);
 bool def_write_userfile(FILE *f, struct userrec *u, struct user_entry *e);
-void *def_get(struct userrec *u, struct user_entry *e);
+void *def_get(struct userrec *u, struct user_entry *e) __attribute__((pure));
 bool def_set(struct userrec *u, struct user_entry *e, void *buf);
 bool def_gotshare(struct userrec *u, struct user_entry *e, char *data, int idx);
 void def_display(int idx, struct user_entry *e, struct userrec *u);
@@ -192,7 +192,7 @@ void backup_userfile();
 void addignore(char *, char *, const char *, time_t);
 char *delignore(char *);
 void tell_ignores(int, char *);
-bool match_ignore(char *);
+bool match_ignore(const char *) __attribute__((pure));
 void check_expired_ignores();
 void autolink_cycle();
 void tell_file_stats(int, char *);