summaryrefslogtreecommitdiffabout
path: root/libical/src/libicalss/icalcstpserver.c
Unidiff
Diffstat (limited to 'libical/src/libicalss/icalcstpserver.c') (more/less context) (ignore whitespace changes)
-rw-r--r--libical/src/libicalss/icalcstpserver.c285
1 files changed, 285 insertions, 0 deletions
diff --git a/libical/src/libicalss/icalcstpserver.c b/libical/src/libicalss/icalcstpserver.c
new file mode 100644
index 0000000..cd8b3bb
--- a/dev/null
+++ b/libical/src/libicalss/icalcstpserver.c
@@ -0,0 +1,285 @@
1/* -*- Mode: C -*-
2 ======================================================================
3 FILE: icalcstpserver.c
4 CREATOR: ebusboom 13 Feb 01
5
6 $Id$
7 $Locker$
8
9 (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of either:
13
14 The LGPL as published by the Free Software Foundation, version
15 2.1, available at: http://www.fsf.org/copyleft/lesser.html
16
17 Or:
18
19 The Mozilla Public License Version 1.0. You may obtain a copy of
20 the License at http://www.mozilla.org/MPL/
21
22
23 ======================================================================*/
24
25#ifdef HAVE_CONFIG_H
26#include "config.h"
27#endif
28
29#include "icalerror.h"
30#include "ical.h"
31#include "icalcstp.h"
32#include "icalcstpserver.h"
33#include "pvl.h"
34
35// Eugen C. <eug@thekompany.com>
36#include <defines.h>
37#ifndef _QTWIN_
38#include <sys/types.h> /* For send(), others */
39#include <sys/socket.h> /* For send(), others. */
40#include<unistd.h>
41#endif
42// Eugen C. <eug@thekompany.com>
43
44#include <errno.h>
45#include <stdlib.h> /* for malloc */
46#include <string.h>
47
48
49
50struct icalcstps_impl {
51 int timeout;
52 icalparser *parser;
53 enum cstps_state major_state;
54 struct icalcstps_commandfp commandfp;
55};
56
57
58
59
60/* This state machine is a Mealy-type: actions occur on the
61 transitions, not in the states.
62
63 Here is the state machine diagram from the CAP draft:
64
65
66 STARTTLS /
67 CAPABILITY
68 +-------+
69 | | +---------------+
70 | +-----------+ AUTHENTICATE | |
71 +-->| Connected |-------------->| Authenticated |
72 +-----------+ | |
73 | +---------------+
74 | |
75 | |
76 | |
77 | | +-----+ STARTTLS /
78 | V | | CAPABILITY /
79 | +---------------+ | IDENTIFY
80 | | |<-+
81 | | Identified |<----+
82 | +--------| | |
83 | | +---------------+ | command
84 | | | | completes
85 V |DISCONNECT | |
86 +--------------+ | |SENDDATA |
87 | Disconnected |<--+ | |
88 +--------------+ | | ABORT
89 A | |
90 | V |
91 | DISCONNECT +---------------+ |
92 +--------------------| Receive |--+
93 | |<--+
94 +---------------+ |
95 | | CONTINUTE
96 +----+
97
98 In this implmenetation, the transition from CONNECTED to IDENTIFIED
99 is non-standard. The spec specifies that on the ATHENTICATE
100 command, the machine transitions from CONNECTED to AUTHENTICATED,
101 and then immediately goes to IDENTIFIED. This makes AUTHENTICATED a
102 useless state, so I removed it */
103
104struct state_table {
105 enum cstps_state major_state;
106 enum icalcstp_command command;
107 void (*action)();
108 enum cstps_state next_state;
109
110} server_state_table[] =
111{
112 { CONNECTED, ICAL_CAPABILITY_COMMAND , 0, CONNECTED},
113 { CONNECTED, ICAL_AUTHENTICATE_COMMAND , 0, IDENTIFIED}, /* Non-standard */
114 { IDENTIFIED, ICAL_STARTTLS_COMMAND, 0, IDENTIFIED},
115 { IDENTIFIED, ICAL_IDENTIFY_COMMAND, 0, IDENTIFIED},
116 { IDENTIFIED, ICAL_CAPABILITY_COMMAND, 0, IDENTIFIED},
117 { IDENTIFIED, ICAL_SENDDATA_COMMAND, 0, RECEIVE},
118 { IDENTIFIED, ICAL_DISCONNECT_COMMAND, 0, DISCONNECTED},
119 { DISCONNECTED, 0, 0, 0},
120 { RECEIVE, ICAL_DISCONNECT_COMMAND, 0, DISCONNECTED},
121 { RECEIVE, ICAL_CONTINUE_COMMAND, 0, RECEIVE},
122 { RECEIVE, ICAL_ABORT_COMMAND , 0, IDENTIFIED},
123 { RECEIVE, ICAL_COMPLETE_COMMAND , 0, IDENTIFIED}
124};
125
126
127/**********************************************************************/
128
129
130
131icalcstps* icalcstps_new(struct icalcstps_commandfp cfp)
132{
133 struct icalcstps_impl* impl;
134
135 if ( ( impl = (struct icalcstps_impl*)
136 malloc(sizeof(struct icalcstps_impl))) == 0) {
137 icalerror_set_errno(ICAL_NEWFAILED_ERROR);
138 return 0;
139 }
140
141 impl->commandfp = cfp;
142 impl->timeout = 10;
143
144 return (icalcstps*)impl;
145
146}
147
148void icalcstps_free(icalcstps* cstp);
149
150int icalcstps_set_timeout(icalcstps* cstp, int sec)
151{
152 struct icalcstps_impl *impl = (struct icalcstps_impl *) cstp;
153
154 icalerror_check_arg_rz( (cstp!=0), "cstp");
155
156 impl->timeout = sec;
157
158 return sec;
159}
160
161 typedef struct icalcstps_response {
162 icalrequeststatus code;
163 char caluid[1024];
164 void* result;
165} icalcstps_response;
166
167
168icalerrorenum prep_abort(struct icalcstps_impl* impl, char* data)
169{
170 return ICAL_NO_ERROR;
171}
172icalerrorenum prep_authenticate(struct icalcstps_impl* impl, char* data)
173{ return ICAL_NO_ERROR;
174}
175icalerrorenum prep_capability(struct icalcstps_impl* impl, char* data)
176{ return ICAL_NO_ERROR;
177}
178icalerrorenum prep_calidexpand(struct icalcstps_impl* impl, char* data)
179{
180 return ICAL_NO_ERROR;
181}
182icalerrorenum prep_continue(struct icalcstps_impl* impl, char* data)
183{
184 return ICAL_NO_ERROR;
185}
186icalerrorenum prep_disconnect(struct icalcstps_impl* impl, char* data)
187{
188 return ICAL_NO_ERROR;
189}
190icalerrorenum prep_identify(struct icalcstps_impl* impl, char* data)
191{
192 return ICAL_NO_ERROR;
193}
194icalerrorenum prep_starttls(struct icalcstps_impl* impl, char* data)
195{
196 return ICAL_NO_ERROR;
197}
198icalerrorenum prep_upnexpand(struct icalcstps_impl* impl, char* data)
199{
200 return ICAL_NO_ERROR;
201}
202icalerrorenum prep_sendata(struct icalcstps_impl* impl, char* data)
203{ return ICAL_NO_ERROR;
204}
205
206char* icalcstps_process_incoming(icalcstps* cstp, char* input)
207{
208 struct icalcstps_impl *impl = (struct icalcstps_impl *) cstp;
209 char *i;
210 char *cmd_or_resp;
211 char *data;
212 char *input_cpy;
213 icalerrorenum error;
214
215 icalerror_check_arg_rz(cstp !=0,"cstp");
216 icalerror_check_arg_rz(input !=0,"input");
217
218 if ((input_cpy = (char*)strdup(input)) == 0){
219 icalerror_set_errno(ICAL_NEWFAILED_ERROR);
220 return 0;
221 }
222
223 i = (char*)strstr(" ",input_cpy);
224
225 cmd_or_resp = input_cpy;
226
227 if (i != 0){
228 *i = '\0';
229 data = ++i;
230 } else {
231 data = 0;
232 }
233
234 printf("cmd: %s\n",cmd_or_resp);
235 printf("data: %s\n",data);
236
237 /* extract the command, look up in the state table, and dispatch
238 to the proper handler */
239
240 if(strcmp(cmd_or_resp,"ABORT") == 0){
241 error = prep_abort(impl,data);
242 } else if(strcmp(cmd_or_resp,"AUTHENTICATE") == 0){
243 error = prep_authenticate(impl,data);
244 } else if(strcmp(cmd_or_resp,"CAPABILITY") == 0){
245 error = prep_capability(impl,data);
246 } else if(strcmp(cmd_or_resp,"CALIDEXPAND") == 0){
247 error = prep_calidexpand(impl,data);
248 } else if(strcmp(cmd_or_resp,"CONTINUE") == 0){
249 error = prep_continue(impl,data);
250 } else if(strcmp(cmd_or_resp,"DISCONNECT") == 0){
251 error = prep_disconnect(impl,data);
252 } else if(strcmp(cmd_or_resp,"IDENTIFY") == 0){
253 error = prep_identify(impl,data);
254 } else if(strcmp(cmd_or_resp,"STARTTLS") == 0){
255 error = prep_starttls(impl,data);
256 } else if(strcmp(cmd_or_resp,"UPNEXPAND") == 0){
257 error = prep_upnexpand(impl,data);
258 } else if(strcmp(cmd_or_resp,"SENDDATA") == 0){
259 error = prep_sendata(impl,data);
260 }
261
262 return 0;
263}
264
265 /* Read data until we get a end of data marker */
266
267
268
269struct icalcstps_server_stubs {
270 icalerrorenum (*abort)(icalcstps* cstp);
271 icalerrorenum (*authenticate)(icalcstps* cstp, char* mechanism,
272 char* data);
273 icalerrorenum (*calidexpand)(icalcstps* cstp, char* calid);
274 icalerrorenum (*capability)(icalcstps* cstp);
275 icalerrorenum (*cont)(icalcstps* cstp, unsigned int time);
276 icalerrorenum (*identify)(icalcstps* cstp, char* id);
277 icalerrorenum (*disconnect)(icalcstps* cstp);
278 icalerrorenum (*sendata)(icalcstps* cstp, unsigned int time,
279 icalcomponent *comp);
280 icalerrorenum (*starttls)(icalcstps* cstp, char* command,
281 char* data);
282 icalerrorenum (*upnexpand)(icalcstps* cstp, char* upn);
283 icalerrorenum (*unknown)(icalcstps* cstp, char* command, char* data);
284};
285