Straightn http client generation
[citadel.git] / citadel / modules / rssclient / rss_atom_parser.c
index a1f9b512d2a58f998987fefe3307ff7dcb37e049..e7065bde39c6ac2fe54e8d407b189203d1898a5e 100644 (file)
@@ -58,6 +58,8 @@
 #include "event_client.h"
 #include "rss_atom_parser.h"
 
+extern pthread_mutex_t RSSQueueMutex;
+
 HashList *StartHandlers = NULL;
 HashList *EndHandlers = NULL;
 HashList *KnownNameSpaces = NULL;
@@ -142,7 +144,7 @@ void rss_xml_start(void *data, const char *supplied_el, const char **attr)
        char            *sep = NULL;
 
        /* Axe the namespace, we don't care about it */
-///    CtdlLogPrintf(0, "RSS: supplied el %d: %s...\n", rssc->Cfg->ItemType, supplied_el);
+///    syslog(LOG_DEBUG, "RSS: supplied el %d: %s...\n", rssc->Cfg->ItemType, supplied_el);
        pel = supplied_el;
        while (sep = strchr(pel, ':'), sep) {
                pel = sep + 1;
@@ -158,7 +160,7 @@ void rss_xml_start(void *data, const char *supplied_el, const char **attr)
                             &v))
                {
 #ifdef DEBUG_RSS
-                       CtdlLogPrintf(0, "RSS: START ignoring because of wrong namespace [%s] = [%s]\n", 
+                       syslog(LOG_DEBUG, "RSS: START ignoring because of wrong namespace [%s]\n", 
                                      supplied_el);
 #endif
                        return;
@@ -188,12 +190,12 @@ void rss_xml_start(void *data, const char *supplied_el, const char **attr)
                }
 #ifdef DEBUG_RSS
                else 
-                       CtdlLogPrintf(0, "RSS: START unhandled: [%s] [%s]...\n", pel, supplied_el);
+                       syslog(LOG_DEBUG, "RSS: START unhandled: [%s] [%s]...\n", pel, supplied_el);
 #endif
        }
 #ifdef DEBUG_RSS
        else 
-               CtdlLogPrintf(0, "RSS: START unhandled: [%s] [%s]...\n", pel,  supplied_el);
+               syslog(LOG_DEBUG, "RSS: START unhandled: [%s] [%s]...\n", pel,  supplied_el);
 #endif
 }
 
@@ -211,7 +213,7 @@ void rss_xml_end(void *data, const char *supplied_el)
        while (sep = strchr(pel, ':'), sep) {
                pel = sep + 1;
        }
-//     CtdlLogPrintf(0, "RSS: END %s...\n", el);
+//     syslog(LOG_DEBUG, "RSS: END %s...\n", el);
        if (pel != supplied_el)
        {
                void *v;
@@ -222,7 +224,7 @@ void rss_xml_end(void *data, const char *supplied_el)
                             &v))
                {
 #ifdef DEBUG_RSS
-                       CtdlLogPrintf(0, "RSS: END ignoring because of wrong namespace [%s] = [%s]\n", 
+                       syslog(LOG_DEBUG, "RSS: END ignoring because of wrong namespace [%s] = [%s]\n", 
                                      supplied_el, ChrPtr(rssc->CData));
 #endif
                        FlushStrBuf(rssc->CData);
@@ -253,12 +255,12 @@ void rss_xml_end(void *data, const char *supplied_el)
                }
 #ifdef DEBUG_RSS
                else 
-                       CtdlLogPrintf(0, "RSS: END   unhandled: [%s]  [%s] = [%s]...\n", pel, supplied_el, ChrPtr(rssc->CData));
+                       syslog(LOG_DEBUG, "RSS: END   unhandled: [%s]  [%s] = [%s]...\n", pel, supplied_el, ChrPtr(rssc->CData));
 #endif
        }
 #ifdef DEBUG_RSS
        else 
-               CtdlLogPrintf(0, "RSS: END   unhandled: [%s]  [%s] = [%s]...\n", pel, supplied_el, ChrPtr(rssc->CData));
+               syslog(LOG_DEBUG, "RSS: END   unhandled: [%s]  [%s] = [%s]...\n", pel, supplied_el, ChrPtr(rssc->CData));
 #endif
        FlushStrBuf(rssc->CData);
        rssc->Current = NULL;
@@ -605,13 +607,25 @@ size_t rss_libcurl_callback(void *ptr, size_t size, size_t nmemb, void *stream)
 
 
 
-eNextState ParseRSSReply(AsyncIO *IO)
+eNextState RSSAggregator_ParseReply(AsyncIO *IO)
 {
+       StrBuf *Buf;
        rss_aggregator *rssc;
        rss_item *ri;
        const char *at;
        char *ptr;
        long len;
+       const char *Key;
+
+
+       if (IO->HttpReq.httpcode != 200)
+       {
+
+               EV_syslog(LOG_DEBUG, "need a 200, got a %ld !\n",
+                         IO->HttpReq.httpcode);
+// TODO: aide error message with rate limit
+               return eAbort;
+       }
 
        rssc = IO->Data;
        ri = rssc->Item;
@@ -642,10 +656,11 @@ eNextState ParseRSSReply(AsyncIO *IO)
        rssc->xp = XML_ParserCreateNS(ptr, ':');
        if (!rssc->xp) {
                syslog(LOG_DEBUG, "Cannot create XML parser!\n");
-               goto shutdown;
+               return eAbort;
        }
        FlushStrBuf(rssc->Key);
 
+       rssc->Messages = NewHash(1, Flathash);
        XML_SetElementHandler(rssc->xp, rss_xml_start, rss_xml_end);
        XML_SetCharacterDataHandler(rssc->xp, rss_xml_chardata);
        XML_SetUserData(rssc->xp, rssc);
@@ -666,16 +681,23 @@ eNextState ParseRSSReply(AsyncIO *IO)
                      XML_ErrorString(
                              XML_GetErrorCode(rssc->xp)));
 
-shutdown:
        XML_ParserFree(rssc->xp);
-
        flush_rss_item(ri);
        FreeStrBuf(&rssc->CData);
        FreeStrBuf(&rssc->Key);
 
-        ///Cfg->next_poll = time(NULL) + config.c_net_freq; 
+       Buf = NewStrBufDup(rssc->rooms);
+       rssc->recp.recp_room = SmashStrBuf(&Buf);
+       rssc->recp.num_room = rssc->roomlist_parts;
+       rssc->recp.recptypes_magic = RECPTYPES_MAGIC;
+
+       rssc->Pos = GetNewHashPos(rssc->Messages, 1);
 
-       return eTerminateConnection;
+        ///Cfg->next_poll = time(NULL) + config.c_net_freq; 
+       if (GetNextHashPos(rssc->Messages, rssc->Pos, &len, &Key, (void**) &rssc->ThisMsg))
+               return QueueDBOperation(IO, RSS_FetchNetworkUsetableEntry);
+       else
+               return eAbort;
 }