mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-18 02:55:12 +00:00
RSS updates: more flexible output and updated prss code
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@873 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
parent
92e5028b99
commit
b6d1465635
41
src/conky.c
41
src/conky.c
@ -95,7 +95,7 @@ static void print_version()
|
|||||||
#endif /* TCP_PORT_MONITOR */
|
#endif /* TCP_PORT_MONITOR */
|
||||||
#ifdef RSS
|
#ifdef RSS
|
||||||
" * rss\n"
|
" * rss\n"
|
||||||
#endif
|
#endif /* RSS */
|
||||||
"\n");
|
"\n");
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -1286,7 +1286,8 @@ struct text_object {
|
|||||||
#ifdef RSS
|
#ifdef RSS
|
||||||
struct {
|
struct {
|
||||||
char *uri;
|
char *uri;
|
||||||
int count;
|
char *action;
|
||||||
|
int act_par;
|
||||||
int delay;
|
int delay;
|
||||||
} rss;
|
} rss;
|
||||||
#endif
|
#endif
|
||||||
@ -2047,6 +2048,7 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
|
|||||||
#ifdef RSS
|
#ifdef RSS
|
||||||
case OBJ_rss:
|
case OBJ_rss:
|
||||||
free(objs[i].data.rss.uri);
|
free(objs[i].data.rss.uri);
|
||||||
|
free(objs[i].data.rss.action);
|
||||||
#endif
|
#endif
|
||||||
case OBJ_pre_exec:
|
case OBJ_pre_exec:
|
||||||
case OBJ_battery:
|
case OBJ_battery:
|
||||||
@ -3120,15 +3122,17 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
|
|||||||
#ifdef RSS
|
#ifdef RSS
|
||||||
OBJ(rss, 0)
|
OBJ(rss, 0)
|
||||||
if (arg) {
|
if (arg) {
|
||||||
int argc, count, delay;
|
int argc, delay, act_par;
|
||||||
char *uri = (char *)malloc(64 * sizeof(char *));
|
char *uri = (char *)malloc(128 * sizeof(char *));
|
||||||
|
char *action = (char *)malloc(64 * sizeof(char *));
|
||||||
|
|
||||||
argc = sscanf(arg, "%63s %d %d", uri, &count, &delay);
|
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.count = count;
|
|
||||||
obj->data.rss.delay = delay;
|
obj->data.rss.delay = delay;
|
||||||
|
obj->data.rss.action = action;
|
||||||
|
obj->data.rss.act_par = act_par;
|
||||||
} else
|
} else
|
||||||
CRIT_ERR("rss: needs arguments (uri, item count, delay in minutes)");
|
CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> [act_par]");
|
||||||
|
|
||||||
END
|
END
|
||||||
#endif
|
#endif
|
||||||
@ -4292,23 +4296,32 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
|
|||||||
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")) {
|
||||||
|
snprintf(p, p_max_size, "%s", data->title);
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
} else if(!strcmp(obj->data.rss.action, "item_titles")) {
|
||||||
if(data->item_count > 0) {
|
if(data->item_count > 0) {
|
||||||
int itmp;
|
int itmp;
|
||||||
char ctmp[64];
|
|
||||||
p[0] = 0;
|
p[0] = 0;
|
||||||
int show;
|
int show;
|
||||||
if(obj->data.rss.count > data->item_count)
|
if(obj->data.rss.act_par > data->item_count)
|
||||||
show = data->item_count;
|
show = data->item_count;
|
||||||
else show = obj->data.rss.count;
|
else show = obj->data.rss.act_par;
|
||||||
for(itmp = 0; itmp < show; itmp++) {
|
for(itmp = 0; itmp < show; itmp++) {
|
||||||
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);
|
||||||
snprintf(ctmp, 64, "%s", item->title);
|
strncat(p, item->title, p_max_size);
|
||||||
strncat(p, ctmp, p_max_size);
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else
|
|
||||||
snprintf(p, p_max_size, "prss: Empty feed");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
18
src/prss.c
18
src/prss.c
@ -26,15 +26,13 @@
|
|||||||
#define PARSE_OPTIONS 0
|
#define PARSE_OPTIONS 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static PRSS* get_data(xmlDocPtr doc);
|
|
||||||
|
|
||||||
PRSS* prss_parse_data(const char* xml_data)
|
PRSS* prss_parse_data(const char* xml_data)
|
||||||
{
|
{
|
||||||
xmlDocPtr doc = xmlReadMemory(xml_data, strlen(xml_data), "", NULL, PARSE_OPTIONS);
|
xmlDocPtr doc = xmlReadMemory(xml_data, strlen(xml_data), "", NULL, PARSE_OPTIONS);
|
||||||
if (!doc)
|
if (!doc)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return get_data(doc);
|
return prss_parse_doc(doc);
|
||||||
}
|
}
|
||||||
PRSS* prss_parse_file(const char* xml_file)
|
PRSS* prss_parse_file(const char* xml_file)
|
||||||
{
|
{
|
||||||
@ -42,7 +40,7 @@ PRSS* prss_parse_file(const char* xml_file)
|
|||||||
if (!doc)
|
if (!doc)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return get_data(doc);
|
return prss_parse_doc(doc);
|
||||||
}
|
}
|
||||||
void prss_free(PRSS* data)
|
void prss_free(PRSS* data)
|
||||||
{
|
{
|
||||||
@ -55,13 +53,11 @@ void prss_free(PRSS* data)
|
|||||||
|
|
||||||
static inline void prss_null(PRSS* p)
|
static inline void prss_null(PRSS* p)
|
||||||
{
|
{
|
||||||
p->title = p->link = p->description = p->language = NULL;
|
memset(p, 0, sizeof(PRSS));
|
||||||
p->items = NULL;
|
|
||||||
p->item_count = 0;
|
|
||||||
}
|
}
|
||||||
static inline void prss_null_item(PRSS_Item* i)
|
static inline void prss_null_item(PRSS_Item* i)
|
||||||
{
|
{
|
||||||
i->title = i->link = i->description = i->category = i->pubdate = NULL;
|
memset(i, 0, sizeof(PRSS_Item));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void read_item(PRSS_Item* res, xmlNodePtr data)
|
static inline void read_item(PRSS_Item* res, xmlNodePtr data)
|
||||||
@ -127,7 +123,9 @@ static inline void read_element(PRSS* res, xmlNodePtr n)
|
|||||||
static inline int parse_rss_2_0(PRSS* res, xmlNodePtr root)
|
static inline int parse_rss_2_0(PRSS* res, xmlNodePtr root)
|
||||||
{
|
{
|
||||||
xmlNodePtr channel = root->children;
|
xmlNodePtr channel = root->children;
|
||||||
while(channel && (channel->type!=XML_ELEMENT_NODE || strcmp((char*)channel->name, "channel")))
|
while(channel
|
||||||
|
&& (channel->type!=XML_ELEMENT_NODE
|
||||||
|
|| strcmp((char*)channel->name, "channel")))
|
||||||
channel = channel->next;
|
channel = channel->next;
|
||||||
if (!channel)
|
if (!channel)
|
||||||
return 0;
|
return 0;
|
||||||
@ -180,7 +178,7 @@ static inline int parse_rss_0_9x(PRSS* res, xmlNodePtr root)
|
|||||||
return parse_rss_2_0(res, root);
|
return parse_rss_2_0(res, root);
|
||||||
}
|
}
|
||||||
|
|
||||||
PRSS* get_data(xmlDocPtr doc)
|
PRSS* prss_parse_doc(xmlDocPtr doc)
|
||||||
{
|
{
|
||||||
xmlNodePtr root = xmlDocGetRootElement(doc);
|
xmlNodePtr root = xmlDocGetRootElement(doc);
|
||||||
PRSS* result = malloc(sizeof(PRSS));
|
PRSS* result = malloc(sizeof(PRSS));
|
||||||
|
@ -50,6 +50,7 @@ typedef struct PRSS_ {
|
|||||||
/* Functions for parsing RSS-data */
|
/* Functions for parsing RSS-data */
|
||||||
PRSS* prss_parse_data(const char *xml_data);
|
PRSS* prss_parse_data(const char *xml_data);
|
||||||
PRSS* prss_parse_file(const char *xml_file);
|
PRSS* prss_parse_file(const char *xml_file);
|
||||||
|
PRSS* prss_parse_doc(xmlDocPtr doc);
|
||||||
|
|
||||||
/* Frees the PRSS-stucture returned by prss_parse_*.
|
/* Frees the PRSS-stucture returned by prss_parse_*.
|
||||||
* The memory area pointed by data becomes invalid
|
* The memory area pointed by data becomes invalid
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
#include <curl/types.h>
|
#include <curl/types.h>
|
||||||
#include <curl/easy.h>
|
#include <curl/easy.h>
|
||||||
|
|
||||||
|
#include "conky.h"
|
||||||
|
|
||||||
#define MAX_FEEDS 16
|
#define MAX_FEEDS 16
|
||||||
|
|
||||||
struct MemoryStruct {
|
struct MemoryStruct {
|
||||||
@ -125,7 +127,8 @@ get_rss_info(char *uri, int delay)
|
|||||||
if(chunk.size) {
|
if(chunk.size) {
|
||||||
curdata = prss_parse_data(chunk.memory);
|
curdata = prss_parse_data(chunk.memory);
|
||||||
free(chunk.memory);
|
free(chunk.memory);
|
||||||
}
|
} else
|
||||||
|
ERR("No data from server");
|
||||||
|
|
||||||
curfeed->data = curdata;
|
curfeed->data = curdata;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user