From 3d1fe95321f318ae8882fcfde1ac63f0954c91fa Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 14 Sep 2010 23:24:57 -0400 Subject: [PATCH] Skeleton renderer for blog view --- webcit/Makefile.in | 4 +- webcit/blogview_renderer.c | 157 +++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 webcit/blogview_renderer.c diff --git a/webcit/Makefile.in b/webcit/Makefile.in index 2b1ba5de4..bfd7e378f 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -46,7 +46,7 @@ setup: setup.o gettext.o webcit: webserver.o context_loop.o ical_dezonify.o \ cookie_conversion.o locate_host.o summary.o \ webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o marchlist.o \ - roomops.o roomlist.o roomtokens.o roomviews.o \ + roomops.o roomlist.o roomtokens.o roomviews.o blogview_renderer.o \ messages.o msg_renderers.o userlist.o paging.o sysmsgs.o \ useredit.o vcard_edit.o preferences.o html2html.o listsub.o roomchat.o \ graphics.o netconf.o siteconfig.o subst.o bbsview_renderer.o \ @@ -62,7 +62,7 @@ webcit: webserver.o context_loop.o ical_dezonify.o \ $(CC) $(LDFLAGS) -o webcit $(LIBOBJS) \ webserver.o context_loop.o cookie_conversion.o marchlist.o \ webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o listsub.o \ - roomops.o roomlist.o roomtokens.o roomviews.o \ + roomops.o roomlist.o roomtokens.o roomviews.o blogview_renderer.o \ messages.o msg_renderers.o userlist.o paging.o sysmsgs.o \ useredit.o locate_host.o siteconfig.o subst.o vcard_edit.o roomchat.o \ graphics.o netconf.o preferences.o html2html.o openid.o bbsview_renderer.o \ diff --git a/webcit/blogview_renderer.c b/webcit/blogview_renderer.c new file mode 100644 index 000000000..6ae055ece --- /dev/null +++ b/webcit/blogview_renderer.c @@ -0,0 +1,157 @@ +/* + * Blog view renderer module for WebCit + * + * Copyright (c) 1996-2010 by the citadel.org team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "webcit.h" +#include "webserver.h" +#include "groupdav.h" + +/* + * Data which gets passed around between the various functions in this module + * + */ +struct blogview { + long *msgs; /* Array of msgnums for messages we are displaying */ + int num_msgs; /* Number of msgnums stored in 'msgs' */ + int alloc_msgs; /* Currently allocated size of array */ +}; + + +/* + * Entry point for message read operations. + */ +int blogview_GetParamsGetServerCall(SharedMessageStatus *Stat, + void **ViewSpecific, + long oper, + char *cmd, + long len) +{ + struct blogview *BLOG = malloc(sizeof(struct blogview)); + memset(BLOG, 0, sizeof(struct blogview)); + *ViewSpecific = BLOG; + + Stat->startmsg = (-1); /* not used here */ + Stat->sortit = 1; /* not used here */ + Stat->num_displayed = DEFAULT_MAXMSGS; /* not used here */ + if (Stat->maxmsgs == 0) Stat->maxmsgs = DEFAULT_MAXMSGS; + + /* perform a "read all" call to fetch the message list -- we'll cut it down later */ + rlid[2].cmd(cmd, len); + + return 200; +} + + +/* + * This function is called for every message in the list. + */ +int blogview_LoadMsgFromServer(SharedMessageStatus *Stat, + void **ViewSpecific, + message_summary* Msg, + int is_new, + int i) +{ + struct blogview *BLOG = (struct blogview *) *ViewSpecific; + + if (BLOG->alloc_msgs == 0) { + BLOG->alloc_msgs = 1000; + BLOG->msgs = malloc(BLOG->alloc_msgs * sizeof(long)); + memset(BLOG->msgs, 0, (BLOG->alloc_msgs * sizeof(long)) ); + } + + /* Check our buffer size */ + if (BLOG->num_msgs >= BLOG->alloc_msgs) { + BLOG->alloc_msgs *= 2; + BLOG->msgs = realloc(BLOG->msgs, (BLOG->alloc_msgs * sizeof(long))); + memset(&BLOG->msgs[BLOG->num_msgs], 0, ((BLOG->alloc_msgs - BLOG->num_msgs) * sizeof(long)) ); + } + + BLOG->msgs[BLOG->num_msgs++] = Msg->msgnum; + + return 200; +} + + +int blogview_sortfunc(const void *s1, const void *s2) { + long l1; + long l2; + + l1 = *(long *)(s1); + l2 = *(long *)(s2); + + if (l1 > l2) return(+1); + if (l1 < l2) return(-1); + return(0); +} + + +int blogview_RenderView_or_Tail(SharedMessageStatus *Stat, + void **ViewSpecific, + long oper) +{ + struct blogview *BLOG = (struct blogview *) *ViewSpecific; + int i; + const StrBuf *Mime; + + wc_printf("
"); + + if (Stat->nummsgs > 0) { + lprintf(9, "sorting %d messages\n", BLOG->num_msgs); + qsort(BLOG->msgs, (size_t)(BLOG->num_msgs), sizeof(long), blogview_sortfunc); + } + + for (i=0; (inum_msgs); ++i) { + if (BLOG->msgs[i] > 0L) { + read_message(WC->WBuf, HKEY("view_message"), BLOG->msgs[i], NULL, &Mime); + } + } + + wc_printf("
\n"); + return(0); +} + + +int blogview_Cleanup(void **ViewSpecific) +{ + struct blogview *BLOG = (struct blogview *) *ViewSpecific; + + if (BLOG->alloc_msgs != 0) { + free(BLOG->msgs); + } + free(BLOG); + + wDumpContent(1); + return 0; +} + + +void +InitModule_BLOGVIEWRENDERERS +(void) +{ + RegisterReadLoopHandlerset( + VIEW_BLOG, + blogview_GetParamsGetServerCall, + NULL, + NULL, + blogview_LoadMsgFromServer, + blogview_RenderView_or_Tail, + blogview_Cleanup + ); +} -- 2.30.2