users.h 4.8 KB

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