#if defined(ENABLE_WWW) #include #include #include #include "bbs.h" extern struct bbs_config conf; char *www_blog() { char *page; int max_len; int len; char buffer[4096]; struct blog_entry_t **blog_entries; int blog_entry_count = 0; int i, j; struct tm thetime; int hour; char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"}; char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"}; page = (char *)malloc(4096); max_len = 4096; len = 0; memset(page, 0, 4096); sprintf(buffer, "

System Blog

\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); } strcat(page, buffer); len += strlen(buffer); blog_entry_count = blog_load(&blog_entries); if (blog_entry_count == 0) { sprintf(buffer, "

No Entries

\n"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); } strcat(page, buffer); len += strlen(buffer); } else { for (i=0;idate, &thetime); if (thetime.tm_hour >= 12) { hour = thetime.tm_hour - 12; } else { hour = thetime.tm_hour; } sprintf(buffer, "

%s

%d:%02d%s %s, %s %d %d
by %s
", blog_entries[i]->subject,(hour == 0 ? 12 : hour), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900, blog_entries[i]->author); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); } strcat(page, buffer); len += strlen(buffer); sprintf(buffer, "
"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); } strcat(page, buffer); len += strlen(buffer); for (j=0;jbody);j++) { if (blog_entries[i]->body[j] == '\r') { sprintf(buffer, "
"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); } strcat(page, buffer); len += strlen(buffer); } else { if (len + 1 > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); } page[len++] = blog_entries[i]->body[j]; page[len] = '\0'; } } sprintf(buffer, "
"); if (len + strlen(buffer) > max_len - 1) { max_len += 4096; page = (char *)realloc(page, max_len); } strcat(page, buffer); len += strlen(buffer); } for (i=0;isubject); free(blog_entries[i]->author); free(blog_entries[i]->body); free(blog_entries[i]); } free(blog_entries); } return page; } #endif