int item_tag_nesting;
StrBuf *author_or_creator;
StrBuf *author_url;
+ StrBuf *author_email;
}rss_item;
///#endif
//#endif
+void AppendLink(StrBuf *Message, StrBuf *link, StrBuf *LinkTitle, const char *Title)
+{
+ if (StrLength(link) > 0)
+ {
+ StrBufAppendBufPlain(Message, HKEY("<a href=\""), 0);
+ StrBufAppendBuf(Message, link, 0);
+ StrBufAppendBufPlain(Message, HKEY("\">"), 0);
+ if (StrLength(LinkTitle) > 0)
+ StrBufAppendBuf(Message, LinkTitle, 0);
+ else if ((Title != NULL) && !IsEmptyStr(Title))
+ StrBufAppendBufPlain(Message, Title, -1, 0);
+ else
+ StrBufAppendBuf(Message, link, 0);
+ StrBufAppendBufPlain(Message, HKEY("</a><br>\n"), 0);
+ }
+}
/*
* Commit a fetched and parsed RSS item to disk
*/
struct CtdlMessage *msg;
struct recptypes *recp = NULL;
int msglen = 0;
+ StrBuf *Message;
recp = (struct recptypes *) malloc(sizeof(struct recptypes));
if (recp == NULL) return;
StrBuf *UserName;
StrBuf *EmailAddress;
StrBuf *EncBuf;
+ int FromAt;
+ int FromLen;
UserName = NewStrBuf();
EmailAddress = NewStrBuf();
EncBuf = NewStrBuf();
////TODO!
+ StrBufTrim(ri->author_or_creator);
From = html_to_ascii(ChrPtr(ri->author_or_creator),
StrLength(ri->author_or_creator),
512, 0);
-
- Encoded = NewStrBufPlain(From, -1);
+ FromLen = strlen(From);
+ if (From[FromLen - 1] == '\n')
+ {
+ From[FromLen - 1] = '\0';
+ }
+ FromAt = strchr(From, '@') != NULL;
+ if (!FromAt && StrLength (ri->author_email) > 0)
+ {
+ Encoded = NewStrBuf();
+ if (!IsEmptyStr(From))
+ {
+ StrBufPrintf(Encoded,
+ "%s<%s>",
+ From,
+ ChrPtr(ri->author_email));
+ }
+ else
+ {
+ StrBufPrintf(Encoded,
+ "<%s>",
+ ChrPtr(ri->author_email));
+ }
+ }
+ else
+ {
+ if (FromAt)
+ Encoded = NewStrBufPlain(From, -1);
+ else
+ {
+ Encoded = NewStrBuf();
+ StrBufPrintf(Encoded,
+ "%s<%s>",
+ From,
+ "rss@localhost"); /// TODO: get hostname?
+ }
+ }
free(From);
StrBufTrim(Encoded);
QPEncoded = StrBufSanitizeEmailRecipientVector(Encoded, UserName, EmailAddress, EncBuf);
StrBufSpaceToBlank(ri->title);
len = StrLength(ri->title);
Sbj = html_to_ascii(ChrPtr(ri->title), len, 512, 0);
- Encoded = NewStrBufPlain(Sbj, -1);
+ len = strlen(Sbj);
+ if (Sbj[len - 1] == '\n')
+ {
+ len --;
+ Sbj[len] = '\0';
+ }
+ Encoded = NewStrBufPlain(Sbj, len);
free(Sbj);
StrBufTrim(Encoded);
if (ri->link == NULL)
ri->link = NewStrBufPlain(HKEY(""));
msglen += 1024 + StrLength(ri->link) + StrLength(ri->description) ;
- msg->cm_fields['M'] = malloc(msglen);
- snprintf(msg->cm_fields['M'], msglen,
+
+ Message = NewStrBufPlain(NULL, StrLength(ri->description));
+
+ StrBufPlain(Message, HKEY(
"Content-type: text/html; charset=\"UTF-8\"\r\n\r\n"
- "<html><body>\n"
- "%s<br><br>\n"
- "<a href=\"%s\">%s</a><br>\n"
- "<a href=\"%s\">%s</a>\n"
- "</body></html>\n"
- ,
- ChrPtr(ri->description),
- ChrPtr(ri->link),
- (StrLength(ri->linkTitle)>0)?ChrPtr(ri->linkTitle):ChrPtr(ri->link),
- ChrPtr(ri->reLink),
- (StrLength(ri->reLinkTitle)>0)?ChrPtr(ri->reLinkTitle):"Reply to this"
- );
+ "<html><body>\n"));
+
+ StrBufAppendBuf(Message, ri->description, 0);
+ StrBufAppendBufPlain(Message, HKEY("<br><br>\n"), 0);
+
+ AppendLink(Message, ri->link, ri->linkTitle, NULL);
+ AppendLink(Message, ri->reLink, ri->reLinkTitle, "Reply to this");
+ StrBufAppendBufPlain(Message, HKEY("</body></html>\n"), 0);
+
+ msg->cm_fields['M'] = SmashStrBuf(&Message);
CtdlSubmitMsg(msg, recp, NULL, 0);
CtdlFreeMessage(msg);
FreeStrBuf(&ri->title);
FreeStrBuf(&ri->link);
FreeStrBuf(&ri->author_or_creator);
+ FreeStrBuf(&ri->author_email);
FreeStrBuf(&ri->author_url);
FreeStrBuf(&ri->description);
}
StrBufTrim(ri->link);
}
}
+void RSS_item_relink_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
+{
+ if (StrLength(CData) > 0) {
+ NewStrBufDupAppendFlush(&ri->reLink, CData, NULL, 0);
+ StrBufTrim(ri->reLink);
+ }
+}
void RSSATOM_item_title_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
{
void ATOM_item_content_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
{
- if (StrLength(CData) > 0) {
- NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
- StrBufTrim(ri->description);
+ long olen = StrLength (ri->description);
+ long clen = StrLength (CData);
+ if (clen > 0)
+ {
+ if (olen == 0) {
+ NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
+ StrBufTrim(ri->description);
+ }
+ else if (olen < clen) {
+ FlushStrBuf(ri->description);
+ NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
+ StrBufTrim(ri->description);
+ }
}
}
void ATOM_item_summary_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
void RSS_item_description_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
{
- if (StrLength(CData) > 0) {
- NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
+ long olen = StrLength (ri->description);
+ long clen = StrLength (CData);
+ if (clen > 0)
+ {
+ if (olen == 0) {
+ NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
+ StrBufTrim(ri->description);
+ }
+ else if (olen < clen) {
+ FlushStrBuf(ri->description);
+ NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
+ StrBufTrim(ri->description);
+ }
}
}
}
}
+void ATOM_item_email_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
+{
+ if (StrLength(CData) > 0) {
+ NewStrBufDupAppendFlush(&ri->author_email, CData, NULL, 0);
+ StrBufTrim(ri->author_email);
+ }
+}
+
void RSS_item_creator_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
{
if ((StrLength(CData) > 0) &&
/*
* Scan for rooms that have RSS client requests configured
*/
-void *rssclient_scan(void *args) {
+void rssclient_scan(void *args) {
static time_t last_run = 0L;
static int doing_rssclient = 0;
rssnetcfg *rptr = NULL;
- CitContext rssclientCC;
-
- /* Give this thread its own private CitContext */
- CtdlFillSystemContext(&rssclientCC, "rssclient");
- citthread_setspecific(MyConKey, (void *)&rssclientCC );
/*
* This is a simple concurrency check to make sure only one rssclient run
CtdlLogPrintf(CTDL_DEBUG, "rssclient ended\n");
last_run = time(NULL);
doing_rssclient = 0;
- if (!CtdlThreadCheckStop())
- CtdlThreadSchedule ("RSS Client", CTDLTHREAD_BIGSTACK, rssclient_scan, NULL, last_run + config.c_net_freq);
- else
- CtdlLogPrintf(CTDL_DEBUG, "rssclient: Task STOPPED.\n");
- CtdlClearSystemContext();
return NULL;
}
if (threading)
{
CtdlLogPrintf(CTDL_INFO, "%s\n", curl_version());
- CtdlThreadSchedule ("RSS Client", CTDLTHREAD_BIGSTACK, rssclient_scan, NULL, 0);
+ CtdlRegisterSessionHook(rssclient_scan, EVT_TIMER);
}
StartHandlers = NewHash(1, NULL);
AddRSSEndHandler(RSS_item_guid_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("guid"));
AddRSSEndHandler(ATOM_item_id_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("id"));
AddRSSEndHandler(RSS_item_link_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("link"));
+#if 0
+// hm, rss to the comments of that blog, might be interesting in future, but...
+ AddRSSEndHandler(RSS_item_relink_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("commentrss"));
+// comment count...
+ AddRSSEndHandler(RSS_item_relink_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("comments"));
+#endif
AddRSSEndHandler(RSSATOM_item_title_end, RSS_ATOM|RSS_RSS|RSS_REQUIRE_BUF, HKEY("title"));
AddRSSEndHandler(ATOM_item_content_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("content"));
- AddRSSEndHandler(RSS_item_description_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("encoded"));
+ AddRSSEndHandler(RSS_item_description_end, RSS_RSS|RSS_ATOM|RSS_REQUIRE_BUF, HKEY("encoded"));
AddRSSEndHandler(ATOM_item_summary_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("summary"));
AddRSSEndHandler(RSS_item_description_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("description"));
AddRSSEndHandler(ATOM_item_published_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("published"));
AddRSSEndHandler(RSS_item_date_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("date"));
AddRSSEndHandler(RSS_item_author_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("author"));
AddRSSEndHandler(RSS_item_creator_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("creator"));
+/* <author> */
+ AddRSSEndHandler(ATOM_item_email_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("email"));
AddRSSEndHandler(ATOM_item_name_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("name"));
AddRSSEndHandler(ATOM_item_uri_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("uri"));
-
+/* </author> */
AddRSSEndHandler(RSS_item_item_end, RSS_RSS, HKEY("item"));
AddRSSEndHandler(RSS_item_rss_end, RSS_RSS, HKEY("rss"));
AddRSSEndHandler(RSS_item_rdf_end, RSS_RSS, HKEY("rdf"));