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