1 module hexchat.capi; 2 3 import core.stdc.time; 4 import std.traits; 5 6 enum HEXCHAT_PRI_HIGHEST = 127; 7 enum HEXCHAT_PRI_HIGH = 64; 8 enum HEXCHAT_PRI_NORM = 0; 9 enum HEXCHAT_PRI_LOW = -64; 10 enum HEXCHAT_PRI_LOWEST = -128; 11 12 enum HEXCHAT_FD_READ = 1; 13 enum HEXCHAT_FD_WRITE = 2; 14 enum HEXCHAT_FD_EXCEPTION = 4; 15 enum HEXCHAT_FD_NOTSOCKET = 8; 16 17 enum HEXCHAT_EAT_NONE = 0; // pass it on through! 18 enum HEXCHAT_EAT_HEXCHAT = 1; // don't let xchat see this event 19 enum HEXCHAT_EAT_PLUGIN = 2; // don't let other plugins see this event 20 enum HEXCHAT_EAT_ALL = HEXCHAT_EAT_HEXCHAT | HEXCHAT_EAT_PLUGIN; // don't let anything see this event 21 22 extern(C): 23 struct hexchat_list {} 24 struct hexchat_hook {} 25 struct hexchat_context {} 26 27 alias extern(C) int function (const(char)** word, const(char)** word_eol, void *user_data) hexchat_cmd_cb; 28 alias extern(C) int function (const(char)** word, void *user_data) hexchat_print_cb; 29 alias extern(C) int function (void *user_data) hexchat_timer_cb; 30 alias extern(C) int function (int fd, int flags, void *user_data) hexchat_fd_cb; 31 32 struct hexchat_plugin 33 { 34 // these are only used on win32 35 extern(C): 36 hexchat_hook *function (hexchat_plugin *ph, const char *name, int pri, hexchat_cmd_cb callback, const char *help_text, void *userdata) hexchat_hook_command; 37 hexchat_hook *function (hexchat_plugin *ph, const char *name, int pri, hexchat_cmd_cb callback, void *userdata) hexchat_hook_server; 38 hexchat_hook *function (hexchat_plugin *ph, const char *name, int pri, hexchat_print_cb callback, void *userdata) hexchat_hook_print; 39 hexchat_hook *function (hexchat_plugin *ph, int timeout, hexchat_timer_cb callback, void *userdata) hexchat_hook_timer; 40 hexchat_hook *function (hexchat_plugin *ph, int fd, int flags, hexchat_fd_cb callback, void *userdata) hexchat_hook_fd; 41 void *function (hexchat_plugin *ph, hexchat_hook *hook) hexchat_unhook; 42 void function (hexchat_plugin *ph, const char *text) hexchat_print; 43 void function (hexchat_plugin *ph, const char *format, ...) hexchat_printf; 44 void function (hexchat_plugin *ph, const char *command) hexchat_command; 45 void function (hexchat_plugin *ph, const char *format, ...) hexchat_commandf; 46 int function (hexchat_plugin *ph, const char *s1, const char *s2) hexchat_nickcmp; 47 int function (hexchat_plugin *ph, hexchat_context *ctx) hexchat_set_context; 48 hexchat_context *function (hexchat_plugin *ph, const char *servname, const char *channel) hexchat_find_context; 49 hexchat_context *function (hexchat_plugin *ph) hexchat_get_context; 50 const char *function (hexchat_plugin *ph, const char *id) hexchat_get_info; 51 int function (hexchat_plugin *ph, const char *name, const char **string, int *integer) hexchat_get_prefs; 52 hexchat_list * function (hexchat_plugin *ph, const char *name) hexchat_list_get; 53 void function (hexchat_plugin *ph, hexchat_list *xlist) hexchat_list_free; 54 const char ** function (hexchat_plugin *ph, const char *name) hexchat_list_fields; 55 int function (hexchat_plugin *ph, hexchat_list *xlist) hexchat_list_next; 56 const char * function (hexchat_plugin *ph, hexchat_list *xlist, const char *name) hexchat_list_str; 57 int function (hexchat_plugin *ph, hexchat_list *xlist, const char *name) hexchat_list_int; 58 void * function (hexchat_plugin *ph, const char *filename, const char *name, const char *desc, const char *_version, char *reserved) hexchat_plugingui_add; 59 void function (hexchat_plugin *ph, void *handle) hexchat_plugingui_remove; 60 int function (hexchat_plugin *ph, const char *event_name, ...) hexchat_emit_print; 61 int function (hexchat_plugin *ph, void *src, char *buf, int *len) hexchat_read_fd; 62 time_t function (hexchat_plugin *ph, hexchat_list *xlist, const char *name) hexchat_list_time; 63 char *function (hexchat_plugin *ph, const char *msgid) hexchat_gettext; 64 void function (hexchat_plugin *ph, const char **targets, int ntargets, int modes_per_line, char sign, char mode) hexchat_send_modes; 65 char *function (hexchat_plugin *ph, const char *str, int len, int flags) hexchat_strip; 66 void function (hexchat_plugin *ph, void *ptr) hexchat_free; 67 } 68 69 version(Windows) 70 { 71 private mixin template WrapMember(string funcname) 72 { 73 mixin("alias typeof(hexchat_plugin.init." ~ funcname ~ ") fun;"); 74 mixin(` 75 ReturnType!fun ` ~ funcname ~ `(ParameterTypeTuple!fun args) 76 { 77 return args[0].` ~ funcname ~ `(args); 78 } 79 `); 80 } 81 82 mixin WrapMember!"hexchat_hook_command"; 83 mixin WrapMember!"hexchat_hook_server"; 84 mixin WrapMember!"hexchat_hook_print"; 85 mixin WrapMember!"hexchat_hook_timer"; 86 mixin WrapMember!"hexchat_hook_fd"; 87 mixin WrapMember!"hexchat_unhook"; 88 mixin WrapMember!"hexchat_print"; 89 mixin WrapMember!"hexchat_command"; 90 mixin WrapMember!"hexchat_nickcmp"; 91 mixin WrapMember!"hexchat_set_context"; 92 mixin WrapMember!"hexchat_find_context"; 93 mixin WrapMember!"hexchat_get_context"; 94 mixin WrapMember!"hexchat_get_info"; 95 mixin WrapMember!"hexchat_get_prefs"; 96 mixin WrapMember!"hexchat_list_get"; 97 mixin WrapMember!"hexchat_list_free"; 98 mixin WrapMember!"hexchat_list_fields"; 99 mixin WrapMember!"hexchat_list_next"; 100 mixin WrapMember!"hexchat_list_str"; 101 mixin WrapMember!"hexchat_list_int"; 102 mixin WrapMember!"hexchat_plugingui_add"; 103 mixin WrapMember!"hexchat_plugingui_remove"; 104 mixin WrapMember!"hexchat_read_fd"; 105 mixin WrapMember!"hexchat_list_time"; 106 mixin WrapMember!"hexchat_gettext"; 107 mixin WrapMember!"hexchat_send_modes"; 108 mixin WrapMember!"hexchat_strip"; 109 mixin WrapMember!"hexchat_free"; 110 111 // WrapMember can't handle varargs 112 void hexchat_printf(Args...)(hexchat_plugin *ph, const char *format, Args args) 113 { 114 ph.hexchat_printf(ph, format, args); 115 } 116 117 void hexchat_commandf(Args...)(hexchat_plugin *ph, const char *format, Args args) 118 { 119 ph.hexchat_commandf(ph, format, args); 120 } 121 122 int hexchat_emit_print(Args...)(hexchat_plugin *ph, const char *event_name, Args args) 123 { 124 ph.hexchat_emit_print(ph, event_name, args); 125 } 126 } 127 else 128 { 129 hexchat_hook * 130 hexchat_hook_command (hexchat_plugin *ph, 131 const char *name, 132 int pri, 133 hexchat_cmd_cb callback, 134 const char *help_text, 135 void *userdata); 136 137 hexchat_hook * 138 hexchat_hook_server (hexchat_plugin *ph, 139 const char *name, 140 int pri, 141 hexchat_cmd_cb callback, 142 void *userdata); 143 144 hexchat_hook * 145 hexchat_hook_print (hexchat_plugin *ph, 146 const char *name, 147 int pri, 148 hexchat_print_cb callback, 149 void *userdata); 150 151 hexchat_hook * 152 hexchat_hook_timer (hexchat_plugin *ph, 153 int timeout, 154 hexchat_timer_cb callback, 155 void *userdata); 156 157 hexchat_hook * 158 hexchat_hook_fd (hexchat_plugin *ph, 159 int fd, 160 int flags, 161 hexchat_fd_cb callback, 162 void *userdata); 163 164 void * 165 hexchat_unhook (hexchat_plugin *ph, 166 hexchat_hook *hook); 167 168 void 169 hexchat_print (hexchat_plugin *ph, 170 const char *text); 171 172 void 173 hexchat_printf (hexchat_plugin *ph, 174 const char *format, ...); 175 176 void 177 hexchat_command (hexchat_plugin *ph, 178 const char *command); 179 180 void 181 hexchat_commandf (hexchat_plugin *ph, 182 const char *format, ...); 183 184 int 185 hexchat_nickcmp (hexchat_plugin *ph, 186 const char *s1, 187 const char *s2); 188 189 int 190 hexchat_set_context (hexchat_plugin *ph, 191 hexchat_context *ctx); 192 193 hexchat_context * 194 hexchat_find_context (hexchat_plugin *ph, 195 const char *servname, 196 const char *channel); 197 198 hexchat_context * 199 hexchat_get_context (hexchat_plugin *ph); 200 201 const(char*) 202 hexchat_get_info (hexchat_plugin *ph, 203 const char *id); 204 205 int 206 hexchat_get_prefs (hexchat_plugin *ph, 207 const char *name, 208 const char **string, 209 int *integer); 210 211 hexchat_list * 212 hexchat_list_get (hexchat_plugin *ph, 213 const char *name); 214 215 void 216 hexchat_list_free (hexchat_plugin *ph, 217 hexchat_list *xlist); 218 219 const(char**) 220 hexchat_list_fields (hexchat_plugin *ph, 221 const char *name); 222 223 int 224 hexchat_list_next (hexchat_plugin *ph, 225 hexchat_list *xlist); 226 227 const(char*) 228 hexchat_list_str (hexchat_plugin *ph, 229 hexchat_list *xlist, 230 const char *name); 231 232 int 233 hexchat_list_int (hexchat_plugin *ph, 234 hexchat_list *xlist, 235 const char *name); 236 237 time_t 238 hexchat_list_time (hexchat_plugin *ph, 239 hexchat_list *xlist, 240 const char *name); 241 242 void * 243 hexchat_plugingui_add (hexchat_plugin *ph, 244 const char *filename, 245 const char *name, 246 const char *desc, 247 const char *_version, 248 char *reserved); 249 250 void 251 hexchat_plugingui_remove (hexchat_plugin *ph, 252 void *handle); 253 254 int 255 hexchat_emit_print (hexchat_plugin *ph, 256 const char *event_name, ...); 257 258 char * 259 hexchat_gettext (hexchat_plugin *ph, 260 const char *msgid); 261 262 void 263 hexchat_send_modes (hexchat_plugin *ph, 264 const char **targets, 265 int ntargets, 266 int modes_per_line, 267 char sign, 268 char mode); 269 270 char * 271 hexchat_strip (hexchat_plugin *ph, 272 const char *str, 273 int len, 274 int flags); 275 276 void 277 hexchat_free (hexchat_plugin *ph, 278 void *ptr); 279 }