ekg2
|
00001 /* $Id$ */ 00002 00003 /* 00004 * (C) Copyright 2001-2003 Wojtek Kaniewski <wojtekka@irc.pl> 00005 * Robert J. Woźny <speedy@ziew.org> 00006 * Paweł Maziarz <drg@go2.pl> 00007 * Dawid Jarosz <dawjar@poczta.onet.pl> 00008 * Piotr Domagalski <szalik@szalik.net> 00009 * Adam Mikuta <adammikuta@poczta.onet.pl> 00010 * 00011 * This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License Version 2 as 00013 * published by the Free Software Foundation. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00023 */ 00024 00025 #ifndef __EKG_STUFF_H 00026 #define __EKG_STUFF_H 00027 00028 #include <sys/types.h> 00029 #include <sys/time.h> 00030 00031 #include "win32.h" 00032 00033 #ifndef NO_POSIX_SYSTEM 00034 #include <sys/socket.h> 00035 #include <netinet/in.h> 00036 #endif 00037 00038 #include <ctype.h> 00039 #include <stdarg.h> 00040 #include <stdio.h> 00041 #include <stdbool.h> 00042 #include <time.h> 00043 00044 #include "dynstuff.h" 00045 #include "plugins.h" 00046 #include "sessions.h" 00047 #include "userlist.h" 00048 00049 #ifdef __cplusplus 00050 extern "C" { 00051 #endif 00052 00053 #define DEBUG_MAX_LINES 50 /* ile linii z debug zrzucać do pliku */ 00054 00055 /* obsługa procesów potomnych */ 00056 00057 struct child_s; 00058 00059 typedef void (*child_handler_t)(struct child_s *c, pid_t pid, const char *name, int status, void *data); 00060 00061 typedef struct child_s { 00062 struct child_s *next; 00063 00064 pid_t pid; /* id procesu */ 00065 plugin_t *plugin; /* obsługujący plugin */ 00066 char *name; /* nazwa, wyświetlana przy /exec */ 00067 child_handler_t handler; /* zakład pogrzebowy */ 00068 void *priv_data; /* dane procesu */ 00069 } child_t; 00070 00071 #ifndef EKG2_WIN32_NOFUNCTION 00072 child_t *child_add(plugin_t *plugin, pid_t pid, const char *name, child_handler_t handler, void *priv_data); 00073 child_t *children_removei(child_t *c); 00074 void children_destroy(void); 00075 #endif 00076 00077 00078 #ifndef EKG2_WIN32_NOFUNCTION 00079 typedef struct alias { 00080 struct alias *next; 00081 00082 char *name; /* nazwa aliasu */ 00083 list_t commands; /* commands->data to (char*) */ 00084 } alias_t; 00085 #endif 00086 00087 enum mesg_t { 00088 MESG_CHECK = -1, 00089 MESG_OFF, 00090 MESG_ON, 00091 MESG_DEFAULT 00092 }; 00093 00094 #define TIMER(x) int x(int type, void *data) 00095 #define TIMER_SESSION(x) int x(int type, session_t *s) 00096 00097 struct timer { 00098 struct timer *next; 00099 00100 char *name; /* nazwa timera */ 00101 plugin_t *plugin; /* wtyczka obsługująca deksryptor */ 00102 struct timeval ends; /* kiedy się kończy? */ 00103 unsigned int period; /* ile milisekund ma trwać czekanie */ 00104 int (*function)(int, void *); /* funkcja do wywołania */ 00105 void *data; /* dane dla funkcji */ 00106 00107 unsigned int persist : 1; /* czy ma być na zawsze? */ 00108 unsigned int at : 1; /* /at? trzeba się tego jakoś pozbyć 00109 * i ujednolicić z /timer */ 00110 unsigned int is_session : 1; /* czy sesyjny */ 00111 }; 00112 00113 struct conference { 00114 struct conference *next; 00115 00116 char *name; 00117 ignore_t ignore; 00118 list_t recipients; 00119 }; 00120 00121 typedef struct newconference { 00122 struct newconference *next; 00123 00124 char *session; 00125 char *name; 00126 struct userlist *participants; 00127 void *priv_data; 00128 } newconference_t; 00129 00130 struct buffer { 00131 struct buffer *next; 00132 00133 time_t ts; 00134 char *target; 00135 char *line; 00136 }; 00137 00138 struct buffer_info { 00139 struct buffer *data; 00140 int count; 00141 int max_lines; 00142 struct buffer *last; /* fast access to last element, esp. for log_raw */ 00143 }; 00144 00145 struct color_map { 00146 int color; 00147 unsigned char r, g, b; 00148 }; 00149 00150 #ifndef EKG2_WIN32_NOFUNCTION 00151 extern child_t *children; 00152 extern alias_t *aliases; 00153 extern list_t autofinds; /* char* data */ 00154 extern struct timer *timers; 00155 extern struct conference *conferences; 00156 extern newconference_t *newconferences; 00157 extern struct buffer_info buffer_debug; 00158 extern struct buffer_info buffer_speech; 00159 00160 extern time_t last_save; 00161 extern char *config_profile; 00162 extern int config_changed; 00163 extern int ekg2_reason_changed; 00164 00165 extern pid_t speech_pid; 00166 00167 extern int no_mouse; 00168 00169 extern int old_stderr; 00170 extern int mesg_startup; 00171 00172 extern char *config_away_reason; 00173 extern int config_auto_save; 00174 extern int config_auto_user_add; 00175 extern char *config_back_reason; 00176 extern int config_beep; 00177 extern int config_beep_msg; 00178 extern int config_beep_chat; 00179 extern int config_beep_notify; 00180 extern int config_completion_notify; 00181 extern char *config_completion_char; 00182 extern int config_debug; 00183 extern int config_default_status_window; 00184 extern int config_display_ack; 00185 extern int config_display_blinking; 00186 extern int config_display_color; 00187 extern char *config_display_color_map; 00188 extern int config_display_crap; 00189 extern int config_display_day_changed; 00190 extern int config_display_notify; 00191 extern int config_display_sent; 00192 extern int config_display_welcome; 00193 extern int config_emoticons; 00194 extern int config_events_delay; 00195 extern int config_expert_mode; 00196 extern int config_history_savedups; 00197 extern int config_keep_reason; 00198 extern int config_last; 00199 extern int config_last_size; 00200 extern int config_lastlog_case; 00201 extern int config_lastlog_noitems; 00202 extern int config_lastlog_display_all; 00203 extern int config_make_window; 00204 extern int config_mesg; 00205 extern int config_query_commands; 00206 extern int config_slash_messages; 00207 extern char *config_quit_reason; 00208 extern int config_save_password; 00209 extern int config_save_quit; 00210 extern char *config_session_default; 00211 extern int config_sessions_save; 00212 extern int config_send_white_lines; 00213 extern int config_sort_windows; 00214 extern char *config_sound_app; 00215 extern char *config_sound_chat_file; 00216 extern char *config_sound_msg_file; 00217 extern char *config_sound_sysmsg_file; 00218 extern char *config_sound_notify_file; 00219 extern char *config_sound_mail_file; 00220 extern char *config_speech_app; 00221 extern char *config_subject_prefix; 00222 extern char *config_subject_reply_prefix; 00223 extern char *config_tab_command; 00224 extern char *config_theme; 00225 extern int config_time_deviation; 00226 extern char *config_timestamp; 00227 extern int config_timestamp_show; 00228 extern int config_use_unicode; /* for instance in jabber plugin if this is on, than we don't need to make iconv from / to unicode.. */ 00229 extern int config_use_iso; /* this for ncurses */ 00230 extern char *config_console_charset; /* */ 00231 extern int config_window_session_allow; 00232 extern char *config_windows_layout; 00233 extern int config_windows_save; 00234 extern char *config_dcc_dir; 00235 extern int config_version; 00236 extern char *config_exit_exec; 00237 extern int config_session_locks; 00238 extern char *config_nickname; 00239 00240 extern char *home_dir; 00241 extern char *config_dir; 00242 extern char *console_charset; 00243 extern int in_autoexec; 00244 extern int ekg_watches_removed; 00245 extern time_t ekg_started; 00246 00247 extern int quit_message_send; 00248 extern int batch_mode; 00249 extern char *batch_line; 00250 extern struct color_map color_map_default[16+10]; 00251 00252 void windows_save(); 00253 00254 int alias_add(const char *string, int quiet, int append); 00255 int alias_remove(const char *name, int quiet); 00256 void aliases_destroy(); 00257 00258 char *base64_encode(const char *buf, size_t len); 00259 char *base64_decode(const char *buf); 00260 00261 int buffer_add(struct buffer_info *type, const char *target, const char *line); 00262 int buffer_add_str(struct buffer_info *type, const char *target, const char *str); 00263 char *buffer_tail(struct buffer_info *type); 00264 void buffer_free(struct buffer_info *type); 00265 00266 void changed_auto_save(const char *var); 00267 void changed_display_blinking(const char *var); 00268 void changed_make_window(const char *var); 00269 void changed_mesg(const char *var); 00270 void changed_theme(const char *var); 00271 00272 const char *compile_time(); 00273 00274 struct conference *conference_add(session_t *session, const char *string, const char *nicklist, int quiet); 00275 int conference_remove(const char *name, int quiet); 00276 struct conference *conference_create(session_t *session, const char *nicks); 00277 struct conference *conference_find(const char *name); 00278 struct conference *conference_find_by_uids(session_t *s, const char *from, const char **recipients, int count, int quiet); 00279 int conference_set_ignore(const char *name, int flag, int quiet); 00280 int conference_rename(const char *oldname, const char *newname, int quiet); 00281 int conference_participant(struct conference *c, const char *uid); 00282 void conferences_destroy(); 00283 00284 /* BEGIN OF newconference API HERE */ 00285 userlist_t *newconference_member_add(newconference_t *conf, const char *uid, const char *nick); 00286 userlist_t *newconference_member_find(newconference_t *conf, const char *uid); 00287 int newconference_member_remove(newconference_t *conf, userlist_t *u); 00288 newconference_t *newconference_create(session_t *s, const char *name, int create_wnd); 00289 newconference_t *newconference_find(session_t *s, const char *name); 00290 void newconference_destroy(newconference_t *conf, int kill_wnd); 00291 void newconferences_destroy(); 00292 /* END of newconference API */ 00293 00294 int ekg_hash(const char *name); 00295 00296 FILE *help_path(char *name, char *plugin); 00297 00298 int mesg_set(int what); 00299 char *strip_spaces(char *line); 00300 int strncasecmp_pl(const char * cs,const char * ct,size_t count); 00301 int mkdir_recursive(const char *pathname, int isdir); 00302 00303 #ifdef __GNUC__ 00304 char *saprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); 00305 #else 00306 char *saprintf(const char *format, ...); 00307 #endif 00308 00309 int play_sound(const char *sound_path); 00310 00311 const char *prepare_path(const char *filename, int do_mkdir); 00312 const char *prepare_pathf(const char *filename, ...); 00313 const char *prepare_path_user(const char *path); 00314 char *read_file(FILE *f, int alloc); 00315 char *read_file_iso(FILE *f, int alloc); 00316 00317 const char *timestamp(const char *format); 00318 const char *timestamp_time(const char *format, time_t t); 00319 char *xstrmid(const char *str, int start, int length); 00320 void xstrtr(char *text, char from, char to); 00321 char *xstrncat_pl(char *dest, const char *src, size_t n); 00322 size_t strlen_pl(const char *s); 00323 char color_map(unsigned char r, unsigned char g, unsigned char b); 00324 char *strcasestr(const char *haystack, const char *needle); 00325 int msg_all(session_t *s, const char *function, const char *what); 00326 int say_it(const char *str); 00327 char *split_line(char **ptr); 00328 00329 int isalpha_pl(unsigned char c); 00330 /* makra, dzięki którym pozbywamy się warning'ów */ 00331 #define xisxdigit(c) isxdigit((int) (unsigned char) c) 00332 #define xisdigit(c) isdigit((int) (unsigned char) c) 00333 #define xisalpha(c) isalpha_pl((int) (unsigned char) c) 00334 #define xisalnum(c) isalnum((int) (unsigned char) c) 00335 #define xisspace(c) isspace((int) (unsigned char) c) 00336 #define xtolower(c) tolower((int) (unsigned char) c) 00337 #define xtoupper(c) toupper((int) (unsigned char) c) 00338 00339 struct timer *timer_add(plugin_t *plugin, const char *name, unsigned int period, int persistent, int (*function)(int, void *), void *data); 00340 struct timer *timer_add_ms(plugin_t *plugin, const char *name, unsigned int period, int persist, int (*function)(int, void *), void *data); 00341 struct timer *timer_add_session(session_t *session, const char *name, unsigned int period, int persist, int (*function)(int, session_t *)); 00342 struct timer *timer_find_session(session_t *session, const char *name); 00343 int timer_remove(plugin_t *plugin, const char *name); 00344 int timer_remove_session(session_t *session, const char *name); 00345 int timer_remove_user(); 00346 void timers_remove(struct timer *t); 00347 struct timer *timers_removei(struct timer *t); 00348 void timers_destroy(); 00349 TIMER(timer_handle_command); 00350 00351 const char *ekg_status_label(const int status, const char *descr, const char *prefix); 00352 void ekg_update_status(session_t *session); 00353 #define ekg_update_status_n(a) ekg_update_status(session_find(a)) 00354 const char *ekg_status_string(const int status, const int cmd); 00355 int ekg_status_int(const char *text); 00356 00357 char *ekg_draw_descr(const int status); 00358 uint32_t *ekg_sent_message_format(const char *text); 00359 00360 void ekg_yield_cpu(); 00361 00362 /* recode.c XXX, przeniesc do recode.h */ 00363 void *ekg_convert_string_init(const char *from, const char *to, void **rev); 00364 void ekg_convert_string_destroy(void *ptr); 00365 char *ekg_convert_string_p(const char *ps, void *ptr); 00366 char *ekg_convert_string(const char *ps, const char *from, const char *to); 00367 string_t ekg_convert_string_t_p(string_t s, void *ptr); 00368 string_t ekg_convert_string_t(string_t s, const char *from, const char *to); 00369 int ekg_converters_display(int quiet); 00370 00371 char *password_input(const char *prompt, const char *rprompt, const bool norepeat); 00372 int is_utf8_string(const char *txt); 00373 00374 00375 /* funkcje poza stuff.c */ 00376 void ekg_exit(); 00377 void ekg_debug_handler(int level, const char *format, va_list ap); 00378 00379 int ekg_close(int fd); 00380 int ekg_write(int fd, const char *buf, int len); 00381 int ekg_writef(int fd, const char *format, ...); 00382 00383 #endif 00384 00385 #ifdef __cplusplus 00386 } 00387 #endif 00388 00389 #endif /* __EKG_STUFF_H */ 00390 00391 /* 00392 * Local Variables: 00393 * mode: c 00394 * c-file-style: "k&r" 00395 * c-basic-offset: 8 00396 * indent-tabs-mode: t 00397 * End: 00398 */