more places where we can use cm_lengths;
[citadel.git] / citadel / modules / wiki / serv_wiki.c
index 33d856310f55e0907e9e04616239cac9af1932d3..ccfc77b7e66495e3c274d32a9a825798a6a1056f 100644 (file)
@@ -45,6 +45,7 @@
 #include "config.h"
 #include "control.h"
 #include "user_ops.h"
+#include "room_ops.h"
 #include "database.h"
 #include "msgbase.h"
 #include "euidindex.h"
@@ -69,7 +70,7 @@ char *wwm = "9999999999.WikiWaybackMachine";
  * 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) {
+int wiki_upload_beforesave(struct CtdlMessage *msg, recptypes *recp) {
        struct CitContext *CCC = CC;
        long old_msgnum = (-1L);
        struct CtdlMessage *old_msg = NULL;
@@ -101,7 +102,7 @@ int wiki_upload_beforesave(struct CtdlMessage *msg) {
        if (msg->cm_format_type != 4) return(0);
 
        /* If there's no EUID we can't do this.  Reject the post. */
-       if (msg->cm_fields[eExclusiveID] == NULL) return(1);
+       if (CM_IsEmpty(msg, eExclusiveID)) return(1);
 
        history_page_len = snprintf(history_page, sizeof history_page,
                                    "%s_HISTORY_", msg->cm_fields[eExclusiveID]);
@@ -109,15 +110,15 @@ int wiki_upload_beforesave(struct CtdlMessage *msg) {
        /* Make sure we're saving a real wiki page rather than a wiki history page.
         * This is important in order to avoid recursing infinitely into this hook.
         */
-       if (    (strlen(msg->cm_fields[eExclusiveID]) >= 9)
-               && (!strcasecmp(&msg->cm_fields[eExclusiveID][strlen(msg->cm_fields[eExclusiveID])-9], "_HISTORY_"))
+       if (    (msg->cm_lengths[eExclusiveID] >= 9)
+               && (!strcasecmp(&msg->cm_fields[eExclusiveID][msg->cm_lengths[eExclusiveID]-9], "_HISTORY_"))
        ) {
                syslog(LOG_DEBUG, "History page not being historied\n");
                return(0);
        }
 
        /* If there's no message text, obviously this is all b0rken and shouldn't happen at all */
-       if (msg->cm_fields[eMesageText] == NULL) return(0);
+       if (CM_IsEmpty(msg, eMesageText)) return(0);
 
        /* Set the message subject identical to the page name */
        CM_CopyField(msg, eMsgSubject, eExclusiveID);
@@ -131,14 +132,14 @@ int wiki_upload_beforesave(struct CtdlMessage *msg) {
                old_msg = NULL;
        }
 
-       if ((old_msg != NULL) && (old_msg->cm_fields[eMesageText] == NULL)) {   /* old version is corrupt? */
-               CtdlFreeMessage(old_msg);
+       if ((old_msg != NULL) && (CM_IsEmpty(old_msg, eMesageText))) {  /* old version is corrupt? */
+               CM_Free(old_msg);
                old_msg = NULL;
        }
        
        /* If no changes were made, don't bother saving it again */
        if ((old_msg != NULL) && (!strcmp(msg->cm_fields[eMesageText], old_msg->cm_fields[eMesageText]))) {
-               CtdlFreeMessage(old_msg);
+               CM_Free(old_msg);
                return(1);
        }
 
@@ -151,13 +152,13 @@ int wiki_upload_beforesave(struct CtdlMessage *msg) {
 
        if (old_msg != NULL) {
                fp = fopen(diff_old_filename, "w");
-               rv = fwrite(old_msg->cm_fields[eMesageText], strlen(old_msg->cm_fields[eMesageText]), 1, fp);
+               rv = fwrite(old_msg->cm_fields[eMesageText], old_msg->cm_lengths[eMesageText], 1, fp);
                fclose(fp);
-               CtdlFreeMessage(old_msg);
+               CM_Free(old_msg);
        }
 
        fp = fopen(diff_new_filename, "w");
-       rv = fwrite(msg->cm_fields[eMesageText], strlen(msg->cm_fields[eMesageText]), 1, fp);
+       rv = fwrite(msg->cm_fields[eMesageText], msg->cm_lengths[eMesageText], 1, fp);
        fclose(fp);
 
        snprintf(diff_cmd, sizeof diff_cmd,
@@ -342,7 +343,7 @@ int wiki_upload_beforesave(struct CtdlMessage *msg) {
        }
 
        free(diffbuf);
-       CtdlFreeMessage(history_msg);
+       CM_Free(history_msg);
        return(0);
 }
 
@@ -394,8 +395,8 @@ void wiki_history(char *pagename) {
                msg = NULL;
        }
 
-       if ((msg != NULL) && (msg->cm_fields[eMesageText] == NULL)) {
-               CtdlFreeMessage(msg);
+       if ((msg != NULL) && CM_IsEmpty(msg, eMesageText)) {
+               CM_Free(msg);
                msg = NULL;
        }
 
@@ -409,7 +410,7 @@ void wiki_history(char *pagename) {
        mime_parser(msg->cm_fields[eMesageText], NULL, *wiki_history_callback, NULL, NULL, NULL, 0);
        cprintf("000\n");
 
-       CtdlFreeMessage(msg);
+       CM_Free(msg);
        return;
 }
 
@@ -526,8 +527,8 @@ void wiki_rev(char *pagename, char *rev, char *operation)
                msg = NULL;
        }
 
-       if ((msg != NULL) && (msg->cm_fields[eMesageText] == NULL)) {
-               CtdlFreeMessage(msg);
+       if ((msg != NULL) && CM_IsEmpty(msg, eMesageText)) {
+               CM_Free(msg);
                msg = NULL;
        }
 
@@ -541,13 +542,13 @@ void wiki_rev(char *pagename, char *rev, char *operation)
        CtdlMakeTempFileName(temp, sizeof temp);
        fp = fopen(temp, "w");
        if (fp != NULL) {
-               r = fwrite(msg->cm_fields[eMesageText], strlen(msg->cm_fields[eMesageText]), 1, fp);
+               r = fwrite(msg->cm_fields[eMesageText], msg->cm_lengths[eMesageText], 1, fp);
                fclose(fp);
        }
        else {
                syslog(LOG_ALERT, "Cannot open %s: %s\n", temp, strerror(errno));
        }
-       CtdlFreeMessage(msg);
+       CM_Free(msg);
 
        /* Get the revision history */
 
@@ -560,8 +561,8 @@ void wiki_rev(char *pagename, char *rev, char *operation)
                msg = NULL;
        }
 
-       if ((msg != NULL) && (msg->cm_fields[eMesageText] == NULL)) {
-               CtdlFreeMessage(msg);
+       if ((msg != NULL) && CM_IsEmpty(msg, eMesageText)) {
+               CM_Free(msg);
                msg = NULL;
        }
 
@@ -580,7 +581,7 @@ void wiki_rev(char *pagename, char *rev, char *operation)
        striplt(hecbd.stop_when);
 
        mime_parser(msg->cm_fields[eMesageText], NULL, *wiki_rev_callback, NULL, NULL, (void *)&hecbd, 0);
-       CtdlFreeMessage(msg);
+       CM_Free(msg);
 
        /* Were we successful? */
        if (hecbd.done == 0) {
@@ -649,7 +650,7 @@ void wiki_rev(char *pagename, char *rev, char *operation)
                        /* Theoretically it is impossible to get here, but throw an error anyway */
                        msgnum = (-1L);
                }
-               CtdlFreeMessage(msg);
+               CM_Free(msg);
                if (msgnum >= 0L) {
                        cprintf("%d %ld\n", CIT_OK, msgnum);            /* Give the client a msgnum */
                }