mixer: 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                 parse_mixer_arg(obj, arg);
730         END OBJ(mixerl, 0)
731                 parse_mixer_arg(obj, arg);
732         END OBJ(mixerr, 0)
733                 parse_mixer_arg(obj, arg);
734 #ifdef X11
735         END OBJ(mixerbar, 0)
736                 scan_mixer_bar(obj, arg);
737         END OBJ(mixerlbar, 0)
738                 scan_mixer_bar(obj, arg);
739         END OBJ(mixerrbar, 0)
740                 scan_mixer_bar(obj, arg);
741 #endif
742         END OBJ_IF(if_mixer_mute, 0)
743                 parse_mixer_arg(obj, arg);
744 #ifdef X11
745         END OBJ(monitor, &update_x11info)
746         END OBJ(monitor_number, &update_x11info)
747         END OBJ(desktop, &update_x11info)
748         END OBJ(desktop_number, &update_x11info)
749         END OBJ(desktop_name, &update_x11info)
750 #endif
751         END OBJ(nodename, 0)
752         END OBJ(processes, &update_total_processes)
753         END OBJ(running_processes, &update_running_processes)
754         END OBJ(shadecolor, 0)
755 #ifdef X11
756                 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
757 #endif /* X11 */
758         END OBJ(outlinecolor, 0)
759 #ifdef X11
760                 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
761 #endif /* X11 */
762         END OBJ(stippled_hr, 0)
763 #ifdef X11
764                 int a = get_stippled_borders(), b = 1;
765
766                 if (arg) {
767                         if (sscanf(arg, "%d %d", &a, &b) != 2) {
768                                 sscanf(arg, "%d", &b);
769                         }
770                 }
771                 if (a <= 0) {
772                         a = 1;
773                 }
774                 obj->data.pair.a = a;
775                 obj->data.pair.b = b;
776 #endif /* X11 */
777         END OBJ(swap, &update_meminfo)
778         END OBJ(swapfree, &update_meminfo)
779         END OBJ(swapmax, &update_meminfo)
780         END OBJ(swapperc, &update_meminfo)
781         END OBJ(swapbar, &update_meminfo)
782                 SIZE_DEFAULTS(bar);
783                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
784         END OBJ(sysname, 0)
785         END OBJ(time, 0)
786                 scan_time(obj, arg);
787         END OBJ(utime, 0)
788                 scan_time(obj, arg);
789         END OBJ(tztime, 0)
790                 scan_tztime(obj, arg);
791 #ifdef HAVE_ICONV
792         END OBJ_ARG(iconv_start, 0, "Iconv requires arguments")
793                 init_iconv_start(obj, free_at_crash, arg);
794         END OBJ(iconv_stop, 0)
795                 init_iconv_stop();
796 #endif
797         END OBJ(totaldown, &update_net_stats)
798                 parse_net_stat_arg(obj, arg, free_at_crash);
799         END OBJ(totalup, &update_net_stats)
800                 parse_net_stat_arg(obj, arg, free_at_crash);
801         END OBJ(updates, 0)
802         END OBJ_IF(if_updatenr, 0)
803                 obj->data.ifblock.i = arg ? atoi(arg) : 0;
804                 if(obj->data.ifblock.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument");
805                 set_updatereset(obj->data.ifblock.i > get_updatereset() ? obj->data.ifblock.i : get_updatereset());
806         END OBJ(alignr, 0)
807                 obj->data.i = arg ? atoi(arg) : 0;
808         END OBJ(alignc, 0)
809                 obj->data.i = arg ? atoi(arg) : 0;
810         END OBJ(upspeed, &update_net_stats)
811                 parse_net_stat_arg(obj, arg, free_at_crash);
812         END OBJ(upspeedf, &update_net_stats)
813                 parse_net_stat_arg(obj, arg, free_at_crash);
814 #ifdef X11
815         END OBJ(upspeedgraph, &update_net_stats)
816                 parse_net_stat_graph_arg(obj, arg, free_at_crash);
817 #endif
818         END OBJ(uptime_short, &update_uptime)
819         END OBJ(uptime, &update_uptime)
820         END OBJ(user_names, &update_users)
821         END OBJ(user_times, &update_users)
822         END OBJ(user_terms, &update_users)
823         END OBJ(user_number, &update_users)
824 #if defined(__linux__)
825         END OBJ(gw_iface, &update_gateway_info)
826         END OBJ(gw_ip, &update_gateway_info)
827 #endif /* !__linux__ */
828 #ifndef __OpenBSD__
829         END OBJ(adt746xcpu, 0)
830         END OBJ(adt746xfan, 0)
831 #endif /* !__OpenBSD__ */
832 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
833                 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
834         END OBJ(apm_adapter, 0)
835         END OBJ(apm_battery_life, 0)
836         END OBJ(apm_battery_time, 0)
837 #endif /* __FreeBSD__ */
838         END OBJ(imap_unseen, 0)
839                 parse_imap_mail_args(obj, arg);
840         END OBJ(imap_messages, 0)
841                 parse_imap_mail_args(obj, arg);
842         END OBJ(pop3_unseen, 0)
843                 parse_pop3_mail_args(obj, arg);
844         END OBJ(pop3_used, 0)
845                 parse_pop3_mail_args(obj, arg);
846 #ifdef IBM
847         END OBJ_ARG(smapi, 0, "smapi needs an argument")
848                 obj->data.s = strndup(arg, text_buffer_size);
849         END OBJ_IF_ARG(if_smapi_bat_installed, 0, "if_smapi_bat_installed needs an argument")
850                 obj->data.ifblock.s = strndup(arg, text_buffer_size);
851         END OBJ_ARG(smapi_bat_perc, 0, "smapi_bat_perc needs an argument")
852                 obj->data.s = strndup(arg, text_buffer_size);
853         END OBJ_ARG(smapi_bat_temp, 0, "smapi_bat_temp needs an argument")
854                 obj->data.s = strndup(arg, text_buffer_size);
855         END OBJ_ARG(smapi_bat_power, 0, "smapi_bat_power needs an argument")
856                 obj->data.s = strndup(arg, text_buffer_size);
857 #ifdef X11
858         END OBJ_ARG(smapi_bat_bar, 0, "smapi_bat_bar needs an argument")
859                 int cnt;
860                 SIZE_DEFAULTS(bar);
861                 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
862                         NORM_ERR("first argument to smapi_bat_bar must be an integer value");
863                         obj->data.i = -1;
864                 } else {
865                         obj->b = 4;
866                         arg = scan_bar(arg + cnt, &obj->a, &obj->b);
867                 }
868 #endif /* X11 */
869 #endif /* IBM */
870 #ifdef MPD
871 #define mpd_set_maxlen(name) \
872                 if (arg) { \
873                         int i; \
874                         sscanf(arg, "%d", &i); \
875                         if (i > 0) \
876                                 obj->data.i = i + 1; \
877                         else \
878                                 NORM_ERR(#name ": invalid length argument"); \
879                 }
880         END OBJ(mpd_artist, &update_mpd)
881                 mpd_set_maxlen(mpd_artist);
882                 init_mpd();
883         END OBJ(mpd_title, &update_mpd)
884                 mpd_set_maxlen(mpd_title);
885                 init_mpd();
886         END OBJ(mpd_random, &update_mpd) init_mpd();
887         END OBJ(mpd_repeat, &update_mpd) init_mpd();
888         END OBJ(mpd_elapsed, &update_mpd) init_mpd();
889         END OBJ(mpd_length, &update_mpd) init_mpd();
890         END OBJ(mpd_track, &update_mpd)
891                 mpd_set_maxlen(mpd_track);
892                 init_mpd();
893         END OBJ(mpd_name, &update_mpd)
894                 mpd_set_maxlen(mpd_name);
895                 init_mpd();
896         END OBJ(mpd_file, &update_mpd)
897                 mpd_set_maxlen(mpd_file);
898                 init_mpd();
899         END OBJ(mpd_percent, &update_mpd) init_mpd();
900         END OBJ(mpd_album, &update_mpd)
901                 mpd_set_maxlen(mpd_album);
902                 init_mpd();
903         END OBJ(mpd_vol, &update_mpd) init_mpd();
904         END OBJ(mpd_bitrate, &update_mpd) init_mpd();
905         END OBJ(mpd_status, &update_mpd) init_mpd();
906         END OBJ(mpd_bar, &update_mpd)
907                 SIZE_DEFAULTS(bar);
908                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
909                 init_mpd();
910         END OBJ(mpd_smart, &update_mpd)
911                 mpd_set_maxlen(mpd_smart);
912                 init_mpd();
913         END OBJ_IF(if_mpd_playing, &update_mpd)
914                 init_mpd();
915 #undef mpd_set_maxlen
916 #endif /* MPD */
917 #ifdef MOC
918         END OBJ(moc_state, &update_moc)
919         END OBJ(moc_file, &update_moc)
920         END OBJ(moc_title, &update_moc)
921         END OBJ(moc_artist, &update_moc)
922         END OBJ(moc_song, &update_moc)
923         END OBJ(moc_album, &update_moc)
924         END OBJ(moc_totaltime, &update_moc)
925         END OBJ(moc_timeleft, &update_moc)
926         END OBJ(moc_curtime, &update_moc)
927         END OBJ(moc_bitrate, &update_moc)
928         END OBJ(moc_rate, &update_moc)
929 #endif /* MOC */
930 #ifdef XMMS2
931         END OBJ(xmms2_artist, &update_xmms2)
932         END OBJ(xmms2_album, &update_xmms2)
933         END OBJ(xmms2_title, &update_xmms2)
934         END OBJ(xmms2_genre, &update_xmms2)
935         END OBJ(xmms2_comment, &update_xmms2)
936         END OBJ(xmms2_url, &update_xmms2)
937         END OBJ(xmms2_tracknr, &update_xmms2)
938         END OBJ(xmms2_bitrate, &update_xmms2)
939         END OBJ(xmms2_date, &update_xmms2)
940         END OBJ(xmms2_id, &update_xmms2)
941         END OBJ(xmms2_duration, &update_xmms2)
942         END OBJ(xmms2_elapsed, &update_xmms2)
943         END OBJ(xmms2_size, &update_xmms2)
944         END OBJ(xmms2_status, &update_xmms2)
945         END OBJ(xmms2_percent, &update_xmms2)
946 #ifdef X11
947         END OBJ(xmms2_bar, &update_xmms2)
948                 SIZE_DEFAULTS(bar);
949                 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
950 #endif /* X11 */
951         END OBJ(xmms2_smart, &update_xmms2)
952         END OBJ(xmms2_playlist, &update_xmms2)
953         END OBJ(xmms2_timesplayed, &update_xmms2)
954         END OBJ_IF(if_xmms2_connected, &update_xmms2)
955 #endif
956 #ifdef AUDACIOUS
957         END OBJ(audacious_status, &update_audacious)
958         END OBJ_ARG(audacious_title, &update_audacious, "audacious_title needs an argument")
959                 sscanf(arg, "%d", &info.audacious.max_title_len);
960                 if (info.audacious.max_title_len > 0) {
961                         info.audacious.max_title_len++;
962                 } else {
963                         CRIT_ERR(obj, free_at_crash, "audacious_title: invalid length argument");
964                 }
965         END OBJ(audacious_length, &update_audacious)
966         END OBJ(audacious_length_seconds, &update_audacious)
967         END OBJ(audacious_position, &update_audacious)
968         END OBJ(audacious_position_seconds, &update_audacious)
969         END OBJ(audacious_bitrate, &update_audacious)
970         END OBJ(audacious_frequency, &update_audacious)
971         END OBJ(audacious_channels, &update_audacious)
972         END OBJ(audacious_filename, &update_audacious)
973         END OBJ(audacious_playlist_length, &update_audacious)
974         END OBJ(audacious_playlist_position, &update_audacious)
975         END OBJ(audacious_main_volume, &update_audacious)
976 #ifdef X11
977         END OBJ(audacious_bar, &update_audacious)
978                 SIZE_DEFAULTS(bar);
979                 scan_bar(arg, &obj->a, &obj->b);
980 #endif /* X11 */
981 #endif
982 #ifdef BMPX
983         END OBJ(bmpx_title, &update_bmpx)
984                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
985         END OBJ(bmpx_artist, &update_bmpx)
986                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
987         END OBJ(bmpx_album, &update_bmpx)
988                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
989         END OBJ(bmpx_track, &update_bmpx)
990                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
991         END OBJ(bmpx_uri, &update_bmpx)
992                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
993         END OBJ(bmpx_bitrate, &update_bmpx)
994                 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
995 #endif
996 #ifdef EVE
997         END OBJ_ARG(eve, 0, "eve needs arguments: <userid> <apikey> <characterid>")
998                 scan_eve(obj, arg);
999 #endif
1000 #ifdef HAVE_CURL
1001         END OBJ_ARG(curl, 0, "curl needs arguments: <uri> <interval in minutes>")
1002                 curl_parse_arg(obj, arg);
1003 #endif
1004 #ifdef RSS
1005         END OBJ_ARG(rss, 0, "rss needs arguments: <uri> <interval in minutes> <action> [act_par] [spaces in front]")
1006                 rss_scan_arg(obj, arg);
1007 #endif
1008 #ifdef WEATHER
1009         END OBJ_ARG(weather, 0, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]")
1010                 scan_weather_arg(obj, arg, free_at_crash);
1011 #endif
1012 #ifdef XOAP
1013         END OBJ_ARG(weather_forecast, 0, "weather_forecast needs arguments: <uri> <locID> <day> <data_type> [interval in minutes]")
1014                 scan_weather_forecast_arg(obj, arg, free_at_crash);
1015 #endif
1016 #ifdef HAVE_LUA
1017         END OBJ_ARG(lua, 0, "lua needs arguments: <function name> [function parameters]")
1018                 obj->data.s = strndup(arg, text_buffer_size);
1019         END OBJ_ARG(lua_parse, 0, "lua_parse needs arguments: <function name> [function parameters]")
1020                 obj->data.s = strndup(arg, text_buffer_size);
1021         END OBJ_ARG(lua_bar, 0, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]")
1022                 SIZE_DEFAULTS(bar);
1023                 arg = scan_bar(arg, &obj->a, &obj->b);
1024                 if(arg) {
1025                         obj->data.s = strndup(arg, text_buffer_size);
1026                 } else {
1027                         CRIT_ERR(obj, free_at_crash, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]");
1028                 }
1029 #ifdef X11
1030         END OBJ_ARG(lua_graph, 0, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]")
1031                 char *buf = 0;
1032                 SIZE_DEFAULTS(graph);
1033                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1034                                 &obj->e, &obj->char_a, &obj->char_b);
1035                 if (buf) {
1036                         obj->data.s = buf;
1037                 } else {
1038                         CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
1039                 }
1040         END OBJ_ARG(lua_gauge, 0, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]")
1041                 SIZE_DEFAULTS(gauge);
1042                 arg = scan_gauge(arg, &obj->a, &obj->b);
1043                 if (arg) {
1044                         obj->data.s = strndup(arg, text_buffer_size);
1045                 } else {
1046                         CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
1047                 }
1048 #endif /* X11 */
1049 #endif /* HAVE_LUA */
1050 #ifdef HDDTEMP
1051         END OBJ(hddtemp, &update_hddtemp)
1052                 if (arg)
1053                         obj->data.s = strndup(arg, text_buffer_size);
1054 #endif /* HDDTEMP */
1055 #ifdef TCP_PORT_MONITOR
1056         END OBJ_ARG(tcp_portmon, &tcp_portmon_update, "tcp_portmon: needs arguments")
1057                 tcp_portmon_init(obj, arg);
1058 #endif /* TCP_PORT_MONITOR */
1059         END OBJ(entropy_avail, &update_entropy)
1060         END OBJ(entropy_perc, &update_entropy)
1061         END OBJ(entropy_poolsize, &update_entropy)
1062         END OBJ(entropy_bar, &update_entropy)
1063                 SIZE_DEFAULTS(bar);
1064                 scan_bar(arg, &obj->a, &obj->b);
1065         END OBJ_ARG(include, 0, "include needs a argument")
1066                 struct conftree *leaf = conftree_add(currentconffile, arg);
1067                 if(leaf) {
1068                         if (load_config_file(arg) == TRUE) {
1069                                 obj->sub = malloc(sizeof(struct text_object));
1070                                 currentconffile = leaf;
1071                                 extract_variable_text_internal(obj->sub, get_global_text());
1072                                 currentconffile = leaf->back;
1073                         } else {
1074                                 NORM_ERR("Can't load configfile '%s'.", arg);
1075                         }
1076                 } else {
1077                         NORM_ERR("You are trying to load '%s' recursively, I'm only going to load it once to prevent an infinite loop.", arg);
1078                 }
1079         END OBJ_ARG(blink, 0, "blink needs a argument")
1080                 obj->sub = malloc(sizeof(struct text_object));
1081                 extract_variable_text_internal(obj->sub, arg);
1082         END OBJ_ARG(to_bytes, 0, "to_bytes needs a argument")
1083                 obj->sub = malloc(sizeof(struct text_object));
1084                 extract_variable_text_internal(obj->sub, arg);
1085         END OBJ(scroll, 0)
1086                 parse_scroll_arg(obj, arg, free_at_crash);
1087         END OBJ_ARG(combine, 0, "combine needs arguments: <text1> <text2>")
1088                 parse_combine_arg(obj, arg, free_at_crash);
1089 #ifdef NVIDIA
1090         END OBJ_ARG(nvidia, 0, "nvidia needs an argument")
1091                 if (set_nvidia_type(obj, arg)) {
1092                         CRIT_ERR(obj, free_at_crash, "nvidia: invalid argument"
1093                                  " specified: '%s'\n", arg);
1094                 }
1095 #endif /* NVIDIA */
1096 #ifdef APCUPSD
1097         END OBJ_ARG(apcupsd, &update_apcupsd, "apcupsd needs arguments: <host> <port>")
1098                 char host[64];
1099                 int port;
1100                 if (sscanf(arg, "%63s %d", host, &port) != 2) {
1101                         CRIT_ERR(obj, free_at_crash, "apcupsd needs arguments: <host> <port>");
1102                 } else {
1103                         info.apcupsd.port = htons(port);
1104                         strncpy(info.apcupsd.host, host, sizeof(info.apcupsd.host));
1105                 }
1106         END OBJ(apcupsd_name, &update_apcupsd)
1107         END OBJ(apcupsd_model, &update_apcupsd)
1108         END OBJ(apcupsd_upsmode, &update_apcupsd)
1109         END OBJ(apcupsd_cable, &update_apcupsd)
1110         END OBJ(apcupsd_status, &update_apcupsd)
1111         END OBJ(apcupsd_linev, &update_apcupsd)
1112         END OBJ(apcupsd_load, &update_apcupsd)
1113         END OBJ(apcupsd_loadbar, &update_apcupsd)
1114                 SIZE_DEFAULTS(bar);
1115                 scan_bar(arg, &obj->a, &obj->b);
1116 #ifdef X11
1117         END OBJ(apcupsd_loadgraph, &update_apcupsd)
1118                 char* buf = 0;
1119                 SIZE_DEFAULTS(graph);
1120                 buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
1121                                 &obj->e, &obj->char_a, &obj->char_b);
1122                 if (buf) free(buf);
1123         END OBJ(apcupsd_loadgauge, &update_apcupsd)
1124                 SIZE_DEFAULTS(gauge);
1125                 scan_gauge(arg, &obj->a, &obj->b);
1126 #endif /* X11 */
1127         END OBJ(apcupsd_charge, &update_apcupsd)
1128         END OBJ(apcupsd_timeleft, &update_apcupsd)
1129         END OBJ(apcupsd_temp, &update_apcupsd)
1130         END OBJ(apcupsd_lastxfer, &update_apcupsd)
1131 #endif /* APCUPSD */
1132         END {
1133                 char buf[256];
1134
1135                 NORM_ERR("unknown variable %s", s);
1136                 obj->type = OBJ_text;
1137                 snprintf(buf, 256, "${%s}", s);
1138                 obj->data.s = strndup(buf, text_buffer_size);
1139         }
1140 #undef OBJ
1141 #undef OBJ_IF
1142 #undef OBJ_ARG
1143 #undef OBJ_IF_ARG
1144 #undef __OBJ_HEAD
1145 #undef __OBJ_IF
1146 #undef __OBJ_ARG
1147 #undef END
1148 #undef SIZE_DEFAULTS
1149
1150         return obj;
1151 }
1152
1153 /*
1154  * - assumes that *string is '#'
1155  * - removes the part from '#' to the end of line ('\n' or '\0')
1156  * - it removes the '\n'
1157  * - copies the last char into 'char *last' argument, which should be a pointer
1158  *   to a char rather than a string.
1159  */
1160 static size_t remove_comment(char *string, char *last)
1161 {
1162         char *end = string;
1163         while (*end != '\0' && *end != '\n') {
1164                 ++end;
1165         }
1166         if (last) *last = *end;
1167         if (*end == '\n') end++;
1168         strfold(string, end - string);
1169         return end - string;
1170 }
1171
1172 size_t remove_comments(char *string)
1173 {
1174         char *curplace;
1175         size_t folded = 0;
1176         for (curplace = string; *curplace != 0; curplace++) {
1177                 if (*curplace == '\\' && *(curplace + 1) == '#') {
1178                         // strcpy can't be used for overlapping strings
1179                         strfold(curplace, 1);
1180                         folded += 1;
1181                 } else if (*curplace == '#') {
1182                         folded += remove_comment(curplace, 0);
1183                 }
1184         }
1185         return folded;
1186 }
1187
1188 int extract_variable_text_internal(struct text_object *retval, const char *const_p)
1189 {
1190         struct text_object *obj;
1191         char *p, *s, *orig_p;
1192         long line;
1193         void *ifblock_opaque = NULL;
1194         char *tmp_p;
1195         char *arg = 0;
1196         size_t len = 0;
1197
1198         p = strndup(const_p, max_user_text - 1);
1199         while (text_contains_templates(p)) {
1200                 char *tmp;
1201                 tmp = find_and_replace_templates(p);
1202                 free(p);
1203                 p = tmp;
1204         }
1205         s = orig_p = p;
1206
1207         if (strcmp(p, const_p)) {
1208                 DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
1209         } else {
1210                 DBGP("no templates to replace");
1211         }
1212
1213         memset(retval, 0, sizeof(struct text_object));
1214
1215         line = global_text_lines;
1216
1217         while (*p) {
1218                 if (*p == '\n') {
1219                         line++;
1220                 }
1221                 if (*p == '$') {
1222                         *p = '\0';
1223                         obj = create_plain_text(s);
1224                         if (obj != NULL) {
1225                                 append_object(retval, obj);
1226                         }
1227                         *p = '$';
1228                         p++;
1229                         s = p;
1230
1231                         if (*p != '$') {
1232                                 char buf[256];
1233                                 const char *var;
1234
1235                                 /* variable is either $foo or ${foo} */
1236                                 if (*p == '{') {
1237                                         unsigned int brl = 1, brr = 0;
1238
1239                                         p++;
1240                                         s = p;
1241                                         while (*p && brl != brr) {
1242                                                 if (*p == '{') {
1243                                                         brl++;
1244                                                 }
1245                                                 if (*p == '}') {
1246                                                         brr++;
1247                                                 }
1248                                                 p++;
1249                                         }
1250                                         p--;
1251                                 } else {
1252                                         s = p;
1253                                         if (*p == '#') {
1254                                                 p++;
1255                                         }
1256                                         while (*p && (isalnum((int) *p) || *p == '_')) {
1257                                                 p++;
1258                                         }
1259                                 }
1260
1261                                 /* copy variable to buffer */
1262                                 len = (p - s > 255) ? 255 : (p - s);
1263                                 strncpy(buf, s, len);
1264                                 buf[len] = '\0';
1265
1266                                 if (*p == '}') {
1267                                         p++;
1268                                 }
1269                                 s = p;
1270
1271                                 /* search for variable in environment */
1272
1273                                 var = getenv(buf);
1274                                 if (var) {
1275                                         obj = create_plain_text(var);
1276                                         if (obj) {
1277                                                 append_object(retval, obj);
1278                                         }
1279                                         continue;
1280                                 }
1281
1282                                 /* if variable wasn't found in environment, use some special */
1283
1284                                 arg = 0;
1285
1286                                 /* split arg */
1287                                 if (strchr(buf, ' ')) {
1288                                         arg = strchr(buf, ' ');
1289                                         *arg = '\0';
1290                                         arg++;
1291                                         while (isspace((int) *arg)) {
1292                                                 arg++;
1293                                         }
1294                                         if (!*arg) {
1295                                                 arg = 0;
1296                                         }
1297                                 }
1298
1299                                 /* lowercase variable name */
1300                                 tmp_p = buf;
1301                                 while (*tmp_p) {
1302                                         *tmp_p = tolower(*tmp_p);
1303                                         tmp_p++;
1304                                 }
1305
1306                                 obj = construct_text_object(buf, arg,
1307                                                 line, &ifblock_opaque, orig_p);
1308                                 if (obj != NULL) {
1309                                         append_object(retval, obj);
1310                                 }
1311                                 continue;
1312                         } else {
1313                                 obj = create_plain_text("$");
1314                                 s = p + 1;
1315                                 if (obj != NULL) {
1316                                         append_object(retval, obj);
1317                                 }
1318                         }
1319                 } else if (*p == '\\' && *(p+1) == '#') {
1320                         strfold(p, 1);
1321                 } else if (*p == '#') {
1322                         char c;
1323                         if (remove_comment(p, &c) && p > orig_p && c == '\n') {
1324                                 /* if remove_comment removed a newline, we need to 'back up' with p */
1325                                 p--;
1326                         }
1327                 }
1328                 p++;
1329         }
1330         obj = create_plain_text(s);
1331         if (obj != NULL) {
1332                 append_object(retval, obj);
1333         }
1334
1335         if (!ifblock_stack_empty(&ifblock_opaque)) {
1336                 NORM_ERR("one or more $endif's are missing");
1337         }
1338
1339         free(orig_p);
1340         return 0;
1341 }
1342
1343 /*
1344  * Frees the list of text objects root points to.  When internal = 1, it won't
1345  * free global objects.
1346  */
1347 void free_text_objects(struct text_object *root, int internal)
1348 {
1349         struct text_object *obj;
1350
1351         if (!root->prev) {
1352                 return;
1353         }
1354
1355 #define data obj->data
1356         for (obj = root->prev; obj; obj = root->prev) {
1357                 root->prev = obj->prev;
1358                 switch (obj->type) {
1359 #ifndef __OpenBSD__
1360                         case OBJ_acpitemp:
1361                                 close(data.i);
1362                                 break;
1363 #endif /* !__OpenBSD__ */
1364 #ifdef __linux__
1365                         case OBJ_i2c:
1366                         case OBJ_platform:
1367                         case OBJ_hwmon:
1368                                 free_sysfs_sensor(obj);
1369                                 break;
1370 #endif /* __linux__ */
1371                         case OBJ_read_tcp:
1372                                 free_read_tcp(obj);
1373                                 break;
1374                         case OBJ_time:
1375                         case OBJ_utime:
1376                                 free_time(obj);
1377                                 break;
1378                         case OBJ_tztime:
1379                                 free_tztime(obj);
1380                                 break;
1381                         case OBJ_mboxscan:
1382                                 free(data.mboxscan.args);
1383                                 free(data.mboxscan.output);
1384                                 break;
1385                         case OBJ_mails:
1386                         case OBJ_new_mails:
1387                         case OBJ_seen_mails:
1388                         case OBJ_unseen_mails:
1389                         case OBJ_flagged_mails:
1390                         case OBJ_unflagged_mails:
1391                         case OBJ_forwarded_mails:
1392                         case OBJ_unforwarded_mails:
1393                         case OBJ_replied_mails:
1394                         case OBJ_unreplied_mails:
1395                         case OBJ_draft_mails:
1396                         case OBJ_trashed_mails:
1397                                 free(data.local_mail.mbox);
1398                                 break;
1399                         case OBJ_imap_unseen:
1400                         case OBJ_imap_messages:
1401                         case OBJ_pop3_unseen:
1402                         case OBJ_pop3_used:
1403                                 free_mail_obj(obj);
1404                                 break;
1405                         case OBJ_if_empty:
1406                         case OBJ_if_match:
1407                                 free_text_objects(obj->sub, 1);
1408                                 free(obj->sub);
1409                                 /* fall through */
1410                         case OBJ_if_existing:
1411                         case OBJ_if_mounted:
1412                         case OBJ_if_running:
1413                                 free(data.ifblock.s);
1414                                 free(data.ifblock.str);
1415                                 break;
1416                         case OBJ_head:
1417                         case OBJ_tail:
1418                                 free_tailhead(obj);
1419                                 break;
1420                         case OBJ_text:
1421                         case OBJ_font:
1422                         case OBJ_image:
1423                         case OBJ_eval:
1424                         case OBJ_exec:
1425                         case OBJ_execbar:
1426 #ifdef X11
1427                         case OBJ_execgauge:
1428                         case OBJ_execgraph:
1429 #endif
1430                         case OBJ_execp:
1431                                 free_exec(obj);
1432                                 break;
1433 #ifdef HAVE_ICONV
1434                         case OBJ_iconv_start:
1435                                 free_iconv();
1436                                 break;
1437 #endif
1438 #ifdef __linux__
1439                         case OBJ_disk_protect:
1440                                 free(data.s);
1441                                 break;
1442                         case OBJ_if_gw:
1443                                 free(data.ifblock.s);
1444                                 free(data.ifblock.str);
1445                         case OBJ_gw_iface:
1446                         case OBJ_gw_ip:
1447                                 free_gateway_info();
1448                                 break;
1449                         case OBJ_ioscheduler:
1450                                 if(data.s)
1451                                         free(data.s);
1452                                 break;
1453 #endif
1454 #if (defined(__FreeBSD__) || defined(__linux__))
1455                         case OBJ_if_up:
1456                                 free(data.ifblock.s);
1457                                 free(data.ifblock.str);
1458                                 break;
1459 #endif
1460 #ifdef XMMS2
1461                         case OBJ_xmms2_artist:
1462                                 if (info.xmms2.artist) {
1463                                         free(info.xmms2.artist);
1464                                         info.xmms2.artist = 0;
1465                                 }
1466                                 break;
1467                         case OBJ_xmms2_album:
1468                                 if (info.xmms2.album) {
1469                                         free(info.xmms2.album);
1470                                         info.xmms2.album = 0;
1471                                 }
1472                                 break;
1473                         case OBJ_xmms2_title:
1474                                 if (info.xmms2.title) {
1475                                         free(info.xmms2.title);
1476                                         info.xmms2.title = 0;
1477                                 }
1478                                 break;
1479                         case OBJ_xmms2_genre:
1480                                 if (info.xmms2.genre) {
1481                                         free(info.xmms2.genre);
1482                                         info.xmms2.genre = 0;
1483                                 }
1484                                 break;
1485                         case OBJ_xmms2_comment:
1486                                 if (info.xmms2.comment) {
1487                                         free(info.xmms2.comment);
1488                                         info.xmms2.comment = 0;
1489                                 }
1490                                 break;
1491                         case OBJ_xmms2_url:
1492                                 if (info.xmms2.url) {
1493                                         free(info.xmms2.url);
1494                                         info.xmms2.url = 0;
1495                                 }
1496                                 break;
1497                         case OBJ_xmms2_date:
1498                                 if (info.xmms2.date) {
1499                                         free(info.xmms2.date);
1500                                         info.xmms2.date = 0;
1501                                 }
1502                                 break;
1503                         case OBJ_xmms2_status:
1504                                 if (info.xmms2.status) {
1505                                         free(info.xmms2.status);
1506                                         info.xmms2.status = 0;
1507                                 }
1508                                 break;
1509                         case OBJ_xmms2_playlist:
1510                                 if (info.xmms2.playlist) {
1511                                         free(info.xmms2.playlist);
1512                                         info.xmms2.playlist = 0;
1513                                 }
1514                                 break;
1515                         case OBJ_xmms2_smart:
1516                                 if (info.xmms2.artist) {
1517                                         free(info.xmms2.artist);
1518                                         info.xmms2.artist = 0;
1519                                 }
1520                                 if (info.xmms2.title) {
1521                                         free(info.xmms2.title);
1522                                         info.xmms2.title = 0;
1523                                 }
1524                                 if (info.xmms2.url) {
1525                                         free(info.xmms2.url);
1526                                         info.xmms2.url = 0;
1527                                 }
1528                                 break;
1529 #endif
1530 #ifdef BMPX
1531                         case OBJ_bmpx_title:
1532                         case OBJ_bmpx_artist:
1533                         case OBJ_bmpx_album:
1534                         case OBJ_bmpx_track:
1535                         case OBJ_bmpx_uri:
1536                         case OBJ_bmpx_bitrate:
1537                                 break;
1538 #endif
1539 #ifdef EVE
1540                         case OBJ_eve:
1541                                 free_eve(obj);
1542                                 break;
1543 #endif
1544 #ifdef HAVE_CURL
1545                         case OBJ_curl:
1546                                 curl_obj_free(obj);
1547                                 break;
1548 #endif
1549 #ifdef RSS
1550                         case OBJ_rss:
1551                                 rss_free_obj_info(obj);
1552                                 break;
1553 #endif
1554 #ifdef WEATHER
1555                         case OBJ_weather:
1556                                 free_weather(obj);
1557                                 break;
1558 #endif
1559 #ifdef XOAP
1560                         case OBJ_weather_forecast:
1561                                 free_weather(obj);
1562                                 break;
1563 #endif
1564 #ifdef HAVE_LUA
1565                         case OBJ_lua:
1566                         case OBJ_lua_parse:
1567                         case OBJ_lua_bar:
1568 #ifdef X11
1569                         case OBJ_lua_graph:
1570                         case OBJ_lua_gauge:
1571 #endif /* X11 */
1572                                 free(data.s);
1573                                 break;
1574 #endif /* HAVE_LUA */
1575                         case OBJ_pre_exec:
1576                                 break;
1577 #ifndef __OpenBSD__
1578                         case OBJ_battery:
1579                                 free(data.s);
1580                                 break;
1581                         case OBJ_battery_short:
1582                                 free(data.s);
1583                                 break;
1584                         case OBJ_battery_time:
1585                                 free(data.s);
1586                                 break;
1587 #endif /* !__OpenBSD__ */
1588                         case OBJ_execpi:
1589                         case OBJ_execi:
1590                         case OBJ_execibar:
1591                         case OBJ_texeci:
1592 #ifdef X11
1593                         case OBJ_execigraph:
1594                         case OBJ_execigauge:
1595 #endif /* X11 */
1596                                 free_execi(obj);
1597                                 break;
1598                         case OBJ_nameserver:
1599                                 free_dns_data();
1600                                 break;
1601                         case OBJ_top:
1602                         case OBJ_top_mem:
1603                         case OBJ_top_time:
1604 #ifdef IOSTATS
1605                         case OBJ_top_io:
1606 #endif
1607                                 if (info.first_process && !internal) {
1608                                         free_all_processes();
1609                                         info.first_process = NULL;
1610                                 }
1611                                 if (data.top.s) free(data.top.s);
1612                                 break;
1613 #ifdef HDDTEMP
1614                         case OBJ_hddtemp:
1615                                 if (data.s) {
1616                                         free(data.s);
1617                                         data.s = NULL;
1618                                 }
1619                                 free_hddtemp();
1620                                 break;
1621 #endif /* HDDTEMP */
1622                         case OBJ_entropy_avail:
1623                         case OBJ_entropy_perc:
1624                         case OBJ_entropy_poolsize:
1625                         case OBJ_entropy_bar:
1626                                 break;
1627                         case OBJ_user_names:
1628                                 if (info.users.names) {
1629                                         free(info.users.names);
1630                                         info.users.names = 0;
1631                                 }
1632                                 break;
1633                         case OBJ_user_terms:
1634                                 if (info.users.terms) {
1635                                         free(info.users.terms);
1636                                         info.users.terms = 0;
1637                                 }
1638                                 break;
1639                         case OBJ_user_times:
1640                                 if (info.users.times) {
1641                                         free(info.users.times);
1642                                         info.users.times = 0;
1643                                 }
1644                                 break;
1645 #ifdef IBM
1646                         case OBJ_smapi:
1647                         case OBJ_smapi_bat_perc:
1648                         case OBJ_smapi_bat_temp:
1649                         case OBJ_smapi_bat_power:
1650                                 free(data.s);
1651                                 break;
1652                         case OBJ_if_smapi_bat_installed:
1653                                 free(data.ifblock.s);
1654                                 free(data.ifblock.str);
1655                                 break;
1656 #endif /* IBM */
1657 #ifdef NVIDIA
1658                         case OBJ_nvidia:
1659                                 free_nvidia(obj);
1660                                 break;
1661 #endif /* NVIDIA */
1662 #ifdef MPD
1663                         case OBJ_mpd_title:
1664                         case OBJ_mpd_artist:
1665                         case OBJ_mpd_album:
1666                         case OBJ_mpd_random:
1667                         case OBJ_mpd_repeat:
1668                         case OBJ_mpd_vol:
1669                         case OBJ_mpd_bitrate:
1670                         case OBJ_mpd_status:
1671                         case OBJ_mpd_bar:
1672                         case OBJ_mpd_elapsed:
1673                         case OBJ_mpd_length:
1674                         case OBJ_mpd_track:
1675                         case OBJ_mpd_name:
1676                         case OBJ_mpd_file:
1677                         case OBJ_mpd_percent:
1678                         case OBJ_mpd_smart:
1679                         case OBJ_if_mpd_playing:
1680                                 free_mpd();
1681                                 break;
1682 #endif /* MPD */
1683 #ifdef MOC
1684                         case OBJ_moc_state:
1685                         case OBJ_moc_file:
1686                         case OBJ_moc_title:
1687                         case OBJ_moc_artist:
1688                         case OBJ_moc_song:
1689                         case OBJ_moc_album:
1690                         case OBJ_moc_totaltime:
1691                         case OBJ_moc_timeleft:
1692                         case OBJ_moc_curtime:
1693                         case OBJ_moc_bitrate:
1694                         case OBJ_moc_rate:
1695                                 free_moc();
1696                                 break;
1697 #endif /* MOC */
1698                         case OBJ_include:
1699                         case OBJ_blink:
1700                         case OBJ_to_bytes:
1701                                 if(obj->sub) {
1702                                         free_text_objects(obj->sub, 1);
1703                                         free(obj->sub);
1704                                 }
1705                                 break;
1706                         case OBJ_scroll:
1707                                 free_scroll(obj);
1708                                 break;
1709                         case OBJ_combine:
1710                                 free_combine(obj);
1711                                 break;
1712 #ifdef APCUPSD
1713                         case OBJ_apcupsd:
1714                         case OBJ_apcupsd_name:
1715                         case OBJ_apcupsd_model:
1716                         case OBJ_apcupsd_upsmode:
1717                         case OBJ_apcupsd_cable:
1718                         case OBJ_apcupsd_status:
1719                         case OBJ_apcupsd_linev:
1720                         case OBJ_apcupsd_load:
1721                         case OBJ_apcupsd_loadbar:
1722 #ifdef X11
1723                         case OBJ_apcupsd_loadgraph:
1724                         case OBJ_apcupsd_loadgauge:
1725 #endif /* X11 */
1726                         case OBJ_apcupsd_charge:
1727                         case OBJ_apcupsd_timeleft:
1728                         case OBJ_apcupsd_temp:
1729                         case OBJ_apcupsd_lastxfer:
1730                                 break;
1731 #endif /* APCUPSD */
1732 #ifdef TCP_PORT_MONITOR
1733                         case OBJ_tcp_portmon:
1734                                 tcp_portmon_free(obj);
1735                                 break;
1736 #endif /* TCP_PORT_MONITOR */
1737 #ifdef X11
1738                         case OBJ_desktop:
1739                         case OBJ_desktop_number:
1740                         case OBJ_desktop_name:
1741                                 if(info.x11.desktop.name && !internal) {
1742                                   free(info.x11.desktop.name);
1743                                   info.x11.desktop.name = NULL;
1744                                 }
1745                                 if(info.x11.desktop.all_names && !internal) {
1746                                   free(info.x11.desktop.all_names);
1747                                   info.x11.desktop.all_names = NULL;
1748                                 }
1749                                 break;
1750 #endif /* X11 */
1751                 }
1752                 free(obj);
1753         }
1754 #undef data
1755 }
1756