RSS was not really disabled when it was supposed to be. Experimental wireless support.
[monky] / src / conky.c
index 8e8719d..34a24b2 100644 (file)
@@ -101,6 +101,10 @@ static void print_version()
        exit(0);
 }
 
+#if defined(__linux__)
+int post_21_kernel;
+#endif /* __linux__ */
+
 #ifdef X11
 
 /*
@@ -299,7 +303,6 @@ static int draw_shades, draw_outline;
 static int border_margin, border_width;
 
 static long default_fg_color, default_bg_color, default_out_color;
-static long color0, color1, color2, color3, color4, color5, color6, color7, color8, color9;
 
 /* create own window or draw stuff to root? */
 static int set_transparent = 0;
@@ -321,6 +324,8 @@ static int maximum_width;
 static int sensor_device;
 #endif
 
+static long color0, color1, color2, color3, color4, color5, color6, color7, color8, color9;
+
 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
 
@@ -333,7 +338,7 @@ unsigned int text_buffer_size = TEXT_BUFFER_SIZE;
 #ifdef HAVE_ICONV
 #define CODEPAGE_LENGTH 20
 long iconv_selected;
-long iconv_count;
+long iconv_count = 0;
 char iconv_converting;
 static iconv_t **iconv_cd = 0;
 
@@ -360,8 +365,9 @@ void free_iconv(void)
 {
        if (iconv_cd) {
                long i;
-               for (i = iconv_count; i < 0; i++) {
+               for (i = 0; i < iconv_count; i++) {
                        if (iconv_cd[i]) {
+                               iconv_close(*iconv_cd[i]);
                                free(iconv_cd[i]);
                        }
                }
@@ -428,42 +434,6 @@ static int blockdepth = 0;
 static int if_jumped = 0;
 static int blockstart[MAX_IF_BLOCK_DEPTH];
 
-int check_mount(char *s)
-{
-#if defined(__linux__)
-       int ret = 0;
-       FILE *mtab = fopen("/etc/mtab", "r");
-       if (mtab) {
-               char buf1[256], buf2[128];
-               while (fgets(buf1, 256, mtab)) {
-                       sscanf(buf1, "%*s %128s", buf2);
-                       if (!strcmp(s, buf2)) {
-                               ret = 1;
-                               break;
-                       }
-               }
-               fclose(mtab);
-       } else {
-               ERR("Could not open mtab");
-       }
-       return ret;
-#elif defined(__FreeBSD__)
-       struct statfs *mntbuf;
-       int i, mntsize;
-
-       mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
-       for (i = mntsize - 1; i >= 0; i--)
-               if (strcmp(mntbuf[i].f_mntonname, s) == 0)
-                       return 1;
-
-       return 0;
-#elif defined(__OpenBSD__)
-       /* stub */
-       return 0;
-#endif
-}
-
-
 int check_contains(char *f, char *s)
 {
        int ret = 0;
@@ -678,9 +648,9 @@ static const char *scan_bar(const char *args, int *w, int *h)
 
 static char *scan_font(const char *args)
 {
-       if (args && sizeof(args) < 127) {
+  if (args && *args)
                return strdup(args);
-       }
+  
        return NULL;
 }
 
@@ -1031,6 +1001,13 @@ enum text_object_type {
         OBJ_pb_battery,
        OBJ_voltage_mv,
        OBJ_voltage_v,
+       OBJ_wireless_essid,
+       OBJ_wireless_mode,
+       OBJ_wireless_bitrate,
+       OBJ_wireless_link_qual,
+       OBJ_wireless_link_qual_max,
+       OBJ_wireless_link_bar,
+       OBJ_wireless_ap,
 #endif /* __linux__ */
        OBJ_if_empty,
        OBJ_if_existing,
@@ -1864,7 +1841,8 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
                                free(objs[i].data.tail.logfile);
                                free(objs[i].data.tail.buffer);
                                break;
-                       case OBJ_text: case OBJ_font:
+                       case OBJ_text:
+                       case OBJ_font:
                                free(objs[i].data.s);
                                break;
                        case OBJ_image:
@@ -2049,6 +2027,7 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
                        case OBJ_rss:
                                free(objs[i].data.rss.uri);
                                free(objs[i].data.rss.action);
+                               break;
 #endif
                        case OBJ_pre_exec:
                        case OBJ_battery:
@@ -2193,6 +2172,46 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
            obj->data.cpu_index=atoi(&arg[0]);
        }
        obj->a = 1;
+
+#ifdef HAVE_IWLIB
+       END OBJ(wireless_essid, INFO_NET)
+       if(arg)
+               obj->data.net = get_net_stat(arg);
+       else
+               CRIT_ERR("wireless_essid: needs an argument");
+       END OBJ(wireless_mode, INFO_NET)
+       if(arg)
+               obj->data.net = get_net_stat(arg);
+       else
+               CRIT_ERR("wireless_mode: needs an argument");
+       END OBJ(wireless_ap, INFO_NET)
+       if(arg)
+               obj->data.net = get_net_stat(arg);
+       else
+               CRIT_ERR("wireless_ap: needs an argument");
+       END OBJ(wireless_bitrate, INFO_NET)
+       if(arg)
+               obj->data.net = get_net_stat(arg);
+       else
+               CRIT_ERR("wireless_bitrate: needs an argument");
+       END OBJ(wireless_link_qual, INFO_NET)
+       if(arg)
+               obj->data.net = get_net_stat(arg);
+       else
+               CRIT_ERR("wireless_link_qual: needs an argument");
+       END OBJ(wireless_link_qual_max, INFO_NET)
+       if(arg)
+               obj->data.net = get_net_stat(arg);
+       else
+               CRIT_ERR("wireless_link_qual_max: needs an argument");
+       END OBJ(wireless_link_bar, INFO_NET)
+       if(arg) {
+               arg = scan_bar(arg, &obj->a, &obj->b);
+               obj->data.net = get_net_stat(arg);
+       } else
+               CRIT_ERR("wireless_link_bar: needs an argument");
+#endif /* HAVE_IWLIB */
+
 #endif /* __linux__ */
        END OBJ(freq_dyn, 0);
        END OBJ(freq_dyn_g, 0);
@@ -2226,6 +2245,7 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
        } else {
                strcpy(bat, "BAT0");
        }
+       obj->data.s = strdup(bat);
 #if defined(__linux__)
        END OBJ(i8k_version, INFO_I8K)
                END OBJ(i8k_bios, INFO_I8K)
@@ -2364,8 +2384,7 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
                obj->data.l = color9;
        END OBJ(font, 0)
                obj->data.s = scan_font(arg);
-       END
-               OBJ(downspeed, INFO_NET) 
+       END OBJ(downspeed, INFO_NET) 
                if(arg) {
                        obj->data.net = get_net_stat(arg);
                }
@@ -2632,6 +2651,7 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
                else {
                        CRIT_ERR("addr needs argument");
                }
+#if 0
        END OBJ(linkstatus, INFO_WIFI) 
                if(arg) {
                        obj->data.net = get_net_stat(arg);
@@ -2639,6 +2659,7 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
                else {
                        CRIT_ERR("linkstatus needs argument");
                }
+#endif
        END OBJ(tail, 0)
                char buf[64];
        int n1, n2;
@@ -3030,8 +3051,18 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
                }
                END
 #ifdef MPD
-               OBJ(mpd_artist, INFO_MPD)
-               END OBJ(mpd_title, INFO_MPD)
+               OBJ(mpd_artist, INFO_MPD) END
+               OBJ(mpd_title, INFO_MPD)
+               {
+                       if (arg)
+                       {
+                           sscanf (arg, "%d", &info.mpd.max_title_len);
+                           if (info.mpd.max_title_len > 0)
+                               info.mpd.max_title_len++;
+                           else
+                               CRIT_ERR ("mpd_title: invalid length argument");
+                       }
+               }
                END OBJ(mpd_random, INFO_MPD)
                END OBJ(mpd_repeat, INFO_MPD)
                END OBJ(mpd_elapsed, INFO_MPD)
@@ -3123,14 +3154,16 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
        OBJ(rss, 0) 
                if (arg) {
                        int argc, delay, act_par;
-                       char *uri = (char *)malloc(128 * sizeof(char *));
-                       char *action = (char *)malloc(64 * sizeof(char *));
+                       char *uri = (char *)malloc(128 * sizeof(char));
+                       char *action = (char *)malloc(64 * sizeof(char));
 
                        argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action, &act_par);
                        obj->data.rss.uri = uri;
                        obj->data.rss.delay = delay;
                        obj->data.rss.action = action;
                        obj->data.rss.act_par = act_par;
+
+                       init_rss_info();
                } else
                        CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> [act_par]");
 
@@ -3496,6 +3529,30 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
                                                obj->a = get_voltage(p, p_max_size, "%'.3f", 1000, obj->data.cpu_index);
                                        }
                                }
