struct.h (7604B)
1 /* 2 * src/struct.h from hirc 3 * 4 * Copyright (c) 2021-2022 hhvn <dev@hhvn.uk> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 * 18 */ 19 20 #ifndef H_STRUCT 21 #define H_STRUCT 22 23 #include <time.h> 24 #include <sys/time.h> 25 #include <poll.h> 26 27 struct Nick { 28 struct Nick *prev; 29 char priv; /* [~&@%+ ] */ 30 char *prefix; 31 char *nick; 32 char *ident; 33 char *host; 34 int self; 35 struct Nick *next; 36 }; 37 38 enum Activity { 39 /* There used to be an Activity_ignore = 0, but it served no purpose */ 40 Activity_none = 1, 41 Activity_self = Activity_none, 42 Activity_status = 2, 43 Activity_notice = Activity_status, 44 Activity_error = 3, 45 Activity_message = 4, 46 Activity_hilight = 5, 47 Activity_last = 6 48 }; 49 50 enum HistOpt { 51 /* H - options signal hist functions to perform different actions 52 * C - options are checked later to be handled in different ways 53 * R - options which are read from logs (in HIST_LOGACCEPT) */ 54 HIST_SHOW = 1, /* [CR] show in buffer */ 55 HIST_LOG = 2, /* [H] log to log.dir */ 56 HIST_MAIN = 4, /* [H] copy to &main_buf */ 57 HIST_SELF = 8, /* [H] from = self */ 58 HIST_TMP = 16, /* [C] purge later */ 59 HIST_GREP = 32, /* [C] generated by /grep */ 60 HIST_ERR = 64, /* [CR] generated by ui_error and friends */ 61 HIST_SERR = 128, /* [CR] generated by 400-599 numerics (which should be errors) */ 62 HIST_RLOG = 256, /* [C] messages read from log, useful for clearing the log */ 63 HIST_IGN = 512, /* [CR] added to ignored messages */ 64 HIST_NIGN = 1024,/* [H] immune to ignoring (SELF_IGNORES_LIST & SELF_ERROR) */ 65 HIST_DFL = HIST_SHOW|HIST_LOG, 66 HIST_UI = HIST_SHOW|HIST_TMP|HIST_MAIN, 67 HIST_LOGACCEPT = HIST_SHOW|HIST_ERR|HIST_SERR|HIST_IGN, 68 HIST_ALL = 0xFFFF 69 }; 70 71 struct History { 72 struct History *prev; 73 time_t timestamp; 74 enum Activity activity; 75 enum HistOpt options; 76 char *raw; 77 char **_params; /* contains all params, free from here */ 78 char **params; /* contains params without perfix, don't free */ 79 char *format; /* cached format */ 80 char *rformat; /* cached format without mirc codes */ 81 struct HistInfo *origin; 82 struct Nick *from; 83 struct History *next; 84 }; 85 86 struct HistInfo { 87 enum Activity activity; 88 int unread; 89 int ignored; 90 struct Server *server; 91 struct Channel *channel; 92 struct History *history; 93 }; 94 95 struct Channel { 96 struct Channel *prev; 97 int old; /* are we actually in this channel, 98 or just keeping it for memory */ 99 char *name; 100 char *mode; 101 char *topic; 102 int query; 103 struct Nick *nicks; 104 struct HistInfo *history; 105 struct Server *server; 106 struct Channel *next; 107 }; 108 109 enum ConnStatus { 110 ConnStatus_notconnected, 111 ConnStatus_connecting, 112 ConnStatus_connected, 113 ConnStatus_file, 114 }; 115 116 struct Support { 117 struct Support *prev; 118 char *key; 119 char *value; 120 struct Support *next; 121 }; 122 123 enum Expect { 124 /* 125 * The expect system is how a command or handler is able to change the 126 * actions performed by subsequent handlers (without changing 127 * server/chan/nick structs with I prefer to primarily track data, not 128 * actions). 129 * 130 * Each element in the expect array (contained in every server struct) 131 * can be set to either NULL or an arbitrary string (usually a channel 132 * name), as such they aren't really standard - the best way to know 133 * what each does is to grep through the source. 134 * 135 * I think this system works pretty well considering its simplicity. 136 * Alternatively handlers could look back in history - this would 137 * likely be much more robust, whilst being much less effecient as a 138 * handler needs to perform extra logic rather than looking up a 139 * string. There could also be some system utilizing callbacks that 140 * performs logic itself, rather than having handlers perform logic 141 * with the return value of expect_get: this may be more elegant and 142 * "proper", but it seems needlessly complicated to me. 143 * 144 */ 145 Expect_join, 146 Expect_part, 147 Expect_pong, 148 Expect_names, 149 Expect_topic, 150 Expect_topicwhotime, 151 Expect_channelmodeis, 152 Expect_nicknameinuse, 153 Expect_nosuchnick, /* currently set by commands that send MODE 154 and subsequently unset by handle_mode */ 155 Expect_last, 156 }; 157 158 enum Sched { 159 Sched_now, 160 Sched_connected, /* when 001, or end of motd is received */ 161 }; 162 163 struct Schedule { 164 struct Schedule *prev; 165 enum Sched when; 166 char *msg; 167 struct Schedule *next; 168 }; 169 170 struct Server { 171 struct Server *prev; 172 int wfd; 173 int rfd; 174 struct { 175 char *buf; 176 size_t size; 177 size_t pos; 178 } input; 179 struct pollfd *rpollfd; 180 enum ConnStatus status; 181 char *name; 182 char *username; 183 char *realname; 184 char *password; 185 char *host; 186 char *port; 187 struct Support *supports; 188 struct Nick *self; 189 struct HistInfo *history; 190 struct Channel *channels; 191 struct Channel *queries; 192 struct Schedule *schedule; 193 int reconnect; 194 char *expect[Expect_last]; 195 char **autocmds; 196 int connectfail; /* number of failed connections */ 197 time_t lastconnected; /* last time a connection was lost */ 198 time_t lastrecv; /* last time a message was received from server */ 199 time_t pingsent; /* last time a ping was sent to server */ 200 #ifdef TLS 201 int tls; 202 int tls_verify; 203 struct tls *tls_ctx; 204 #endif /* TLS */ 205 struct Server *next; 206 }; 207 208 /* messages received from server */ 209 struct Handler { 210 char *cmd; /* or numeric */ 211 void (*func)(struct Server *server, struct History *msg); 212 }; 213 214 /* commands received from user */ 215 struct Command { 216 char *name; 217 void (*func)(struct Server *server, struct Channel *channel, char *str); 218 int need; /* 0 - nothing 219 1 - server 220 2 - channel (and implicitly server) 221 3+ - implementation defined (pfft. who's gonna reimplement hirc?) */ 222 char *description[64]; 223 }; 224 225 struct CommandOpts { 226 char *opt; 227 int arg; 228 int ret; 229 }; 230 231 enum Valtype { 232 Val_string, 233 Val_bool, 234 Val_colour, 235 Val_signed, 236 Val_unsigned, 237 Val_nzunsigned, 238 Val_pair, 239 Val_colourpair, 240 Val_location, 241 }; 242 243 struct Config { 244 char *name; 245 int isdef; 246 enum Valtype valtype; 247 char *description[64]; 248 char *str; 249 long num; 250 long pair[2]; 251 int (*strhandle)(struct Config *, char *); 252 int (*numhandle)(struct Config *, long); 253 int (*pairhandle)(struct Config *, long, long); 254 }; 255 256 enum WindowLocation { 257 Location_hidden, 258 Location_left, 259 Location_right, 260 }; 261 262 #include <ncurses.h> 263 struct Window { 264 int x, y; 265 int h, w; 266 int refresh; 267 int scroll; 268 enum WindowLocation location; 269 void (*handler)(void); 270 WINDOW *window; 271 }; 272 273 enum Windows { 274 Win_dummy, 275 Win_main, 276 Win_nicklist, 277 Win_buflist, 278 Win_input, /* should always be 279 last to refresh */ 280 Win_last, 281 }; 282 283 struct Selected { 284 struct Channel *channel; 285 struct Server *server; 286 struct HistInfo *history; 287 char *name; 288 int showign; 289 int hasnicks; 290 }; 291 292 #include <wchar.h> 293 struct Keybind { 294 struct Keybind *prev; 295 char *binding; 296 wchar_t *wbinding; 297 char *cmd; 298 struct Keybind *next; 299 }; 300 301 struct Alias { 302 struct Alias *prev; 303 char *alias; 304 char *cmd; 305 struct Alias *next; 306 }; 307 308 #include <regex.h> 309 struct Ignore { 310 struct Ignore *prev; 311 char *format; 312 char *text; 313 regex_t regex; 314 int regopt; 315 int noact; 316 char *server; 317 struct Ignore *next; 318 }; 319 320 #endif /* H_STRUCT */