Diffstat (limited to 'libical/src/libicalss/icalcstpclient.c') (more/less context) (show whitespace changes)
-rw-r--r-- | libical/src/libicalss/icalcstpclient.c | 350 |
1 files changed, 350 insertions, 0 deletions
diff --git a/libical/src/libicalss/icalcstpclient.c b/libical/src/libicalss/icalcstpclient.c new file mode 100644 index 0000000..03a70dd --- a/dev/null +++ b/libical/src/libicalss/icalcstpclient.c | |||
@@ -0,0 +1,350 @@ | |||
1 | /* -*- Mode: C -*- | ||
2 | ====================================================================== | ||
3 | FILE: icalcstps.c | ||
4 | CREATOR: ebusboom 23 Jun 2000 | ||
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 "icalcstpclient.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 | #define EOL "\n" | ||
49 | |||
50 | |||
51 | /* Client state machine */ | ||
52 | |||
53 | typedef enum icalcstpc_line_type { | ||
54 | ICALCSTPC_RESPONSE_CODE_LINE, | ||
55 | ICALCSTPC_TERMINATOR_LINE, | ||
56 | ICALCSTPC_APPLICATION_DATA_LINE | ||
57 | } icalcstpc_line_type; | ||
58 | |||
59 | typedef enum icalcstpc_state { | ||
60 | ICALCSTPC_SEND_STATE, | ||
61 | ICALCSTPC_RESPONSE_CODE_STATE, | ||
62 | ICALCSTPC_RESPONSE_DATA_STATE | ||
63 | } icalcstpc_state; | ||
64 | |||
65 | |||
66 | |||
67 | struct icalcstpc_impl { | ||
68 | int timeout; | ||
69 | icalparser *parser; | ||
70 | icalcstp_command command; | ||
71 | icalcstpc_state state; | ||
72 | char* next_output; | ||
73 | char* next_input; | ||
74 | }; | ||
75 | |||
76 | icalcstpc* icalcstpc_new() | ||
77 | { | ||
78 | struct icalcstpc_impl *impl; | ||
79 | |||
80 | impl = malloc(sizeof(struct icalcstpc_impl)); | ||
81 | |||
82 | if(impl == 0){ | ||
83 | icalerror_set_errno(ICAL_NEWFAILED_ERROR); | ||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | memset(impl,0,sizeof(struct icalcstpc_impl)); | ||
88 | |||
89 | return impl; | ||
90 | } | ||
91 | |||
92 | void icalcstpc_free(icalcstpc* cstpc) | ||
93 | { | ||
94 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstpc; | ||
95 | |||
96 | if(impl->next_output != 0){ | ||
97 | free(impl->next_output); | ||
98 | } | ||
99 | |||
100 | if(impl->next_input != 0){ | ||
101 | free(impl->next_input); | ||
102 | } | ||
103 | |||
104 | |||
105 | if(impl->parser != 0){ | ||
106 | icalparser_free(impl->parser); | ||
107 | } | ||
108 | } | ||
109 | |||
110 | /* Get the next string to send to the server */ | ||
111 | char* icalcstpc_next_output(icalcstpc* cstp, char * line) | ||
112 | { | ||
113 | char* out; | ||
114 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstp; | ||
115 | |||
116 | if(impl->next_output == 0){ | ||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | out = impl->next_output; | ||
121 | |||
122 | impl->next_output = 0; | ||
123 | |||
124 | icalmemory_add_tmp_buffer(out); | ||
125 | |||
126 | return out; | ||
127 | } | ||
128 | |||
129 | /* process the next string sent by the server */ | ||
130 | int icalcstpc_next_input(icalcstpc* cstp, char* line) | ||
131 | { | ||
132 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstp; | ||
133 | icalcstpc_line_type line_type; | ||
134 | |||
135 | if(icalcstp_line_is_endofdata(line) || line == 0){ | ||
136 | return 0; | ||
137 | } | ||
138 | |||
139 | switch (impl->command){ | ||
140 | case ICAL_ABORT_COMMAND:{ | ||
141 | break; | ||
142 | } | ||
143 | case ICAL_AUTHENTICATE_COMMAND:{ | ||
144 | break; | ||
145 | } | ||
146 | case ICAL_CAPABILITY_COMMAND:{ | ||
147 | break; | ||
148 | } | ||
149 | case ICAL_CONTINUE_COMMAND:{ | ||
150 | break; | ||
151 | } | ||
152 | case ICAL_CALIDEXPAND_COMMAND:{ | ||
153 | break; | ||
154 | } | ||
155 | case ICAL_IDENTIFY_COMMAND:{ | ||
156 | break; | ||
157 | } | ||
158 | case ICAL_DISCONNECT_COMMAND:{ | ||
159 | break; | ||
160 | } | ||
161 | case ICAL_SENDDATA_COMMAND:{ | ||
162 | break; | ||
163 | } | ||
164 | case ICAL_STARTTLS_COMMAND:{ | ||
165 | break; | ||
166 | } | ||
167 | case ICAL_UPNEXPAND_COMMAND:{ | ||
168 | break; | ||
169 | } | ||
170 | case ICAL_COMPLETE_COMMAND:{ | ||
171 | break; | ||
172 | } | ||
173 | case ICAL_UNKNOWN_COMMAND:{ | ||
174 | break; | ||
175 | } | ||
176 | default: | ||
177 | break; | ||
178 | } | ||
179 | } | ||
180 | |||
181 | /* After icalcstpc_next_input returns a 0, there are responses | ||
182 | ready. use these to get them */ | ||
183 | icalcstpc_response icalcstpc_first_response(icalcstpc* cstp) | ||
184 | { | ||
185 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstp; | ||
186 | |||
187 | } | ||
188 | |||
189 | |||
190 | icalcstpc_response icalcstpc_next_response(icalcstpc* cstp) | ||
191 | { | ||
192 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstp; | ||
193 | } | ||
194 | |||
195 | |||
196 | int icalcstpc_set_timeout(icalcstpc* cstp, int sec) | ||
197 | { | ||
198 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstp; | ||
199 | } | ||
200 | |||
201 | icalerrorenum icalcstpc_abort(icalcstpc* cstp) | ||
202 | { | ||
203 | struct icalcstpc_impl* impl = (struct icalcstpc_impl*)cstp; | ||
204 | |||
205 | icalerror_check_arg_re(cstp!=0,"cstp",ICAL_BADARG_ERROR); | ||
206 | |||
207 | impl->next_output = "ABORT\n"; | ||
208 | |||
209 | return ICAL_NO_ERROR; | ||
210 | } | ||
211 | |||
212 | icalerrorenum icalcstpclient_setup_output(icalcstpc* cstp, size_t sz) | ||
213 | { | ||
214 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstp; | ||
215 | |||
216 | if(impl->next_output != 0){ | ||
217 | icalerror_set_errno(ICAL_USAGE_ERROR); | ||
218 | return ICAL_USAGE_ERROR; | ||
219 | } | ||
220 | |||
221 | impl->next_output = malloc(sz); | ||
222 | |||
223 | if(impl->next_output == 0){ | ||
224 | icalerror_set_errno(ICAL_NEWFAILED_ERROR); | ||
225 | return ICAL_NEWFAILED_ERROR; | ||
226 | } | ||
227 | |||
228 | return ICAL_NO_ERROR; | ||
229 | |||
230 | } | ||
231 | |||
232 | icalerrorenum icalcstpc_authenticate(icalcstpc* cstp, char* mechanism, | ||
233 | char* data, char* f(char*)) | ||
234 | { | ||
235 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstp; | ||
236 | char* command_str; | ||
237 | icalerrorenum error; | ||
238 | size_t sz; | ||
239 | |||
240 | icalerror_check_arg_re(cstp!=0,"cstp",ICAL_BADARG_ERROR); | ||
241 | icalerror_check_arg_re(mechanism!=0,"mechanism",ICAL_BADARG_ERROR); | ||
242 | icalerror_check_arg_re(data!=0,"data",ICAL_BADARG_ERROR); | ||
243 | icalerror_check_arg_re(f!=0,"f",ICAL_BADARG_ERROR); | ||
244 | |||
245 | impl->command = ICAL_AUTHENTICATE_COMMAND; | ||
246 | |||
247 | command_str = icalcstp_command_to_string(impl->command); | ||
248 | |||
249 | sz = strlen(command_str) + strlen(mechanism) + strlen(data) + 4; | ||
250 | |||
251 | if((error=icalcstpclient_setup_output(cstp,sz)) != ICAL_NO_ERROR){ | ||
252 | return error; | ||
253 | } | ||
254 | |||
255 | sprintf(impl->next_output,"%s %s %s%s",command_str,mechanism,data,EOL); | ||
256 | |||
257 | return ICAL_NO_ERROR; | ||
258 | } | ||
259 | |||
260 | icalerrorenum icalcstpc_capability(icalcstpc* cstp) | ||
261 | { | ||
262 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstp; | ||
263 | char* command_str; | ||
264 | icalerrorenum error; | ||
265 | size_t sz; | ||
266 | |||
267 | icalerror_check_arg_re(cstp!=0,"cstp",ICAL_BADARG_ERROR); | ||
268 | |||
269 | impl->command = ICAL_CAPABILITY_COMMAND; | ||
270 | |||
271 | command_str = icalcstp_command_to_string(impl->command); | ||
272 | |||
273 | sz = strlen(command_str); | ||
274 | |||
275 | if((error=icalcstpclient_setup_output(cstp,sz)) != ICAL_NO_ERROR){ | ||
276 | return error; | ||
277 | } | ||
278 | |||
279 | return ICAL_NO_ERROR; | ||
280 | } | ||
281 | |||
282 | icalerrorenum icalcstpc_calidexpand(icalcstpc* cstp,char* calid) | ||
283 | { | ||
284 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstp; | ||
285 | |||
286 | impl->command = ICAL_CALIDEXPAND_COMMAND; | ||
287 | return ICAL_NO_ERROR; | ||
288 | } | ||
289 | |||
290 | icalerrorenum icalcstpc_continue(icalcstpc* cstp, unsigned int time) | ||
291 | { | ||
292 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstp; | ||
293 | |||
294 | impl->command = ICAL_CONTINUE_COMMAND; | ||
295 | return ICAL_NO_ERROR; | ||
296 | } | ||
297 | |||
298 | icalerrorenum icalcstpc_disconnect(icalcstpc* cstp) | ||
299 | { | ||
300 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstp; | ||
301 | |||
302 | |||
303 | impl->command = ICAL_DISCONNECT_COMMAND; | ||
304 | |||
305 | return ICAL_NO_ERROR; | ||
306 | } | ||
307 | |||
308 | icalerrorenum icalcstpc_identify(icalcstpc* cstp, char* id) | ||
309 | { | ||
310 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstp; | ||
311 | |||
312 | |||
313 | impl->command = ICAL_IDENTIFY_COMMAND; | ||
314 | |||
315 | return ICAL_NO_ERROR; | ||
316 | } | ||
317 | |||
318 | icalerrorenum icalcstpc_starttls(icalcstpc* cstp, char* command, | ||
319 | char* data, char * f(char*)) | ||
320 | { | ||
321 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstp; | ||
322 | |||
323 | impl->command = ICAL_STARTTLS_COMMAND; | ||
324 | |||
325 | return ICAL_NO_ERROR; | ||
326 | } | ||
327 | |||
328 | icalerrorenum icalcstpc_upnexpand(icalcstpc* cstp,char* calid) | ||
329 | { | ||
330 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstp; | ||
331 | |||
332 | |||
333 | impl->command = ICAL_UPNEXPAND_COMMAND; | ||
334 | |||
335 | return ICAL_NO_ERROR; | ||
336 | } | ||
337 | |||
338 | icalerrorenum icalcstpc_sendata(icalcstpc* cstp, unsigned int time, | ||
339 | icalcomponent *comp) | ||
340 | { | ||
341 | struct icalcstpc_impl *impl = (struct icalcstpc_impl *)cstp; | ||
342 | |||
343 | impl->command = ICAL_SENDDATA_COMMAND; | ||
344 | |||
345 | return ICAL_NO_ERROR; | ||
346 | } | ||
347 | |||
348 | |||
349 | |||
350 | |||