+#ifdef HAVE_IWLIB
+                               OBJ(wireless_essid) {
+                                       snprintf(p, p_max_size, "%s", obj->data.net->essid);
+                               }
+                               OBJ(wireless_mode) {
+                                       snprintf(p, p_max_size, "%s", obj->data.net->mode);
+                               }
+                               OBJ(wireless_bitrate) {
+                                       snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
+                               }
+                               OBJ(wireless_ap) {
+                                       snprintf(p, p_max_size, "%s", obj->data.net->ap);
+                               }
+                               OBJ(wireless_link_qual) {
+                                       snprintf(p, p_max_size, "%d", obj->data.net->link_qual);
+                               }
+                               OBJ(wireless_link_qual_max) {
+                                       snprintf(p, p_max_size, "%d", obj->data.net->link_qual_max);
+                               }
+                               OBJ(wireless_link_bar) {
+                                       new_bar(p, obj->a, obj->b, ((double)obj->data.net->link_qual/obj->data.net->link_qual_max)*255.0);
+                               }
+#endif /* HAVE_IWLIB */
+
 #endif /* __linux__ */
 
                                OBJ(freq_dyn) {
@@ -3714,11 +3771,11 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
                                }
 #endif /* __OpenBSD__ */
 
-#ifdef X11
                                OBJ(font) {
+#ifdef X11
                                        new_font(p, obj->data.s);
-                               }
 #endif /* X11 */
