/*
- * Destructor for 'struct blogpost' which does the rendering first.
- * By rendering from here, we eliminate the need for a separate iterator, although
- * we might run into trouble when we get around to displaying newest-to-oldest...
+ * Render (maybe) a single blog post and (maybe) its comments
*/
-void blogpost_render_and_destroy(struct blogpost *bp) {
+void blogpost_render(struct blogpost *bp) {
const StrBuf *Mime;
int p = 0;
int i;
}
}
-
- if (bp->alloc_msgs > 0) {
- free(bp->msgs);
- }
-
/* offer the comment box */
if (p == bp->top_level_id) {
do_template("blog_comment_box");
}
+}
+
+
+/*
+ * Destructor for "struct blogpost"
+ */
+void blogpost_destroy(struct blogpost *bp) {
+ if (bp->alloc_msgs > 0) {
+ free(bp->msgs);
+ }
free(bp);
}
bp = malloc(sizeof(struct blogpost));
if (!bp) return(200);
memset(bp, 0, sizeof (struct blogpost));
- bp->top_level_id = b.id;
- Put(BLOG, (const char *)&b.id, sizeof(b.id), bp,
- (DeleteHashDataFunc)blogpost_render_and_destroy);
+ bp->top_level_id = b.id;
+ Put(BLOG, (const char *)&b.id, sizeof(b.id), bp, (DeleteHashDataFunc)blogpost_destroy);
}
else {
GetHash(BLOG, (const char *)&b.refs , sizeof(b.refs), (void *)&bp);
/*
* Sort a list of 'struct blogpost' objects by newest-to-oldest msgnum.
- */
int blogview_sortfunc(const void *s1, const void *s2) {
long *l1 = (long *)(s1);
long *l2 = (long *)(s2);
if (*l1 < *l2) return(+1);
return(0);
}
+ */
+
+/*
+ * All blogpost entries are now in the hash list.
+ * Sort them, (FIXME cull by date range if needed,) and render what we want to see.
+ */
int blogview_render(SharedMessageStatus *Stat, void **ViewSpecific, long oper)
{
- /* HashList *BLOG = (HashList *) *ViewSpecific; */
+ HashList *BLOG = (HashList *) *ViewSpecific;
+ HashPos *it;
+ const char *Key;
+ void *Data;
+ long len;
+ struct blogpost *bp;
+ int i;
+ struct blogpost **blogposts = NULL;
+ int num_blogposts = 0;
+ int num_blogposts_alloc = 0;
- /*
- * No code needed here -- we render during disposition.
- * Maybe this is the location where we want to handle pretty permalinks.
- */
+ it = GetNewHashPos(BLOG, 0);
+ while (GetNextHashPos(BLOG, it, &len, &Key, &Data)) {
+ bp = (struct blogpost *) Data;
+
+ if (num_blogposts >= num_blogposts_alloc) {
+ if (num_blogposts_alloc == 0) {
+ num_blogposts_alloc = 100;
+ }
+ else {
+ num_blogposts_alloc *= 2;
+ }
+ blogposts = realloc(blogposts, (num_blogposts_alloc * sizeof (struct blogpost *)));
+ }
+ blogposts[num_blogposts++] = bp;
+ }
+
+ DeleteHashPos(&it);
+
+ if (num_blogposts > 0) {
+ for (i=0; i<num_blogposts; ++i) {
+ wc_printf("Top level ID is %d", blogposts[i]->top_level_id);
+ wc_printf("; top level msgnum is %ld", blogposts[i]->msgs[0]);
+ blogpost_render(blogposts[i]);
+ }
+ free(blogposts);
+ }
return(0);
}