I have tried to use kv_t to store some data without success. I have also tried to the examples forum.c & kv.c. forum.c hangs when trying to create the second Forum thread while kv.c crashes.s.
When I have 1 item added to the kv, kv_do will succeed. After adding the second item, trying to call kv_do will result in an infinite loop and the data doesn`t seem valid too.
#include "stdio.h"
int list_threads(kv_item *item, xbuf_t *reply)
{
Thread *thread = (Thread*)item->val;
xbuf_t thread_li;
xbuf_init(&thread_li);
//using sprintf-like formatting
xbuf_xcat(&thread_li,
"<li>"
"<a href='/?forum_simple/act=t/id=%llu'>%s</a> (%lu)"
"</li>",
thread->id, thread->title.ptr, thread->posts.nbr_items
);
char *pos = (char*)xbuf_findstr(reply, "<!--tpl-->");
if (pos) xbuf_insert(reply, pos, thread_li.len, thread_li.ptr);
printf("-----------listing threads------\n");
xbuf_free(&thread_li);
return 1;
}
The code above is from forum.c. trying after creating the first forum Thread, trying to create the second one will hang because the list_threads function if invoked infinitely. the ---------listing threads----------- is getting printed on the terminal infinitely