Overhauled RSS and weather, added $curl.
[monky] / src / text_object.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-2009 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 #ifndef _TEXT_OBJECT_H
28 #define _TEXT_OBJECT_H
29
30 #include "config.h"             /* for the defines */
31 #include "timed_thread.h"       /* timed_thread */
32
33 #ifdef TCP_PORT_MONITOR
34 #include "tcp-portmon.h"        /* tcp_port_monitor_data */
35 #endif
36
37 #include "mail.h"               /* local_mail_s */
38 #include "fs.h"                 /* struct fs_stat */
39
40 #ifdef NVIDIA
41 #include "nvidia.h"             /* nvidia_s */
42 #endif
43
44 enum text_object_type {
45         OBJ_read_tcp,
46         OBJ_addr,
47 #if defined(__linux__)
48         OBJ_addrs,
49 #endif /* __linux__ */
50 #ifndef __OpenBSD__
51         OBJ_acpiacadapter,
52         OBJ_adt746xcpu,
53         OBJ_adt746xfan,
54         OBJ_acpifan,
55         OBJ_acpitemp,
56         OBJ_battery,
57         OBJ_battery_time,
58         OBJ_battery_percent,
59         OBJ_battery_bar,
60         OBJ_battery_short,
61 #endif /* !__OpenBSD__ */
62         OBJ_buffers,
63         OBJ_cached,
64         OBJ_color,
65         OBJ_color0,
66         OBJ_color1,
67         OBJ_color2,
68         OBJ_color3,
69         OBJ_color4,
70         OBJ_color5,
71         OBJ_color6,
72         OBJ_color7,
73         OBJ_color8,
74         OBJ_color9,
75         OBJ_conky_version,
76         OBJ_conky_build_date,
77         OBJ_conky_build_arch,
78         OBJ_font,
79         OBJ_cpu,
80         OBJ_cpubar,
81 #ifdef X11
82         OBJ_cpugauge,
83         OBJ_cpugraph,
84         OBJ_loadgraph,
85 #endif /* X11 */
86         OBJ_diskio,
87         OBJ_diskio_read,
88         OBJ_diskio_write,
89 #ifdef X11
90         OBJ_diskiograph,
91         OBJ_diskiograph_read,
92         OBJ_diskiograph_write,
93 #endif /* X11 */
94         OBJ_downspeed,
95         OBJ_downspeedf,
96 #ifdef X11
97         OBJ_downspeedgraph,
98 #endif /* X11 */
99         OBJ_else,
100         OBJ_endif,
101         OBJ_eval,
102         OBJ_image,
103         OBJ_exec,
104         OBJ_execi,
105         OBJ_texeci,
106         OBJ_execbar,
107         OBJ_execibar,
108 #ifdef X11
109         OBJ_execgauge,
110         OBJ_execgraph,
111         OBJ_execigraph,
112         OBJ_execigauge,
113 #endif /* X11 */
114         OBJ_execp,
115         OBJ_execpi,
116         OBJ_freq,
117         OBJ_freq_g,
118         OBJ_fs_bar,
119         OBJ_fs_bar_free,
120         OBJ_fs_free,
121         OBJ_fs_free_perc,
122         OBJ_fs_size,
123         OBJ_fs_type,
124         OBJ_fs_used,
125         OBJ_fs_used_perc,
126         OBJ_goto,
127         OBJ_tab,
128         OBJ_hr,
129         OBJ_offset,
130         OBJ_voffset,
131         OBJ_alignr,
132         OBJ_alignc,
133         OBJ_i2c,
134         OBJ_platform,
135         OBJ_hwmon,
136 #if defined(__linux__)
137         OBJ_disk_protect,
138         OBJ_i8k_version,
139         OBJ_i8k_bios,
140         OBJ_i8k_serial,
141         OBJ_i8k_cpu_temp,
142         OBJ_i8k_left_fan_status,
143         OBJ_i8k_right_fan_status,
144         OBJ_i8k_left_fan_rpm,
145         OBJ_i8k_right_fan_rpm,
146         OBJ_i8k_ac_status,
147         OBJ_i8k_buttons_status,
148 #if defined(IBM)
149         OBJ_ibm_fan,
150         OBJ_ibm_temps,
151         OBJ_ibm_volume,
152         OBJ_ibm_brightness,
153         OBJ_smapi,
154 #ifdef X11
155         OBJ_smapi_bat_bar,
156 #endif /* X11 */
157         OBJ_smapi_bat_perc,
158         OBJ_smapi_bat_temp,
159         OBJ_smapi_bat_power,
160         OBJ_if_smapi_bat_installed,
161 #endif /* IBM */
162         /* information from sony_laptop kernel module
163          * /sys/devices/platform/sony-laptop */
164         OBJ_sony_fanspeed,
165         OBJ_if_gw,
166         OBJ_ioscheduler,
167         OBJ_gw_iface,
168         OBJ_gw_ip,
169         OBJ_laptop_mode,
170         OBJ_pb_battery,
171         OBJ_voltage_mv,
172         OBJ_voltage_v,
173         OBJ_wireless_essid,
174         OBJ_wireless_mode,
175         OBJ_wireless_bitrate,
176         OBJ_wireless_ap,
177         OBJ_wireless_link_qual,
178         OBJ_wireless_link_qual_max,
179         OBJ_wireless_link_qual_perc,
180         OBJ_wireless_link_bar,
181 #endif /* __linux__ */
182 #if defined(__FreeBSD__) || defined(__linux__)
183         OBJ_if_up,
184 #endif
185         OBJ_if_empty,
186         OBJ_if_match,
187         OBJ_if_existing,
188         OBJ_if_mounted,
189         OBJ_if_running,
190         OBJ_if_updatenr,
191         OBJ_top,
192         OBJ_top_mem,
193         OBJ_top_time,
194 #ifdef IOSTATS
195         OBJ_top_io,
196 #endif
197         OBJ_tail,
198         OBJ_head,
199         OBJ_lines,
200         OBJ_words,
201         OBJ_kernel,
202         OBJ_loadavg,
203         OBJ_machine,
204         OBJ_mails,
205         OBJ_new_mails,
206         OBJ_seen_mails,
207         OBJ_unseen_mails,
208         OBJ_flagged_mails,
209         OBJ_unflagged_mails,
210         OBJ_forwarded_mails,
211         OBJ_unforwarded_mails,
212         OBJ_replied_mails,
213         OBJ_unreplied_mails,
214         OBJ_draft_mails,
215         OBJ_trashed_mails,
216         OBJ_mboxscan,
217         OBJ_mem,
218         OBJ_memeasyfree,
219         OBJ_memfree,
220 #ifdef X11
221         OBJ_memgauge,
222         OBJ_memgraph,
223 #endif /* X11 */
224         OBJ_membar,
225         OBJ_memmax,
226         OBJ_memperc,
227         OBJ_mixer,
228         OBJ_mixerl,
229         OBJ_mixerr,
230 #ifdef X11
231         OBJ_mixerbar,
232         OBJ_mixerlbar,
233         OBJ_mixerrbar,
234 #endif /* X11 */
235         OBJ_if_mixer_mute,
236 #ifdef X11
237         OBJ_monitor,
238         OBJ_monitor_number,
239         OBJ_desktop,
240         OBJ_desktop_number,
241         OBJ_desktop_name,
242 #endif /* X11 */
243         OBJ_nameserver,
244         OBJ_nodename,
245         OBJ_nvidia,
246         OBJ_pre_exec,
247         OBJ_processes,
248         OBJ_running_processes,
249         OBJ_shadecolor,
250         OBJ_outlinecolor,
251         OBJ_stippled_hr,
252         OBJ_swap,
253         OBJ_swapfree,
254         OBJ_swapbar,
255         OBJ_swapmax,
256         OBJ_swapperc,
257         OBJ_sysname,
258         OBJ_text,
259         OBJ_time,
260         OBJ_utime,
261         OBJ_tztime,
262         OBJ_totaldown,
263         OBJ_totalup,
264         OBJ_updates,
265         OBJ_upspeed,
266         OBJ_upspeedf,
267 #ifdef X11
268         OBJ_upspeedgraph,
269 #endif /* X11 */
270         OBJ_uptime,
271         OBJ_uptime_short,
272         OBJ_user_names,
273         OBJ_user_terms,
274         OBJ_user_times,
275         OBJ_user_number,
276         OBJ_imap_messages,
277         OBJ_imap_unseen,
278         OBJ_pop3_unseen,
279         OBJ_pop3_used,
280 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
281                 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
282         OBJ_apm_adapter,
283         OBJ_apm_battery_time,
284         OBJ_apm_battery_life,
285 #endif /* __FreeBSD__ __OpenBSD__ */
286 #ifdef __OpenBSD__
287         OBJ_obsd_sensors_temp,
288         OBJ_obsd_sensors_fan,
289         OBJ_obsd_sensors_volt,
290         OBJ_obsd_vendor,
291         OBJ_obsd_product,
292 #endif /* __OpenBSD__ */
293 #ifdef MPD
294         OBJ_mpd_title,
295         OBJ_mpd_artist,
296         OBJ_mpd_album,
297         OBJ_mpd_random,
298         OBJ_mpd_repeat,
299         OBJ_mpd_vol,
300         OBJ_mpd_bitrate,
301         OBJ_mpd_status,
302         OBJ_mpd_bar,
303         OBJ_mpd_elapsed,
304         OBJ_mpd_length,
305         OBJ_mpd_track,
306         OBJ_mpd_name,
307         OBJ_mpd_file,
308         OBJ_mpd_percent,
309         OBJ_mpd_smart,
310         OBJ_if_mpd_playing,
311 #endif /* MPD */
312 #ifdef MOC
313         OBJ_moc_state,
314         OBJ_moc_file,
315         OBJ_moc_title,
316         OBJ_moc_artist,
317         OBJ_moc_song,
318         OBJ_moc_album,
319         OBJ_moc_totaltime,
320         OBJ_moc_timeleft,
321         OBJ_moc_curtime,
322         OBJ_moc_bitrate,
323         OBJ_moc_rate,
324 #endif /* MOC */
325 #ifdef XMMS2
326         OBJ_xmms2_artist,
327         OBJ_xmms2_album,
328         OBJ_xmms2_title,
329         OBJ_xmms2_genre,
330         OBJ_xmms2_comment,
331         OBJ_xmms2_url,
332         OBJ_xmms2_date,
333         OBJ_xmms2_tracknr,
334         OBJ_xmms2_bitrate,
335         OBJ_xmms2_id,
336         OBJ_xmms2_duration,
337         OBJ_xmms2_elapsed,
338         OBJ_xmms2_size,
339         OBJ_xmms2_percent,
340         OBJ_xmms2_status,
341 #ifdef X11
342         OBJ_xmms2_bar,
343 #endif /* X11 */
344         OBJ_xmms2_smart,
345         OBJ_xmms2_playlist,
346         OBJ_xmms2_timesplayed,
347         OBJ_if_xmms2_connected,
348 #endif /* XMMS2 */
349 #ifdef AUDACIOUS
350         OBJ_audacious_status,
351         OBJ_audacious_title,
352         OBJ_audacious_length,
353         OBJ_audacious_length_seconds,
354         OBJ_audacious_position,
355         OBJ_audacious_position_seconds,
356         OBJ_audacious_bitrate,
357         OBJ_audacious_frequency,
358         OBJ_audacious_channels,
359         OBJ_audacious_filename,
360         OBJ_audacious_playlist_length,
361         OBJ_audacious_playlist_position,
362         OBJ_audacious_main_volume,
363 #ifdef X11
364         OBJ_audacious_bar,
365 #endif /* X11 */
366 #endif /* AUDACIOUS */
367 #ifdef BMPX
368         OBJ_bmpx_title,
369         OBJ_bmpx_artist,
370         OBJ_bmpx_album,
371         OBJ_bmpx_track,
372         OBJ_bmpx_uri,
373         OBJ_bmpx_bitrate,
374 #endif /* BMPX */
375 #ifdef EVE
376         OBJ_eve,
377 #endif /* EVE */
378 #ifdef HAVE_CURL
379         OBJ_curl,
380 #endif /* HAVE_CURL */
381 #ifdef RSS
382         OBJ_rss,
383 #endif /* RSS */
384 #ifdef WEATHER
385         OBJ_weather,
386 #endif /* WEATHER */
387 #ifdef HAVE_LUA
388         OBJ_lua,
389         OBJ_lua_parse,
390         OBJ_lua_bar,
391 #ifdef X11
392         OBJ_lua_graph,
393         OBJ_lua_gauge,
394 #endif /* X11 */
395 #endif /* HAVE_LUA */
396 #ifdef TCP_PORT_MONITOR
397         OBJ_tcp_portmon,
398 #endif /* TCP_PORT_MONITOR */
399 #ifdef HAVE_ICONV
400         OBJ_iconv_start,
401         OBJ_iconv_stop,
402 #endif /* HAVE_ICONV */
403 #ifdef HDDTEMP
404         OBJ_hddtemp,
405 #endif /* HDDTEMP */
406         OBJ_blink,
407         OBJ_to_bytes,
408         OBJ_scroll,
409         OBJ_combine,
410         OBJ_entropy_avail,
411         OBJ_entropy_perc,
412         OBJ_entropy_poolsize,
413         OBJ_entropy_bar,
414 #ifdef APCUPSD
415         OBJ_apcupsd,
416         OBJ_apcupsd_name,
417         OBJ_apcupsd_model,
418         OBJ_apcupsd_upsmode,
419         OBJ_apcupsd_cable,
420         OBJ_apcupsd_status,
421         OBJ_apcupsd_linev,
422         OBJ_apcupsd_load,
423         OBJ_apcupsd_loadbar,
424 #ifdef X11
425         OBJ_apcupsd_loadgraph,
426         OBJ_apcupsd_loadgauge,
427 #endif /* X11 */
428         OBJ_apcupsd_charge,
429         OBJ_apcupsd_timeleft,
430         OBJ_apcupsd_temp,
431         OBJ_apcupsd_lastxfer,
432 #endif /* APCUPSD */
433 };
434
435 struct text_object {
436         struct text_object *next, *prev;        /* doubly linked list of text objects */
437         struct text_object *sub;                /* for objects parsing text into objects */
438         union {
439                 char *s;                /* some string */
440                 int i;                  /* some integer */
441                 long l;                 /* some other integer */
442                 unsigned int sensor;
443                 struct net_stat *net;
444                 struct fs_stat *fs;
445                 struct diskio_stat *diskio;
446                 unsigned char loadavg[3];
447                 unsigned int cpu_index;
448                 struct mail_s *mail;
449
450                 struct {
451                         char *args;
452                         char *output;
453                 } mboxscan;
454
455                 struct {
456                         char *tz;       /* timezone variable */
457                         char *fmt;      /* time display formatting */
458                 } tztime;
459
460                 struct {
461                         struct fs_stat *fs;
462                         int w, h;
463                 } fsbar;                /* 3 */
464
465 #ifdef X11
466                 struct {
467                         int l;
468                         int w, h;
469                 } mixerbar;             /* 3 */
470 #endif
471
472                 struct {
473                         int fd;
474                         int arg;
475                         char devtype[256];
476                         char type[64];
477                         float factor, offset;
478                 } sysfs;
479
480                 struct {
481                         struct text_object *next;
482                         char *s;
483                         int i;
484                         char *str;
485                 } ifblock;
486
487                 struct {
488                         int num;
489                         int type;
490                         int was_parsed;
491                         char *s;
492                 } top;
493
494                 struct {
495                         int wantedlines;
496                         int readlines;
497                         char *logfile;
498                         double last_update;
499                         float interval;
500                         char *buffer;
501                         /* If not -1, a file descriptor to read from when
502                          * logfile is a FIFO. */
503                         int fd;
504                 } tail;
505
506                 struct {
507                         double last_update;
508                         float interval;
509                         char *cmd;
510                         char *buffer;
511                         double data;
512                 } execi;                /* 5 */
513
514                 struct {
515                         float interval;
516                         char *cmd;
517                         char *buffer;
518                         double data;
519                         timed_thread *p_timed_thread;
520                 } texeci;
521
522                 struct {
523                         int a, b;
524                 } pair;                 /* 2 */
525 #ifdef TCP_PORT_MONITOR
526                 struct tcp_port_monitor_data tcp_port_monitor;
527 #endif
528 #ifdef HDDTEMP
529                 struct {
530                         char *addr;
531                         int port;
532                         char *dev;
533                         double update_time;
534                         char *temp;
535                 } hddtemp;              /* 2 */
536 #endif
537 #ifdef EVE
538                 struct {
539                         char *apikey;
540                         char *charid;
541                         char *userid;
542                 } eve;
543 #endif
544 #ifdef HAVE_CURL
545                 struct {
546                         char *uri;
547                         float interval;
548                 } curl;
549 #endif
550 #ifdef RSS
551                 struct {
552                         char *uri;
553                         char *action;
554                         int act_par;
555                         float interval;
556                         unsigned int nrspaces;
557                 } rss;
558 #endif
559 #ifdef WEATHER
560                 struct {
561                         char *uri;
562                         char *data_type;
563                         int interval;
564                 } weather;
565 #endif
566                 struct {
567                         char *text;
568                         unsigned int show;
569                         unsigned int step;
570                         unsigned int start;
571                         long resetcolor;
572                 } scroll;
573
574                 struct {
575                         char *left;
576                         char *seperation;
577                         char *right;
578                 } combine;
579
580                 struct {
581                         char *host;
582                         unsigned int port;
583                 } read_tcp;
584
585                 struct local_mail_s local_mail;
586 #ifdef NVIDIA
587                 struct nvidia_s nvidia;
588 #endif /* NVIDIA */
589
590         } data;
591         int type;
592         int a, b;
593         long line;
594         unsigned int c, d, e;
595         float f;
596         char char_a, char_b;
597 };
598
599 /* text object list helpers */
600 int append_object(struct text_object *root, struct text_object *obj);
601
602 /* ifblock helpers
603  *
604  * Opaque is a pointer to the address of the ifblock stack's top object.
605  * Calling clients should pass the address of a defined void pointer which
606  * was initialised to NULL (empty stack).
607  * */
608 int obj_be_ifblock_if(void **opaque, struct text_object *);
609 int obj_be_ifblock_else(void **opaque, struct text_object *);
610 int obj_be_ifblock_endif(void **opaque, struct text_object *);
611 int ifblock_stack_empty(void **opaque);
612
613 #endif /* _TEXT_OBJECT_H */