static char rcsid[] = "$Id: feed.c,v 1.2 2008/10/16 19:36:19 jordan Exp $"; #include #include #include #include #include /* configure accordingly */ #define MAXIMUM_HITS 50 static char _indexes[] = "index.older index.ThisYear index.swish-e"; static char _title[] = "LBO Talk"; static char _link[] = "http://mailman.lbo-talk.org/"; static void _DumpElement(char *tag, char *val, char *ind) { printf(" %s<%s>%s\n", ind, tag, val, tag); } static void _DumpPropCData(SW_RESULT res, char *prop, char *name) { if (NULL == name) name = prop; char *value = SwishResultPropertyStr(res, prop); if (NULL != value) printf(" <%s>\n", name, value, name); } static void _DumpDateGMT(SW_RESULT res, char *name, char *ind) { char buf[BUFSIZ]; time_t t = SwishResultPropertyULong(res, "unixdate"); struct tm *tm = gmtime(&t); strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", tm); _DumpElement(name, buf, ind); } /* XXX */ extern int headers_initialized; int main(int argc, char **argv) { cgi_init(); cgi_process_form(); /* XXX cgi_init_headers(); */ printf("Content-type: text/xml\r\n\r\n"); headers_initialized = 1; puts(""); puts("\n\n en-us"); printf(" %s\n %s\n", _title, _link); /* check for specific searches */ char *p, buf[BUFSIZ]; p = cgi_param("author"); if (NULL != p) snprintf(buf, sizeof(buf), "author=(%.*s)", sizeof(buf) - 10, p); else if (NULL != (p = cgi_param("subject"))) snprintf(buf, sizeof(buf), "swishtitle=(%.*s)", sizeof(buf) - 14, p); else if (NULL != (p = cgi_param("msg"))) snprintf(buf, sizeof(buf), "swishdefault=(%.*s)", sizeof(buf) - 16, p); /* default to all */ if (NULL == p) snprintf(buf, sizeof(buf), "author=(not pppplugh)"); SW_HANDLE sh = SwishInit(_indexes); SW_SEARCH search = New_Search_Object(sh, "foo"); SwishSetSort(search, "unixdate desc"); SW_RESULTS sr = SwishExecute(search, buf); /* limit to some max */ int hits = SwishHits(sr); #ifdef MAXIMUM_HITS if (hits > MAXIMUM_HITS) hits = MAXIMUM_HITS; #endif if (hits > 0) { /* find the most recent article and use that as the RSS build date */ SwishSeekResult(sr, 0); SW_RESULT res = SwishNextResult(sr); _DumpDateGMT(res, "lastBuildDate", ""); int i; for (i = 0; i < hits; i++) { /* give up on any errors */ if (SwishSeekResult(sr, i) < 0) break; if (NULL == (res = SwishNextResult(sr))) break; puts(" "); _DumpPropCData(res, "swishtitle", "title"); _DumpPropCData(res, "author", NULL); _DumpDateGMT(res, "pubDate", " "); char *value = SwishResultPropertyStr(res, "swishdocpath"); _DumpElement("link", value, " "); _DumpPropCData(res, "swishdescription", "description"); puts(" "); } } puts(""); return 0; }