mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-05 21:07:52 +00:00
Again fixed things in the RSS code. Removed possible trailing \n from RSS data. Hopefully fixed iconv memory freeing problems. Graps had non-freed malloced data.
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@876 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
parent
3872bafeef
commit
2c8426dcc7
42
src/conky.c
42
src/conky.c
@ -333,7 +333,7 @@ unsigned int text_buffer_size = TEXT_BUFFER_SIZE;
|
|||||||
#ifdef HAVE_ICONV
|
#ifdef HAVE_ICONV
|
||||||
#define CODEPAGE_LENGTH 20
|
#define CODEPAGE_LENGTH 20
|
||||||
long iconv_selected;
|
long iconv_selected;
|
||||||
long iconv_count;
|
long iconv_count = 0;
|
||||||
char iconv_converting;
|
char iconv_converting;
|
||||||
static iconv_t **iconv_cd = 0;
|
static iconv_t **iconv_cd = 0;
|
||||||
|
|
||||||
@ -360,8 +360,9 @@ void free_iconv(void)
|
|||||||
{
|
{
|
||||||
if (iconv_cd) {
|
if (iconv_cd) {
|
||||||
long i;
|
long i;
|
||||||
for (i = iconv_count; i < 0; i++) {
|
for (i = 0; i < iconv_count; i++) {
|
||||||
if (iconv_cd[i]) {
|
if (iconv_cd[i]) {
|
||||||
|
iconv_close(*iconv_cd[i]);
|
||||||
free(iconv_cd[i]);
|
free(iconv_cd[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2049,6 +2050,7 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
|
|||||||
case OBJ_rss:
|
case OBJ_rss:
|
||||||
free(objs[i].data.rss.uri);
|
free(objs[i].data.rss.uri);
|
||||||
free(objs[i].data.rss.action);
|
free(objs[i].data.rss.action);
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
case OBJ_pre_exec:
|
case OBJ_pre_exec:
|
||||||
case OBJ_battery:
|
case OBJ_battery:
|
||||||
@ -3123,14 +3125,16 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
|
|||||||
OBJ(rss, 0)
|
OBJ(rss, 0)
|
||||||
if (arg) {
|
if (arg) {
|
||||||
int argc, delay, act_par;
|
int argc, delay, act_par;
|
||||||
char *uri = (char *)malloc(128 * sizeof(char *));
|
char *uri = (char *)malloc(128 * sizeof(char));
|
||||||
char *action = (char *)malloc(64 * sizeof(char *));
|
char *action = (char *)malloc(64 * sizeof(char));
|
||||||
|
|
||||||
argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action, &act_par);
|
argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action, &act_par);
|
||||||
obj->data.rss.uri = uri;
|
obj->data.rss.uri = uri;
|
||||||
obj->data.rss.delay = delay;
|
obj->data.rss.delay = delay;
|
||||||
obj->data.rss.action = action;
|
obj->data.rss.action = action;
|
||||||
obj->data.rss.act_par = act_par;
|
obj->data.rss.act_par = act_par;
|
||||||
|
|
||||||
|
init_rss_info();
|
||||||
} else
|
} else
|
||||||
CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> [act_par]");
|
CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> [act_par]");
|
||||||
|
|
||||||
@ -4293,18 +4297,28 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
|
|||||||
#ifdef RSS
|
#ifdef RSS
|
||||||
OBJ(rss) {
|
OBJ(rss) {
|
||||||
PRSS* data = get_rss_info(obj->data.rss.uri, obj->data.rss.delay);
|
PRSS* data = get_rss_info(obj->data.rss.uri, obj->data.rss.delay);
|
||||||
|
char *str;
|
||||||
if(data == NULL)
|
if(data == NULL)
|
||||||
snprintf(p, p_max_size, "prss: Error reading RSS data\n");
|
snprintf(p, p_max_size, "prss: Error reading RSS data\n");
|
||||||
else {
|
else {
|
||||||
if(!strcmp(obj->data.rss.action, "feed_title")) {
|
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")) {
|
} else if(!strcmp(obj->data.rss.action, "item_title")) {
|
||||||
if(obj->data.rss.act_par < data->item_count) {
|
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")) {
|
} else if(!strcmp(obj->data.rss.action, "item_desc")) {
|
||||||
if(obj->data.rss.act_par < data->item_count) {
|
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")) {
|
} else if(!strcmp(obj->data.rss.action, "item_titles")) {
|
||||||
if(data->item_count > 0) {
|
if(data->item_count > 0) {
|
||||||
@ -4318,6 +4332,9 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
|
|||||||
PRSS_Item *item = &data->items[itmp];
|
PRSS_Item *item = &data->items[itmp];
|
||||||
if(i>0)
|
if(i>0)
|
||||||
strncat(p, "\n", p_max_size);
|
strncat(p, "\n", p_max_size);
|
||||||
|
str = item->title;
|
||||||
|
if(str[strlen(str)-1] == '\n')
|
||||||
|
str[strlen(str)-1] = 0; // remove trailing new line if one exists
|
||||||
strncat(p, item->title, p_max_size);
|
strncat(p, item->title, p_max_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6507,10 +6524,17 @@ void clean_up(void)
|
|||||||
destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
|
destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
|
||||||
info.p_tcp_port_monitor_collection = NULL;
|
info.p_tcp_port_monitor_collection = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef RSS
|
||||||
|
free_rss_info();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (specials) {
|
if (specials) {
|
||||||
free (specials);
|
unsigned int i;
|
||||||
specials=NULL;
|
for(i=0;i<special_count;i++)
|
||||||
|
if(specials[i].type == GRAPH)
|
||||||
|
free(specials[i].graph);
|
||||||
|
free (specials);
|
||||||
|
specials=NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -599,6 +599,8 @@ char *get_hddtemp_info(char *dev, char *addr, int port, char *unit);
|
|||||||
/* in rss.c */
|
/* in rss.c */
|
||||||
#ifdef RSS
|
#ifdef RSS
|
||||||
PRSS* get_rss_info(char *uri, int delay);
|
PRSS* get_rss_info(char *uri, int delay);
|
||||||
|
void init_rss_info();
|
||||||
|
void free_rss_info();
|
||||||
#endif /* RSS */
|
#endif /* RSS */
|
||||||
|
|
||||||
/* in linux.c */
|
/* in linux.c */
|
||||||
|
35
src/rss.c
35
src/rss.c
@ -70,6 +70,24 @@ int rss_delay(int *wait, int delay)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init_rss_info()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < MAX_FEEDS; i++) {
|
||||||
|
feeds[i].uri = NULL;
|
||||||
|
feeds[i].data = NULL;
|
||||||
|
feeds[i].last_update = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_rss_info()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < num_feeds; i++)
|
||||||
|
if(feeds[i].uri != NULL)
|
||||||
|
free(feeds[i].uri);
|
||||||
|
}
|
||||||
|
|
||||||
PRSS*
|
PRSS*
|
||||||
get_rss_info(char *uri, int delay)
|
get_rss_info(char *uri, int delay)
|
||||||
{
|
{
|
||||||
@ -88,21 +106,18 @@ get_rss_info(char *uri, int delay)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
// first seek for the uri in list
|
// first seek for the uri in list
|
||||||
if(num_feeds > 0) {
|
for(i = 0; i < num_feeds; i++) {
|
||||||
for(i = 0; i < num_feeds; i++) {
|
if(feeds[i].uri != NULL)
|
||||||
if(feeds[i].uri != NULL)
|
if(!strcmp(feeds[i].uri, uri)) {
|
||||||
if(!strcmp(feeds[i].uri, uri)) {
|
curfeed = &feeds[i];
|
||||||
curfeed = &feeds[i];
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!curfeed) { // new feed
|
if(!curfeed) { // new feed
|
||||||
if(num_feeds == MAX_FEEDS-1) return NULL;
|
if(num_feeds == MAX_FEEDS-1) return NULL;
|
||||||
curfeed = &feeds[num_feeds];
|
curfeed = &feeds[num_feeds];
|
||||||
curfeed->uri = (char *)malloc(sizeof(char) * strlen(uri)+1);
|
curfeed->uri = strdup(uri);
|
||||||
strncpy(curfeed->uri, uri, strlen(uri)+1);
|
|
||||||
num_feeds++;
|
num_feeds++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user