+ /* Start patching backwards (newest to oldest) through the revision history until we
+ * hit the revision uuid requested by the user. (The callback will perform each one.)
+ */
+
+ memset(&hecbd, 0, sizeof(struct HistoryEraserCallBackData));
+ hecbd.tempfilename = temp;
+ hecbd.stop_when = rev;
+ striplt(hecbd.stop_when);
+
+ mime_parser(CM_RANGE(msg, eMesageText), *wiki_rev_callback, NULL, NULL, (void *)&hecbd, 0);
+ CM_Free(msg);
+
+ /* Were we successful? */
+ if (hecbd.done == 0) {
+ cprintf("%d Revision '%s' of page '%s' was not found.\n",
+ ERROR + MESSAGE_NOT_FOUND, rev, pagename
+ );
+ }
+
+ /* We have the desired revision on disk. Now do something with it. */
+
+ else if ( (!strcasecmp(operation, "fetch")) || (!strcasecmp(operation, "revert")) ) {
+ msg = malloc(sizeof(struct CtdlMessage));
+ memset(msg, 0, sizeof(struct CtdlMessage));
+ msg->cm_magic = CTDLMESSAGE_MAGIC;
+ msg->cm_anon_type = MES_NORMAL;
+ msg->cm_format_type = FMT_RFC822;
+ fp = fopen(temp, "r");
+ if (fp) {
+ char *msgbuf;
+ fseek(fp, 0L, SEEK_END);
+ len = ftell(fp);
+ fseek(fp, 0L, SEEK_SET);
+ msgbuf = malloc(len + 1);
+ rv = fread(msgbuf, len, 1, fp);
+ syslog(LOG_DEBUG, "did %d blocks of %ld bytes\n", rv, len);
+ msgbuf[len] = '\0';
+ CM_SetAsField(msg, eMesageText, &msgbuf, len);
+ fclose(fp);
+ }
+ if (len <= 0) {
+ msgnum = (-1L);
+ }
+ 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); /* Store the revision here */
+
+ /*
+ * WARNING: VILE SLEAZY HACK
+ * This will avoid the 'message xxx is not in this room' security error,
+ * 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;
+ }
+ CCC->cached_msglist = malloc(sizeof(long));
+ if (CCC->cached_msglist != NULL) {
+ CCC->cached_num_msgs = 1;
+ CCC->cached_msglist[0] = msgnum;
+ }
+
+ }
+ else if (!strcasecmp(operation, "revert")) {
+ CM_SetFieldLONG(msg, eTimestamp, time(NULL));
+ if (!IsEmptyStr(CCC->user.fullname)) {
+ CM_SetField(msg, eAuthor, CCC->user.fullname, strlen(CCC->user.fullname));
+ }
+
+ if (!IsEmptyStr(CCC->cs_inet_email)) {
+ CM_SetField(msg, erFc822Addr, CCC->cs_inet_email, strlen(CCC->cs_inet_email));
+ }
+
+ if (!IsEmptyStr(CCC->room.QRname)) {
+ CM_SetField(msg, eOriginalRoom, CCC->room.QRname, strlen(CCC->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 */
+ msgnum = (-1L);
+ }
+ CM_Free(msg);
+ if (msgnum >= 0L) {
+ cprintf("%d %ld\n", CIT_OK, msgnum); /* Give the client a msgnum */
+ }
+ else {
+ cprintf("%d Error %ld has occurred.\n", ERROR+INTERNAL_ERROR, msgnum);
+ }
+ }
+
+ /* We did all this work for nothing. Express anguish to the caller. */
+ else {
+ cprintf("%d An unknown operation was requested.\n", ERROR+CMD_NOT_SUPPORTED);
+ }