users.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * users.h
  3. * structures and definitions used by users.c and userrec.c
  4. *
  5. */
  6. #ifndef _EGG_USERS_H
  7. #define _EGG_USERS_H
  8. #ifdef HAVE_CONFIG_H
  9. # include "config.h"
  10. #endif
  11. /* List functions :) , next *must* be the 1st item in the struct */
  12. struct list_type {
  13. struct list_type *next;
  14. char *extra;
  15. };
  16. #define list_insert(a,b) { \
  17. (b)->next = *(a); \
  18. *(a) = (b); \
  19. }
  20. static inline bool
  21. list_append(struct list_type **h, struct list_type *i)
  22. {
  23. for (; *h; h = &((*h)->next))
  24. ;
  25. *h = i;
  26. return 1;
  27. }
  28. static inline bool
  29. list_delete(struct list_type **h, struct list_type *i)
  30. {
  31. for (; *h; h = &((*h)->next))
  32. if (*h == i) {
  33. *h = i->next;
  34. return 1;
  35. }
  36. return 0;
  37. }
  38. static inline bool __attribute__((pure))
  39. list_contains(const struct list_type *h, const struct list_type *i)
  40. {
  41. for (; h; h = h->next)
  42. if (h == i) {
  43. return 1;
  44. }
  45. return 0;
  46. }
  47. namespace bd {
  48. class Stream;
  49. }
  50. /* New userfile format stuff
  51. */
  52. struct userrec;
  53. struct user_entry;
  54. struct user_entry_type {
  55. struct user_entry_type *next;
  56. bool (*got_share) (struct userrec *, struct user_entry *, char *, int);
  57. bool (*unpack) (struct userrec *, struct user_entry *);
  58. void (*write_userfile) (bd::Stream&, const struct userrec *, const struct user_entry *, int);
  59. bool (*kill) (struct user_entry *);
  60. void *(*get) (struct userrec *, struct user_entry *);
  61. bool (*set) (struct userrec *, struct user_entry *, void *);
  62. void (*display) (int idx, struct user_entry *, struct userrec *);
  63. const char *name;
  64. };
  65. extern struct user_entry_type USERENTRY_COMMENT, USERENTRY_LASTON,
  66. USERENTRY_INFO, USERENTRY_BOTADDR, USERENTRY_HOSTS,
  67. USERENTRY_PASS, USERENTRY_STATS, USERENTRY_ADDED, USERENTRY_MODIFIED,
  68. USERENTRY_SET, USERENTRY_SECPASS, USERENTRY_USERNAME, USERENTRY_NODENAME,
  69. USERENTRY_OS, USERENTRY_PASS1, USERENTRY_ARCH, USERENTRY_OSVER,
  70. USERENTRY_FFLAGS;
  71. struct laston_info {
  72. time_t laston;
  73. char *lastonplace;
  74. };
  75. struct bot_addr {
  76. char *address;
  77. char *uplink;
  78. unsigned short hublevel;
  79. in_port_t telnet_port;
  80. in_port_t relay_port;
  81. };
  82. struct xtra_key {
  83. struct xtra_key *next;
  84. char *key;
  85. char *data;
  86. };
  87. struct user_entry {
  88. struct user_entry *next;
  89. struct user_entry_type *type;
  90. union {
  91. char *string;
  92. void *extra;
  93. struct xtra_key *xk;
  94. struct list_type *list;
  95. unsigned long ulong;
  96. } u;
  97. char *name;
  98. };
  99. struct filesys_stats {
  100. int uploads;
  101. int upload_ks;
  102. int dnloads;
  103. int dnload_ks;
  104. };
  105. bool add_entry_type(struct user_entry_type *);
  106. struct user_entry_type *find_entry_type(const char *) __attribute__((pure));
  107. struct user_entry *find_user_entry(struct user_entry_type *, struct userrec *);
  108. void *get_user(struct user_entry_type *, struct userrec *);
  109. bool user_has_host(const char *, struct userrec *, char *);
  110. bool user_has_matching_host(const char *handle, struct userrec *u, char *host);
  111. bool set_user(struct user_entry_type *, struct userrec *, void *);
  112. #define is_bot(u) ((u) && (u)->bot)
  113. /* Fake users used to store ignores and bans
  114. */
  115. #define IGNORE_NAME "*ignore"
  116. #define BAN_NAME "*ban"
  117. #define EXEMPT_NAME "*exempt"
  118. #define INVITE_NAME "*Invite"
  119. #define CHANS_NAME "*channels"
  120. #define SET_NAME "*Set"
  121. /* Channel-specific info
  122. */
  123. struct chanuserrec {
  124. struct chanuserrec *next;
  125. flag_t flags;
  126. time_t laston;
  127. char *info;
  128. char channel[81];
  129. };
  130. /* New-style userlist
  131. */
  132. struct userrec {
  133. struct user_entry *entries;
  134. struct chanuserrec *chanrec;
  135. struct userrec *next;
  136. flag_t flags;
  137. int fflags;
  138. char handle[HANDLEN + 1];
  139. char bot;
  140. };
  141. struct igrec {
  142. struct igrec *next;
  143. time_t expire;
  144. time_t added;
  145. int flags;
  146. char *igmask;
  147. char *user;
  148. char *msg;
  149. };
  150. extern struct igrec *global_ign;
  151. #define IGREC_PERM 2
  152. /*
  153. * Note: Flags are in eggdrop.h
  154. */
  155. /* All the default userentry stuff, for code re-use
  156. */
  157. bool def_unpack(struct userrec *u, struct user_entry *e);
  158. bool def_kill(struct user_entry *e);
  159. bool def_write_userfile(FILE *f, struct userrec *u, struct user_entry *e);
  160. void *def_get(struct userrec *u, struct user_entry *e);
  161. bool def_set(struct userrec *u, struct user_entry *e, void *buf);
  162. bool def_gotshare(struct userrec *u, struct user_entry *e, char *data, int idx);
  163. void def_display(int idx, struct user_entry *e, struct userrec *u);
  164. void backup_userfile();
  165. void addignore(char *, char *, const char *, time_t);
  166. char *delignore(char *);
  167. void tell_ignores(int, char *);
  168. bool match_ignore(char *);
  169. void check_expired_ignores();
  170. void autolink_cycle();
  171. void tell_file_stats(int, char *);
  172. void tell_user_ident(int, char *);
  173. void tell_users_match(int, char *, int, int, char *, int);
  174. int readuserfile(const char *, struct userrec **);
  175. int stream_readuserfile(bd::Stream&, struct userrec **);
  176. void check_pmode();
  177. void link_pref_val(struct userrec *u, char *lval);
  178. void check_stale_dcc_users();
  179. extern char userfile[], autolink_failed[];
  180. extern interval_t ignore_time;
  181. extern bool dont_restructure;
  182. #endif /* _EGG_USERS_H */