1 /* 2 * users.h 3 * structures and definitions used by users.c and userrec.c 4 */ 5 /* 6 * Copyright (C) 1997 Robey Pointer 7 * Copyright (C) 1999 - 2021 Eggheads Development Team 8 * 9 * This program is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU General Public License 11 * as published by the Free Software Foundation; either version 2 12 * of the License, or (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 */ 23 24 #ifndef _EGG_USERS_H 25 #define _EGG_USERS_H 26 27 /* List functions :) , next *must* be the 1st item in the struct */ 28 struct list_type { 29 struct list_type *next; 30 char *extra; 31 }; 32 33 #define list_insert(a,b) { \ 34 (b)->next = *(a); \ 35 *(a) = (b); \ 36 } 37 int egg_list_append(struct list_type **, struct list_type *); 38 int egg_list_delete(struct list_type **, struct list_type *); 39 int egg_list_contains(struct list_type *, struct list_type *); 40 41 42 /* New userfile format stuff 43 */ 44 struct userrec; 45 struct user_entry; 46 struct user_entry_type { 47 struct user_entry_type *next; 48 int (*got_share) (struct userrec *, struct user_entry *, char *, int); 49 int (*dup_user) (struct userrec *, struct userrec *, struct user_entry *); 50 int (*unpack) (struct userrec *, struct user_entry *); 51 int (*pack) (struct userrec *, struct user_entry *); 52 int (*write_userfile) (FILE *, struct userrec *, struct user_entry *); 53 int (*kill) (struct user_entry *); 54 void *(*get) (struct userrec *, struct user_entry *); 55 int (*set) (struct userrec *, struct user_entry *, void *); 56 int (*tcl_get) (Tcl_Interp *, struct userrec *, struct user_entry *, 57 int, char **); 58 int (*tcl_set) (Tcl_Interp *, struct userrec *, struct user_entry *, 59 int, char **); 60 int (*expmem) (struct user_entry *); 61 void (*display) (int idx, struct user_entry *); 62 char *name; 63 int (*tcl_append) (Tcl_Interp *, struct userrec *, struct user_entry *); 64 }; 65 66 67 #ifndef MAKING_MODS 68 extern struct user_entry_type USERENTRY_COMMENT, USERENTRY_LASTON, 69 USERENTRY_XTRA, USERENTRY_INFO, USERENTRY_BOTADDR, USERENTRY_HOSTS, 70 USERENTRY_PASS, USERENTRY_PASS2, USERENTRY_BOTFL; 71 #ifdef TLS 72 extern struct user_entry_type USERENTRY_FPRINT; 73 #endif 74 #endif 75 76 77 struct laston_info { 78 time_t laston; 79 char *lastonplace; 80 }; 81 82 struct bot_addr { 83 int telnet_port; 84 int relay_port; 85 char *address; 86 #ifdef TLS 87 # define TLS_BOT 1 88 # define TLS_RELAY 2 89 int ssl; 90 #endif 91 }; 92 93 struct user_entry { 94 struct user_entry *next; 95 struct user_entry_type *type; 96 union { 97 char *string; 98 void *extra; 99 struct list_type *list; 100 unsigned long ulong; 101 } u; 102 char *name; 103 }; 104 105 struct xtra_key { 106 struct xtra_key *next; 107 char *key; 108 char *data; 109 }; 110 111 struct filesys_stats { 112 int uploads; 113 int upload_ks; 114 int dnloads; 115 int dnload_ks; 116 }; 117 118 void *_user_malloc(int size, const char *file, int line); 119 void *_user_realloc(void *ptr, int size, const char *file, int line); 120 121 #ifndef MAKING_MODS 122 # define user_malloc(x) _user_malloc(x, __FILE__, __LINE__) 123 # define user_realloc(x, y) _user_realloc(x, y, __FILE__, __LINE__) 124 #endif 125 126 int add_entry_type(struct user_entry_type *); 127 int del_entry_type(struct user_entry_type *); 128 struct user_entry_type *find_entry_type(char *); 129 struct user_entry *find_user_entry(struct user_entry_type *, struct userrec *); 130 void *get_user(struct user_entry_type *, struct userrec *); 131 int set_user(struct user_entry_type *, struct userrec *, void *); 132 133 #define bot_flags(u) ((long)get_user(&USERENTRY_BOTFL, (u))) 134 #define is_bot(u) ((u) && ((u)->flags & USER_BOT)) 135 #define is_owner(u) ((u) && ((u)->flags & USER_OWNER)) 136 137 /* Fake users used to store ignores and bans 138 */ 139 #define IGNORE_NAME "*ignore" 140 #define BAN_NAME "*ban" 141 #define EXEMPT_NAME "*exempt" 142 #define INVITE_NAME "*Invite" 143 144 /* Channel-specific info 145 */ 146 struct chanuserrec { 147 struct chanuserrec *next; 148 char channel[CHANNELLEN + 1]; 149 time_t laston; 150 unsigned long flags; 151 unsigned long flags_udef; 152 char *info; 153 }; 154 155 /* New-style userlist 156 */ 157 struct userrec { 158 struct userrec *next; 159 char handle[HANDLEN + 1]; 160 unsigned long flags; 161 unsigned long flags_udef; 162 struct chanuserrec *chanrec; 163 struct user_entry *entries; 164 }; 165 166 struct igrec { 167 struct igrec *next; 168 char *igmask; 169 time_t expire; 170 char *user; 171 time_t added; 172 char *msg; 173 int flags; 174 }; 175 extern struct igrec *global_ign; 176 177 #define IGREC_PERM 2 178 179 /* 180 * Note: Flags are in eggdrop.h 181 */ 182 183 struct userrec *adduser(); 184 struct userrec *get_user_by_handle(struct userrec *, char *); 185 struct userrec *get_user_by_host(char *); 186 struct userrec *get_user_by_nick(char *); 187 struct userrec *check_chanlist(); 188 struct userrec *check_chanlist_hand(); 189 190 /* All the default userentry stuff, for code re-use 191 */ 192 int def_unpack(struct userrec *u, struct user_entry *e); 193 int def_pack(struct userrec *u, struct user_entry *e); 194 int def_kill(struct user_entry *e); 195 int def_write_userfile(FILE *f, struct userrec *u, struct user_entry *e); 196 void *def_get(struct userrec *u, struct user_entry *e); 197 int def_set(struct userrec *u, struct user_entry *e, void *buf); 198 int def_gotshare(struct userrec *u, struct user_entry *e, char *data, int idx); 199 int def_tcl_get(Tcl_Interp *interp, struct userrec *u, 200 struct user_entry *e, int argc, char **argv); 201 int def_tcl_set(Tcl_Interp *irp, struct userrec *u, 202 struct user_entry *e, int argc, char **argv); 203 int def_expmem(struct user_entry *e); 204 void def_display(int idx, struct user_entry *e); 205 int def_dupuser(struct userrec *new, struct userrec *old, struct user_entry *e); 206 207 #endif /* _EGG_USERS_H */ 208