* Introduced (buggy) support for IMAP IDLE
[monky] / src / conky.h
1 /* Conky, a system monitor, based on torsmo
2  *
3  * Any original torsmo code is licensed under the BSD license
4  *
5  * All code written since the fork of torsmo is licensed under the GPL
6  *
7  * Please see COPYING for details
8  *
9  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10  * Copyright (c) 2005-2008 Brenden Matthews, Philip Kovacs, et. al.
11  *      (see AUTHORS)
12  * All rights reserved.
13  *
14  * This program is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  *
26  * $Id$
27  *
28  */
29
30 #ifndef _conky_h_
31 #define _conky_h_
32
33 #if defined(HAS_MCHECK_H)
34 #include <mcheck.h>
35 #endif /* HAS_MCHECK_H */
36
37 #undef EQUAL
38 #undef FALSE
39 #undef TRUE
40 #define EQUAL 0 //returnvalue of strcmp-variants when strings are equal
41 #define FALSE 0
42 #define TRUE 1
43
44 #include "config.h"
45 #include <sys/utsname.h>
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
49 #include <locale.h>
50 #include <langinfo.h>
51 #include <wchar.h>
52 #include <sys/param.h>
53
54 #if !defined(__GNUC__)
55 #  define __attribute__(x) /* nothing */
56 #endif
57
58 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
59 #include "freebsd.h"
60 #endif /* __FreeBSD__ || __FreeBSD_kernel__ */
61
62 #if defined(__OpenBSD__)
63 #include "openbsd.h"
64 #endif /* __OpenBSD__ */
65
66 #ifndef HAVE_STRNDUP
67 // use our own strndup() if it's not available
68 char *strndup(const char *s, size_t n);
69 #endif /* HAVE_STRNDUP */
70
71 #ifdef AUDACIOUS
72 #include "audacious.h"
73 #endif
74
75 #ifdef XMMS2
76 #include <xmmsclient/xmmsclient.h>
77 #endif
78
79 #ifdef RSS
80 #include "rss.h"
81 #endif
82
83 #ifdef EVE
84 #include "eve.h"
85 #endif
86
87 #ifdef SMAPI
88 #include "smapi.h"
89 #endif
90
91 #ifdef NVIDIA
92 #include "nvidia.h"
93 #endif
94
95 #include "mboxscan.h"
96 #include "timed_thread.h"
97 #include "top.h"
98
99 #define DEFAULT_TEXT_BUFFER_SIZE 256
100 extern unsigned int text_buffer_size;
101
102 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
103 #define MAX_SPECIALS_DEFAULT 512
104
105 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
106 #define MAX_USER_TEXT_DEFAULT 16384
107
108 #include <sys/socket.h>
109
110 #define ERR(...) { \
111         fprintf(stderr, PACKAGE_NAME": "); \
112         fprintf(stderr, __VA_ARGS__); \
113         fprintf(stderr, "\n"); \
114 }
115
116 /* critical error */
117 #define CRIT_ERR(...) \
118         { ERR(__VA_ARGS__); exit(EXIT_FAILURE); }
119
120 struct net_stat {
121         const char *dev;
122         int up;
123         long long last_read_recv, last_read_trans;
124         long long recv, trans;
125         double recv_speed, trans_speed;
126         struct sockaddr addr;
127         char* addrs;
128         double net_rec[15], net_trans[15];
129         // wireless extensions
130         char essid[32];
131         char bitrate[16];
132         char mode[16];
133         int link_qual;
134         int link_qual_max;
135         char ap[18];
136 };
137
138 struct dns_data {
139         int nscount;
140         char **ns_list;
141 };
142
143 struct fs_stat {
144         char path[DEFAULT_TEXT_BUFFER_SIZE];
145         char type[DEFAULT_TEXT_BUFFER_SIZE];
146         long long size;
147         long long avail;
148         long long free;
149         char set;
150 };
151
152 #include "diskio.h"
153
154 struct mail_s {                 // for imap and pop3
155         unsigned long unseen;
156         unsigned long messages;
157         unsigned long used;
158         unsigned long quota;
159         unsigned long port;
160         unsigned int retries;
161         float interval;
162         double last_update;
163         char host[128];
164         char user[128];
165         char pass[128];
166         char command[1024];
167         char folder[128];
168         timed_thread *p_timed_thread;
169         char secure;
170 };
171
172 /* struct cpu_stat {
173         unsigned int user, nice, system, idle, iowait, irq, softirq;
174         int cpu_avg_samples;
175 }; */
176
177 #ifdef MPD
178 #include "mpd.h"
179 #endif
180
181 #ifdef MOC
182 #include "moc.h"
183 #endif
184
185 #ifdef XMMS2
186 #include "xmms2.h"
187 #endif
188
189 #ifdef AUDACIOUS
190 #include "audacious.h"
191 #endif
192
193 #ifdef BMPX
194 #include "bmpx.h"
195 #endif
196
197 void update_entropy(void);
198 struct entropy_s {
199         unsigned int entropy_avail;
200         unsigned int poolsize;
201 };
202
203 struct usr_info {
204         char *names;
205         char *times;
206         char *terms;
207         int number;
208 };
209
210 struct gateway_info {
211         char *iface;
212         char *ip;
213         int count;
214 };
215
216 #ifdef X11
217 struct monitor_info {
218         int number;
219         int current;
220 };
221
222 struct x11_info {
223         struct monitor_info monitor;
224 };
225 #endif
226
227 #ifdef TCP_PORT_MONITOR
228 #include "libtcp-portmon.h"
229 #endif
230
231 enum {
232         INFO_CPU = 0,
233         INFO_MAIL = 1,
234         INFO_MEM = 2,
235         INFO_NET = 3,
236         INFO_PROCS = 4,
237         INFO_RUN_PROCS = 5,
238         INFO_UPTIME = 6,
239         INFO_BUFFERS = 7,
240         INFO_FS = 8,
241         INFO_SYSFS = 9,
242         INFO_MIXER = 10,
243         INFO_LOADAVG = 11,
244         INFO_UNAME = 12,
245         INFO_FREQ = 13,
246 #ifdef MPD
247         INFO_MPD = 14,
248 #endif
249         INFO_TOP = 15,
250         INFO_WIFI = 16,
251         INFO_DISKIO = 17,
252         INFO_I8K = 18,
253 #ifdef TCP_PORT_MONITOR
254         INFO_TCP_PORT_MONITOR = 19,
255 #endif
256 #ifdef AUDACIOUS
257         INFO_AUDACIOUS = 20,
258 #endif
259 #ifdef BMPX
260         INFO_BMPX = 21,
261 #endif
262 #ifdef XMMS2
263         INFO_XMMS2 = 22,
264 #endif
265         INFO_ENTROPY = 23,
266 #ifdef RSS
267         INFO_RSS = 24,
268 #endif
269 #ifdef SMAPI
270         INFO_SMAPI = 25,
271 #endif
272         INFO_USERS = 26,
273         INFO_GW = 27,
274 #ifdef NVIDIA
275         INFO_NVIDIA = 28,
276 #endif
277 #ifdef X11
278         INFO_X11 = 29,
279 #endif
280         INFO_DNS = 30,
281 #ifdef MOC
282   INFO_MOC = 31
283 #endif
284 };
285
286 /* get_battery_stuff() item selector */
287 enum {
288         BATTERY_STATUS,
289         BATTERY_TIME
290 };
291
292 /* if_up strictness selector */
293 enum {
294         IFUP_UP,
295         IFUP_LINK,
296         IFUP_ADDR
297 } ifup_strictness;
298
299 /* Update interval */
300 double update_interval;
301
302 volatile int g_signal_pending;
303
304 struct information {
305         unsigned int mask;
306
307         struct utsname uname_s;
308
309         char freq[10];
310
311         double uptime;
312
313         /* memory information in kilobytes */
314         unsigned long long mem, memeasyfree, memfree, memmax, swap, swapmax;
315         unsigned long long bufmem, buffers, cached;
316
317         unsigned short procs;
318         unsigned short run_procs;
319
320         float *cpu_usage;
321         /* struct cpu_stat cpu_summed; what the hell is this? */
322         unsigned int cpu_count;
323         unsigned int cpu_avg_samples;
324
325         unsigned int net_avg_samples;
326
327         float loadavg[3];
328
329         struct mail_s *mail;
330         int mail_running;
331 #ifdef MPD
332         struct mpd_s mpd;
333 #endif
334 #ifdef MOC
335   struct moc_s moc;
336 #endif
337 #ifdef XMMS2
338         struct xmms2_s xmms2;
339         int xmms2_conn_state;
340         xmms_socket_t xmms2_fd;
341         fd_set xmms2_fdset;
342         xmmsc_connection_t *xmms2_conn;
343 #endif
344 #ifdef AUDACIOUS
345         AUDACIOUS_S audacious;
346 #endif
347 #ifdef BMPX
348         struct bmpx_s bmpx;
349 #endif
350         struct usr_info users;
351         struct gateway_info gw_info;
352         struct dns_data nameserver_info;
353         struct process *cpu[10];
354         struct process *memu[10];
355         struct process *first_process;
356         unsigned long looped;
357 #ifdef TCP_PORT_MONITOR
358         tcp_port_monitor_collection_t *p_tcp_port_monitor_collection;
359 #endif
360         struct entropy_s entropy;
361         double music_player_interval;
362
363 #ifdef X11
364         struct x11_info x11;
365 #endif
366
367         short kflags;   /* kernel settings, see enum KFLAG */
368
369         unsigned int diskio_value;
370         unsigned int diskio_read_value;
371         unsigned int diskio_write_value;
372 };
373
374 enum {
375         /* set to true if kernel uses "long" format for /proc/stats */
376         KFLAG_IS_LONGSTAT = 0x01,
377         /* set to true if kernel shows # of threads for the proc value
378          * in sysinfo() call */
379         KFLAG_PROC_IS_THREADS = 0x02
380         /* bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
381         /* KFLAG_NEXT_ONE = 0x04 */
382 };
383
384 #define KFLAG_SETON(a) info.kflags |= a
385 #define KFLAG_SETOFF(a) info.kflags &= (~a)
386 #define KFLAG_FLIP(a) info.kflags ^= a
387 #define KFLAG_ISSET(a) info.kflags & a
388
389 #define TO_X 1
390 #define TO_STDOUT 2
391 int output_methods;
392
393 int top_cpu;
394 int top_mem;
395
396 int use_spacer;
397
398 enum spacer_opts { NO_SPACER = 0, LEFT_SPACER, RIGHT_SPACER };
399
400 char *tmpstring1;
401 char *tmpstring2;
402
403 #ifdef X11
404 #include "x11.h"
405 #endif /* X11 */
406
407 int cpu_separate;
408 int short_units;
409
410 /* struct that has all info */
411 struct information info;
412
413 void signal_handler(int);
414 void reload_config(void);
415 void clean_up(void);
416
417 void update_uname(void);
418 double get_time(void);
419 FILE *open_file(const char *file, int *reported);
420 void variable_substitute(const char *s, char *dest, unsigned int n);
421 void format_seconds(char *buf, unsigned int n, long t);
422 void format_seconds_short(char *buf, unsigned int n, long t);
423 struct net_stat *get_net_stat(const char *dev);
424 void clear_net_stats(void);
425 void free_dns_data(void);
426 void update_dns_data(void);
427 void update_users(void);
428
429 #ifdef X11
430 void update_x11info(void);
431 #endif
432
433 void update_stuff(void);
434
435 int round_to_int(float f);
436
437 extern unsigned long long need_mask;
438
439 extern double current_update_time, last_update_time;
440
441 extern int no_buffers;
442
443 #if defined(__linux__)
444 #include "linux.h"
445 #endif
446
447 #include "fs.h"
448 #include "mixer.h"
449 #include "mail.h"
450
451 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
452                 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
453 int apm_getinfo(int fd, apm_info_t aip);
454 char *get_apm_adapter(void);
455 char *get_apm_battery_life(void);
456 char *get_apm_battery_time(void);
457 #endif
458
459 #ifdef HDDTEMP
460 #include "hddtemp.h"
461 #endif /* HDDTEMP */
462
463 #endif