Back to index

citadel  8.12
serv_blog.c
Go to the documentation of this file.
00001 /*
00002  * Support for blog rooms
00003  *
00004  * Copyright (c) 1999-2011 by the citadel.org team
00005  *
00006  * This program is open source software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License as published
00008  * by the Free Software Foundation; either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00019  */
00020 
00021 #include "sysdep.h"
00022 #include <stdlib.h>
00023 #include <unistd.h>
00024 #include <stdio.h>
00025 #include <fcntl.h>
00026 #include <signal.h>
00027 #include <pwd.h>
00028 #include <errno.h>
00029 #include <ctype.h>
00030 #include <sys/types.h>
00031 
00032 #if TIME_WITH_SYS_TIME
00033 # include <sys/time.h>
00034 # include <time.h>
00035 #else
00036 # if HAVE_SYS_TIME_H
00037 #  include <sys/time.h>
00038 # else
00039 #  include <time.h>
00040 # endif
00041 #endif
00042 
00043 #include <sys/wait.h>
00044 #include <string.h>
00045 #include <limits.h>
00046 #include <libcitadel.h>
00047 #include "citadel.h"
00048 #include "server.h"
00049 #include "citserver.h"
00050 #include "support.h"
00051 #include "config.h"
00052 #include "control.h"
00053 #include "user_ops.h"
00054 #include "database.h"
00055 #include "msgbase.h"
00056 #include "internet_addressing.h"
00057 #include "serv_vcard.h"
00058 #include "citadel_ldap.h"
00059 #include "ctdl_module.h"
00060 
00061 /*
00062  * Pre-save hook for saving a message in a blog room.
00063  * (Do we want to only do this for top-level messages?)
00064  */
00065 int blog_upload_beforesave(struct CtdlMessage *msg) {
00066 
00067        /* Only run this hook for blog rooms */
00068        if (CC->room.QRdefaultview != VIEW_BLOG) {
00069               return(0);
00070        }
00071 
00072        /* 
00073         * If the message doesn't have an EUID, give it one.
00074         */
00075        if (msg->cm_fields['E'] == NULL)
00076        {
00077               char uuid[BLOG_EUIDBUF_SIZE];
00078               generate_uuid(uuid);
00079               msg->cm_fields['E'] = strdup(uuid);
00080        }
00081 
00082        /*
00083         * We also want to define a maximum length, whether we generated it or not.
00084         */
00085        else if (strlen(msg->cm_fields['E']) >= BLOG_EUIDBUF_SIZE) {
00086               msg->cm_fields['E'][BLOG_EUIDBUF_SIZE-1] = 0;
00087        }
00088 
00089        /* Now allow the save to complete. */
00090        return(0);
00091 }
00092 
00093 
00094 CTDL_MODULE_INIT(blog)
00095 {
00096        if (!threading)
00097        {
00098               CtdlRegisterMessageHook(blog_upload_beforesave, EVT_BEFORESAVE);
00099        }
00100        
00101        /* return our module id for the Log */
00102        return "blog";
00103 }