ekg2
 All Struktury Danych Pliki Funkcje Zmienne Definicje typów Wyliczenia Wartości wyliczeń Definicje Grupay Strony
stuff.h
Idź do dokumentacji tego pliku.
1 /* $Id$ */
2 
3 /*
4  * (C) Copyright 2001-2003 Wojtek Kaniewski <wojtekka@irc.pl>
5  * Robert J. Woźny <speedy@ziew.org>
6  * Paweł Maziarz <drg@go2.pl>
7  * Dawid Jarosz <dawjar@poczta.onet.pl>
8  * Piotr Domagalski <szalik@szalik.net>
9  * Adam Mikuta <adammikuta@poczta.onet.pl>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License Version 2 as
13  * published by the Free Software Foundation.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24 
25 #ifndef __EKG_STUFF_H
26 #define __EKG_STUFF_H
27 
28 #include <sys/types.h>
29 #include <sys/time.h>
30 
31 #include "win32.h"
32 
33 #ifndef NO_POSIX_SYSTEM
34 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #endif
37 
38 #include <ctype.h>
39 #include <stdarg.h>
40 #include <stdio.h>
41 #include <stdbool.h>
42 #include <time.h>
43 
44 #include "dynstuff.h"
45 #include "plugins.h"
46 #include "sessions.h"
47 #include "userlist.h"
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 #define DEBUG_MAX_LINES 50 /* ile linii z debug zrzucać do pliku */
54 
55 /* obsługa procesów potomnych */
56 
57 struct child_s;
58 
59 typedef void (*child_handler_t)(struct child_s *c, pid_t pid, const char *name, int status, void *data);
60 
61 typedef struct child_s {
62  struct child_s *next;
63 
64  pid_t pid; /* id procesu */
65  plugin_t *plugin; /* obsługujący plugin */
66  char *name; /* nazwa, wyświetlana przy /exec */
67  child_handler_t handler; /* zakład pogrzebowy */
68  void *priv_data; /* dane procesu */
69 } child_t;
70 
71 #ifndef EKG2_WIN32_NOFUNCTION
72 child_t *child_add(plugin_t *plugin, pid_t pid, const char *name, child_handler_t handler, void *priv_data);
74 void children_destroy(void);
75 #endif
76 
77 
78 #ifndef EKG2_WIN32_NOFUNCTION
79 typedef struct alias {
80  struct alias *next;
81 
82  char *name; /* nazwa aliasu */
83  list_t commands; /* commands->data to (char*) */
84 } alias_t;
85 #endif
86 
87 enum mesg_t {
88  MESG_CHECK = -1,
92 };
93 
94 #define TIMER(x) int x(int type, void *data)
95 #define TIMER_SESSION(x) int x(int type, session_t *s)
96 
97 struct timer {
98  struct timer *next;
99 
100  char *name; /* nazwa timera */
101  plugin_t *plugin; /* wtyczka obsługująca deksryptor */
102  struct timeval ends; /* kiedy się kończy? */
103  unsigned int period; /* ile milisekund ma trwać czekanie */
104  int (*function)(int, void *); /* funkcja do wywołania */
105  void *data; /* dane dla funkcji */
106 
107  unsigned int persist : 1; /* czy ma być na zawsze? */
108  unsigned int at : 1; /* /at? trzeba się tego jakoś pozbyć
109  * i ujednolicić z /timer */
110  unsigned int is_session : 1; /* czy sesyjny */
111 };
112 
113 struct conference {
114  struct conference *next;
115 
116  char *name;
119 };
120 
121 typedef struct newconference {
123 
124  char *session;
125  char *name;
127  void *priv_data;
129 
130 struct buffer {
131  struct buffer *next;
132 
133  time_t ts;
134  char *target;
135  char *line;
136 };
137 
138 struct buffer_info {
139  struct buffer *data;
140  int count;
142  struct buffer *last; /* fast access to last element, esp. for log_raw */
143 };
144 
145 struct color_map {
146  int color;
147  unsigned char r, g, b;
148 };
149 
150 #ifndef EKG2_WIN32_NOFUNCTION
151 extern child_t *children;
152 extern alias_t *aliases;
153 extern list_t autofinds; /* char* data */
154 extern struct timer *timers;
155 extern struct conference *conferences;
157 extern struct buffer_info buffer_debug;
158 extern struct buffer_info buffer_speech;
159 
160 extern time_t last_save;
161 extern char *config_profile;
162 extern int config_changed;
163 extern int ekg2_reason_changed;
164 
165 extern pid_t speech_pid;
166 
167 extern int no_mouse;
168 
169 extern int old_stderr;
170 extern int mesg_startup;
171 
172 extern char *config_away_reason;
173 extern int config_auto_save;
174 extern int config_auto_user_add;
175 extern char *config_back_reason;
176 extern int config_beep;
177 extern int config_beep_msg;
178 extern int config_beep_chat;
179 extern int config_beep_notify;
180 extern int config_completion_notify;
181 extern char *config_completion_char;
182 extern int config_debug;
184 extern int config_display_ack;
185 extern int config_display_blinking;
186 extern int config_display_color;
187 extern char *config_display_color_map;
188 extern int config_display_crap;
189 extern int config_display_day_changed;
190 extern int config_display_notify;
191 extern int config_display_sent;
192 extern int config_display_welcome;
193 extern int config_emoticons;
194 extern int config_events_delay;
195 extern int config_expert_mode;
196 extern int config_history_savedups;
197 extern int config_keep_reason;
198 extern int config_last;
199 extern int config_last_size;
200 extern int config_lastlog_case;
201 extern int config_lastlog_noitems;
202 extern int config_lastlog_display_all;
203 extern int config_make_window;
204 extern int config_mesg;
205 extern int config_query_commands;
206 extern int config_slash_messages;
207 extern char *config_quit_reason;
208 extern int config_save_password;
209 extern int config_save_quit;
210 extern char *config_session_default;
211 extern int config_sessions_save;
212 extern int config_send_white_lines;
213 extern int config_sort_windows;
214 extern char *config_sound_app;
215 extern char *config_sound_chat_file;
216 extern char *config_sound_msg_file;
217 extern char *config_sound_sysmsg_file;
218 extern char *config_sound_notify_file;
219 extern char *config_sound_mail_file;
220 extern char *config_speech_app;
221 extern char *config_subject_prefix;
222 extern char *config_subject_reply_prefix;
223 extern char *config_tab_command;
224 extern char *config_theme;
225 extern int config_time_deviation;
226 extern char *config_timestamp;
227 extern int config_timestamp_show;
228 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.. */
229 extern int config_use_iso; /* this for ncurses */
230 extern char *config_console_charset; /* */
231 extern int config_window_session_allow;
232 extern char *config_windows_layout;
233 extern int config_windows_save;
234 extern char *config_dcc_dir;
235 extern int config_version;
236 extern char *config_exit_exec;
237 extern int config_session_locks;
238 extern char *config_nickname;
239 
240 extern char *home_dir;
241 extern char *config_dir;
242 extern char *console_charset;
243 extern int in_autoexec;
244 extern int ekg_watches_removed;
245 extern time_t ekg_started;
246 
247 extern int quit_message_send;
248 extern int batch_mode;
249 extern char *batch_line;
250 extern struct color_map color_map_default[16+10];
251 
252 void windows_save();
253 
254 int alias_add(const char *string, int quiet, int append);
255 int alias_remove(const char *name, int quiet);
256 void aliases_destroy();
257 
258 char *base64_encode(const char *buf, size_t len);
259 char *base64_decode(const char *buf);
260 
261 int buffer_add(struct buffer_info *type, const char *target, const char *line);
262 int buffer_add_str(struct buffer_info *type, const char *target, const char *str);
263 char *buffer_tail(struct buffer_info *type);
264 void buffer_free(struct buffer_info *type);
265 
266 void changed_auto_save(const char *var);
267 void changed_display_blinking(const char *var);
268 void changed_make_window(const char *var);
269 void changed_mesg(const char *var);
270 void changed_theme(const char *var);
271 
272 const char *compile_time();
273 
274 struct conference *conference_add(session_t *session, const char *string, const char *nicklist, int quiet);
275 int conference_remove(const char *name, int quiet);
276 struct conference *conference_create(session_t *session, const char *nicks);
277 struct conference *conference_find(const char *name);
278 struct conference *conference_find_by_uids(session_t *s, const char *from, const char **recipients, int count, int quiet);
279 int conference_set_ignore(const char *name, int flag, int quiet);
280 int conference_rename(const char *oldname, const char *newname, int quiet);
281 int conference_participant(struct conference *c, const char *uid);
282 void conferences_destroy();
283 
284 /* BEGIN OF newconference API HERE */
285 userlist_t *newconference_member_add(newconference_t *conf, const char *uid, const char *nick);
288 newconference_t *newconference_create(session_t *s, const char *name, int create_wnd);
289 newconference_t *newconference_find(session_t *s, const char *name);
290 void newconference_destroy(newconference_t *conf, int kill_wnd);
292 /* END of newconference API */
293 
294 int ekg_hash(const char *name);
295 
296 FILE *help_path(char *name, char *plugin);
297 
298 int mesg_set(int what);
299 char *strip_spaces(char *line);
300 int strncasecmp_pl(const char * cs,const char * ct,size_t count);
301 int mkdir_recursive(const char *pathname, int isdir);
302 
303 #ifdef __GNUC__
304 char *saprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
305 #else
306 char *saprintf(const char *format, ...);
307 #endif
308 
309 int play_sound(const char *sound_path);
310 
311 const char *prepare_path(const char *filename, int do_mkdir);
312 const char *prepare_pathf(const char *filename, ...);
313 const char *prepare_path_user(const char *path);
314 char *read_file(FILE *f, int alloc);
315 char *read_file_iso(FILE *f, int alloc);
316 
317 const char *timestamp(const char *format);
318 const char *timestamp_time(const char *format, time_t t);
319 char *xstrmid(const char *str, int start, int length);
320 void xstrtr(char *text, char from, char to);
321 char *xstrncat_pl(char *dest, const char *src, size_t n);
322 size_t strlen_pl(const char *s);
323 char color_map(unsigned char r, unsigned char g, unsigned char b);
324 char *strcasestr(const char *haystack, const char *needle);
325 int msg_all(session_t *s, const char *function, const char *what);
326 int say_it(const char *str);
327 char *split_line(char **ptr);
328 
329 int isalpha_pl(unsigned char c);
330 /* makra, dzięki którym pozbywamy się warning'ów */
331 #define xisxdigit(c) isxdigit((int) (unsigned char) c)
332 #define xisdigit(c) isdigit((int) (unsigned char) c)
333 #define xisalpha(c) isalpha_pl((int) (unsigned char) c)
334 #define xisalnum(c) isalnum((int) (unsigned char) c)
335 #define xisspace(c) isspace((int) (unsigned char) c)
336 #define xtolower(c) tolower((int) (unsigned char) c)
337 #define xtoupper(c) toupper((int) (unsigned char) c)
338 
339 struct timer *timer_add(plugin_t *plugin, const char *name, unsigned int period, int persistent, int (*function)(int, void *), void *data);
340 struct timer *timer_add_ms(plugin_t *plugin, const char *name, unsigned int period, int persist, int (*function)(int, void *), void *data);
341 struct timer *timer_add_session(session_t *session, const char *name, unsigned int period, int persist, int (*function)(int, session_t *));
342 struct timer *timer_find_session(session_t *session, const char *name);
343 int timer_remove(plugin_t *plugin, const char *name);
344 int timer_remove_session(session_t *session, const char *name);
345 int timer_remove_user();
346 void timers_remove(struct timer *t);
347 struct timer *timers_removei(struct timer *t);
348 void timers_destroy();
350 
351 const char *ekg_status_label(const int status, const char *descr, const char *prefix);
352 void ekg_update_status(session_t *session);
353 #define ekg_update_status_n(a) ekg_update_status(session_find(a))
354 const char *ekg_status_string(const int status, const int cmd);
355 int ekg_status_int(const char *text);
356 
357 char *ekg_draw_descr(const int status);
358 uint32_t *ekg_sent_message_format(const char *text);
359 
360 void ekg_yield_cpu();
361 
362 /* recode.c XXX, przeniesc do recode.h */
363 void *ekg_convert_string_init(const char *from, const char *to, void **rev);
364 void ekg_convert_string_destroy(void *ptr);
365 char *ekg_convert_string_p(const char *ps, void *ptr);
366 char *ekg_convert_string(const char *ps, const char *from, const char *to);
368 string_t ekg_convert_string_t(string_t s, const char *from, const char *to);
370 
371 char *password_input(const char *prompt, const char *rprompt, const bool norepeat);
372 int is_utf8_string(const char *txt);
373 
374 
375 /* funkcje poza stuff.c */
376 void ekg_exit();
377 void ekg_debug_handler(int level, const char *format, va_list ap);
378 
379 int ekg_close(int fd);
380 int ekg_write(int fd, const char *buf, int len);
381 int ekg_writef(int fd, const char *format, ...);
382 
383 #endif
384 
385 #ifdef __cplusplus
386 }
387 #endif
388 
389 #endif /* __EKG_STUFF_H */
390 
391 /*
392  * Local Variables:
393  * mode: c
394  * c-file-style: "k&r"
395  * c-basic-offset: 8
396  * indent-tabs-mode: t
397  * End:
398  */