* do typedef the visit struct, remove all those 'struct' statements from all over...
[citadel.git] / citadel / modules / pop3 / serv_pop3.c
index baee5a2aafc6926e7687f76d7da763d6a188323f..50c2749016b7c28af44e7a9bfbff82f72a2cb07a 100644 (file)
@@ -61,9 +61,7 @@
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "room_ops.h"
 #include "user_ops.h"
-#include "policy.h"
 #include "database.h"
 #include "msgbase.h"
 #include "internet_addressing.h"
@@ -170,15 +168,10 @@ void pop3_add_message(long msgnum, void *userdata) {
         */
        GetMetaData(&smi, msgnum);
        if (smi.meta_rfc822_length <= 0L) {
-               CC->redirect_buffer = malloc(SIZ);
-               CC->redirect_len = 0;
-               CC->redirect_alloc = SIZ;
+               CC->redirect_buffer = NewStrBufPlain(NULL, SIZ);
                CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1, NULL, SUPPRESS_ENV_TO);
-               smi.meta_rfc822_length = CC->redirect_len;
-               free(CC->redirect_buffer);
-               CC->redirect_buffer = NULL;
-               CC->redirect_len = 0;
-               CC->redirect_alloc = 0;
+               smi.meta_rfc822_length = StrLength(CC->redirect_buffer);
+               FreeStrBuf(&CC->redirect_buffer); /* TODO: WHEW, all this for just knowing the length???? */
                PutMetaData(&smi);
        }
        POP3->msgs[POP3->num_msgs-1].rfc822_length = smi.meta_rfc822_length;
@@ -192,10 +185,10 @@ void pop3_add_message(long msgnum, void *userdata) {
  * of messages in the inbox, or -1 for error)
  */
 int pop3_grab_mailbox(void) {
-        struct visit vbuf;
+        visit vbuf;
        int i;
 
-       if (getroom(&CC->room, MAILROOM) != 0) return(-1);
+       if (CtdlGetRoom(&CC->room, MAILROOM) != 0) return(-1);
 
        /* Load up the messages */
        CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL,
@@ -266,7 +259,7 @@ void pop3_apop(char *argbuf)
        return;
    }
    
-   if (getuser(&CC->user, CC->curr_user))
+   if (CtdlGetUser(&CC->user, CC->curr_user))
    {
        cprintf("-ERR No such user.\r\n");
        return;
@@ -291,11 +284,11 @@ void pop3_apop(char *argbuf)
 void pop3_pass(char *argbuf) {
        char password[SIZ];
 
-       strcpy(password, argbuf);
+       safestrncpy(password, argbuf, sizeof password);
        striplt(password);
 
        /* CtdlLogPrintf(CTDL_DEBUG, "Trying <%s>\n", password); */
-       if (CtdlTryPassword(password) == pass_ok) {
+       if (CtdlTryPassword(password, strlen(password)) == pass_ok) {
                pop3_login();
        }
        else {
@@ -403,8 +396,8 @@ void pop3_top(char *argbuf) {
        int lines_requested = 0;
        int lines_dumped = 0;
        char buf[1024];
-       char *msgtext;
-       char *ptr;
+       StrBuf *msgtext;
+       const char *ptr;
        int in_body = 0;
        int done = 0;
 
@@ -419,20 +412,15 @@ void pop3_top(char *argbuf) {
                return;
        }
 
-       CC->redirect_buffer = malloc(SIZ);
-       CC->redirect_len = 0;
-       CC->redirect_alloc = SIZ;
+       CC->redirect_buffer = NewStrBufPlain(NULL, SIZ);
        CtdlOutputMsg(POP3->msgs[which_one - 1].msgnum, MT_RFC822, HEADERS_ALL, 0, 1, NULL, SUPPRESS_ENV_TO);
        msgtext = CC->redirect_buffer;
        CC->redirect_buffer = NULL;
-       CC->redirect_len = 0;
-       CC->redirect_alloc = 0;
 
        cprintf("+OK Message %d:\r\n", which_one);
-
-       ptr = msgtext;
-
-       while (ptr = memreadline(ptr, buf, (sizeof buf - 2)),
+       
+       ptr = ChrPtr(msgtext);
+       while (ptr = cmemreadline(ptr, buf, (sizeof buf - 2)),
              ( (*ptr != 0) && (done == 0))) {
                strcat(buf, "\r\n");
                if (in_body == 1) {
@@ -450,7 +438,7 @@ void pop3_top(char *argbuf) {
        }
 
        if (buf[strlen(buf)-1] != 10) cprintf("\n");
-       free(msgtext);
+       FreeStrBuf(&msgtext);
 
        cprintf(".\r\n");
 }
@@ -484,7 +472,7 @@ void pop3_dele(char *argbuf) {
  */
 void pop3_update(void) {
        int i;
-        struct visit vbuf;
+        visit vbuf;
 
        long *deletemsgs = NULL;
        int num_deletemsgs = 0;
@@ -505,14 +493,14 @@ void pop3_update(void) {
 
        /* Set last read pointer */
        if (POP3->num_msgs > 0) {
-               lgetuser(&CC->user, CC->curr_user);
+               CtdlGetUserLock(&CC->user, CC->curr_user);
 
                CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
                snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld",
                        POP3->msgs[POP3->num_msgs-1].msgnum);
                CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
 
-               lputuser(&CC->user);
+               CtdlPutUserLock(&CC->user);
        }
 
 }