/*
* Server-side module for Wiki rooms. This handles things like version control.
*
- * Copyright (c) 2009-2012 by the citadel.org team
+ * Copyright (c) 2009-2021 by the citadel.org team
*
* This program is open source software. You can redistribute it and/or
* modify it under the terms of the GNU General Public License, version 3.
#include <errno.h>
#include <ctype.h>
#include <sys/types.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-# include <sys/time.h>
-# else
-# include <time.h>
-# endif
-#endif
-
+#include <time.h>
#include <sys/wait.h>
#include <string.h>
#include <limits.h>
* Before allowing a wiki page save to execute, we have to perform version control.
* This involves fetching the old version of the page if it exists.
*/
-int wiki_upload_beforesave(struct CtdlMessage *msg, recptypes *recp) {
- struct CitContext *CCC = CC;
+int wiki_upload_beforesave(struct CtdlMessage *msg, struct recptypes *recp) {
long old_msgnum = (-1L);
struct CtdlMessage *old_msg = NULL;
long history_msgnum = (-1L);
char *diffbuf = NULL;
size_t diffbuf_len = 0;
char *ptr = NULL;
+ long newmsgid;
+ StrBuf *msgidbuf;
- if (!CCC->logged_in) return(0); /* Only do this if logged in. */
+ if (!CC->logged_in) return(0); /* Only do this if logged in. */
/* Is this a room with a Wiki in it, don't run this hook. */
- if ((CCC->room.QRdefaultview != VIEW_WIKI) &&
- (CCC->room.QRdefaultview != VIEW_WIKIMD)) {
+ if (CC->room.QRdefaultview != VIEW_WIKI) {
return(0);
}
/* If there's no EUID we can't do this. Reject the post. */
if (CM_IsEmpty(msg, eExclusiveID)) return(1);
+ newmsgid = get_new_message_number();
+ msgidbuf = NewStrBuf();
+ StrBufPrintf(msgidbuf, "%08lX-%08lX@%s/%s",
+ (long unsigned int) time(NULL),
+ (long unsigned int) newmsgid,
+ CtdlGetConfigStr("c_fqdn"),
+ msg->cm_fields[eExclusiveID]
+ );
+
+ CM_SetAsFieldSB(msg, emessageId, &msgidbuf);
+
history_page_len = snprintf(history_page, sizeof history_page,
"%s_HISTORY_", msg->cm_fields[eExclusiveID]);
CM_CopyField(msg, eMsgSubject, eExclusiveID);
/* See if we can retrieve the previous version. */
- old_msgnum = CtdlLocateMessageByEuid(msg->cm_fields[eExclusiveID], &CCC->room);
+ old_msgnum = CtdlLocateMessageByEuid(msg->cm_fields[eExclusiveID], &CC->room);
if (old_msgnum > 0L) {
old_msg = CtdlFetchMessage(old_msgnum, 1);
}
/* Now look for the existing edit history */
- history_msgnum = CtdlLocateMessageByEuid(history_page, &CCC->room);
+ history_msgnum = CtdlLocateMessageByEuid(history_page, &CC->room);
history_msg = NULL;
if (history_msgnum > 0L) {
history_msg = CtdlFetchMessage(history_msgnum, 1);
history_msg->cm_anon_type = MES_NORMAL;
history_msg->cm_format_type = FMT_RFC822;
CM_SetField(history_msg, eAuthor, HKEY("Citadel"));
- CM_SetField(history_msg, eRecipient, CCC->room.QRname, strlen(CCC->room.QRname));
+ if (!IsEmptyStr(CC->room.QRname)){
+ CM_SetField(history_msg, eRecipient, CC->room.QRname, strlen(CC->room.QRname));
+ }
CM_SetField(history_msg, eExclusiveID, history_page, history_page_len);
CM_SetField(history_msg, eMsgSubject, history_page, history_page_len);
CM_SetField(history_msg, eSuppressIdx, HKEY("1")); /* suppress full text indexing */
memolen = snprintf(memo, sizeof(memo), "%s|%ld|%s|%s",
uuid,
Now,
- CCC->user.fullname,
- config.c_nodename);
+ CC->user.fullname,
+ CtdlGetConfigStr("c_nodename"));
memolen = CtdlEncodeBase64(encoded_memo, memo, memolen, 0);
CM_SetFieldLONG(history_msg, eTimestamp, Now);
- CtdlSubmitMsg(history_msg, NULL, "", 0);
+ CtdlSubmitMsg(history_msg, NULL, "");
}
else {
syslog(LOG_ALERT, "Empty boundary string in history message. No history!\n");
*/
void wiki_rev(char *pagename, char *rev, char *operation)
{
- struct CitContext *CCC = CC;
int r;
char history_page_name[270];
long msgnum;
/* Begin by fetching the current version of the page. We're going to patch
* backwards through the diffs until we get the one we want.
*/
- msgnum = CtdlLocateMessageByEuid(pagename, &CCC->room);
+ msgnum = CtdlLocateMessageByEuid(pagename, &CC->room);
if (msgnum > 0L) {
msg = CtdlFetchMessage(msgnum, 1);
}
fclose(fp);
}
else {
- syslog(LOG_ALERT, "Cannot open %s: %s\n", temp, strerror(errno));
+ syslog(LOG_ERR, "%s: %m", temp);
}
CM_Free(msg);
/* Get the revision history */
snprintf(history_page_name, sizeof history_page_name, "%s_HISTORY_", pagename);
- msgnum = CtdlLocateMessageByEuid(history_page_name, &CCC->room);
+ msgnum = CtdlLocateMessageByEuid(history_page_name, &CC->room);
if (msgnum > 0L) {
msg = CtdlFetchMessage(msgnum, 1);
}
else if (!strcasecmp(operation, "fetch")) {
CM_SetField(msg, eAuthor, HKEY("Citadel"));
CtdlCreateRoom(wwm, 5, "", 0, 1, 1, VIEW_BBS); /* Not an error if already exists */
- msgnum = CtdlSubmitMsg(msg, NULL, wwm, 0); /* Store the revision here */
+ msgnum = CtdlSubmitMsg(msg, NULL, wwm); /* Store the revision here */
/*
* WARNING: VILE SLEAZY HACK
* but only if the client fetches the message we just generated immediately
* without first trying to perform other fetch operations.
*/
- if (CCC->cached_msglist != NULL) {
- free(CCC->cached_msglist);
- CCC->cached_msglist = NULL;
- CCC->cached_num_msgs = 0;
+ if (CC->cached_msglist != NULL) {
+ free(CC->cached_msglist);
+ CC->cached_msglist = NULL;
+ CC->cached_num_msgs = 0;
}
- CCC->cached_msglist = malloc(sizeof(long));
- if (CCC->cached_msglist != NULL) {
- CCC->cached_num_msgs = 1;
- CCC->cached_msglist[0] = msgnum;
+ CC->cached_msglist = malloc(sizeof(long));
+ if (CC->cached_msglist != NULL) {
+ CC->cached_num_msgs = 1;
+ CC->cached_msglist[0] = msgnum;
}
}
else if (!strcasecmp(operation, "revert")) {
CM_SetFieldLONG(msg, eTimestamp, time(NULL));
- CM_SetField(msg, eAuthor, CCC->user.fullname, strlen(CCC->user.fullname));
- CM_SetField(msg, erFc822Addr, CCC->cs_inet_email, strlen(CCC->cs_inet_email));
- CM_SetField(msg, eOriginalRoom, CCC->room.QRname, strlen(CCC->room.QRname));
- CM_SetField(msg, eNodeName, CFG_KEY(c_nodename));
- CM_SetField(msg, eExclusiveID, pagename, strlen(pagename));
- msgnum = CtdlSubmitMsg(msg, NULL, "", 0); /* Replace the current revision */
+ if (!IsEmptyStr(CC->user.fullname)) {
+ CM_SetField(msg, eAuthor, CC->user.fullname, strlen(CC->user.fullname));
+ }
+
+ if (!IsEmptyStr(CC->cs_inet_email)) {
+ CM_SetField(msg, erFc822Addr, CC->cs_inet_email, strlen(CC->cs_inet_email));
+ }
+
+ if (!IsEmptyStr(CC->room.QRname)) {
+ CM_SetField(msg, eOriginalRoom, CC->room.QRname, strlen(CC->room.QRname));
+ }
+
+ if (!IsEmptyStr(pagename)) {
+ CM_SetField(msg, eExclusiveID, pagename, strlen(pagename));
+ }
+ msgnum = CtdlSubmitMsg(msg, NULL, ""); /* Replace the current revision */
}
else {
/* Theoretically it is impossible to get here, but throw an error anyway */