hirc.h (9408B)
1 /* 2 * src/hirc.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_HIRC 21 #define H_HIRC 22 23 #include <wchar.h> 24 #include "struct.h" 25 #define PARAM_MAX 64 26 #define INPUT_MAX 8192 27 #define INPUT_HIST_MAX 64 28 #define HIST_MAX 8192 29 /* real maximum = HIST_MAX * (channels + servers + queries) */ 30 #define CONSTLEN(str) ((size_t)((sizeof(str) - sizeof(str[0])) / sizeof(str[0]))) 31 /* compile-time char/wchar_t literals */ 32 #define assert(x) ((void)((x) || (die(1, "assertion '%s' failed at %s:%d in %s()\n", #x, __FILE__, __LINE__, __func__),0))) 33 #ifdef ASSERT_ALWAYS_DIES 34 #define assert_warn(x,ret) assert(x) 35 #else 36 #define assert_warn(x,ret) do {if (!(x)) {ui_error("assertion '%s' failed", #x); return ret;}} while(0) 37 #endif /* ASSERT_ALWAYS_DIES */ 38 39 /* strlcpy/wcslcpy.c */ 40 #ifdef HIRC_STRLCPY 41 #undef strlcpy 42 size_t strlcpy(char *, const char *, size_t); 43 #endif /* HIST_STRLCPY */ 44 #ifdef HIRC_WCSLCPY 45 #undef wcslcpy 46 size_t wcslcpy(wchar_t *, const wchar_t *, size_t); 47 #endif /* HIST_WCSLCPY */ 48 49 /* main.c */ 50 void die(int code, char *format, ...); 51 void cleanup(char *quitmsg); 52 53 /* params.c */ 54 void param_free(char **params); 55 int param_len(char **params); 56 char ** param_create(char *msg); 57 58 /* str.c */ 59 wchar_t * stowc(char *str); 60 char * wctos(wchar_t *str); 61 char * homepath(char *path); 62 int strcmp_n(const char *s1, const char *s2); 63 char * struntil(char *str, char until); 64 int strisnum(char *str, int allowneg); 65 char * strntok(char *str, char *sep, int n); 66 char * strrdate(time_t secs); 67 char * smprintf(size_t len, char *fmt, ...); 68 69 /* mem.c */ 70 void pfree_(void **ptr); 71 #define pfree(ptr) pfree_((void **)ptr) 72 void * emalloc(size_t size); 73 void * erealloc(void *ptr, size_t size); 74 char * estrdup(const char *str); 75 void * talloc(size_t size); 76 char * tstrdup(const char *str); 77 wchar_t * ewcsdup(const wchar_t *str); 78 79 /* chan.c */ 80 void chan_free(struct Channel *channel); 81 void chan_free_list(struct Channel **head); 82 struct Channel *chan_create(struct Server *server, char *name, int query); 83 struct Channel *chan_get(struct Channel **head, char *name, int old); 84 struct Channel *chan_add(struct Server *server, struct Channel **head, char *name, int query); 85 int chan_isold(struct Channel *channel); 86 void chan_setold(struct Channel *channel, int old); 87 /* struct Channel *chan_dup(struct Channel *channel); */ 88 int chan_remove(struct Channel **head, char *name); 89 int chan_selected(struct Channel *channel); 90 91 /* nick.c */ 92 void prefix_tokenize(char *prefix, char **nick, char **ident, char **host); 93 short nick_getcolour(struct Nick *nick); 94 void nick_free(struct Nick *nick); 95 void nick_free_list(struct Nick **head); 96 struct Nick * nick_create(char *prefix, char priv, struct Server *server); 97 struct Nick * nick_get(struct Nick **head, char *nick); 98 struct Nick * nick_add(struct Nick **head, char *prefix, char priv, struct Server *server); 99 struct Nick * nick_dup(struct Nick *nick); 100 int nick_isself(struct Nick *nick); 101 int nick_isself_server(struct Nick *nick, struct Server *server); 102 int nick_remove(struct Nick **head, char *nick); 103 void nick_sort(struct Nick **head, struct Server *server); 104 105 /* hist.c */ 106 void hist_free(struct History *history); 107 void hist_free_list(struct HistInfo *histinfo); 108 struct History *hist_create(struct HistInfo *histinfo, struct Nick *from, char *msg, 109 enum Activity activity, time_t timestamp, enum HistOpt options); 110 struct History *hist_addp(struct HistInfo *histinfo, struct History *p, 111 enum Activity activity, enum HistOpt options); 112 struct History *hist_add(struct HistInfo *histinfo, 113 char *msg, enum Activity activity, 114 time_t timestamp, enum HistOpt options); 115 struct History *hist_format(struct HistInfo *history, enum Activity activity, 116 enum HistOpt options, char *format, ...); 117 int hist_len(struct History **history); 118 int hist_log(struct History *hist); 119 struct History *hist_loadlog(struct HistInfo *hist, char *server, char *channel); 120 void hist_purgeopt(struct HistInfo *histinfo, enum HistOpt options); 121 122 /* serv.c */ 123 void serv_free(struct Server *server); 124 void serv_connect(struct Server *server); 125 void serv_read(struct Server *sp); 126 int serv_write(struct Server *server, enum Sched when, char *format, ...); 127 struct Server * serv_create(char *name, char *host, char *port, char *nick, 128 char *username, char *realname, char *password, int tls, int tls_verify); 129 void serv_update(struct Server *sp, char *nick, char *username, 130 char *realname, char *password, int tls, int tls_verify); 131 struct Server * serv_get(struct Server **head, char *name); 132 struct Server * serv_add(struct Server **head, char *name, char *host, char *port, char *nick, 133 char *username, char *realname, char *password, int tls, int tls_verify); 134 int serv_len(struct Server **head); 135 int serv_poll(struct Server **head, int timeout); 136 int serv_remove(struct Server **head, char *name); 137 int serv_selected(struct Server *server); 138 void serv_disconnect(struct Server *server, int reconnect, char *msg); 139 int serv_ischannel(struct Server *server, char *str); 140 void serv_auto_add(struct Server *server, char *cmd); 141 void serv_auto_free(struct Server *server); 142 void serv_auto_send(struct Server *server); 143 int serv_auto_haschannel(struct Server *server, char *chan); 144 char * support_get(struct Server *server, char *key); 145 void support_set(struct Server *server, char *key, char *value); 146 void schedule(struct Server *server, enum Sched when, char *msg); 147 void schedule_send(struct Server *server, enum Sched when); 148 void expect_set(struct Server *server, enum Expect cmd, char *about); 149 char * expect_get(struct Server *server, enum Expect cmd); 150 151 /* handle.c */ 152 void handle(struct Server *server, char *msg); 153 154 /* ui.c */ 155 void ui_init(void); 156 #define ui_deinit() endwin() 157 void ui_read(void); 158 void ui_complete(wchar_t *str, size_t size); 159 int ui_input_insert(char c, int counter); 160 int ui_input_delete(int num, int counter); 161 void ui_redraw(void); 162 void ui_draw_input(void); 163 void ui_draw_nicklist(void); 164 void ui_draw_buflist(void); 165 void ui_draw_main(void); 166 int ui_buflist_count(int *ret_servers, int *ret_channels, int *ret_queries); 167 int ui_buflist_get(int num, struct Server **server, struct Channel **chan); 168 int ui_get_pair(short fg, short bg); 169 int ui_wprintc(struct Window *window, int lines, char *format, ...); 170 int ui_strlenc(struct Window *window, char *s, int *lines); 171 void ui_select(struct Server *server, struct Channel *channel); 172 char * ui_rectrl(char *str); 173 char * ui_unctrl(char *str); 174 int ui_bind(char *binding, char *cmd); 175 int ui_unbind(char *binding); 176 void ui_error_(char *file, int line, const char *func, char *format, ...); 177 #define ui_error(format, ...) ui_error_(__FILE__, __LINE__, __func__, format, __VA_ARGS__) 178 void ui_perror_(char *file, int line, const char *func, char *str); 179 #define ui_perror(str) ui_perror_(__FILE__, __LINE__, __func__, str) 180 #ifdef TLS 181 #include <tls.h> 182 void ui_tls_config_error_(char *file, int line, const char *func, struct tls_config *config, char *str); 183 #define ui_tls_config_error(config, str) ui_tls_config_error_(__FILE__, __LINE__, __func__, config, str) 184 void ui_tls_error_(char *file, int line, const char *func, struct tls *ctx, char *str); 185 #define ui_tls_error(ctx, str) ui_tls_error_(__FILE__, __LINE__, __func__, ctx, str) 186 #endif /* TLS */ 187 188 /* format.c */ 189 char * format_get_bufact(int activity); 190 char * format_get(struct History *hist); 191 char * format(struct Window *window, char *format, struct History *hist); 192 193 /* commands.c */ 194 void command_eval(struct Server *server, char *str); 195 int command_getopt(char **str, struct CommandOpts *opts); 196 int alias_add(char *binding, char *cmd); 197 int alias_remove(char *binding); 198 char * alias_eval(char *cmd); 199 200 /* config.c */ 201 char * config_get_pretty(struct Config *conf, int pairbrace); 202 long config_getl(char *name); 203 char * config_gets(char *name); 204 void config_getr(char *name, long *a, long *b); 205 struct Config * config_getp(char *name); 206 void config_set(char *name, char *str); 207 void config_setl(struct Config *conf, long num); 208 void config_sets(struct Config *conf, char *str); 209 void config_setr(struct Config *conf, long a, long b); 210 int config_read(char *filename); 211 212 /* complete.c */ 213 void complete(wchar_t *str, size_t size, unsigned *counter); 214 215 /* main.c */ 216 extern struct Server *servers; 217 extern struct HistInfo *main_buf; 218 219 /* handle.c */ 220 extern struct Ignore *ignores; 221 222 /* ui.c */ 223 extern struct Selected selected; 224 extern struct Keybind *keybinds; 225 extern struct Window windows[Win_last]; 226 extern int uineedredraw; 227 extern int nouich; 228 229 /* config.c */ 230 extern struct Config config[]; 231 232 /* commands.c */ 233 extern struct Command commands[]; 234 extern struct Alias *aliases; 235 236 #endif /* H_HIRC */