struct rssparser {
StrBuf *CData;
struct CtdlMessage *msg;
+ char *link;
+ char *description;
+ struct rssroom *rooms;
};
time_t last_run = 0L;
void rss_start_element(void *data, const char *el, const char **attribute)
{
struct rssparser *r = (struct rssparser *)data;
+ int i;
if (
(!strcasecmp(el, "entry"))
r->msg->cm_anon_type = MES_NORMAL;
r->msg->cm_format_type = FMT_RFC822;
}
+
+ else if (!strcasecmp(el, "link")) { // atom feeds have the link as an attribute
+ for(i = 0; attribute[i]; i += 2) {
+ if (!strcasecmp(attribute[i], "href")) {
+ if (r->link != NULL) {
+ free(r->link);
+ r->link = NULL;
+ }
+ r->link = strdup(attribute[i+1]);
+ striplt(r->link);
+ }
+ }
+ }
}
|| (!strcasecmp(el, "item"))
) {
- // FIXME check the use table
+ if (r->msg != NULL) { // Save the message to the rooms
+
+ // FIXME check the use table
+
+ StrBuf *TheMessage = NewStrBuf();
+ StrBufAppendPrintf(TheMessage,
+ "Content-type: text/html\n\n"
+ "\n\n"
+ "<html><head></head><body>"
+ );
+
+ if (r->description != NULL) {
+ StrBufAppendPrintf(TheMessage, "%s<br><br>\r\n", r->description);
+ free(r->description);
+ r->description = NULL;
+ }
+
+ if (r->link != NULL) {
+ StrBufAppendPrintf(TheMessage, "<a href=\"%s\">%s</a>\r\n", r->link, r->link);
+ free(r->link);
+ r->link = NULL;
+ }
- if (r->msg != NULL) {
- // FIXME WRITE IT TO THE ROOMS HERE, DUMMEH
+ StrBufAppendPrintf(TheMessage, "</body></html>\r\n");
+
+ syslog(LOG_DEBUG, "------------------\n%s\n------------------", ChrPtr(TheMessage));
+ FreeStrBuf(&TheMessage);
+
+
+
+ struct rssroom *rr;
+ for (rr=r->rooms; rr!=NULL; rr=rr->next) {
+ syslog(LOG_DEBUG, "Saving item %s to %s", r->link, rr->room);
+ }
CM_Free(r->msg);
r->msg = NULL;
}
+
+
+
}
else if (!strcasecmp(el, "title")) { // item subject (rss and atom)
if ((r->msg != NULL) && (r->msg->cm_fields[eMsgSubject] == NULL)) {
r->msg->cm_fields[eMsgSubject] = strdup(ChrPtr(r->CData));
+ striplt(r->msg->cm_fields[eMsgSubject]);
}
}
else if (!strcasecmp(el, "author")) { // author of item (rss and maybe atom)
if ((r->msg != NULL) && (r->msg->cm_fields[eAuthor] == NULL)) {
r->msg->cm_fields[eAuthor] = strdup(ChrPtr(r->CData));
+ striplt(r->msg->cm_fields[eAuthor]);
}
}
// FIXME parse it
}
+ else if (!strcasecmp(el, "link")) { // link to story (rss)
+ if (r->link != NULL) {
+ free(r->link);
+ r->link = NULL;
+ }
+ r->link = strdup(ChrPtr(r->CData));
+ striplt(r->link);
+ }
+
+ else if (
+ (!strcasecmp(el, "description")) // message text (rss)
+ || (!strcasecmp(el, "summary")) // message text (atom)
+ ) {
+ if (r->description != NULL) {
+ free(r->description);
+ r->description = NULL;
+ }
+ r->description = strdup(ChrPtr(r->CData));
+ striplt(r->description);
+ }
+
if (r->CData != NULL) {
FreeStrBuf(&r->CData);
r->CData = NULL;
// Feed has been downloaded, now parse it.
//
-void rss_parse_feed(StrBuf *Feed)
+void rss_parse_feed(StrBuf *Feed, struct rssroom *rooms)
{
struct rssparser r;
memset(&r, 0, sizeof r);
+ r.rooms = rooms;
XML_Parser p = XML_ParserCreateNS("UTF-8", ':');
XML_SetElementHandler(p, rss_start_element, rss_end_element);
XML_SetCharacterDataHandler(p, rss_handle_data);
//
void rss_pull_one_feed(struct rssurl *url)
{
- struct rssroom *r;
CURL *curl;
CURLcode res;
StrBuf *Downloaded = NULL;
}
curl_easy_cleanup(curl);
- rss_parse_feed(Downloaded); // parse the feed
-
- for (r=url->rooms; r!=NULL; r=r->next) { // we might move this somewhere else
- syslog(LOG_DEBUG, "Saving item to %s", r->room);
- // FIXME save to rooms
- }
-
- FreeStrBuf(&Downloaded);
+ rss_parse_feed(Downloaded, url->rooms); // parse the feed
+ FreeStrBuf(&Downloaded); // free the downloaded feed data
}