users.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 *);
  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_CONFIG, USERENTRY_SECPASS, USERENTRY_USERNAME, USERENTRY_NODENAME, USERENTRY_OS,
  42. USERENTRY_TMPPASS;
  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 set_user(struct user_entry_type *, struct userrec *, void *);
  82. #define is_bot(u) ((u) && (u)->bot)
  83. /* Fake users used to store ignores and bans
  84. */
  85. #define IGNORE_NAME "*ignore"
  86. #define BAN_NAME "*ban"
  87. #define EXEMPT_NAME "*exempt"
  88. #define INVITE_NAME "*Invite"
  89. #define CHANS_NAME "*channels"
  90. #define CONFIG_NAME "*Config"
  91. /* Channel-specific info
  92. */
  93. struct chanuserrec {
  94. struct chanuserrec *next;
  95. flag_t flags;
  96. time_t laston;
  97. char *info;
  98. char channel[81];
  99. };
  100. /* New-style userlist
  101. */
  102. struct userrec {
  103. struct user_entry *entries;
  104. struct chanuserrec *chanrec;
  105. struct userrec *next;
  106. flag_t flags;
  107. char handle[HANDLEN + 1];
  108. char bot;
  109. };
  110. struct igrec {
  111. struct igrec *next;
  112. time_t expire;
  113. time_t added;
  114. int flags;
  115. char *igmask;
  116. char *user;
  117. char *msg;
  118. };
  119. extern struct igrec *global_ign;
  120. #define IGREC_PERM 2
  121. /*
  122. * Note: Flags are in eggdrop.h
  123. */
  124. struct userrec *get_user_by_handle(struct userrec *, char *);
  125. struct userrec *get_user_by_host(char *);
  126. struct userrec *check_chanlist(const char *);
  127. struct userrec *check_chanlist_hand(const char *);
  128. /* All the default userentry stuff, for code re-use
  129. */
  130. bool def_unpack(struct userrec *u, struct user_entry *e);
  131. bool def_kill(struct user_entry *e);
  132. bool def_write_userfile(FILE *f, struct userrec *u, struct user_entry *e);
  133. void *def_get(struct userrec *u, struct user_entry *e);
  134. bool def_set(struct userrec *u, struct user_entry *e, void *buf);
  135. bool def_gotshare(struct userrec *u, struct user_entry *e, char *data, int idx);
  136. void def_display(int idx, struct user_entry *e, struct userrec *u);
  137. void backup_userfile();
  138. void addignore(char *, char *, const char *, time_t);
  139. int delignore(char *);
  140. void tell_ignores(int, char *);
  141. bool match_ignore(char *);
  142. void check_expired_ignores();
  143. void autolink_cycle(char *);
  144. void tell_file_stats(int, char *);
  145. void tell_user_ident(int, char *);
  146. void tell_users_match(int, char *, int, int, char *, int);
  147. int readuserfile(const char *, struct userrec **);
  148. void check_pmode();
  149. void link_pref_val(struct userrec *u, char *lval);
  150. extern char userfile[];
  151. extern time_t ignore_time;
  152. #endif /* _EGG_USERS_H */