ekg/stuff.h

Go to the documentation of this file.
00001 /* $Id: stuff.h 4731 2008-10-30 09:24:29Z darkjames $ */
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            *private;       /* 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 *private);
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 sekund 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            *private;
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 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_audio_device;
00173 extern char *config_away_reason;
00174 extern int config_auto_save;
00175 extern int config_auto_user_add;
00176 extern char *config_back_reason;
00177 extern int config_beep;
00178 extern int config_beep_msg;
00179 extern int config_beep_chat;
00180 extern int config_beep_notify;
00181 extern int config_completion_notify;
00182 extern char *config_completion_char;
00183 extern int config_debug;
00184 extern int config_default_status_window;
00185 extern int config_display_ack;
00186 extern int config_display_blinking;
00187 extern int config_display_color;
00188 extern char *config_display_color_map;
00189 extern int config_display_crap;
00190 extern int config_display_day_changed;
00191 extern int config_display_notify;
00192 extern int config_display_pl_chars;
00193 extern int config_display_sent;
00194 extern int config_display_welcome;
00195 extern int config_emoticons;
00196 extern int config_events_delay;
00197 extern int config_expert_mode;
00198 extern int config_history_savedups;
00199 extern int config_keep_reason;
00200 extern int config_last;
00201 extern int config_last_size;
00202 extern int config_lastlog_case;
00203 extern int config_lastlog_noitems;
00204 extern int config_lastlog_display_all;
00205 extern int config_make_window;
00206 extern int config_mesg;
00207 extern int config_query_commands;
00208 extern int config_slash_messages;
00209 extern char *config_quit_reason;
00210 extern int config_reason_limit;
00211 extern int config_save_password;
00212 extern int config_save_quit;
00213 extern char *config_session_default;
00214 extern int config_sessions_save;
00215 extern int config_sort_windows;
00216 extern char *config_sound_app;
00217 extern char *config_sound_chat_file;
00218 extern char *config_sound_msg_file;
00219 extern char *config_sound_sysmsg_file;
00220 extern char *config_sound_notify_file;
00221 extern char *config_sound_mail_file;
00222 extern char *config_speech_app;
00223 extern char *config_subject_prefix;
00224 extern char *config_subject_reply_prefix;
00225 extern char *config_tab_command;
00226 extern char *config_theme;
00227 extern int config_time_deviation;
00228 extern char *config_timestamp;
00229 extern int config_timestamp_show;
00230 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.. */
00231 extern int config_use_iso;  /* this for ncurses */
00232 extern char *config_console_charset;    /* */
00233 extern int config_window_session_allow;
00234 extern char *config_windows_layout;
00235 extern int config_windows_save;
00236 extern char *config_dcc_dir;
00237 extern int config_version;
00238 extern char *config_exit_exec;
00239 extern int config_session_locks;
00240 extern char *config_nickname;
00241 
00242 extern char *home_dir;
00243 extern char *config_dir;
00244 extern char *console_charset;
00245 extern int in_autoexec;
00246 extern int ekg_watches_removed;
00247 extern time_t ekg_started;
00248 
00249 extern int quit_message_send;
00250 extern int batch_mode;
00251 extern char *batch_line;
00252 extern struct color_map color_map_default[16+10];
00253 
00254 void windows_save();
00255 
00256 int alias_add(const char *string, int quiet, int append);
00257 int alias_remove(const char *name, int quiet);
00258 void aliases_destroy();
00259 
00260 char *base64_encode(const char *buf, size_t len);
00261 char *base64_decode(const char *buf);
00262 
00263 int buffer_add(struct buffer_info *type, const char *target, const char *line);
00264 int buffer_add_str(struct buffer_info *type, const char *target, const char *str);
00265 char *buffer_tail(struct buffer_info *type);
00266 void buffer_free(struct buffer_info *type);
00267 
00268 void changed_auto_save(const char *var);
00269 void changed_display_blinking(const char *var);
00270 void changed_make_window(const char *var);
00271 void changed_mesg(const char *var);
00272 void changed_theme(const char *var);
00273 
00274 const char *compile_time();
00275 
00276 struct conference *conference_add(session_t *session, const char *string, const char *nicklist, int quiet);
00277 int conference_remove(const char *name, int quiet);
00278 struct conference *conference_create(session_t *session, const char *nicks);
00279 struct conference *conference_find(const char *name);
00280 struct conference *conference_find_by_uids(session_t *s, const char *from, const char **recipients, int count, int quiet);
00281 int conference_set_ignore(const char *name, int flag, int quiet);
00282 int conference_rename(const char *oldname, const char *newname, int quiet);
00283 int conference_participant(struct conference *c, const char *uid);
00284 void conferences_destroy();
00285 
00286 /* BEGIN OF newconference API HERE */
00287 userlist_t *newconference_member_add(newconference_t *conf, const char *uid, const char *nick);
00288 userlist_t *newconference_member_find(newconference_t *conf, const char *uid);
00289 int newconference_member_remove(newconference_t *conf, userlist_t *u);
00290 newconference_t *newconference_create(session_t *s, const char *name, int create_wnd);
00291 newconference_t *newconference_find(session_t *s, const char *name);
00292 void newconference_destroy(newconference_t *conf, int kill_wnd);
00293 void newconferences_destroy();
00294 /* END of newconference API */
00295 
00296 int ekg_hash(const char *name);
00297 
00298 FILE *help_path(char *name, char *plugin);
00299 
00300 int mesg_set(int what);
00301 void iso_to_ascii(unsigned char *buf);
00302 char *strip_spaces(char *line);
00303 int strncasecmp_pl(const char * cs,const char * ct,size_t count);
00304 int strcasecmp_pl(const char *cs, const char *ct);
00305 int mkdir_recursive(const char *pathname, int isdir);
00306 
00307 #ifdef __GNUC__
00308 char *saprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
00309 #else
00310 char *saprintf(const char *format, ...);
00311 #endif
00312 
00313 int play_sound(const char *sound_path);
00314 
00315 const char *prepare_path(const char *filename, int do_mkdir);
00316 const char *prepare_pathf(const char *filename, ...);
00317 const char *prepare_path_user(const char *path);
00318 char *read_file(FILE *f, int alloc);
00319 
00320 const char *timestamp(const char *format);
00321 const char *timestamp_time(const char *format, time_t t);
00322 int on_off(const char *value);
00323 char *xstrmid(const char *str, int start, int length);
00324 void xstrtr(char *text, char from, char to);
00325 char color_map(unsigned char r, unsigned char g, unsigned char b);
00326 char *strcasestr(const char *haystack, const char *needle);
00327 int msg_all(session_t *s, const char *function, const char *what);
00328 int say_it(const char *str);
00329 char *split_line(char **ptr);
00330 
00331 int isalpha_pl(unsigned char c);
00332 /* makra, dzięki którym pozbywamy się warning'ów */
00333 #define xisxdigit(c) isxdigit((int) (unsigned char) c)
00334 #define xisdigit(c) isdigit((int) (unsigned char) c)
00335 #define xisalpha(c) isalpha_pl((int) (unsigned char) c)
00336 #define xisalnum(c) isalnum((int) (unsigned char) c)
00337 #define xisspace(c) isspace((int) (unsigned char) c)
00338 #define xtolower(c) tolower((int) (unsigned char) c)
00339 #define xtoupper(c) toupper((int) (unsigned char) c)
00340 
00341 struct timer *timer_add(plugin_t *plugin, const char *name, unsigned int period, int persistent, int (*function)(int, void *), void *data);
00342 struct timer *timer_add_ms(plugin_t *plugin, const char *name, unsigned int period, int persist, int (*function)(int, void *), void *data);
00343 struct timer *timer_add_session(session_t *session, const char *name, unsigned int period, int persist, int (*function)(int, session_t *));
00344 struct timer *timer_find_session(session_t *session, const char *name);
00345 int timer_remove(plugin_t *plugin, const char *name);
00346 int timer_remove_session(session_t *session, const char *name);
00347 int timer_remove_user();
00348 void timers_remove(struct timer *t);
00349 struct timer *timers_removei(struct timer *t);
00350 void timers_destroy();
00351 TIMER(timer_handle_command);
00352 
00353 const char *ekg_status_label(const int status, const char *descr, const char *prefix);
00354 void ekg_update_status(session_t *session);
00355 #define ekg_update_status_n(a) ekg_update_status(session_find(a))
00356 const char *ekg_status_string(const int status, const int cmd);
00357 int ekg_status_int(const char *text);
00358 
00359 char *ekg_draw_descr(const int status);
00360 uint32_t *ekg_sent_message_format(const char *text);
00361 
00362 void ekg_yield_cpu();
00363 
00364 /* recode.c XXX, przeniesc do recode.h */
00365 void *ekg_convert_string_init(const char *from, const char *to, void **rev);
00366 void ekg_convert_string_destroy(void *ptr);
00367 char *ekg_convert_string_p(const char *ps, void *ptr);
00368 char *ekg_convert_string(const char *ps, const char *from, const char *to);
00369 string_t ekg_convert_string_t_p(string_t s, void *ptr);
00370 string_t ekg_convert_string_t(string_t s, const char *from, const char *to);
00371 int ekg_converters_display(int quiet);
00372 
00373 char *ekg_locale_to_cp(char *buf);
00374 char *ekg_cp_to_locale(char *buf);
00375 char *ekg_locale_to_latin2(char *buf);
00376 char *ekg_latin2_to_locale(char *buf);
00377 char *ekg_locale_to_utf8(char *buf);
00378 char *ekg_utf8_to_locale(char *buf);
00379 char *ekg_any_to_locale(char *buf, char *inp);
00380 char *ekg_locale_to_any(char *buf, char *inp);
00381 
00382 
00383 char *password_input(const char *prompt, const char *rprompt, const bool norepeat);
00384 
00385 /* funkcje poza stuff.c */
00386 void ekg_exit();
00387 void ekg_debug_handler(int level, const char *format, va_list ap);
00388 
00389 int ekg_close(int fd);
00390 int ekg_write(int fd, const char *buf, int len);
00391 int ekg_writef(int fd, const char *format, ...);
00392 
00393 #endif
00394         
00395 #ifdef __cplusplus
00396 }
00397 #endif
00398 
00399 #endif /* __EKG_STUFF_H */
00400 
00401 /*
00402  * Local Variables:
00403  * mode: c
00404  * c-file-style: "k&r"
00405  * c-basic-offset: 8
00406  * indent-tabs-mode: t
00407  * End:
00408  */

Generated on Sat Nov 22 22:30:42 2008 for ekg2 by  doxygen 1.5.1