Commit 0d961fe9 0d961fe97ba3cf531a92967be2959e2e95a456aa by Alain Magloire

* pop3d/extra.c (pop3_readline) : Since the length of the string

is known, we can use memcpy() and friends for string manipulations.
memXXX() functions are builtin in GNU C (gcc) and are much faster
then the strXXX() counterparts. Small change in the loop to take
advantage of this.

* pop3d/quit.c : The rfc1939 insist that after a QUIT, we must
release any resources and close the connection:
"Whether the removal was successful or not, the server
then releases any exclusive-access lock on the maildrop
and closes the TCP connection."  This was not done if error
occured while expunging, no we will close the connection and
notify the client of the error(ERR_FILE).
1 parent 9a3839df
...@@ -169,6 +169,7 @@ pop3_readline (int fd) ...@@ -169,6 +169,7 @@ pop3_readline (int fd)
169 struct timeval tv; 169 struct timeval tv;
170 char buf[512], *ret = NULL; 170 char buf[512], *ret = NULL;
171 int nread; 171 int nread;
172 int total = 0;
172 int available; 173 int available;
173 174
174 FD_ZERO (&rfds); 175 FD_ZERO (&rfds);
...@@ -190,19 +191,13 @@ pop3_readline (int fd) ...@@ -190,19 +191,13 @@ pop3_readline (int fd)
190 pop3_abquit (ERR_DEAD_SOCK); 191 pop3_abquit (ERR_DEAD_SOCK);
191 192
192 buf[nread] = '\0'; 193 buf[nread] = '\0';
193 194 ret = realloc (ret, (total + nread + 1) * sizeof (char));
194 if (ret == NULL) 195 if (ret == NULL)
195 { 196 pop3_abquit (ERR_NO_MEM);
196 ret = malloc ((nread + 1) * sizeof (char)); 197 memcpy (ret + total, buf, nread + 1);
197 strcpy (ret, buf); 198 total += nread;
198 }
199 else
200 {
201 ret = realloc (ret, (strlen (ret) + nread + 1) * sizeof (char));
202 strcat (ret, buf);
203 }
204 } 199 }
205 while (strchr (buf, '\n') == NULL); 200 while (memchr (buf, '\n', nread) == NULL);
206 201
207 return ret; 202 return ret;
208 } 203 }
......
...@@ -117,6 +117,7 @@ main (int argc, char **argv) ...@@ -117,6 +117,7 @@ main (int argc, char **argv)
117 { 117 {
118 list_t bookie; 118 list_t bookie;
119 registrar_get_list (&bookie); 119 registrar_get_list (&bookie);
120 /* list_append (bookie, mbox_record); */
120 list_append (bookie, path_record); 121 list_append (bookie, path_record);
121 } 122 }
122 123
...@@ -300,6 +301,8 @@ pop3_mainloop (int infile, int outfile) ...@@ -300,6 +301,8 @@ pop3_mainloop (int infile, int outfile)
300 fprintf (ofile, "-ERR [IN-USE] " MBOX_LOCK "\r\n"); 301 fprintf (ofile, "-ERR [IN-USE] " MBOX_LOCK "\r\n");
301 else if (status == ERR_TOO_LONG) 302 else if (status == ERR_TOO_LONG)
302 fprintf (ofile, "-ERR " TOO_LONG "\r\n"); 303 fprintf (ofile, "-ERR " TOO_LONG "\r\n");
304 else if (status == ERR_FILE)
305 fprintf (ofile, "-ERR " FILE_EXP "\r\n");
303 else 306 else
304 fprintf (ofile, "-ERR unknown error\r\n"); 307 fprintf (ofile, "-ERR unknown error\r\n");
305 308
......
...@@ -56,6 +56,9 @@ ...@@ -56,6 +56,9 @@
56 /* The command argument was > 40 characters */ 56 /* The command argument was > 40 characters */
57 #define TOO_LONG "Argument too long" 57 #define TOO_LONG "Argument too long"
58 58
59 /* An error occured when expunging. */
60 #define FILE_EXP "Some deleted messages not removed"
61
59 /* APOP password file, without .db or .passwd, which are added based on file 62 /* APOP password file, without .db or .passwd, which are added based on file
60 type automatically */ 63 type automatically */
61 #define APOP_PASSFILE "/etc/apop" 64 #define APOP_PASSFILE "/etc/apop"
......
...@@ -18,17 +18,24 @@ ...@@ -18,17 +18,24 @@
18 #include "pop3d.h" 18 #include "pop3d.h"
19 19
20 /* Enters the UPDATE phase and deletes marked messages */ 20 /* Enters the UPDATE phase and deletes marked messages */
21 /* Note:
22 Whether the removal was successful or not, the server
23 then releases any exclusive-access lock on the maildrop
24 and closes the TCP connection. */
21 25
22 int 26 int
23 pop3_quit (const char *arg) 27 pop3_quit (const char *arg)
24 { 28 {
29 int err = OK;
25 if (strlen (arg) != 0) 30 if (strlen (arg) != 0)
26 return ERR_BAD_ARGS; 31 return ERR_BAD_ARGS;
27 32
28 if (state == TRANSACTION) 33 if (state == TRANSACTION)
29 { 34 {
30 if (mailbox_expunge (mbox) != 0 || mailbox_close (mbox) != 0 ) 35 if (mailbox_expunge (mbox) != 0)
31 return ERR_FILE; 36 err = ERR_FILE;
37 if (mailbox_close (mbox) != 0)
38 err = ERR_FILE;
32 mailbox_destroy (&mbox); 39 mailbox_destroy (&mbox);
33 syslog (LOG_INFO, "Session ended for user: %s", username); 40 syslog (LOG_INFO, "Session ended for user: %s", username);
34 } 41 }
...@@ -39,6 +46,7 @@ pop3_quit (const char *arg) ...@@ -39,6 +46,7 @@ pop3_quit (const char *arg)
39 free (username); 46 free (username);
40 free (md5shared); 47 free (md5shared);
41 48
42 fprintf (ofile, "+OK\r\n"); 49 if (err == OK)
43 return OK; 50 fprintf (ofile, "+OK\r\n");
51 return err;
44 } 52 }
......