0402e0190e650c6b4e01a79f3e6d38978a188a9b
[citadel.git] / citadel / modules / blog / serv_blog.c
1 /*
2  * Support for blog rooms
3  *
4  * Copyright (c) 1999-2011 by the citadel.org team
5  *
6  * This program is open source software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as published
8  * by the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20
21 #include "sysdep.h"
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <stdio.h>
25 #include <fcntl.h>
26 #include <signal.h>
27 #include <pwd.h>
28 #include <errno.h>
29 #include <ctype.h>
30 #include <sys/types.h>
31
32 #if TIME_WITH_SYS_TIME
33 # include <sys/time.h>
34 # include <time.h>
35 #else
36 # if HAVE_SYS_TIME_H
37 #  include <sys/time.h>
38 # else
39 #  include <time.h>
40 # endif
41 #endif
42
43 #include <sys/wait.h>
44 #include <string.h>
45 #include <limits.h>
46 #include <libcitadel.h>
47 #include "citadel.h"
48 #include "server.h"
49 #include "citserver.h"
50 #include "support.h"
51 #include "config.h"
52 #include "control.h"
53 #include "user_ops.h"
54 #include "database.h"
55 #include "msgbase.h"
56 #include "internet_addressing.h"
57 #include "serv_vcard.h"
58 #include "citadel_ldap.h"
59 #include "ctdl_module.h"
60
61 /*
62  * Pre-save hook for saving a message in a blog room.
63  * (Do we want to only do this for top-level messages?)
64  */
65 int blog_upload_beforesave(struct CtdlMessage *msg, recptypes *recp) {
66
67         /* Only run this hook for blog rooms */
68         if (CC->room.QRdefaultview != VIEW_BLOG) {
69                 return(0);
70         }
71
72         /* 
73          * If the message doesn't have an EUID, give it one.
74          */
75         if (CM_IsEmpty(msg, eExclusiveID))
76         {
77                 char uuid[SIZ];
78                 generate_uuid(uuid);
79                 CM_SetField(msg, eExclusiveID, uuid, strlen(uuid));
80         }
81
82         /*
83          * We also want to define a maximum length, whether we generated it or not.
84          */
85         CM_CutFieldAt(msg, eExclusiveID, BLOG_EUIDBUF_SIZE - 1);
86         
87         /* Now allow the save to complete. */
88         return(0);
89 }
90
91
92 CTDL_MODULE_INIT(blog)
93 {
94         if (!threading)
95         {
96                 CtdlRegisterMessageHook(blog_upload_beforesave, EVT_BEFORESAVE);
97         }
98         
99         /* return our module id for the Log */
100         return "blog";
101 }