removed command.{c,h} -- absorbed into main.c
added a TODO file for imap cleaned up Makefile.am to match broke lots of things in main.c
Showing
6 changed files
with
82 additions
and
82 deletions
1 | 1999-10-12 Sean 'Shaleh' Perry <shaleh@debian.org> | ||
2 | |||
3 | * made sure that the imap4 was REALLY broken | ||
4 | |||
1 | 1999-10-11 Jeff Bailey <jbailey@cr499794-a.crdva1.bc.wave.home.com> | 5 | 1999-10-11 Jeff Bailey <jbailey@cr499794-a.crdva1.bc.wave.home.com> |
2 | 6 | ||
3 | * imap4d/Makefile.am: New file | 7 | * imap4d/Makefile.am: New file | ... | ... |
... | @@ -4,24 +4,20 @@ CPPFLAGS = -Wall -pedantic -ansi | ... | @@ -4,24 +4,20 @@ CPPFLAGS = -Wall -pedantic -ansi |
4 | sbin_PROGRAMS = imap4d | 4 | sbin_PROGRAMS = imap4d |
5 | 5 | ||
6 | imap4d_SOURCES = capability.c \ | 6 | imap4d_SOURCES = capability.c \ |
7 | command.c \ | ||
8 | login.c \ | 7 | login.c \ |
9 | logout.c \ | 8 | logout.c \ |
10 | main.c \ | 9 | main.c \ |
11 | noop.c \ | 10 | noop.c |
12 | readline.c | ||
13 | 11 | ||
14 | imap4d_LDADD = ../libmailbox/libmailbox.la \ | 12 | imap4d_LDADD = ../libmailbox/libmailbox.la \ |
15 | ../lib/libmailutils.a \ | 13 | ../lib/libmailutils.a \ |
16 | @AUTHLIBS@ | 14 | @AUTHLIBS@ |
17 | 15 | ||
18 | noinst_HEADERS = capability.h \ | 16 | noinst_HEADERS = capability.h \ |
19 | command.h \ | ||
20 | imap.h \ | 17 | imap.h \ |
21 | imap_commands.h \ | 18 | imap_commands.h \ |
22 | imap_types.h \ | 19 | imap_types.h \ |
23 | login.h \ | 20 | login.h \ |
24 | logout.h \ | 21 | logout.h \ |
25 | noop.h \ | 22 | noop.h |
26 | readline.h | ||
27 | 23 | ... | ... |
imap4d/TODO
0 → 100644
imap4d/command.c
deleted
100644 → 0
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <string.h> | ||
4 | #include "command.h" | ||
5 | |||
6 | Command* parse_command(char *string) { | ||
7 | |||
8 | size_t len, tmp; | ||
9 | Command *command; | ||
10 | |||
11 | if( string == NULL ) | ||
12 | return NULL; | ||
13 | |||
14 | command = malloc(sizeof(Command)); | ||
15 | memset(command, '\0', sizeof(Command)); | ||
16 | |||
17 | len = strcspn(string, " "); | ||
18 | if( len > 0 ) { | ||
19 | tmp = strcspn(string, "\r\n"); | ||
20 | string[tmp] = '\0'; | ||
21 | strncpy(command->tag, string, len > 15 ? 15 : len); | ||
22 | } else { | ||
23 | strcpy(command->tag, "gibberish"); | ||
24 | return command; | ||
25 | } | ||
26 | |||
27 | tmp = len; | ||
28 | ++tmp; /* skip space char */ | ||
29 | len = strcspn(string + tmp, " "); | ||
30 | if( len > 0 ) | ||
31 | strncpy(command->cmd, string + tmp, len > 15 ? 15 : len); | ||
32 | else { | ||
33 | strcpy(command->cmd, "gibberish"); | ||
34 | return command; | ||
35 | } | ||
36 | /* args is the rest of the string */ | ||
37 | command->args = string + len + tmp + 1; | ||
38 | |||
39 | if( command->args[0] == '\0' ) /* no args */ | ||
40 | command->args = NULL; | ||
41 | |||
42 | return command; | ||
43 | } | ||
44 | |||
45 | void free_command(Command *command) { | ||
46 | |||
47 | free(command); | ||
48 | } |
imap4d/command.h
deleted
100644 → 0
... | @@ -13,7 +13,11 @@ static void init(void); | ... | @@ -13,7 +13,11 @@ static void init(void); |
13 | static int mainloop(void); | 13 | static int mainloop(void); |
14 | static void cleanup(void); | 14 | static void cleanup(void); |
15 | static void greeting(void); | 15 | static void greeting(void); |
16 | static STATUS action(Command *command); | 16 | static Command* parse_command(char *string); |
17 | |||
18 | #define action(cmd) cmd->info->action ? cmd->info->action(cmd) : BAD; | ||
19 | |||
20 | #define free_command(cmd) free(cmd); | ||
17 | 21 | ||
18 | /* state the server is in */ | 22 | /* state the server is in */ |
19 | STATES state = NON_AUTH; | 23 | STATES state = NON_AUTH; |
... | @@ -25,6 +29,14 @@ FILE *output = NULL; | ... | @@ -25,6 +29,14 @@ FILE *output = NULL; |
25 | static char *status_word[3] = {"BAD", "NO", "OK"}; | 29 | static char *status_word[3] = {"BAD", "NO", "OK"}; |
26 | static char *status_code[3] = {"invalid", "failed", "completed"}; | 30 | static char *status_code[3] = {"invalid", "failed", "completed"}; |
27 | 31 | ||
32 | static imap4_cmd_t COMMANDS[] = { | ||
33 | { "capability", imap_capability, , , }, | ||
34 | { "noop" , imap_noop, , , }, | ||
35 | { "logout" , imap_logout, , , }, | ||
36 | { "login" , imap_login, , , }, | ||
37 | { "", , NULL, , , } | ||
38 | }; | ||
39 | |||
28 | 40 | ||
29 | int main(int argc, char *argv[]) { | 41 | int main(int argc, char *argv[]) { |
30 | 42 | ||
... | @@ -77,12 +89,16 @@ static int mainloop(void) { | ... | @@ -77,12 +89,16 @@ static int mainloop(void) { |
77 | 89 | ||
78 | while( getline(&client_string, &len, input) != -1 ) { | 90 | while( getline(&client_string, &len, input) != -1 ) { |
79 | command = parse_command(client_string); | 91 | command = parse_command(client_string); |
80 | status = action(command); | 92 | if(command) { |
81 | 93 | status = action(command); | |
82 | fprintf(output, "%s %s %s %s\r\n", command->tag, status_word[status], | 94 | fprintf(output, "%s %s %s %s\r\n", command->tag, status_word[status], |
83 | command->cmd, status_code[status]); | 95 | command->cmd, status_code[status]); |
84 | 96 | free_command(command); | |
85 | free_command(command); | 97 | } |
98 | else { | ||
99 | /* FIXME: properly handle this */ | ||
100 | fprintf(output, ""); | ||
101 | } | ||
86 | 102 | ||
87 | if( state == LOGOUT ) /* all done, let's go */ | 103 | if( state == LOGOUT ) /* all done, let's go */ |
88 | break; | 104 | break; |
... | @@ -92,20 +108,52 @@ static int mainloop(void) { | ... | @@ -92,20 +108,52 @@ static int mainloop(void) { |
92 | return 1; | 108 | return 1; |
93 | } | 109 | } |
94 | 110 | ||
95 | STATUS action(Command *command) { | 111 | imap4_action_t check_command(const char *command) { |
96 | 112 | ||
97 | if( strcasecmp(command->cmd, "capability") == 0 ) { | 113 | for(i = 0; COMMANDS[i]; ++i) { |
98 | return imap_capability(command); | 114 | if(strcasecmp(command, COMMANDS[i].cmd) == 0) |
115 | return COMMANDS[i]; | ||
99 | } | 116 | } |
100 | else if( strcasecmp(command->cmd, "noop") == 0 ) { | 117 | return NULL; |
101 | return imap_noop(command); | 118 | } |
102 | } | 119 | |
103 | else if( strcasecmp(command->cmd, "logout") == 0 ) { | 120 | Command* parse_command(char *string) { |
104 | return imap_logout(command); | 121 | |
105 | } | 122 | size_t len, tmp; |
106 | else if( strcasecmp(command->cmd, "login") == 0 ) { | 123 | Command *command; |
107 | return imap_login(command); | 124 | |
125 | if( string == NULL ) | ||
126 | return NULL; | ||
127 | |||
128 | command = malloc(sizeof(Command)); | ||
129 | memset(command, '\0', sizeof(Command)); | ||
130 | |||
131 | len = strcspn(string, " "); | ||
132 | if( len > 0 ) { | ||
133 | tmp = strcspn(string, "\r\n"); | ||
134 | string[tmp] = '\0'; | ||
135 | strncpy(command->tag, string, len > 15 ? 15 : len); | ||
136 | } else { | ||
137 | strcpy(command->tag, "gibberish"); | ||
138 | return command; | ||
108 | } | 139 | } |
109 | 140 | ||
110 | return BAD; | 141 | tmp = len; |
142 | ++tmp; /* skip space char */ | ||
143 | len = strcspn(string + tmp, " "); | ||
144 | if( len > 0 ) | ||
145 | strncpy(command->cmd, string + tmp, len > 15 ? 15 : len); | ||
146 | else { | ||
147 | strcpy(command->cmd, "gibberish"); | ||
148 | return command; | ||
149 | } | ||
150 | /* args is the rest of the string */ | ||
151 | command->args = string + len + tmp + 1; | ||
152 | |||
153 | if( command->args[0] == '\0' ) /* no args */ | ||
154 | command->args = NULL; | ||
155 | |||
156 | command->info = check_command(command->cmd); | ||
157 | |||
158 | return command; | ||
111 | } | 159 | } | ... | ... |
-
Please register or sign in to post a comment