Indent with tabs, as God intended.
[citadel.git] / citadel / server / modules / blog / serv_blog.c
1 // Support for blog rooms
2 //
3 // Copyright (c) 1999-2024 by the citadel.org team
4 //
5 // This program is open source software.  Use, duplication, or disclosure
6 // is subject to the terms of the GNU General Public License, version 3.
7
8 #include "../../sysdep.h"
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <signal.h>
14 #include <pwd.h>
15 #include <errno.h>
16 #include <ctype.h>
17 #include <sys/types.h>
18 #include <time.h>
19 #include <sys/wait.h>
20 #include <string.h>
21 #include <limits.h>
22 #include <libcitadel.h>
23 #include "../../citadel_defs.h"
24 #include "../../server.h"
25 #include "../../citserver.h"
26 #include "../../support.h"
27 #include "../../config.h"
28 #include "../../control.h"
29 #include "../../user_ops.h"
30 #include "../../database.h"
31 #include "../../msgbase.h"
32 #include "../../internet_addressing.h"
33 #include "../../serv_vcard.h"
34 #include "../../citadel_ldap.h"
35 #include "../../ctdl_module.h"
36
37 // Pre-save hook for saving a message in a blog room.
38 // (Do we want to only do this for top-level messages?)
39 int blog_upload_beforesave(struct CtdlMessage *msg, struct recptypes *recp) {
40
41         // Only run this hook for blog rooms
42         if (CC->room.QRdefaultview != VIEW_BLOG) {
43                 return(0);
44         }
45
46         // If the message doesn't have an EUID, give it one.
47         if (CM_IsEmpty(msg, eExclusiveID)) {
48                 char uuid[SIZ];
49                 generate_uuid(uuid);
50                 CM_SetField(msg, eExclusiveID, uuid);
51         }
52
53         // We also want to define a maximum length, whether we generated it or not.
54         CM_CutFieldAt(msg, eExclusiveID, BLOG_EUIDBUF_SIZE - 1);
55         
56         // Now allow the save to complete.
57         return(0);
58 }
59
60
61 // Initialization function, called from modules_init.c
62 char *ctdl_module_init_blog(void) {
63         if (!threading) {
64                 CtdlRegisterMessageHook(blog_upload_beforesave, EVT_BEFORESAVE);
65         }
66         
67         // return our module id for the log
68         return "blog";
69 }