users.h 4.5 KB

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