+                               }
                                void format_diskio(unsigned int diskio_value)
                                {
                                        if (!use_spacer) {
@@ -4293,18 +4350,28 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
 #ifdef RSS
                        OBJ(rss) {
                                PRSS* data = get_rss_info(obj->data.rss.uri, obj->data.rss.delay);
+                               char *str;
                                if(data == NULL)
                                        snprintf(p, p_max_size, "prss: Error reading RSS data\n");
                                else {
                                        if(!strcmp(obj->data.rss.action, "feed_title")) {
-                                                       snprintf(p, p_max_size, "%s", data->title);
+                                                       str = data->title;
+                                                       if(str[strlen(str)-1] == '\n')
+                                                               str[strlen(str)-1] = 0; // remove trailing new line if one exists
+                                                       snprintf(p, p_max_size, "%s", str);
                                        } else if(!strcmp(obj->data.rss.action, "item_title")) {
                                                if(obj->data.rss.act_par < data->item_count) {
-                                                       snprintf(p, p_max_size, "%s", data->items[obj->data.rss.act_par].title);
+                                                       str = data->items[obj->data.rss.act_par].title;
+                                                       if(str[strlen(str)-1] == '\n')
+                                                               str[strlen(str)-1] = 0; // remove trailing new line if one exists
+                                                       snprintf(p, p_max_size, "%s", str);
                                                }
                                        } else if(!strcmp(obj->data.rss.action, "item_desc")) {
                                                if(obj->data.rss.act_par < data->item_count) {
-                                                       snprintf(p, p_max_size, "%s", data->items[obj->data.rss.act_par].description);
+                                                       str = data->items[obj->data.rss.act_par].description;
+                                                       if(str[strlen(str)-1] == '\n')
+                                                               str[strlen(str)-1] = 0; // remove trailing new line if one exists
+                                                       snprintf(p, p_max_size, "%s", str);
                                                }
                                        } else if(!strcmp(obj->data.rss.action, "item_titles")) {
                                                if(data->item_count > 0) {
@@ -4316,9 +4383,14 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
                                                        else    show = obj->data.rss.act_par;
                                                        for(itmp = 0; itmp < show; itmp++) {
                                                                PRSS_Item *item = &data->items[itmp];
-                                                               if(i>0)
-                                                                       strncat(p, "\n", p_max_size);
-                                                               strncat(p, item->title, p_max_size);
+                                                               str = item->title;
+                                                               if(str) {
+                                                                       if(itmp>0) // don't add new line before first item
+                                                                               strncat(p, "\n", p_max_size);
+                                                                       if(str[strlen(str)-1] == '\n')
+                                                                               str[strlen(str)-1] = 0; // remove trailing new line if one exists, we have our own
+                                                                       strncat(p, str, p_max_size);
+                                                               }
                                                        }
                                                }
                                        }
@@ -4616,7 +4688,7 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
                                                        trans_speed /
                                                        1024));
                                else
-                                       snprintf(p, 5, "%d     ",
+                                       snprintf(p, 6, "%d     ",
                                                 (int) (obj->data.net->
                                                        trans_speed /
                                                        1024));
@@ -4671,7 +4743,9 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
 
 #ifdef MPD
                        OBJ(mpd_title) {
-                               snprintf(p, p_max_size, "%s", cur->mpd.title);
+                           snprintf(p, cur->mpd.max_title_len > 0 ?
+                                       cur->mpd.max_title_len : p_max_size, "%s", 
+                                    cur->mpd.title);
                        }
                        OBJ(mpd_artist) {
                                snprintf(p, p_max_size, "%s", cur->mpd.artist);
@@ -4920,25 +4994,23 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
                                if (obj->data.top.type == TOP_NAME
                                    && obj->data.top.num >= 0
                                    && obj->data.top.num < 10) {
-                                       // if we limit the buffer and add a bunch of space after, it stops the thing from
-                                       // moving other shit around, which is really fucking annoying
-                                       snprintf(p, 17, "%s                              ", cur->cpu[obj->data.top.num]->name);
+                                       snprintf(p, 17, "%-17s", cur->cpu[obj->data.top.num]->name);
                                } else if (obj->data.top.type == TOP_CPU
                                           && obj->data.top.num >= 0
                                           && obj->data.top.num < 10) {
-                                       snprintf(p, 7, "%3.2f      ",
+                                       snprintf(p, 7, "%7.3f",
                                                 cur->cpu[obj->data.top.
                                                          num]->amount);
                                } else if (obj->data.top.type == TOP_PID
                                           && obj->data.top.num >= 0
                                           && obj->data.top.num < 10) {
-                                       snprintf(p, 8, "%i           ",
+                                       snprintf(p, 8, "%7i",
                                                 cur->cpu[obj->data.top.
                                                          num]->pid);
                                } else if (obj->data.top.type == TOP_MEM
                                           && obj->data.top.num >= 0
                                           && obj->data.top.num < 10) {
-                                       snprintf(p, 7, "%3.2f       ",
+                                       snprintf(p, 7, "%7.3f",
                                                 cur->cpu[obj->data.top.
                                                          num]->totalmem);
                                }
@@ -4947,28 +5019,25 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
                                if (obj->data.top.type == TOP_NAME
                                    && obj->data.top.num >= 0
                                    && obj->data.top.num < 10) {
-                                       // if we limit the buffer and add a bunch of space after, it stops the thing from
-                                       // moving other shit around, which is really fucking annoying
-                                       snprintf(p, 17,
-                                                "%s                              ",
+                                       snprintf(p, 17, "%-17s",
                                                 cur->memu[obj->data.top.
                                                           num]->name);
                                } else if (obj->data.top.type == TOP_CPU
                                           && obj->data.top.num >= 0
                                           && obj->data.top.num < 10) {
-                                       snprintf(p, 7, "%3.2f      ",
+                                       snprintf(p, 7, "%7.3f",
                                                 cur->memu[obj->data.top.
                                                           num]->amount);
                                } else if (obj->data.top.type == TOP_PID
                                           && obj->data.top.num >= 0
                                           && obj->data.top.num < 10) {
-                                       snprintf(p, 8, "%i           ",
+                                       snprintf(p, 8, "%7i",
                                                 cur->memu[obj->data.top.
                                                           num]->pid);
                                } else if (obj->data.top.type == TOP_MEM
                                           && obj->data.top.num >= 0
                                           && obj->data.top.num < 10) {
-                                       snprintf(p, 7, "%3.2f       ",
+                                       snprintf(p, 7, "%7.3f",
                                                 cur->memu[obj->data.top.
                                                           num]->totalmem);
                                }
@@ -6507,10 +6576,17 @@ void clean_up(void)
        destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
        info.p_tcp_port_monitor_collection = NULL;
 #endif
+#ifdef RSS
+       free_rss_info();
+#endif
 
        if (specials) {
-           free (specials);
-           specials=NULL;
+               unsigned int i;
+               for(i=0;i<special_count;i++)
+                       if(specials[i].type == GRAPH)
+                               free(specials[i].graph);
+               free (specials);
+               specials=NULL;
        }
 }
 
@@ -6585,6 +6661,9 @@ static void set_default_configurations(void)
     info.xmms2.status = NULL;
 #endif
        use_spacer = 0;
+#if defined(__linux__)
+       post_21_kernel = 0;
+#endif /* __linux__ */
 #ifdef X11
        out_to_console = 0;
 #else
@@ -6917,6 +6996,11 @@ else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
                CONF("draw_outline") {
                        draw_outline = string_to_bool(value);
                }
+#if defined(__linux__)
+               CONF("post_21_kernel") {
+                       post_21_kernel = string_to_bool(value);
+               }
+#endif /* __linux__ */
 #endif /* X11 */
                CONF("out_to_console") {
                        out_to_console = string_to_bool(value);