From 2e7a8005192118c2be41965c90b7924e515ed779 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 20 May 2011 12:58:15 -0400 Subject: [PATCH] Generate UUID in blog posts to be used in permalinks --- citadel/modules/blog/serv_blog.c | 21 +++++++++++---------- webcit/blogview_renderer.c | 12 +++++++++++- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/citadel/modules/blog/serv_blog.c b/citadel/modules/blog/serv_blog.c index 6997a057e..5459898f7 100644 --- a/citadel/modules/blog/serv_blog.c +++ b/citadel/modules/blog/serv_blog.c @@ -1,11 +1,11 @@ /* * Support for blog rooms * - * Copyright (c) 1999-2010 by the citadel.org team + * Copyright (c) 1999-2011 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 + * This program is open source 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, @@ -15,7 +15,7 @@ * * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "sysdep.h" @@ -59,10 +59,10 @@ #include "ctdl_module.h" /* - * sd sdhfksdjhkjsdfhk jsdhfkjsdfhkjsd hkfjhsdkjfhsdkjfhksdjfhsd + * Pre-save hook for saving a message in a blog room. + * (Do we want to only do this for top-level messages?) */ int blog_upload_beforesave(struct CtdlMessage *msg) { - char buf[SIZ]; /* Only run this hook for blog rooms */ if (CC->room.QRdefaultview != VIEW_BLOG) { @@ -72,10 +72,11 @@ int blog_upload_beforesave(struct CtdlMessage *msg) { /* * If the message doesn't have an EUID, give it one. */ - if (msg->cm_fields['E'] != NULL) + if (msg->cm_fields['E'] == NULL) { - generate_uuid(buf); - msg->cm_fields['E'] = strdup(buf); + char uuid[37]; + generate_uuid(uuid); + msg->cm_fields['E'] = strdup(uuid); } /* Now allow the save to complete. */ diff --git a/webcit/blogview_renderer.c b/webcit/blogview_renderer.c index 215fa94ef..8190cb8c8 100644 --- a/webcit/blogview_renderer.c +++ b/webcit/blogview_renderer.c @@ -87,6 +87,7 @@ void blogpost_render_and_destroy(struct blogpost *bp) { struct bltr { int id; int refs; + StrBuf *euid; }; @@ -123,7 +124,7 @@ struct bltr blogview_learn_thread_references(long msgnum) StrBuf *Buf; StrBuf *r; int len; - struct bltr bltr = { 0, 0 } ; + struct bltr bltr = { 0, 0, NULL }; Buf = NewStrBuf(); r = NewStrBuf(); serv_printf("MSG0 %ld|1", msgnum); /* top level citadel headers only */ @@ -142,6 +143,10 @@ struct bltr blogview_learn_thread_references(long msgnum) StrBufExtract_token(r, Buf, 0, '|'); bltr.refs = HashLittle(ChrPtr(r), StrLength(r)); } + else if (!strncasecmp(ChrPtr(Buf), "exti=", 5)) { + StrBufCutLeft(Buf, 5); /* trim the field name */ + bltr.euid = NewStrBufDup(Buf); + } } } FreeStrBuf(&Buf); @@ -165,6 +170,11 @@ int blogview_LoadMsgFromServer(SharedMessageStatus *Stat, b = blogview_learn_thread_references(Msg->msgnum); + if (b.euid != NULL) { + syslog(LOG_DEBUG, "\033[7m%s\033[0m", ChrPtr(b.euid)); + FreeStrBuf(&b.euid); + } + /* FIXME an optimization here -- one we ought to perform -- is to exit this * function immediately if the viewer is only interested in a single post and * that message ID is neither the id nor the refs. Actually, that might *be* -- 2.30.2