فهرست منبع

Simplify using xtra_key with a union rather than a cast

Bryan Drewery 8 سال پیش
والد
کامیت
169a5c6188
2فایلهای تغییر یافته به همراه13 افزوده شده و 12 حذف شده
  1. 6 6
      src/userent.cc
  2. 7 6
      src/users.h

+ 6 - 6
src/userent.cc

@@ -241,7 +241,7 @@ struct user_entry_type USERENTRY_ADDED = {
 
 static bool set_set(struct userrec *u, struct user_entry *e, void *buf)
 {
-  struct xtra_key *curr = (struct xtra_key *) e->u.extra, 
+  struct xtra_key *curr = e->u.xk,
                   *newxk = (struct xtra_key *) buf, *old = NULL;
 
   /* find the curr key if it exists */
@@ -284,7 +284,7 @@ static bool set_set(struct userrec *u, struct user_entry *e, void *buf)
 
   /* add the new entry if it's not empty */
   if ((!old || old != newxk) && newxk->data && newxk->data[0]) {
-    list_insert((struct xtra_key **) (&e->u.extra), newxk);
+    list_insert((&e->u.xk), newxk);
   } else {
     free(newxk->data);
     free(newxk->key);
@@ -310,7 +310,7 @@ static bool set_unpack(struct userrec *u, struct user_entry *e)
       t = (struct xtra_key *) calloc(1, sizeof(struct xtra_key));
       t->key = strdup(key);
       t->data = strdup(data);
-      list_insert((struct xtra_key **) (&e->u.extra), t);
+      list_insert((&e->u.xk), t);
     }
     curr = curr->next;
   }
@@ -322,7 +322,7 @@ static bool set_unpack(struct userrec *u, struct user_entry *e)
 static void set_display(int idx, struct user_entry *e, struct userrec *u)
 {
   if (conf.bot->hub) {
-    struct xtra_key *xk = (struct xtra_key *) e->u.extra;
+    struct xtra_key *xk = e->u.xk;
     struct flag_record fr = {FR_GLOBAL, 0, 0, 0 };
 
     dprintf(idx, "  BOTSET:\n");
@@ -357,7 +357,7 @@ static bool set_gotshare(struct userrec *u, struct user_entry *e, char *buf, int
 static void set_write_userfile(bd::Stream& stream, const struct userrec *u, const struct user_entry *e, int idx)
 {
   int localhub = nextbot(u->handle);
-  struct xtra_key *x = (struct xtra_key *) e->u.extra;
+  struct xtra_key *x = e->u.xk;
 
   for (; x; x = x->next) {
     /*
@@ -375,7 +375,7 @@ static void set_write_userfile(bd::Stream& stream, const struct userrec *u, cons
 
 static bool set_kill(struct user_entry *e)
 {
-  struct xtra_key *x = (struct xtra_key *) e->u.extra, *y = NULL;
+  struct xtra_key *x = e->u.xk, *y = NULL;
 
   for (; x; x = y) {
     y = x->next;

+ 7 - 6
src/users.h

@@ -66,24 +66,25 @@ struct bot_addr {
   in_port_t relay_port;
 };
 
+struct xtra_key {
+  struct xtra_key *next;
+  char *key;
+  char *data;
+};
+
 struct user_entry {
   struct user_entry *next;
   struct user_entry_type *type;
   union {
     char *string;
     void *extra;
+    struct xtra_key *xk;
     struct list_type *list;
     unsigned long ulong;
   } u;
   char *name;
 };
 
-struct xtra_key {
-  struct xtra_key *next;
-  char *key;
-  char *data;
-};
-
 struct filesys_stats {
   int uploads;
   int upload_ks;