Commit 86506722 865067223c5fe78dd2b48b3aa1496fcd2a7ae5fd by Jakob Kaivo

more imap4d infrastructure

1 parent e4695e88
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
24 int 24 int
25 imap4d_append (int argc, char **argv) 25 imap4d_append (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc < 4)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_FEW;
29 return NOT_IMPL;
29 } 30 }
......
...@@ -18,12 +18,11 @@ ...@@ -18,12 +18,11 @@
18 #include "imap4d.h" 18 #include "imap4d.h"
19 19
20 /* 20 /*
21 * 21 * What types of auth should be supported?
22 */ 22 */
23 23
24 int 24 int
25 imap4d_authenticate (int argc, char **argv) 25 imap4d_authenticate (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 return util_finish (argc, argv, RESP_NO, NULL, "Type not supported");
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented");
29 } 28 }
......
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include "imap4d.h"
19
20 int
21 imap4d_capability (int argc, char **argv)
22 {
23 if (argc > 2)
24 return TOO_MANY;
25 util_out (argv[0], TAG_NONE, "CAPABILITY IMAP4rev1");
26 return util_finish (argc, argv, RESP_OK, NULL, "Completed");
27 }
...@@ -18,12 +18,13 @@ ...@@ -18,12 +18,13 @@
18 #include "imap4d.h" 18 #include "imap4d.h"
19 19
20 /* 20 /*
21 * 21 * Do we need to do anything here?
22 */ 22 */
23 23
24 int 24 int
25 imap4d_check (int argc, char **argv) 25 imap4d_check (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc > 2)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_MANY;
29 return util_finish (argc, argc, RESP_OK, NULL, "Completed");
29 } 30 }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
24 int 24 int
25 imap4d_close (int argc, char **argv) 25 imap4d_close (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc > 2)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_MANY;
29 return NOT_IMPL;
29 } 30 }
......
...@@ -18,29 +18,29 @@ ...@@ -18,29 +18,29 @@
18 #include "imap4d.h" 18 #include "imap4d.h"
19 19
20 const struct imap4d_command imap4d_command_table [] = { 20 const struct imap4d_command imap4d_command_table [] = {
21 { "capability", imap4d_capability, STATE_ALL }, 21 { "capability", imap4d_capability, STATE_ALL, STATE_NONE, STATE_NONE },
22 { "noop", imap4d_noop, STATE_ALL }, 22 { "noop", imap4d_noop, STATE_ALL, STATE_NONE, STATE_NONE },
23 { "logout", imap4d_logout, STATE_ALL }, 23 { "logout", imap4d_logout, STATE_ALL, STATE_LOGOUT, STATE_NONE },
24 { "authenticate", imap4d_authenticate, STATE_NONAUTH }, 24 { "authenticate", imap4d_authenticate, STATE_NONAUTH, STATE_NONE, STATE_AUTH },
25 { "login", imap4d_login, STATE_NONAUTH }, 25 { "login", imap4d_login, STATE_NONAUTH, STATE_NONE, STATE_AUTH },
26 { "select", imap4d_select, STATE_AUTH | STATE_SEL }, 26 { "select", imap4d_select, STATE_AUTH | STATE_SEL, STATE_AUTH, STATE_SEL },
27 { "examine", imap4d_examine, STATE_AUTH | STATE_SEL }, 27 { "examine", imap4d_examine, STATE_AUTH | STATE_SEL, STATE_AUTH, STATE_SEL },
28 { "create", imap4d_create, STATE_AUTH | STATE_SEL }, 28 { "create", imap4d_create, STATE_AUTH | STATE_SEL, STATE_NONE, STATE_NONE },
29 { "delete", imap4d_delete, STATE_AUTH | STATE_SEL }, 29 { "delete", imap4d_delete, STATE_AUTH | STATE_SEL, STATE_NONE, STATE_NONE },
30 { "rename", imap4d_rename, STATE_AUTH | STATE_SEL }, 30 { "rename", imap4d_rename, STATE_AUTH | STATE_SEL, STATE_NONE, STATE_NONE },
31 { "subscribe", imap4d_subscribe, STATE_AUTH | STATE_SEL }, 31 { "subscribe", imap4d_subscribe, STATE_AUTH | STATE_SEL, STATE_NONE, STATE_NONE },
32 { "unsubscribe", imap4d_unsubscribe, STATE_AUTH | STATE_SEL }, 32 { "unsubscribe", imap4d_unsubscribe, STATE_AUTH | STATE_SEL, STATE_NONE, STATE_NONE },
33 { "list", imap4d_list, STATE_AUTH | STATE_SEL }, 33 { "list", imap4d_list, STATE_AUTH | STATE_SEL, STATE_NONE, STATE_NONE },
34 { "lsub", imap4d_lsub, STATE_AUTH | STATE_SEL }, 34 { "lsub", imap4d_lsub, STATE_AUTH | STATE_SEL, STATE_NONE, STATE_NONE },
35 { "status", imap4d_status, STATE_AUTH | STATE_SEL }, 35 { "status", imap4d_status, STATE_AUTH | STATE_SEL, STATE_NONE, STATE_NONE },
36 { "append", imap4d_append, STATE_AUTH | STATE_SEL }, 36 { "append", imap4d_append, STATE_AUTH | STATE_SEL, STATE_NONE, STATE_NONE },
37 { "check", imap4d_check, STATE_SEL }, 37 { "check", imap4d_check, STATE_SEL, STATE_NONE, STATE_NONE },
38 { "close", imap4d_close, STATE_SEL }, 38 { "close", imap4d_close, STATE_SEL, STATE_AUTH, STATE_AUTH },
39 { "expunge", imap4d_expunge, STATE_SEL }, 39 { "expunge", imap4d_expunge, STATE_SEL, STATE_NONE, STATE_NONE },
40 { "search", imap4d_search, STATE_SEL }, 40 { "search", imap4d_search, STATE_SEL, STATE_NONE, STATE_NONE },
41 { "fetch", imap4d_fetch, STATE_SEL }, 41 { "fetch", imap4d_fetch, STATE_SEL, STATE_NONE, STATE_NONE },
42 { "store", imap4d_store, STATE_SEL }, 42 { "store", imap4d_store, STATE_SEL, STATE_NONE, STATE_NONE },
43 { "copy", imap4d_copy, STATE_SEL }, 43 { "copy", imap4d_copy, STATE_SEL, STATE_NONE, STATE_NONE },
44 { "uid", imap4d_uid, STATE_SEL }, 44 { "uid", imap4d_uid, STATE_SEL, STATE_NONE, STATE_NONE },
45 { 0, 0, 0} 45 { 0, 0, 0}
46 }; 46 };
......
...@@ -18,12 +18,15 @@ ...@@ -18,12 +18,15 @@
18 #include "imap4d.h" 18 #include "imap4d.h"
19 19
20 /* 20 /*
21 * 21 * copy messages in argv[2] to mailbox in argv[3]
22 */ 22 */
23 23
24 int 24 int
25 imap4d_copy (int argc, char **argv) 25 imap4d_copy (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc > 4)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_MANY;
29 else if (argc < 4)
30 return TOO_FEW;
31 return NOT_IMPL;
29 } 32 }
......
...@@ -18,12 +18,15 @@ ...@@ -18,12 +18,15 @@
18 #include "imap4d.h" 18 #include "imap4d.h"
19 19
20 /* 20 /*
21 * 21 * must create a new mailbox
22 */ 22 */
23 23
24 int 24 int
25 imap4d_create (int argc, char **argv) 25 imap4d_create (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc > 3)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_MANY;
29 else if (argc < 3)
30 return TOO_FEW;
31 return NOT_IMPL;
29 } 32 }
......
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
24 int 24 int
25 imap4d_delete (int argc, char **argv) 25 imap4d_delete (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc > 3)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_MANY;
29 if (argc < 3)
30 return TOO_FEW;
31 return NOT_IMPL;
29 } 32 }
......
...@@ -18,12 +18,11 @@ ...@@ -18,12 +18,11 @@
18 #include "imap4d.h" 18 #include "imap4d.h"
19 19
20 /* 20 /*
21 * 21 * copy things from select.c
22 */ 22 */
23 23
24 int 24 int
25 imap4d_examine (int argc, char **argv) 25 imap4d_examine (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 return NOT_IMPL;
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented");
29 } 28 }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
24 int 24 int
25 imap4d_expunge (int argc, char **argv) 25 imap4d_expunge (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc > 2)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_MANY;
29 return NOT_IMPL;
29 } 30 }
......
...@@ -18,12 +18,14 @@ ...@@ -18,12 +18,14 @@
18 #include "imap4d.h" 18 #include "imap4d.h"
19 19
20 /* 20 /*
21 * 21 * This will suck, too
22 */ 22 */
23 23
24 int 24 int
25 imap4d_fetch (int argc, char **argv) 25 imap4d_fetch (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc < 4)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_FEW;
29 /* check for paren list */
30 return NOT_IMPL;
29 } 31 }
......
...@@ -66,6 +66,8 @@ struct imap4d_command { ...@@ -66,6 +66,8 @@ struct imap4d_command {
66 char *name; 66 char *name;
67 Function *func; 67 Function *func;
68 int states; 68 int states;
69 int success;
70 int failure;
69 }; 71 };
70 72
71 /* Global variables and constants*/ 73 /* Global variables and constants*/
...@@ -87,6 +89,10 @@ struct imap4d_command { ...@@ -87,6 +89,10 @@ struct imap4d_command {
87 89
88 extern const struct imap4d_command imap4d_command_table[]; 90 extern const struct imap4d_command imap4d_command_table[];
89 91
92 #define TOO_MANY (util_finish (argc, argv, RESP_BAD, NULL, "Too many args"))
93 #define TOO_FEW (util_finish (argc, argv, RESP_BAD, NULL, "Too few args"))
94 #define NOT_IMPL (util_finish (argc, argv, RESP_BAD, NULL, "Not implemented"))
95
90 /* Functions */ 96 /* Functions */
91 int imap4d_capability __P ((int argc, char **argv)); 97 int imap4d_capability __P ((int argc, char **argv));
92 int imap4d_noop __P ((int argc, char **argv)); 98 int imap4d_noop __P ((int argc, char **argv));
...@@ -115,8 +121,9 @@ int imap4d_uid __P ((int argc, char **argv)); ...@@ -115,8 +121,9 @@ int imap4d_uid __P ((int argc, char **argv));
115 121
116 int util_out __P ((char *seq, int tag, char *f, ...)); 122 int util_out __P ((char *seq, int tag, char *f, ...));
117 int util_start __P ((char *seq)); 123 int util_start __P ((char *seq));
118 int util_finish __P ((int argc, char **argv, int resp, char *f, ...)); 124 int util_finish __P ((int argc, char **argv, int resp, char *r, char *f, ...));
119 int util_getstate __P((void)); 125 int util_getstate __P ((void));
126 struct imap4d_command *util_getcommand __P ((char *cmd));
120 127
121 #ifdef __cplusplus 128 #ifdef __cplusplus
122 } 129 }
......
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
24 int 24 int
25 imap4d_list (int argc, char **argv) 25 imap4d_list (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc > 4)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_MANY;
29 if (argc < 4)
30 return TOO_FEW;
31 return NOT_IMPL;
29 } 32 }
......
...@@ -18,12 +18,17 @@ ...@@ -18,12 +18,17 @@
18 #include "imap4d.h" 18 #include "imap4d.h"
19 19
20 /* 20 /*
21 * 21 * argv[2] == username
22 * argv[3] == password
23 * this should support PAM, shadow, and normal password
22 */ 24 */
23 25
24 int 26 int
25 imap4d_login (int argc, char **argv) 27 imap4d_login (int argc, char **argv)
26 { 28 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 29 if (argv > 4)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 30 return TOO_MANY;
31 else if (argv < 4)
32 return TOO_FEW;
33 return NOT_IMPL;
29 } 34 }
......
...@@ -18,12 +18,15 @@ ...@@ -18,12 +18,15 @@
18 #include "imap4d.h" 18 #include "imap4d.h"
19 19
20 /* 20 /*
21 * 21 * This needs to properly close the mailbox
22 */ 22 */
23 23
24 int 24 int
25 imap4d_logout (int argc, char **argv) 25 imap4d_logout (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc > 2)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_MANY;
29 util_out (argv[0], TAG_NONE, "BYE Logging out");
30 util_finish (argc, argv, RESP_OK, NULL, "Completed");
31 exit (0);
29 } 32 }
......
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
24 int 24 int
25 imap4d_lsub (int argc, char **argv) 25 imap4d_lsub (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc > 4)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_MANY;
29 if (argc < 4)
30 return TOO_FEW;
31 return NOT_IMPL;
29 } 32 }
......
...@@ -17,14 +17,10 @@ ...@@ -17,14 +17,10 @@
17 17
18 #include "imap4d.h" 18 #include "imap4d.h"
19 19
20 /*
21 *
22 */
23
24 int 20 int
25 imap4d_noop (int argc, char **argv) 21 imap4d_noop (int argc, char **argv)
26 { 22 {
27 if (argc > 2) 23 if (argc > 2)
28 return util_finish (argc, argv, RESP_BAD, "Too many arguments"); 24 return TOO_MANY;
29 return util_finish (argc, argv, RESP_OK, "Completed"); 25 return util_finish (argc, argv, RESP_OK, NULL, "Completed");
30 } 26 }
......
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
24 int 24 int
25 imap4d_rename (int argc, char **argv) 25 imap4d_rename (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc > 4)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_MANY;
29 if (argc < 4)
30 return TOO_FEW;
31 return NOT_IMPL;
29 } 32 }
......
...@@ -18,12 +18,13 @@ ...@@ -18,12 +18,13 @@
18 #include "imap4d.h" 18 #include "imap4d.h"
19 19
20 /* 20 /*
21 * 21 * This will be a royal pain in the arse to implement
22 */ 22 */
23 23
24 int 24 int
25 imap4d_search (int argc, char **argv) 25 imap4d_search (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc < 3)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_FEW;
29 return NOT_IMPL;
29 } 30 }
......
...@@ -18,12 +18,27 @@ ...@@ -18,12 +18,27 @@
18 #include "imap4d.h" 18 #include "imap4d.h"
19 19
20 /* 20 /*
21 * 21 * argv[2] == mailbox
22 * this needs to share code with EXAMINE
22 */ 23 */
23 24
24 int 25 int
25 imap4d_select (int argc, char **argv) 26 imap4d_select (int argc, char **argv)
26 { 27 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 28 if (argc > 3)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 29 return TOO_MANY;
30 else if (argc < 3)
31 return TOO_FEW;
32
33 /* close previous mailbox */
34 if ( /* open mailbox (argv[2]) == */ 0)
35 {
36 char *flags = NULL;
37 int num_messages = 0, recent = 0, uid = 0;
38 util_out (argv[0], TAG_NONE, "FLAGS %s", flags);
39 util_out (argv[0], TAG_NONE, "%d EXISTS", num_messages);
40 util_out (argv[0], TAG_NONE, "%d RECENT", recent);
41 return util_finish (argc, argv, RESP_OK, NULL, "Complete");
42 }
43 return util_finish (argc, argv, RESP_NO, NULL, "Couldn't open %s", argv[2]);
29 } 44 }
......
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
24 int 24 int
25 imap4d_status (int argc, char **argv) 25 imap4d_status (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc < 4)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_FEW;
29 if (argv[3][0] != '(' || argv[argc-1][strlen(argv[argc-1])-1] != ')')
30 return util_finish (argc, argv, RESP_BAD, NULL, "Invalid args");
31 return NOT_IMPL;
29 } 32 }
......
...@@ -18,12 +18,11 @@ ...@@ -18,12 +18,11 @@
18 #include "imap4d.h" 18 #include "imap4d.h"
19 19
20 /* 20 /*
21 * 21 * Now you're messing with a sumbitch
22 */ 22 */
23 23
24 int 24 int
25 imap4d_store (int argc, char **argv) 25 imap4d_store (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 return NOT_IMPL;
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented");
29 } 28 }
......
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
24 int 24 int
25 imap4d_subscribe (int argc, char **argv) 25 imap4d_subscribe (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc > 3)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_MANY;
29 if (argc < 3)
30 return TOO_FEW;
31 return NOT_IMPL;
29 } 32 }
......
...@@ -18,12 +18,12 @@ ...@@ -18,12 +18,12 @@
18 #include "imap4d.h" 18 #include "imap4d.h"
19 19
20 /* 20 /*
21 * 21 * see comment in store.c, raise to the nth power
22 * this is really going to sux0r (maybe)
22 */ 23 */
23 24
24 int 25 int
25 imap4d_uid (int argc, char **argv) 26 imap4d_uid (int argc, char **argv)
26 { 27 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 28 return NOT_IMPL;
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented");
29 } 29 }
......
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
24 int 24 int
25 imap4d_unsubscribe (int argc, char **argv) 25 imap4d_unsubscribe (int argc, char **argv)
26 { 26 {
27 util_out (argv[0], TAG_NONE, "BAD %s Command not implemented", argv[1]); 27 if (argc > 3)
28 return util_finish (argc, argv, RESP_BAD, "Command not implemented"); 28 return TOO_MANY;
29 if (argc < 3)
30 return TOO_FEW;
31 return NOT_IMPL;
29 } 32 }
......
...@@ -45,10 +45,11 @@ util_out (char *seq, int tag, char *f, ...) ...@@ -45,10 +45,11 @@ util_out (char *seq, int tag, char *f, ...)
45 } 45 }
46 46
47 int 47 int
48 util_finish (int argc, char **argv, int resp, char *f, ...) 48 util_finish (int argc, char **argv, int resp, char *rc, char *f, ...)
49 { 49 {
50 char *buf = NULL, *buf2 = NULL, *code = NULL; 50 char *buf = NULL, *buf2 = NULL, *code = NULL;
51 int len = 0; 51 int len = 0;
52 struct imap4d_command *cmd = util_getcommand (argv[1]);
52 va_list ap; 53 va_list ap;
53 va_start (ap, f); 54 va_start (ap, f);
54 55
...@@ -56,25 +57,32 @@ util_finish (int argc, char **argv, int resp, char *f, ...) ...@@ -56,25 +57,32 @@ util_finish (int argc, char **argv, int resp, char *f, ...)
56 { 57 {
57 case RESP_OK: 58 case RESP_OK:
58 code = strdup ("OK"); 59 code = strdup ("OK");
60 /* set state (cmd->success); */
59 break; 61 break;
60 case RESP_BAD: 62 case RESP_BAD:
61 code = strdup ("BAD"); 63 code = strdup ("BAD");
62 break; 64 break;
63 case RESP_NO: 65 case RESP_NO:
64 code = strdup ("NO"); 66 code = strdup ("NO");
67 /* set state (cmd->failure); */
65 break; 68 break;
66 default: 69 default:
67 code = strdup ("X-BUG"); 70 code = strdup ("X-BUG");
68 } 71 }
69 72
70 vasprintf (&buf, f, ap); 73 vasprintf (&buf, f, ap);
71 len = asprintf (&buf2, "%s %s %s %s\r\n", argv[0], code, argv[1], buf); 74 if (rc != NULL)
75 len = asprintf (&buf, "%s %s %s %s %s\r\n", argv[0],code,rc,argv[1],buf);
76 else
77 len = asprintf (&buf2, "%s %s %s %s\r\n", argv[0], code, argv[1], buf);
72 78
73 write (ofile, buf2, len); 79 write (ofile, buf2, len);
74 80
75 free (buf); 81 free (buf);
76 free (buf2); 82 free (buf2);
77 free (code); 83 free (code);
84 free (rc);
85 argcv_free (argc, argv);
78 86
79 return resp; 87 return resp;
80 } 88 }
...@@ -123,65 +131,35 @@ util_getline (void) ...@@ -123,65 +131,35 @@ util_getline (void)
123 int 131 int
124 util_do_command (char *cmd) 132 util_do_command (char *cmd)
125 { 133 {
134 int argc = 0, i = 0;
135 char **argv = NULL;
136 struct imap4d_command *command = NULL;
137
126 if (cmd == NULL) 138 if (cmd == NULL)
127 return 0; 139 return 0;
128 else
129 {
130 int argc = 0, status = 0, i = 0, len;
131 char **argv = NULL;
132 struct imap4d_command *command = NULL;
133
134 if (argcv_get (cmd, &argc, &argv) != 0)
135 {
136 argcv_free (argc, argv);
137 return 1;
138 }
139
140 140
141 util_start (argv[0]); 141 if (argcv_get (cmd, &argc, &argv) != 0)
142 142 {
143 if (argc < 2) 143 argcv_free (argc, argv);
144 { 144 return 1;
145 util_finish (argc, argv, RESP_BAD, 145 }
146 "Client did not send space after tag");
147 argcv_free (argc, argv);
148 return 1;
149 }
150 146
151 len = strlen (argv[1]); 147 util_start (argv[0]);
152 for (i=0; i < len; i++)
153 argv[1][i] = tolower (argv[1][i]);
154
155 for (i=0; command == NULL && imap4d_command_table[i].name != 0; i++)
156 {
157 if (strlen (imap4d_command_table[i].name) == len &&
158 !strcmp (imap4d_command_table[i].name, argv[1]))
159 command = &imap4d_command_table[i];
160 }
161 148
162 for (i=0; i < len; i++) 149 if (argc < 2)
163 argv[1][i] = toupper (argv[1][i]); 150 return util_finish (argc, argv, RESP_BAD, NULL, "No space after tag");
151
152 command = util_getcommand (argv[1]);
153
154 for (i=0; i < strlen (argv[1]); i++)
155 argv[1][i] = toupper (argv[1][i]);
156
157 if (command == NULL)
158 return util_finish (argc, argv, RESP_BAD, NULL, "Invalid command");
159 else if (! (command->states & util_getstate ()))
160 return util_finish (argc, argv, RESP_BAD, NULL, "Incorrect state");
164 161
165 if (command == NULL) 162 return command->func (argc, argv);
166 {
167 util_finish (argc, argv, RESP_BAD, "Invalid command");
168 argcv_free (argc, argv);
169 return 1;
170 }
171 else if (! (command->states & util_getstate ()))
172 {
173 util_finish (argc, argv, RESP_BAD, "Incorrect state");
174 argcv_free (argc, argv);
175 return 1;
176 }
177 else
178 {
179 status = command->func (argc, argv);
180 argcv_free (argc, argv);
181 return status;
182 }
183 }
184 return 1;
185 } 163 }
186 164
187 int 165 int
...@@ -195,3 +173,17 @@ util_getstate (void) ...@@ -195,3 +173,17 @@ util_getstate (void)
195 { 173 {
196 return STATE_NONAUTH; 174 return STATE_NONAUTH;
197 } 175 }
176
177 struct imap4d_command *
178 util_getcommand (char *cmd)
179 {
180 int i = 0, len = strlen (cmd);
181
182 for (i = 0; imap4d_command_table[i].name != 0; i++)
183 {
184 if (strlen (imap4d_command_table[i].name) == len &&
185 !strcasecmp (imap4d_command_table[i].name, cmd))
186 return &imap4d_command_table[i];
187 }
188 return NULL;
189 }
......