From: Art Cancro Date: Sun, 26 Feb 2017 20:42:54 +0000 (-0500) Subject: More work on the simplified parser X-Git-Tag: v939~632 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=57741a679f45ad92aaead204023c266e32675580 More work on the simplified parser --- diff --git a/citadel/modules/rssclient/serv_rssclient.c b/citadel/modules/rssclient/serv_rssclient.c index 3435eb4dd..4a2c4f647 100644 --- a/citadel/modules/rssclient/serv_rssclient.c +++ b/citadel/modules/rssclient/serv_rssclient.c @@ -63,6 +63,9 @@ struct rssurl { struct rssparser { StrBuf *CData; struct CtdlMessage *msg; + char *link; + char *description; + struct rssroom *rooms; }; time_t last_run = 0L; @@ -86,6 +89,7 @@ struct rssurl *rsstodo = NULL; void rss_start_element(void *data, const char *el, const char **attribute) { struct rssparser *r = (struct rssparser *)data; + int i; if ( (!strcasecmp(el, "entry")) @@ -102,6 +106,19 @@ void rss_start_element(void *data, const char *el, const char **attribute) 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); + } + } + } } @@ -116,24 +133,59 @@ void rss_end_element(void *data, const char *el) || (!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" + "" + ); + + if (r->description != NULL) { + StrBufAppendPrintf(TheMessage, "%s

\r\n", r->description); + free(r->description); + r->description = NULL; + } + + if (r->link != NULL) { + StrBufAppendPrintf(TheMessage, "%s\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, "\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]); } } @@ -145,6 +197,27 @@ void rss_end_element(void *data, const char *el) // 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; @@ -168,11 +241,12 @@ void rss_handle_data(void *data, const char *content, int length) // 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); @@ -227,7 +301,6 @@ size_t rss_pof_write_data(void *buffer, size_t size, size_t nmemb, void *userp) // void rss_pull_one_feed(struct rssurl *url) { - struct rssroom *r; CURL *curl; CURLcode res; StrBuf *Downloaded = NULL; @@ -252,14 +325,8 @@ void rss_pull_one_feed(struct rssurl *url) } 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 }