2 * Blog view renderer module for WebCit
4 * Copyright (c) 1996-2010 by the citadel.org team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "webserver.h"
26 * Data which gets passed around between the various functions in this module
30 long *msgs; /* Array of msgnums for messages we are displaying */
31 int num_msgs; /* Number of msgnums stored in 'msgs' */
32 int alloc_msgs; /* Currently allocated size of array */
37 * Entry point for message read operations.
39 int blogview_GetParamsGetServerCall(SharedMessageStatus *Stat,
45 struct blogview *BLOG = malloc(sizeof(struct blogview));
46 memset(BLOG, 0, sizeof(struct blogview));
49 Stat->startmsg = (-1); /* not used here */
50 Stat->sortit = 1; /* not used here */
51 Stat->num_displayed = DEFAULT_MAXMSGS; /* not used here */
52 if (Stat->maxmsgs == 0) Stat->maxmsgs = DEFAULT_MAXMSGS;
54 /* perform a "read all" call to fetch the message list -- we'll cut it down later */
55 rlid[2].cmd(cmd, len);
62 * This function is called for every message in the list.
64 int blogview_LoadMsgFromServer(SharedMessageStatus *Stat,
70 struct blogview *BLOG = (struct blogview *) *ViewSpecific;
72 if (BLOG->alloc_msgs == 0) {
73 BLOG->alloc_msgs = 1000;
74 BLOG->msgs = malloc(BLOG->alloc_msgs * sizeof(long));
75 memset(BLOG->msgs, 0, (BLOG->alloc_msgs * sizeof(long)) );
78 /* Check our buffer size */
79 if (BLOG->num_msgs >= BLOG->alloc_msgs) {
80 BLOG->alloc_msgs *= 2;
81 BLOG->msgs = realloc(BLOG->msgs, (BLOG->alloc_msgs * sizeof(long)));
82 memset(&BLOG->msgs[BLOG->num_msgs], 0, ((BLOG->alloc_msgs - BLOG->num_msgs) * sizeof(long)) );
85 BLOG->msgs[BLOG->num_msgs++] = Msg->msgnum;
91 int blogview_sortfunc(const void *s1, const void *s2) {
98 if (l1 > l2) return(+1);
99 if (l1 < l2) return(-1);
104 int blogview_RenderView_or_Tail(SharedMessageStatus *Stat,
108 struct blogview *BLOG = (struct blogview *) *ViewSpecific;
112 wc_printf("<div class=\"fix_scrollbar_bug\">");
114 if (Stat->nummsgs > 0) {
115 lprintf(9, "sorting %d messages\n", BLOG->num_msgs);
116 qsort(BLOG->msgs, (size_t)(BLOG->num_msgs), sizeof(long), blogview_sortfunc);
119 for (i=0; (i<BLOG->num_msgs); ++i) {
120 if (BLOG->msgs[i] > 0L) {
121 read_message(WC->WBuf, HKEY("view_message"), BLOG->msgs[i], NULL, &Mime);
125 wc_printf("</div>\n");
130 int blogview_Cleanup(void **ViewSpecific)
132 struct blogview *BLOG = (struct blogview *) *ViewSpecific;
134 if (BLOG->alloc_msgs != 0) {
145 InitModule_BLOGVIEWRENDERERS
148 RegisterReadLoopHandlerset(
150 blogview_GetParamsGetServerCall,
153 blogview_LoadMsgFromServer,
154 blogview_RenderView_or_Tail,