users.h 4.7 KB

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