sysfs objects: convert to generic object payload
[monky] / src / core.c
1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
2  * vim: ts=4 sw=4 noet ai cindent syntax=c
3  *
4  * Conky, a system monitor, based on torsmo
5  *
6  * Any original torsmo code is licensed under the BSD license
7  *
8  * All code written since the fork of torsmo is licensed under the GPL
9  *
10  * Please see COPYING for details
11  *
12  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
13  * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
14  *      (see AUTHORS)
15  * All rights reserved.
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  * You should have received a copy of the GNU General Public License
27  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
28  *
29  */
30
31 /* local headers */
32 #include "core.h"
33 #include "text_object.h"
34 #include "algebra.h"
35 #include "build.h"
36 #include "colours.h"
37 #include "combine.h"
38 #include "diskio.h"
39 #include "exec.h"
40 #ifdef X11
41 #include "fonts.h"
42 #endif
43 #include "fs.h"
44 #ifdef HAVE_ICONV
45 #include "iconv_tools.h"
46 #endif
47 #include "logging.h"
48 #include "mixer.h"
49 #include "mail.h"
50 #include "mboxscan.h"
51 #include "net_stat.h"
52 #ifdef NVIDIA
53 #include "nvidia.h"
54 #endif
55 #include "read_tcp.h"
56 #include "scroll.h"
57 #include "specials.h"
58 #include "temphelper.h"
59 #include "template.h"
60 #include "tailhead.h"
61 #include "timeinfo.h"
62 #include "top.h"
63
64 #ifdef NCURSES
65 #include <ncurses.h>
66 #endif
67
68 /* check for OS and include appropriate headers */
69 #if defined(__linux__)
70 #include "linux.h"
71 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
72 #include "freebsd.h"
73 #elif defined(__OpenBSD__)
74 #include "openbsd.h"
75 #endif
76
77 /* OS specific prototypes to be implemented by linux.c & Co. */
78 void update_entropy(void);
79
80 #include <string.h>
81 #include <ctype.h>
82
83 /* strip a leading /dev/ if any, following symlinks first
84  *
85  * BEWARE: this function returns a pointer to static content
86  *         which gets overwritten in consecutive calls. I.e.:
87  *         this function is NOT reentrant.
88  */
89 const char *dev_name(const char *path)
90 {
91         static char buf[255];   /* should be enough for pathnames */
92         ssize_t buflen;
93
94         if (!path)
95                 return NULL;
96
97 #define DEV_NAME(x) \
98   x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 ? x + 5 : x
99         if ((buflen = readlink(path, buf, 254)) == -1)
100                 return DEV_NAME(path);
101         buf[buflen] = '\0';
102         return DEV_NAME(buf);
103 #undef DEV_NAME
104 }
105
106 static struct text_object *new_text_object_internal(void)
107 {
108         struct text_object *obj = malloc(sizeof(struct text_object));
109         memset(obj, 0, sizeof(struct text_object));
110         return obj;
111 }
112
113 static struct text_object *create_plain_text(const char *s)
114 {
115         struct text_object *obj;
116
117         if (s == NULL || *s == '\0') {
118                 return NULL;
119         }
120
121         obj = new_text_object_internal();
122
123         obj->type = OBJ_text;
124         obj->data.s = strndup(s, text_buffer_size);
125         return obj;
126 }
127
128 /* construct_text_object() creates a new text_object */
129 struct text_object *construct_text_object(const char *s, const char *arg, long
130                 line, void **ifblock_opaque, void *free_at_crash)
131 {
132         // struct text_object *obj = new_text_object();
133         struct text_object *obj = new_text_object_internal();
134
135         obj->line = line;
136
137 /* helper defines for internal use only */
138 #define __OBJ_HEAD(a, n) if (!strcmp(s, #a)) { \
139         obj->type = OBJ_##a; add_update_callback(n);
140 #define __OBJ_IF obj_be_ifblock_if(ifblock_opaque, obj)
141 #define __OBJ_ARG(...) if (!arg) { CRIT_ERR(obj, free_at_crash, __VA_ARGS__); }
142
143 /* defines to be used below */
144 #define OBJ(a, n) __OBJ_HEAD(a, n) {
145 #define OBJ_ARG(a, n, ...) __OBJ_HEAD(a, n) __OBJ_ARG(__VA_ARGS__) {
146 #define OBJ_IF(a, n) __OBJ_HEAD(a, n) __OBJ_IF; {
147 #define OBJ_IF_ARG(a, n, ...) __OBJ_HEAD(a, n) __OBJ_ARG(__VA_ARGS__) __OBJ_IF; {
148 #define END } } else
149
150 #ifdef X11
151         if (s[0] == '#') {
152                 obj->type = OBJ_color;
153                 obj->data.l = get_x11_color(s);
154         } else
155 #endif /* X11 */
156 #ifdef __OpenBSD__
157         OBJ(freq, 0)
158 #else
159         OBJ(acpitemp, 0)
160                 obj->data.i = open_acpi_temperature(arg);
161         END OBJ(acpiacadapter, 0)
162         END OBJ(freq, 0)
163 #endif /* !__OpenBSD__ */
164                 get_cpu_count();
165                 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
166                                 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
167                         obj->data.cpu_index = 1;
168                         /* NORM_ERR("freq: Invalid CPU number or you don't have that many CPUs! "
169                                 "Displaying the clock for CPU 1."); */
170                 } else {
171                         obj->data.cpu_index = atoi(&arg[0]);
172                 }
173                 obj->a = 1;
174         END OBJ(freq_g, 0)
175                 get_cpu_count();
176                 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
177                                 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
178                         obj->data.cpu_index = 1;
179                         /* NORM_ERR("freq_g: Invalid CPU number or you don't have that many "
180                                 "CPUs! Displaying the clock for CPU 1."); */
181                 } else {
182                         obj->data.cpu_index = atoi(&arg[0]);
183                 }
184                 obj->a = 1;
185         END OBJ_ARG(read_tcp, 0, "read_tcp: Needs \"(host) port\" as argument(s)")
186                 parse_read_tcp_arg(obj, arg, free_at_crash);
187 #if defined(__linux__)
188         END OBJ(voltage_mv, 0)
189                 get_cpu_count();
190                 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
191                                 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
192                         obj->data.cpu_index = 1;
193                         /* NORM_ERR("voltage_mv: Invalid CPU number or you don't have that many "
194                                 "CPUs! Displaying voltage for CPU 1."); */
195                 } else {
196                         obj->data.cpu_index = atoi(&arg[0]);
197                 }
198                 obj->a = 1;
199         END OBJ(voltage_v, 0)
200                 get_cpu_count();
201                 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
202                                 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
203                         obj->data.cpu_index = 1;
204                         /* NORM_ERR("voltage_v: Invalid CPU number or you don't have that many "
205                                 "CPUs! Displaying voltage for CPU 1."); */
206                 } else {
207                         obj->data.cpu_index = atoi(&arg[0]);
208                 }
209                 obj->a = 1;
210
211 #ifdef HAVE_IWLIB
212         END OBJ(wireless_essid, &update_net_stats)
213                 parse_net_stat_arg(obj, arg, free_at_crash);
214         END OBJ(wireless_mode, &update_net_stats)
215                 parse_net_stat_arg(obj, arg, free_at_crash);
216         END OBJ(wireless_bitrate, &update_net_stats)
217                 parse_net_stat_arg(obj, arg, free_at_crash);
218         END OBJ(wireless_ap, &update_net_stats)
219                 parse_net_stat_arg(obj, arg, free_at_crash);
220         END OBJ(wireless_link_qual, &update_net_stats)
221                 parse_net_stat_arg(obj, arg, free_at_crash);
222         END OBJ(wireless_link_qual_max, &update_net_stats)
223                 parse_net_stat_arg(obj, arg, free_at_crash);
224         END OBJ(wireless_link_qual_perc, &update_net_stats)
225                 parse_net_stat_arg(obj, arg, free_at_crash);
226         END OBJ(wireless_link_bar, &update_net_stats)
227                 parse_net_stat_bar_arg(obj, arg, free_at_crash);
228 #endif /* HAVE_IWLIB */
229
230 #endif /* __linux__ */
231
232 #ifndef __OpenBSD__
233         END OBJ(acpifan, 0)
234         END OBJ(battery, 0)
235                 char bat[64];
236
237                 if (arg) {
238                         sscanf(arg, "%63s", bat);
239                 } else {
240                         strcpy(bat, "BAT0");
241                 }
242                 obj->data.s = strndup(bat, text_buffer_size);
243         END OBJ(battery_short, 0)
244                 char bat[64];
245
246                 if (arg) {
247                         sscanf(arg, "%63s", bat);
248                 } else {
249                         strcpy(bat, "BAT0");
250                 }
251                 obj->data.s = strndup(bat, text_buffer_size);
252         END OBJ(battery_time, 0)
253                 char bat[64];
254
255                 if (arg) {
256                         sscanf(arg, "%63s", bat);
257                 } else {
258                         strcpy(bat, "BAT0");
259                 }
260                 obj->data.s = strndup(bat, text_buffer_size);
261         END OBJ(battery_percent, 0)
262                 char bat[64];
263
264                 if (arg) {
265                         sscanf(arg, "%63s", bat);
266                 } else {
267                         strcpy(bat, "BAT0");
268                 }
269                 obj->data.s = strndup(bat, text_buffer_size);
270         END OBJ(battery_bar, 0)
271                 char bat[64];
272                 SIZE_DEFAULTS(bar);
273                 obj->b = 6;
274                 if (arg) {
275                         arg = scan_bar(arg, &obj->a, &obj->b);
276                         sscanf(arg, "%63s", bat);
277                 } else {
278                         strcpy(bat, "BAT0");
279                 }
280                 obj->data.s = strndup(bat, text_buffer_size);
281 #endif /* !__OpenBSD__ */
282
283 #if defined(__linux__)
284         END OBJ_ARG(disk_protect, 0, "disk_protect needs an argument")
285                 obj->data.s = strndup(dev_name(arg), text_buffer_size);
286         END OBJ(i8k_version, &update_i8k)
287         END OBJ(i8k_bios, &update_i8k)
288         END OBJ(i8k_serial, &update_i8k)
289         END OBJ(i8k_cpu_temp, &update_i8k)
290         END OBJ(i8k_left_fan_status, &update_i8k)
291         END OBJ(i8k_right_fan_status, &update_i8k)
292         END OBJ(i8k_left_fan_rpm, &update_i8k)
293         END OBJ(i8k_right_fan_rpm, &update_i8k)
294         END OBJ(i8k_ac_status, &update_i8k)
295         END OBJ(i8k_buttons_status, &update_i8k)
296 #if defined(IBM)
297         END OBJ(ibm_fan, 0)
298         END OBJ(ibm_temps, &get_ibm_acpi_temps, "ibm_temps: needs an argument")
299                 parse_ibm_temps_arg(obj, arg);
300         END OBJ(ibm_volume, 0)
301         END OBJ(ibm_brightness, 0)
302 #endif
303         /* information from sony_laptop kernel module
304          * /sys/devices/platform/sony-laptop */
305         END OBJ(sony_fanspeed, 0)
306         END OBJ_IF(if_gw, &update_gateway_info)
307         END OBJ_ARG(ioscheduler, 0, "get_ioscheduler needs an argument (e.g. hda)")
308                 obj->data.s = strndup(dev_name(arg), text_buffer_size);
309         END OBJ(laptop_mode, 0)
310         END OBJ_ARG(pb_battery, 0, "pb_battery: needs one argument: status, percent or time")
311                 if (strcmp(arg, "status") == EQUAL) {
312                         obj->data.i = PB_BATT_STATUS;
313                 } else if (strcmp(arg, "percent") == EQUAL) {
314                         obj->data.i = PB_BATT_PERCENT;
315                 } else if (strcmp(arg, "time") == EQUAL) {
316                         obj->data.i = PB_BATT_TIME;
317                 } else {
318                         NORM_ERR("pb_battery: illegal argument '%s', defaulting to status", arg);
319                         obj->data.i = PB_BATT_STATUS;
320                 }
321 #endif /* __linux__ */
322 #if (defined(__FreeBSD__) || defined(__linux__))
323         END OBJ_IF_ARG(if_up, 0, "if_up needs an argument")
324                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
325 #endif
326 #if defined(__OpenBSD__)
327         END OBJ_ARG(obsd_sensors_temp, 0, "obsd_sensors_temp: needs an argument")
328                 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
329                                 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
330                         obj->data.sensor = 0;
331                         NORM_ERR("Invalid temperature sensor number!");
332                 } else
333                         obj->data.sensor = atoi(&arg[0]);
334         END OBJ_ARG(obsd_sensors_fan, 0, "obsd_sensors_fan: needs 2 arguments (device and sensor number)")
335                 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
336                                 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
337                         obj->data.sensor = 0;
338                         NORM_ERR("Invalid fan sensor number!");
339                 } else
340                         obj->data.sensor = atoi(&arg[0]);
341         END OBJ_ARG(obsd_sensors_volt, 0, "obsd_sensors_volt: needs 2 arguments (device and sensor number)")
342                 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
343                                 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
344                         obj->data.sensor = 0;
345                         NORM_ERR("Invalid voltage sensor number!");
346                 } else
347                         obj->data.sensor = atoi(&arg[0]);
348         END OBJ(obsd_vendor, 0)
349         END OBJ(obsd_product, 0)
350 #endif /* __OpenBSD__ */
351         END OBJ(buffers, &update_meminfo)
352         END OBJ(cached, &update_meminfo)
353 #define SCAN_CPU(__arg, __var) { \
354         int __offset = 0; \
355         if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \
356                 __arg += __offset; \
357         else \
358                 __var = 0; \
359 }
360         END OBJ(cpu, &update_cpu_usage)
361                 SCAN_CPU(arg, obj->data.cpu_index);
362                 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
363 #ifdef X11
364         END OBJ(cpugauge, &update_cpu_usage)
365                 SIZE_DEFAULTS(gauge);
366                 SCAN_CPU(arg, obj->data.cpu_index);
367                 scan_gauge(arg, &obj->a, &obj->b);
368                 DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
369 #endif /* X11 */
370         END OBJ(cpubar, &update_cpu_usage)
371                 SIZE_DEFAULTS(bar);
372                 SCAN_CPU(arg, obj->data.cpu_index);
373                 scan_bar(arg, &obj->a, &obj->b);
374                 DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
375 #ifdef X11
376         END OBJ(cpugraph, &update_cpu_usage)
377                 char *buf = 0;
378                 SIZE_DEFAULTS(graph);
379                 SCAN_CPU(arg, obj->data.cpu_index);
380                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
381                         &obj->e, &obj->char_a, &obj->char_b);
382                 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
383                 if (buf) free(buf);
384         END OBJ(loadgraph, &update_load_average)
385                 char *buf = 0;
386                 SIZE_DEFAULTS(graph);
387                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
388                                 &obj->e, &obj->char_a, &obj->char_b);
389                 if (buf) {
390                         int a = 1, r = 3;
391                         if (arg) {
392                                 r = sscanf(arg, "%d", &a);
393                         }
394                         obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
395                         free(buf);
396                 }
397 #endif /* X11 */
398         END OBJ(diskio, &update_diskio)
399                 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
400         END OBJ(diskio_read, &update_diskio)
401                 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
402         END OBJ(diskio_write, &update_diskio)
403                 obj->data.diskio = prepare_diskio_stat(dev_name(arg));
404 #ifdef X11
405         END OBJ(diskiograph, &update_diskio)
406                 char *buf = 0;
407                 SIZE_DEFAULTS(graph);
408                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
409                                 &obj->e, &obj->char_a, &obj->char_b);
410
411                 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
412                 if (buf) free(buf);
413         END OBJ(diskiograph_read, &update_diskio)
414                 char *buf = 0;
415                 SIZE_DEFAULTS(graph);
416                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
417                                 &obj->e, &obj->char_a, &obj->char_b);
418
419                 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
420                 if (buf) free(buf);
421         END OBJ(diskiograph_write, &update_diskio)
422                 char *buf = 0;
423                 SIZE_DEFAULTS(graph);
424                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
425                                 &obj->e, &obj->char_a, &obj->char_b);
426
427                 obj->data.diskio = prepare_diskio_stat(dev_name(buf));
428                 if (buf) free(buf);
429 #endif /* X11 */
430         END OBJ(color, 0)
431 #ifdef X11
432                 if (output_methods & TO_X) {
433                         obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
434                         set_current_text_color(obj->data.l);
435                 }
436 #endif /* X11 */
437 #ifdef NCURSES
438                 if (output_methods & TO_NCURSES) {
439                         obj->data.l = COLOR_WHITE;
440                         if(arg) {
441                                 if(strcasecmp(arg, "red") == 0) {
442                                         obj->data.l = COLOR_RED;
443                                 }else if(strcasecmp(arg, "green") == 0) {
444                                         obj->data.l = COLOR_GREEN;
445                                 }else if(strcasecmp(arg, "yellow") == 0) {
446                                         obj->data.l = COLOR_YELLOW;
447                                 }else if(strcasecmp(arg, "blue") == 0) {
448                                         obj->data.l = COLOR_BLUE;
449                                 }else if(strcasecmp(arg, "magenta") == 0) {
450                                         obj->data.l = COLOR_MAGENTA;
451                                 }else if(strcasecmp(arg, "cyan") == 0) {
452                                         obj->data.l = COLOR_CYAN;
453                                 }else if(strcasecmp(arg, "black") == 0) {
454                                         obj->data.l = COLOR_BLACK;
455                                 }
456                         }
457                         set_current_text_color(obj->data.l);
458                         init_pair(obj->data.l, obj->data.l, COLOR_BLACK);
459                 }
460 #endif /* NCURSES */
461         END OBJ(color0, 0)
462                 obj->data.l = color0;
463                 set_current_text_color(obj->data.l);
464         END OBJ(color1, 0)
465                 obj->data.l = color1;
466                 set_current_text_color(obj->data.l);
467         END OBJ(color2, 0)
468                 obj->data.l = color2;
469                 set_current_text_color(obj->data.l);
470         END OBJ(color3, 0)
471                 obj->data.l = color3;
472                 set_current_text_color(obj->data.l);
473         END OBJ(color4, 0)
474                 obj->data.l = color4;
475                 set_current_text_color(obj->data.l);
476         END OBJ(color5, 0)
477                 obj->data.l = color5;
478                 set_current_text_color(obj->data.l);
479         END OBJ(color6, 0)
480                 obj->data.l = color6;
481                 set_current_text_color(obj->data.l);
482         END OBJ(color7, 0)
483                 obj->data.l = color7;
484                 set_current_text_color(obj->data.l);
485         END OBJ(color8, 0)
486                 obj->data.l = color8;
487                 set_current_text_color(obj->data.l);
488         END OBJ(color9, 0)
489                 obj->data.l = color9;
490                 set_current_text_color(obj->data.l);
491 #ifdef X11
492         END OBJ(font, 0)
493                 obj->data.s = scan_font(arg);
494 #endif /* X11 */
495         END OBJ(conky_version, 0)
496         END OBJ(conky_build_date, 0)
497         END OBJ(conky_build_arch, 0)
498         END OBJ(downspeed, &update_net_stats)
499                 parse_net_stat_arg(obj, arg, free_at_crash);
500         END OBJ(downspeedf, &update_net_stats)
501                 parse_net_stat_arg(obj, arg, free_at_crash);
502 #ifdef X11
503         END OBJ(downspeedgraph, &update_net_stats)
504                 parse_net_stat_graph_arg(obj, arg, free_at_crash);
505 #endif /* X11 */
506         END OBJ(else, 0)
507                 obj_be_ifblock_else(ifblock_opaque, obj);
508         END OBJ(endif, 0)
509                 obj_be_ifblock_endif(ifblock_opaque, obj);
510         END OBJ(eval, 0)
511                 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
512 #if defined(IMLIB2) && defined(X11)
513         END OBJ(image, 0)
514                 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
515 #endif /* IMLIB2 */
516         END OBJ(exec, 0)
517                 scan_exec_arg(obj, arg);
518         END OBJ(execp, 0)
519                 scan_exec_arg(obj, arg);
520         END OBJ(execbar, 0)
521                 SIZE_DEFAULTS(bar);
522                 scan_exec_arg(obj, arg);
523 #ifdef X11
524         END OBJ(execgauge, 0)
525                 SIZE_DEFAULTS(gauge);
526                 scan_exec_arg(obj, arg);
527         END OBJ(execgraph, 0)
528                 SIZE_DEFAULTS(graph);
529                 scan_exec_arg(obj, arg);
530 #endif /* X11 */
531         END OBJ_ARG(execibar, 0, "execibar needs arguments")
532                 SIZE_DEFAULTS(bar);
533                 scan_execi_arg(obj, arg);
534 #ifdef X11
535         END OBJ_ARG(execigraph, 0, "execigraph needs arguments")
536                 SIZE_DEFAULTS(graph);
537                 scan_execi_arg(obj, arg);
538         END OBJ_ARG(execigauge, 0, "execigauge needs arguments")
539                 SIZE_DEFAULTS(gauge);
540                 scan_execi_arg(obj, arg);
541 #endif /* X11 */
542         END OBJ_ARG(execi, 0, "execi needs arguments")
543                 scan_execi_arg(obj, arg);
544         END OBJ_ARG(execpi, 0, "execpi needs arguments")
545                 scan_execi_arg(obj, arg);
546         END OBJ_ARG(texeci, 0, "texeci needs arguments")
547                 scan_execi_arg(obj, arg);
548         END OBJ(pre_exec, 0)
549                 scan_pre_exec_arg(obj, arg);
550         END OBJ(fs_bar, &update_fs_stats)
551                 init_fs_bar(obj, arg);
552         END OBJ(fs_bar_free, &update_fs_stats)
553                 init_fs_bar(obj, arg);
554         END OBJ(fs_free, &update_fs_stats)
555                 init_fs(obj, arg);
556         END OBJ(fs_used_perc, &update_fs_stats)
557                 init_fs(obj, arg);
558         END OBJ(fs_free_perc, &update_fs_stats)
559                 init_fs(obj, arg);
560         END OBJ(fs_size, &update_fs_stats)
561                 init_fs(obj, arg);
562         END OBJ(fs_type, &update_fs_stats)
563                 init_fs(obj, arg);
564         END OBJ(fs_used, &update_fs_stats)
565                 init_fs(obj, arg);
566         END OBJ(hr, 0)
567                 obj->data.i = arg ? atoi(arg) : 1;
568         END OBJ(nameserver, &update_dns_data)
569                 parse_nameserver_arg(obj, arg);
570         END OBJ(offset, 0)
571                 obj->data.i = arg ? atoi(arg) : 1;
572         END OBJ(voffset, 0)
573                 obj->data.i = arg ? atoi(arg) : 1;
574         END OBJ_ARG(goto, 0, "goto needs arguments")
575                 obj->data.i = atoi(arg);
576         END OBJ(tab, 0)
577                 int a = 10, b = 0;
578
579                 if (arg) {
580                         if (sscanf(arg, "%d %d", &a, &b) != 2) {
581                                 sscanf(arg, "%d", &b);
582                         }
583                 }
584                 if (a <= 0) {
585                         a = 1;
586                 }
587                 obj->data.pair.a = a;
588                 obj->data.pair.b = b;
589
590 #ifdef __linux__
591         END OBJ_ARG(i2c, 0, "i2c needs arguments")
592                 parse_i2c_sensor(obj, arg);
593         END OBJ_ARG(platform, 0, "platform needs arguments")
594                 parse_platform_sensor(obj, arg);
595         END OBJ_ARG(hwmon, 0, "hwmon needs argumanets")
596                 parse_hwmon_sensor(obj, arg);
597 #endif /* __linux__ */
598
599         END
600         /* we have four different types of top (top, top_mem, top_time and top_io). To
601          * avoid having almost-same code four times, we have this special
602          * handler. */
603         if (strncmp(s, "top", 3) == EQUAL) {
604                 add_update_callback(&update_meminfo);
605                 add_update_callback(&update_top);
606                 if (!parse_top_args(s, arg, obj)) {
607                         return NULL;
608                 }
609         } else OBJ(addr, &update_net_stats)
610                 parse_net_stat_arg(obj, arg, free_at_crash);
611 #if defined(__linux__)
612         END OBJ(addrs, &update_net_stats)
613                 parse_net_stat_arg(obj, arg, free_at_crash);
614 #endif /* __linux__ */
615         END OBJ_ARG(tail, 0, "tail needs arguments")
616                 init_tailhead("tail", arg, obj, free_at_crash);
617         END OBJ_ARG(head, 0, "head needs arguments")
618                 init_tailhead("head", arg, obj, free_at_crash);
619         END OBJ_ARG(lines, 0, "lines needs an argument")
620                 obj->data.s = strndup(arg, text_buffer_size);
621         END OBJ_ARG(words, 0, "words needs a argument")
622                 obj->data.s = strndup(arg, text_buffer_size);
623         END OBJ(loadavg, &update_load_average)
624                 int a = 1, b = 2, c = 3, r = 3;
625
626                 if (arg) {
627                         r = sscanf(arg, "%d %d %d", &a, &b, &c);
628                         if (r >= 3 && (c < 1 || c > 3)) {
629                                 r--;
630                         }
631                         if (r >= 2 && (b < 1 || b > 3)) {
632                                 r--, b = c;
633                         }
634                         if (r >= 1 && (a < 1 || a > 3)) {
635                                 r--, a = b, b = c;
636                         }
637                 }
638                 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
639                 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
640                 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
641         END OBJ_IF_ARG(if_empty, 0, "if_empty needs an argument")
642                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
643                 obj->sub = malloc(sizeof(struct text_object));
644                 extract_variable_text_internal(obj->sub, obj->data.ifblock.s);
645         END OBJ_IF_ARG(if_match, 0, "if_match needs arguments")
646                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
647                 obj->sub = malloc(sizeof(struct text_object));
648                 extract_variable_text_internal(obj->sub, obj->data.ifblock.s);
649         END OBJ_IF_ARG(if_existing, 0, "if_existing needs an argument or two")
650                 char buf1[256], buf2[256];
651                 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
652
653                 if (r == 1) {
654                         obj->data.ifblock.s = strndup(buf1, text_buffer_size);
655                         obj->data.ifblock.str = NULL;
656                 } else {
657                         obj->data.ifblock.s = strndup(buf1, text_buffer_size);
658                         obj->data.ifblock.str = strndup(buf2, text_buffer_size);
659                 }
660                 DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
661         END OBJ_IF_ARG(if_mounted, 0, "if_mounted needs an argument")
662                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
663 #ifdef __linux__
664         END OBJ_IF_ARG(if_running, &update_top, "if_running needs an argument")
665                 top_running = 1;
666                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
667 #else
668         END OBJ_IF_ARG(if_running, 0, "if_running needs an argument")
669                 char buf[256];
670
671                 snprintf(buf, 256, "pidof %s >/dev/null", arg);
672                 obj->data.ifblock.s = strndup(buf, text_buffer_size);
673 #endif
674         END OBJ(kernel, 0)
675         END OBJ(machine, 0)
676         END OBJ(mails, 0)
677                 parse_local_mail_args(obj, arg);
678         END OBJ(new_mails, 0)
679                 parse_local_mail_args(obj, arg);
680         END OBJ(seen_mails, 0)
681                 parse_local_mail_args(obj, arg);
682         END OBJ(unseen_mails, 0)
683                 parse_local_mail_args(obj, arg);
684         END OBJ(flagged_mails, 0)
685                 parse_local_mail_args(obj, arg);
686         END OBJ(unflagged_mails, 0)
687                 parse_local_mail_args(obj, arg);
688         END OBJ(forwarded_mails, 0)
689                 parse_local_mail_args(obj, arg);
690         END OBJ(unforwarded_mails, 0)
691                 parse_local_mail_args(obj, arg);
692         END OBJ(replied_mails, 0)
693                 parse_local_mail_args(obj, arg);
694         END OBJ(unreplied_mails, 0)
695                 parse_local_mail_args(obj, arg);
696         END OBJ(draft_mails, 0)
697                 parse_local_mail_args(obj, arg);
698         END OBJ(trashed_mails, 0)
699                 parse_local_mail_args(obj, arg);
700         END OBJ(mboxscan, 0)
701                 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
702                 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
703                 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
704                 obj->data.mboxscan.output[0] = 1;
705                 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
706         END OBJ(mem, &update_meminfo)
707         END OBJ(memeasyfree, &update_meminfo)
708         END OBJ(memfree, &update_meminfo)
709         END OBJ(memmax, &update_meminfo)
710         END OBJ(memperc, &update_meminfo)
711 #ifdef X11
712         END OBJ(memgauge, &update_meminfo)
713                 SIZE_DEFAULTS(gauge);
714                 scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
715 #endif /* X11*/
716         END OBJ(membar, &update_meminfo)
717                 SIZE_DEFAULTS(bar);
718                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
719 #ifdef X11
720         END OBJ(memgraph, &update_meminfo)
721                 char *buf = 0;
722                 SIZE_DEFAULTS(graph);
723                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
724                                 &obj->e, &obj->char_a, &obj->char_b);
725
726                 if (buf) free(buf);
727 #endif /* X11*/
728         END OBJ(mixer, 0)
729                 obj->data.l = mixer_init(arg);
730         END OBJ(mixerl, 0)
731                 obj->data.l = mixer_init(arg);
732         END OBJ(mixerr, 0)
733                 obj->data.l = mixer_init(arg);
734 #ifdef X11
735         END OBJ(mixerbar, 0)
736                 SIZE_DEFAULTS(bar);
737                 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
738                         &obj->data.mixerbar.h);
739         END OBJ(mixerlbar, 0)
740                 SIZE_DEFAULTS(bar);
741                 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
742                         &obj->data.mixerbar.h);
743         END OBJ(mixerrbar, 0)
744                 SIZE_DEFAULTS(bar);
745                 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
746                         &obj->data.mixerbar.h);
747 #endif
748         END OBJ_IF(if_mixer_mute, 0)
749                 obj->data.ifblock.i = mixer_init(arg);
750 #ifdef X11
751         END OBJ(monitor, &update_x11info)
752         END OBJ(monitor_number, &update_x11info)
753         END OBJ(desktop, &update_x11info)
754         END OBJ(desktop_number, &update_x11info)
755         END OBJ(desktop_name, &update_x11info)
756 #endif
757         END OBJ(nodename, 0)
758         END OBJ(processes, &update_total_processes)
759         END OBJ(running_processes, &update_running_processes)
760         END OBJ(shadecolor, 0)
761 #ifdef X11
762                 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
763 #endif /* X11 */
764         END OBJ(outlinecolor, 0)
765 #ifdef X11
766                 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
767 #endif /* X11 */
768         END OBJ(stippled_hr, 0)
769 #ifdef X11
770                 int a = get_stippled_borders(), b = 1;
771
772                 if (arg) {
773                         if (sscanf(arg, "%d %d", &a, &b) != 2) {
774                                 sscanf(arg, "%d", &b);
775                         }
776                 }
777                 if (a <= 0) {
778                         a = 1;
779                 }
780                 obj->data.pair.a = a;
781                 obj->data.pair.b = b;
782 #endif /* X11 */
783         END OBJ(swap, &update_meminfo)
784         END OBJ(swapfree, &update_meminfo)
785         END OBJ(swapmax, &update_meminfo)
786         END OBJ(swapperc, &update_meminfo)
787         END OBJ(swapbar, &update_meminfo)
788                 SIZE_DEFAULTS(bar);
789                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
790         END OBJ(sysname, 0)
791         END OBJ(time, 0)
792                 scan_time(obj, arg);
793         END OBJ(utime, 0)
794                 scan_time(obj, arg);
795         END OBJ(tztime, 0)
796                 scan_tztime(obj, arg);
797 #ifdef HAVE_ICONV
798         END OBJ_ARG(iconv_start, 0, "Iconv requires arguments")
799                 init_iconv_start(obj, free_at_crash, arg);
800         END OBJ(iconv_stop, 0)
801                 init_iconv_stop();
802 #endif
803         END OBJ(totaldown, &update_net_stats)
804                 parse_net_stat_arg(obj, arg, free_at_crash);
805         END OBJ(totalup, &update_net_stats)
806                 parse_net_stat_arg(obj, arg, free_at_crash);
807         END OBJ(updates, 0)
808         END OBJ_IF(if_updatenr, 0)
809                 obj->data.ifblock.i = arg ? atoi(arg) : 0;
810                 if(obj->data.ifblock.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument");
811                 set_updatereset(obj->data.ifblock.i > get_updatereset() ? obj->data.ifblock.i : get_updatereset());
812         END OBJ(alignr, 0)
813                 obj->data.i = arg ? atoi(arg) : 0;
814         END OBJ(alignc, 0)
815                 obj->data.i = arg ? atoi(arg) : 0;
816         END OBJ(upspeed, &update_net_stats)
817                 parse_net_stat_arg(obj, arg, free_at_crash);
818         END OBJ(upspeedf, &update_net_stats)
819                 parse_net_stat_arg(obj, arg, free_at_crash);
820 #ifdef X11
821         END OBJ(upspeedgraph, &update_net_stats)
822                 parse_net_stat_graph_arg(obj, arg, free_at_crash);
823 #endif
824         END OBJ(uptime_short, &update_uptime)
825         END OBJ(uptime, &update_uptime)
826         END OBJ(user_names, &update_users)
827         END OBJ(user_times, &update_users)
828         END OBJ(user_terms, &update_users)
829         END OBJ(user_number, &update_users)
830 #if defined(__linux__)
831         END OBJ(gw_iface, &update_gateway_info)
832         END OBJ(gw_ip, &update_gateway_info)
833 #endif /* !__linux__ */
834 #ifndef __OpenBSD__
835         END OBJ(adt746xcpu, 0)
836         END OBJ(adt746xfan, 0)
837 #endif /* !__OpenBSD__ */
838 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
839                 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
840         END OBJ(apm_adapter, 0)
841         END OBJ(apm_battery_life, 0)
842         END OBJ(apm_battery_time, 0)
843 #endif /* __FreeBSD__ */
844         END OBJ(imap_unseen, 0)
845                 parse_imap_mail_args(obj, arg);
846         END OBJ(imap_messages, 0)
847                 parse_imap_mail_args(obj, arg);
848         END OBJ(pop3_unseen, 0)
849                 parse_pop3_mail_args(obj, arg);
850         END OBJ(pop3_used, 0)
851                 parse_pop3_mail_args(obj, arg);
852 #ifdef IBM
853         END OBJ_ARG(smapi, 0, "smapi needs an argument")
854                 obj->data.s = strndup(arg, text_buffer_size);
855         END OBJ_IF_ARG(if_smapi_bat_installed, 0, "if_smapi_bat_installed needs an argument")
856                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
857         END OBJ_ARG(smapi_bat_perc, 0, "smapi_bat_perc needs an argument")
858                 obj->data.s = strndup(arg, text_buffer_size);
859         END OBJ_ARG(smapi_bat_temp, 0, "smapi_bat_temp needs an argument")
860                 obj->data.s = strndup(arg, text_buffer_size);
861         END OBJ_ARG(smapi_bat_power, 0, "smapi_bat_power needs an argument")
862                 obj->data.s = strndup(arg, text_buffer_size);
863 #ifdef X11
864         END OBJ_ARG(smapi_bat_bar, 0, "smapi_bat_bar needs an argument")
865                 int cnt;
866                 SIZE_DEFAULTS(bar);
867                 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
868                         NORM_ERR("first argument to smapi_bat_bar must be an integer value");
869                         obj->data.i = -1;
870                 } else {
871                         obj->b = 4;
872                         arg = scan_bar(arg + cnt, &obj->a, &obj->b);
873                 }
874 #endif /* X11 */
875 #endif /* IBM */
876 #ifdef MPD
877 #define mpd_set_maxlen(name) \
878                 if (arg) { \
879                         int i; \
880                         sscanf(arg, "%d", &i); \
881                         if (i > 0) \
882                                 obj->data.i = i + 1; \
883                         else \
884                                 NORM_ERR(#name ": invalid length argument"); \
885                 }
886         END OBJ(mpd_artist, &update_mpd)
887                 mpd_set_maxlen(mpd_artist);
888                 init_mpd();
889         END OBJ(mpd_title, &update_mpd)
890                 mpd_set_maxlen(mpd_title);
891                 init_mpd();
892         END OBJ(mpd_random, &update_mpd) init_mpd();
893         END OBJ(mpd_repeat, &update_mpd) init_mpd();
894         END OBJ(mpd_elapsed, &update_mpd) init_mpd();
895         END OBJ(mpd_length, &update_mpd) init_mpd();
896         END OBJ(mpd_track, &update_mpd)
897                 mpd_set_maxlen(mpd_track);
898                 init_mpd();
899         END OBJ(mpd_name, &update_mpd)
900                 mpd_set_maxlen(mpd_name);
901                 init_mpd();
902         END OBJ(mpd_file, &update_mpd)
903                 mpd_set_maxlen(mpd_file);
904                 init_mpd();
905         END OBJ(mpd_percent, &update_mpd) init_mpd();
906         END OBJ(mpd_album, &update_mpd)
907                 mpd_set_maxlen(mpd_album);
908                 init_mpd();
909         END OBJ(mpd_vol, &update_mpd) init_mpd();
910         END OBJ(mpd_bitrate, &update_mpd) init_mpd();
911         END OBJ(mpd_status, &update_mpd) init_mpd();
912         END OBJ(mpd_bar, &update_mpd)
913                 SIZE_DEFAULTS(bar);
914                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
915                 init_mpd();
916         END OBJ(mpd_smart, &update_mpd)
917                 mpd_set_maxlen(mpd_smart);
918                 init_mpd();
919         END OBJ_IF(if_mpd_playing, &update_mpd)
920                 init_mpd();
921 #undef mpd_set_maxlen
922 #endif /* MPD */
923 #ifdef MOC
924         END OBJ(moc_state, &update_moc)
925         END OBJ(moc_file, &update_moc)
926         END OBJ(moc_title, &update_moc)
927         END OBJ(moc_artist, &update_moc)
928         END OBJ(moc_song, &update_moc)
929         END OBJ(moc_album, &update_moc)
930         END OBJ(moc_totaltime, &update_moc)
931         END OBJ(moc_timeleft, &update_moc)
932         END OBJ(moc_curtime, &update_moc)
933         END OBJ(moc_bitrate, &update_moc)
934         END OBJ(moc_rate, &update_moc)
935 #endif /* MOC */
936 #ifdef XMMS2
937         END OBJ(xmms2_artist, &update_xmms2)
938         END OBJ(xmms2_album, &update_xmms2)
939         END OBJ(xmms2_title, &update_xmms2)
940         END OBJ(xmms2_genre, &update_xmms2)
941         END OBJ(xmms2_comment, &update_xmms2)
942         END OBJ(xmms2_url, &update_xmms2)
943         END OBJ(xmms2_tracknr, &update_xmms2)
944         END OBJ(xmms2_bitrate, &update_xmms2)
945         END OBJ(xmms2_date, &update_xmms2)
946         END OBJ(xmms2_id, &update_xmms2)
947         END OBJ(xmms2_duration, &update_xmms2)
948         END OBJ(xmms2_elapsed, &update_xmms2)
949         END OBJ(xmms2_size, &update_xmms2)
950         END OBJ(xmms2_status, &update_xmms2)
951         END OBJ(xmms2_percent, &update_xmms2)
952 #ifdef X11
953         END OBJ(xmms2_bar, &update_xmms2)
954                 SIZE_DEFAULTS(bar);
955                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
956 #endif /* X11 */
957         END OBJ(xmms2_smart, &update_xmms2)
958         END OBJ(xmms2_playlist, &update_xmms2)
959         END OBJ(xmms2_timesplayed, &update_xmms2)
960         END OBJ_IF(if_xmms2_connected, &update_xmms2)
961 #endif
962 #ifdef AUDACIOUS
963         END OBJ(audacious_status, &update_audacious)
964         END OBJ_ARG(audacious_title, &update_audacious, "audacious_title needs an argument")
965                 sscanf(arg, "%d", &info.audacious.max_title_len);
966                 if (info.audacious.max_title_len > 0) {
967                         info.audacious.max_title_len++;
968                 } else {
969                         CRIT_ERR(obj, free_at_crash, "audacious_title: invalid length argument");
970                 }
971         END OBJ(audacious_length, &update_audacious)
972         END OBJ(audacious_length_seconds, &update_audacious)
973         END OBJ(audacious_position, &update_audacious)
974         END OBJ(audacious_position_seconds, &update_audacious)
975         END OBJ(audacious_bitrate, &update_audacious)
976         END OBJ(audacious_frequency, &update_audacious)
977         END OBJ(audacious_channels, &update_audacious)
978         END OBJ(audacious_filename, &update_audacious)
979         END OBJ(audacious_playlist_length, &update_audacious)
980         END OBJ(audacious_playlist_position, &update_audacious)
981         END OBJ(audacious_main_volume, &update_audacious)
982 #ifdef X11
983         END OBJ(audacious_bar, &update_audacious)
984                 SIZE_DEFAULTS(bar);
985                 scan_bar(arg, &obj->a, &obj->b);
986 #endif /* X11 */
987 #endif
988 #ifdef BMPX
989         END OBJ(bmpx_title, &update_bmpx)
990                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
991         END OBJ(bmpx_artist, &update_bmpx)
992                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
993         END OBJ(bmpx_album, &update_bmpx)
994                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
995         END OBJ(bmpx_track, &update_bmpx)
996                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
997         END OBJ(bmpx_uri, &update_bmpx)
998                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
999         END OBJ(bmpx_bitrate, &update_bmpx)
1000                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
1001 #endif
1002 #ifdef EVE
1003         END OBJ_ARG(eve, 0, "eve needs arguments: <userid> <apikey> <characterid>")
1004                 scan_eve(obj, arg);
1005 #endif
1006 #ifdef HAVE_CURL
1007         END OBJ_ARG(curl, 0, "curl needs arguments: <uri> <interval in minutes>")
1008                 curl_parse_arg(obj, arg);
1009 #endif
1010 #ifdef RSS
1011         END OBJ_ARG(rss, 0, "rss needs arguments: <uri> <interval in minutes> <action> [act_par] [spaces in front]")
1012                 rss_scan_arg(obj, arg);
1013 #endif
1014 #ifdef WEATHER
1015         END OBJ_ARG(weather, 0, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]")
1016                 scan_weather_arg(obj, arg, free_at_crash);
1017 #endif
1018 #ifdef XOAP
1019         END OBJ_ARG(weather_forecast, 0, "weather_forecast needs arguments: <uri> <locID> <day> <data_type> [interval in minutes]")
1020                 scan_weather_forecast_arg(obj, arg, free_at_crash);
1021 #endif
1022 #ifdef HAVE_LUA
1023         END OBJ_ARG(lua, 0, "lua needs arguments: <function name> [function parameters]")
1024                 obj->data.s = strndup(arg, text_buffer_size);
1025         END OBJ_ARG(lua_parse, 0, "lua_parse needs arguments: <function name> [function parameters]")
1026                 obj->data.s = strndup(arg, text_buffer_size);
1027         END OBJ_ARG(lua_bar, 0, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]")
1028                 SIZE_DEFAULTS(bar);
1029                 arg = scan_bar(arg, &obj->a, &obj->b);
1030                 if(arg) {
1031                         obj->data.s = strndup(arg, text_buffer_size);
1032                 } else {
1033                         CRIT_ERR(obj, free_at_crash, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
1034                 }
1035 #ifdef X11
1036         END OBJ_ARG(lua_graph, 0, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]")
1037                 char *buf = 0;
1038                 SIZE_DEFAULTS(graph);
1039                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1040                                 &obj->e, &obj->char_a, &obj->char_b);
1041                 if (buf) {
1042                         obj->data.s = buf;
1043                 } else {
1044                         CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
1045                 }
1046         END OBJ_ARG(lua_gauge, 0, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]")
1047                 SIZE_DEFAULTS(gauge);
1048                 arg = scan_gauge(arg, &obj->a, &obj->b);
1049                 if (arg) {
1050                         obj->data.s = strndup(arg, text_buffer_size);
1051                 } else {
1052                         CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
1053                 }
1054 #endif /* X11 */
1055 #endif /* HAVE_LUA */
1056 #ifdef HDDTEMP
1057         END OBJ(hddtemp, &update_hddtemp)
1058                 if (arg)
1059                         obj->data.s = strndup(arg, text_buffer_size);
1060 #endif /* HDDTEMP */
1061 #ifdef TCP_PORT_MONITOR
1062         END OBJ_ARG(tcp_portmon, &tcp_portmon_update, "tcp_portmon: needs arguments")
1063                 tcp_portmon_init(obj, arg);
1064 #endif /* TCP_PORT_MONITOR */
1065         END OBJ(entropy_avail, &update_entropy)
1066         END OBJ(entropy_perc, &update_entropy)
1067         END OBJ(entropy_poolsize, &update_entropy)
1068         END OBJ(entropy_bar, &update_entropy)
1069                 SIZE_DEFAULTS(bar);
1070                 scan_bar(arg, &obj->a, &obj->b);
1071         END OBJ_ARG(include, 0, "include needs a argument")
1072                 struct conftree *leaf = conftree_add(currentconffile, arg);
1073                 if(leaf) {
1074                         if (load_config_file(arg) == TRUE) {
1075                                 obj->sub = malloc(sizeof(struct text_object));
1076                                 currentconffile = leaf;
1077                                 extract_variable_text_internal(obj->sub, get_global_text());
1078                                 currentconffile = leaf->back;
1079                         } else {
1080                                 NORM_ERR("Can't load configfile '%s'.", arg);
1081                         }
1082                 } else {
1083                         NORM_ERR("You are trying to load '%s' recursively, I'm only going to load it once to prevent an infinite loop.", arg);
1084                 }
1085         END OBJ_ARG(blink, 0, "blink needs a argument")
1086                 obj->sub = malloc(sizeof(struct text_object));
1087                 extract_variable_text_internal(obj->sub, arg);
1088         END OBJ_ARG(to_bytes, 0, "to_bytes needs a argument")
1089                 obj->sub = malloc(sizeof(struct text_object));
1090                 extract_variable_text_internal(obj->sub, arg);
1091         END OBJ(scroll, 0)
1092                 parse_scroll_arg(obj, arg, free_at_crash);
1093         END OBJ_ARG(combine, 0, "combine needs arguments: <text1> <text2>")
1094                 parse_combine_arg(obj, arg, free_at_crash);
1095 #ifdef NVIDIA
1096         END OBJ_ARG(nvidia, 0, "nvidia needs an argument")
1097                 if (set_nvidia_type(obj, arg)) {
1098                         CRIT_ERR(obj, free_at_crash, "nvidia: invalid argument"
1099                                  " specified: '%s'\n", arg);
1100                 }
1101 #endif /* NVIDIA */
1102 #ifdef APCUPSD
1103         END OBJ_ARG(apcupsd, &update_apcupsd, "apcupsd needs arguments: <host> <port>")
1104                 char host[64];
1105                 int port;
1106                 if (sscanf(arg, "%63s %d", host, &port) != 2) {
1107                         CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
1108                 } else {
1109                         info.apcupsd.port = htons(port);
1110                         strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
1111                 }
1112         END OBJ(apcupsd_name, &update_apcupsd)
1113         END OBJ(apcupsd_model, &update_apcupsd)
1114         END OBJ(apcupsd_upsmode, &update_apcupsd)
1115         END OBJ(apcupsd_cable, &update_apcupsd)
1116         END OBJ(apcupsd_status, &update_apcupsd)
1117         END OBJ(apcupsd_linev, &update_apcupsd)
1118         END OBJ(apcupsd_load, &update_apcupsd)
1119         END OBJ(apcupsd_loadbar, &update_apcupsd)
1120                 SIZE_DEFAULTS(bar);
1121                 scan_bar(arg, &obj->a, &obj->b);
1122 #ifdef X11
1123         END OBJ(apcupsd_loadgraph, &update_apcupsd)
1124                 char* buf = 0;
1125                 SIZE_DEFAULTS(graph);
1126                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1127                                 &obj->e, &obj->char_a, &obj->char_b);
1128                 if (buf) free(buf);
1129         END OBJ(apcupsd_loadgauge, &update_apcupsd)
1130                 SIZE_DEFAULTS(gauge);
1131                 scan_gauge(arg, &obj->a, &obj->b);
1132 #endif /* X11 */
1133         END OBJ(apcupsd_charge, &update_apcupsd)
1134         END OBJ(apcupsd_timeleft, &update_apcupsd)
1135         END OBJ(apcupsd_temp, &update_apcupsd)
1136         END OBJ(apcupsd_lastxfer, &update_apcupsd)
1137 #endif /* APCUPSD */
1138         END {
1139                 char buf[256];
1140
1141                 NORM_ERR("unknown variable %s", s);
1142                 obj->type = OBJ_text;
1143                 snprintf(buf, 256, "${%s}", s);
1144                 obj->data.s = strndup(buf, text_buffer_size);
1145         }
1146 #undef OBJ
1147 #undef OBJ_IF
1148 #undef OBJ_ARG
1149 #undef OBJ_IF_ARG
1150 #undef __OBJ_HEAD
1151 #undef __OBJ_IF
1152 #undef __OBJ_ARG
1153 #undef END
1154 #undef SIZE_DEFAULTS
1155
1156         return obj;
1157 }
1158
1159 /*
1160  * - assumes that *string is '#'
1161  * - removes the part from '#' to the end of line ('\n' or '\0')
1162  * - it removes the '\n'
1163  * - copies the last char into 'char *last' argument, which should be a pointer
1164  *   to a char rather than a string.
1165  */
1166 static size_t remove_comment(char *string, char *last)
1167 {
1168         char *end = string;
1169         while (*end != '\0' && *end != '\n') {
1170                 ++end;
1171         }
1172         if (last) *last = *end;
1173         if (*end == '\n') end++;
1174         strfold(string, end - string);
1175         return end - string;
1176 }
1177
1178 size_t remove_comments(char *string)
1179 {
1180         char *curplace;
1181         size_t folded = 0;
1182         for (curplace = string; *curplace != 0; curplace++) {
1183                 if (*curplace == '\\' && *(curplace + 1) == '#') {
1184                         // strcpy can't be used for overlapping strings
1185                         strfold(curplace, 1);
1186                         folded += 1;
1187                 } else if (*curplace == '#') {
1188                         folded += remove_comment(curplace, 0);
1189                 }
1190         }
1191         return folded;
1192 }
1193
1194 int extract_variable_text_internal(struct text_object *retval, const char *const_p)
1195 {
1196         struct text_object *obj;
1197         char *p, *s, *orig_p;
1198         long line;
1199         void *ifblock_opaque = NULL;
1200         char *tmp_p;
1201         char *arg = 0;
1202         size_t len = 0;
1203
1204         p = strndup(const_p, max_user_text - 1);
1205         while (text_contains_templates(p)) {
1206                 char *tmp;
1207                 tmp = find_and_replace_templates(p);
1208                 free(p);
1209                 p = tmp;
1210         }
1211         s = orig_p = p;
1212
1213         if (strcmp(p, const_p)) {
1214                 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
1215         } else {
1216                 DBGP("no templates to replace");
1217         }
1218
1219         memset(retval, 0, sizeof(struct text_object));
1220
1221         line = global_text_lines;
1222
1223         while (*p) {
1224                 if (*p == '\n') {
1225                         line++;
1226                 }
1227                 if (*p == '$') {
1228                         *p = '\0';
1229                         obj = create_plain_text(s);
1230                         if (obj != NULL) {
1231                                 append_object(retval, obj);
1232                         }
1233                         *p = '$';
1234                         p++;
1235                         s = p;
1236
1237                         if (*p != '$') {
1238                                 char buf[256];
1239                                 const char *var;
1240
1241                                 /* variable is either $foo or ${foo} */
1242                                 if (*p == '{') {
1243                                         unsigned int brl = 1, brr = 0;
1244
1245                                         p++;
1246                                         s = p;
1247                                         while (*p && brl != brr) {
1248                                                 if (*p == '{') {
1249                                                         brl++;
1250                                                 }
1251                                                 if (*p == '}') {
1252                                                         brr++;
1253                                                 }
1254                                                 p++;
1255                                         }
1256                                         p--;
1257                                 } else {
1258                                         s = p;
1259                                         if (*p == '#') {
1260                                                 p++;
1261                                         }
1262                                         while (*p && (isalnum((int) *p) || *p == '_')) {
1263                                                 p++;
1264                                         }
1265                                 }
1266
1267                                 /* copy variable to buffer */
1268                                 len = (p - s > 255) ? 255 : (p - s);
1269                                 strncpy(buf, s, len);
1270                                 buf[len] = '\0';
1271
1272                                 if (*p == '}') {
1273                                         p++;
1274                                 }
1275                                 s = p;
1276
1277                                 /* search for variable in environment */
1278
1279                                 var = getenv(buf);
1280                                 if (var) {
1281                                         obj = create_plain_text(var);
1282                                         if (obj) {
1283                                                 append_object(retval, obj);
1284                                         }
1285                                         continue;
1286                                 }
1287
1288                                 /* if variable wasn't found in environment, use some special */
1289
1290                                 arg = 0;
1291
1292                                 /* split arg */
1293                                 if (strchr(buf, ' ')) {
1294                                         arg = strchr(buf, ' ');
1295                                         *arg = '\0';
1296                                         arg++;
1297                                         while (isspace((int) *arg)) {
1298                                                 arg++;
1299                                         }
1300                                         if (!*arg) {
1301                                                 arg = 0;
1302                                         }
1303                                 }
1304
1305                                 /* lowercase variable name */
1306                                 tmp_p = buf;
1307                                 while (*tmp_p) {
1308                                         *tmp_p = tolower(*tmp_p);
1309                                         tmp_p++;
1310                                 }
1311
1312                                 obj = construct_text_object(buf, arg,
1313                                                 line, &ifblock_opaque, orig_p);
1314                                 if (obj != NULL) {
1315                                         append_object(retval, obj);
1316                                 }
1317                                 continue;
1318                         } else {
1319                                 obj = create_plain_text("$");
1320                                 s = p + 1;
1321                                 if (obj != NULL) {
1322                                         append_object(retval, obj);
1323                                 }
1324                         }
1325                 } else if (*p == '\\' && *(p+1) == '#') {
1326                         strfold(p, 1);
1327                 } else if (*p == '#') {
1328                         char c;
1329                         if (remove_comment(p, &c) && p > orig_p && c == '\n') {
1330                                 /* if remove_comment removed a newline, we need to 'back up' with p */
1331                                 p--;
1332                         }
1333                 }
1334                 p++;
1335         }
1336         obj = create_plain_text(s);
1337         if (obj != NULL) {
1338                 append_object(retval, obj);
1339         }
1340
1341         if (!ifblock_stack_empty(&ifblock_opaque)) {
1342                 NORM_ERR("one or more $endif's are missing");
1343         }
1344
1345         free(orig_p);
1346         return 0;
1347 }
1348
1349 /*
1350  * Frees the list of text objects root points to.  When internal = 1, it won't
1351  * free global objects.
1352  */
1353 void free_text_objects(struct text_object *root, int internal)
1354 {
1355         struct text_object *obj;
1356
1357         if (!root->prev) {
1358                 return;
1359         }
1360
1361 #define data obj->data
1362         for (obj = root->prev; obj; obj = root->prev) {
1363                 root->prev = obj->prev;
1364                 switch (obj->type) {
1365 #ifndef __OpenBSD__
1366                         case OBJ_acpitemp:
1367                                 close(data.i);
1368                                 break;
1369 #endif /* !__OpenBSD__ */
1370 #ifdef __linux__
1371                         case OBJ_i2c:
1372                         case OBJ_platform:
1373                         case OBJ_hwmon:
1374                                 free_sysfs_sensor(obj);
1375                                 break;
1376 #endif /* __linux__ */
1377                         case OBJ_read_tcp:
1378                                 free_read_tcp(obj);
1379                                 break;
1380                         case OBJ_time:
1381                         case OBJ_utime:
1382                                 free_time(obj);
1383                                 break;
1384                         case OBJ_tztime:
1385                                 free_tztime(obj);
1386                                 break;
1387                         case OBJ_mboxscan:
1388                                 free(data.mboxscan.args);
1389                                 free(data.mboxscan.output);
1390                                 break;
1391                         case OBJ_mails:
1392                         case OBJ_new_mails:
1393                         case OBJ_seen_mails:
1394                         case OBJ_unseen_mails:
1395                         case OBJ_flagged_mails:
1396                         case OBJ_unflagged_mails:
1397                         case OBJ_forwarded_mails:
1398                         case OBJ_unforwarded_mails:
1399                         case OBJ_replied_mails:
1400                         case OBJ_unreplied_mails:
1401                         case OBJ_draft_mails:
1402                         case OBJ_trashed_mails:
1403                                 free(data.local_mail.mbox);
1404                                 break;
1405                         case OBJ_imap_unseen:
1406                         case OBJ_imap_messages:
1407                         case OBJ_pop3_unseen:
1408                         case OBJ_pop3_used:
1409                                 free_mail_obj(obj);
1410                                 break;
1411                         case OBJ_if_empty:
1412                         case OBJ_if_match:
1413                                 free_text_objects(obj->sub, 1);
1414                                 free(obj->sub);
1415                                 /* fall through */
1416                         case OBJ_if_existing:
1417                         case OBJ_if_mounted:
1418                         case OBJ_if_running:
1419                                 free(data.ifblock.s);
1420                                 free(data.ifblock.str);
1421                                 break;
1422                         case OBJ_head:
1423                         case OBJ_tail:
1424                                 free_tailhead(obj);
1425                                 break;
1426                         case OBJ_text:
1427                         case OBJ_font:
1428                         case OBJ_image:
1429                         case OBJ_eval:
1430                         case OBJ_exec:
1431                         case OBJ_execbar:
1432 #ifdef X11
1433                         case OBJ_execgauge:
1434                         case OBJ_execgraph:
1435 #endif
1436                         case OBJ_execp:
1437                                 free_exec(obj);
1438                                 break;
1439 #ifdef HAVE_ICONV
1440                         case OBJ_iconv_start:
1441                                 free_iconv();
1442                                 break;
1443 #endif
1444 #ifdef __linux__
1445                         case OBJ_disk_protect:
1446                                 free(data.s);
1447                                 break;
1448                         case OBJ_if_gw:
1449                                 free(data.ifblock.s);
1450                                 free(data.ifblock.str);
1451                         case OBJ_gw_iface:
1452                         case OBJ_gw_ip:
1453                                 free_gateway_info();
1454                                 break;
1455                         case OBJ_ioscheduler:
1456                                 if(data.s)
1457                                         free(data.s);
1458                                 break;
1459 #endif
1460 #if (defined(__FreeBSD__) || defined(__linux__))
1461                         case OBJ_if_up:
1462                                 free(data.ifblock.s);
1463                                 free(data.ifblock.str);
1464                                 break;
1465 #endif
1466 #ifdef XMMS2
1467                         case OBJ_xmms2_artist:
1468                                 if (info.xmms2.artist) {
1469                                         free(info.xmms2.artist);
1470                                         info.xmms2.artist = 0;
1471                                 }
1472                                 break;
1473                         case OBJ_xmms2_album:
1474                                 if (info.xmms2.album) {
1475                                         free(info.xmms2.album);
1476                                         info.xmms2.album = 0;
1477                                 }
1478                                 break;
1479                         case OBJ_xmms2_title:
1480                                 if (info.xmms2.title) {
1481                                         free(info.xmms2.title);
1482                                         info.xmms2.title = 0;
1483                                 }
1484                                 break;
1485                         case OBJ_xmms2_genre:
1486                                 if (info.xmms2.genre) {
1487                                         free(info.xmms2.genre);
1488                                         info.xmms2.genre = 0;
1489                                 }
1490                                 break;
1491                         case OBJ_xmms2_comment:
1492                                 if (info.xmms2.comment) {
1493                                         free(info.xmms2.comment);
1494                                         info.xmms2.comment = 0;
1495                                 }
1496                                 break;
1497                         case OBJ_xmms2_url:
1498                                 if (info.xmms2.url) {
1499                                         free(info.xmms2.url);
1500                                         info.xmms2.url = 0;
1501                                 }
1502                                 break;
1503                         case OBJ_xmms2_date:
1504                                 if (info.xmms2.date) {
1505                                         free(info.xmms2.date);
1506                                         info.xmms2.date = 0;
1507                                 }
1508                                 break;
1509                         case OBJ_xmms2_status:
1510                                 if (info.xmms2.status) {
1511                                         free(info.xmms2.status);
1512                                         info.xmms2.status = 0;
1513                                 }
1514                                 break;
1515                         case OBJ_xmms2_playlist:
1516                                 if (info.xmms2.playlist) {
1517                                         free(info.xmms2.playlist);
1518                                         info.xmms2.playlist = 0;
1519                                 }
1520                                 break;
1521                         case OBJ_xmms2_smart:
1522                                 if (info.xmms2.artist) {
1523                                         free(info.xmms2.artist);
1524                                         info.xmms2.artist = 0;
1525                                 }
1526                                 if (info.xmms2.title) {
1527                                         free(info.xmms2.title);
1528                                         info.xmms2.title = 0;
1529                                 }
1530                                 if (info.xmms2.url) {
1531                                         free(info.xmms2.url);
1532                                         info.xmms2.url = 0;
1533                                 }
1534                                 break;
1535 #endif
1536 #ifdef BMPX
1537                         case OBJ_bmpx_title:
1538                         case OBJ_bmpx_artist:
1539                         case OBJ_bmpx_album:
1540                         case OBJ_bmpx_track:
1541                         case OBJ_bmpx_uri:
1542                         case OBJ_bmpx_bitrate:
1543                                 break;
1544 #endif
1545 #ifdef EVE
1546                         case OBJ_eve:
1547                                 break;
1548 #endif
1549 #ifdef HAVE_CURL
1550                         case OBJ_curl:
1551                                 free(data.curl.uri);
1552                                 break;
1553 #endif
1554 #ifdef RSS
1555                         case OBJ_rss:
1556                                 free(data.rss.uri);
1557                                 free(data.rss.action);
1558                                 break;
1559 #endif
1560 #ifdef WEATHER
1561                         case OBJ_weather:
1562                                 free(data.weather.uri);
1563                                 free(data.weather.data_type);
1564                                 break;
1565 #endif
1566 #ifdef XOAP
1567                         case OBJ_weather_forecast:
1568                                 free(data.weather_forecast.uri);
1569                                 free(data.weather_forecast.data_type);
1570                                 break;
1571 #endif
1572 #ifdef HAVE_LUA
1573                         case OBJ_lua:
1574                         case OBJ_lua_parse:
1575                         case OBJ_lua_bar:
1576 #ifdef X11
1577                         case OBJ_lua_graph:
1578                         case OBJ_lua_gauge:
1579 #endif /* X11 */
1580                                 free(data.s);
1581                                 break;
1582 #endif /* HAVE_LUA */
1583                         case OBJ_pre_exec:
1584                                 break;
1585 #ifndef __OpenBSD__
1586                         case OBJ_battery:
1587                                 free(data.s);
1588                                 break;
1589                         case OBJ_battery_short:
1590                                 free(data.s);
1591                                 break;
1592                         case OBJ_battery_time:
1593                                 free(data.s);
1594                                 break;
1595 #endif /* !__OpenBSD__ */
1596                         case OBJ_execpi:
1597                         case OBJ_execi:
1598                         case OBJ_execibar:
1599                         case OBJ_texeci:
1600 #ifdef X11
1601                         case OBJ_execigraph:
1602                         case OBJ_execigauge:
1603 #endif /* X11 */
1604                                 free_execi(obj);
1605                                 break;
1606                         case OBJ_nameserver:
1607                                 free_dns_data();
1608                                 break;
1609                         case OBJ_top:
1610                         case OBJ_top_mem:
1611                         case OBJ_top_time:
1612 #ifdef IOSTATS
1613                         case OBJ_top_io:
1614 #endif
1615                                 if (info.first_process && !internal) {
1616                                         free_all_processes();
1617                                         info.first_process = NULL;
1618                                 }
1619                                 if (data.top.s) free(data.top.s);
1620                                 break;
1621 #ifdef HDDTEMP
1622                         case OBJ_hddtemp:
1623                                 if (data.s) {
1624                                         free(data.s);
1625                                         data.s = NULL;
1626                                 }
1627                                 free_hddtemp();
1628                                 break;
1629 #endif /* HDDTEMP */
1630                         case OBJ_entropy_avail:
1631                         case OBJ_entropy_perc:
1632                         case OBJ_entropy_poolsize:
1633                         case OBJ_entropy_bar:
1634                                 break;
1635                         case OBJ_user_names:
1636                                 if (info.users.names) {
1637                                         free(info.users.names);
1638                                         info.users.names = 0;
1639                                 }
1640                                 break;
1641                         case OBJ_user_terms:
1642                                 if (info.users.terms) {
1643                                         free(info.users.terms);
1644                                         info.users.terms = 0;
1645                                 }
1646                                 break;
1647                         case OBJ_user_times:
1648                                 if (info.users.times) {
1649                                         free(info.users.times);
1650                                         info.users.times = 0;
1651                                 }
1652                                 break;
1653 #ifdef IBM
1654                         case OBJ_smapi:
1655                         case OBJ_smapi_bat_perc:
1656                         case OBJ_smapi_bat_temp:
1657                         case OBJ_smapi_bat_power:
1658                                 free(data.s);
1659                                 break;
1660                         case OBJ_if_smapi_bat_installed:
1661                                 free(data.ifblock.s);
1662                                 free(data.ifblock.str);
1663                                 break;
1664 #endif /* IBM */
1665 #ifdef NVIDIA
1666                         case OBJ_nvidia:
1667                                 free_nvidia(obj);
1668                                 break;
1669 #endif /* NVIDIA */
1670 #ifdef MPD
1671                         case OBJ_mpd_title:
1672                         case OBJ_mpd_artist:
1673                         case OBJ_mpd_album:
1674                         case OBJ_mpd_random:
1675                         case OBJ_mpd_repeat:
1676                         case OBJ_mpd_vol:
1677                         case OBJ_mpd_bitrate:
1678                         case OBJ_mpd_status:
1679                         case OBJ_mpd_bar:
1680                         case OBJ_mpd_elapsed:
1681                         case OBJ_mpd_length:
1682                         case OBJ_mpd_track:
1683                         case OBJ_mpd_name:
1684                         case OBJ_mpd_file:
1685                         case OBJ_mpd_percent:
1686                         case OBJ_mpd_smart:
1687                         case OBJ_if_mpd_playing:
1688                                 free_mpd();
1689                                 break;
1690 #endif /* MPD */
1691 #ifdef MOC
1692                         case OBJ_moc_state:
1693                         case OBJ_moc_file:
1694                         case OBJ_moc_title:
1695                         case OBJ_moc_artist:
1696                         case OBJ_moc_song:
1697                         case OBJ_moc_album:
1698                         case OBJ_moc_totaltime:
1699                         case OBJ_moc_timeleft:
1700                         case OBJ_moc_curtime:
1701                         case OBJ_moc_bitrate:
1702                         case OBJ_moc_rate:
1703                                 free_moc();
1704                                 break;
1705 #endif /* MOC */
1706                         case OBJ_include:
1707                         case OBJ_blink:
1708                         case OBJ_to_bytes:
1709                                 if(obj->sub) {
1710                                         free_text_objects(obj->sub, 1);
1711                                         free(obj->sub);
1712                                 }
1713                                 break;
1714                         case OBJ_scroll:
1715                                 free_scroll(obj);
1716                                 break;
1717                         case OBJ_combine:
1718                                 free_combine(obj);
1719                                 break;
1720 #ifdef APCUPSD
1721                         case OBJ_apcupsd:
1722                         case OBJ_apcupsd_name:
1723                         case OBJ_apcupsd_model:
1724                         case OBJ_apcupsd_upsmode:
1725                         case OBJ_apcupsd_cable:
1726                         case OBJ_apcupsd_status:
1727                         case OBJ_apcupsd_linev:
1728                         case OBJ_apcupsd_load:
1729                         case OBJ_apcupsd_loadbar:
1730 #ifdef X11
1731                         case OBJ_apcupsd_loadgraph:
1732                         case OBJ_apcupsd_loadgauge:
1733 #endif /* X11 */
1734                         case OBJ_apcupsd_charge:
1735                         case OBJ_apcupsd_timeleft:
1736                         case OBJ_apcupsd_temp:
1737                         case OBJ_apcupsd_lastxfer:
1738                                 break;
1739 #endif /* APCUPSD */
1740 #ifdef TCP_PORT_MONITOR
1741                         case OBJ_tcp_portmon:
1742                                 tcp_portmon_free(obj);
1743                                 break;
1744 #endif /* TCP_PORT_MONITOR */
1745 #ifdef X11
1746                         case OBJ_desktop:
1747                         case OBJ_desktop_number:
1748                         case OBJ_desktop_name:
1749                                 if(info.x11.desktop.name && !internal) {
1750                                   free(info.x11.desktop.name);
1751                                   info.x11.desktop.name = NULL;
1752                                 }
1753                                 if(info.x11.desktop.all_names && !internal) {
1754                                   free(info.x11.desktop.all_names);
1755                                   info.x11.desktop.all_names = NULL;
1756                                 }
1757                                 break;
1758 #endif /* X11 */
1759                 }
1760                 free(obj);
1761         }
1762 #undef data
1763 }
1764