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