globus_gass_transfer  8.13
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
globus_l_gass_transfer_ftp.h
Go to the documentation of this file.
1 
9 #ifndef GLOBUS_L_GASS_TRANSFER_FTP_H
10 #define GLOBUS_L_GASS_TRANSFER_FTP_H
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 /******************************************************************************
17  Module Specific Constants
18 ******************************************************************************/
19 
20 static globus_mutex_t globus_l_gass_transfer_ftp_mutex;
21 static globus_cond_t globus_l_gass_transfer_ftp_cond;
22 
23 #define globus_l_gass_transfer_ftp_lock() \
24  globus_mutex_lock(&globus_l_gass_transfer_ftp_mutex)/*,*/ \
25  /*printf("locked mutex at %s: %d\n", __FILE__, __LINE__)*/
26 #define globus_l_gass_transfer_ftp_unlock() \
27  /*printf("unlocking mutex at %s: %d\n", __FILE__, __LINE__), */\
28  globus_mutex_unlock(&globus_l_gass_transfer_ftp_mutex)
29 #define globus_l_gass_transfer_ftp_wait() \
30  globus_cond_wait(&globus_l_gass_transfer_ftp_cond, \
31  &globus_l_gass_transfer_ftp_mutex)
32 #define globus_l_gass_transfer_ftp_signal() \
33  globus_cond_signal(&globus_l_gass_transfer_ftp_cond)
34 
35 #define GLOBUS_L_DEFAULT_FAILURE_CODE 400
36 #define GLOBUS_L_DEFAULT_FAILURE_REASON "Bad Request"
37 
38 /* The "client failure" (4xx) response codes defined in RFC 2068 end at 415 */
39 #define GLOBUS_L_PROTOCOL_FAILURE_CODE 416
40 #define GLOBUS_L_PROTOCOL_FAILURE_REASON "Protocol Error"
41 
42 #define GLOBUS_L_MALLOC_FAILURE_CODE 417
43 #define GLOBUS_L_MALLOC_FAILURE_REASON "Malloc Error"
44 
45 /******************************************************************************
46  Module specific Types
47 ******************************************************************************/
48 typedef enum
49 {
50  /* Client-only states */
51  GLOBUS_GASS_TRANSFER_FTP_STATE_CONNECTING,
52  GLOBUS_GASS_TRANSFER_FTP_STATE_REQUESTING,
53  GLOBUS_GASS_TRANSFER_FTP_STATE_CLOSING,
54  GLOBUS_GASS_TRANSFER_FTP_STATE_REFERRED,
55  GLOBUS_GASS_TRANSFER_FTP_STATE_DENIED,
56  GLOBUS_GASS_TRANSFER_FTP_STATE_RESPONDING,
57  /* Common states */
58  GLOBUS_GASS_TRANSFER_FTP_STATE_IDLE,
59  GLOBUS_GASS_TRANSFER_FTP_STATE_DONE,
60  GLOBUS_GASS_TRANSFER_FTP_STATE_PENDING
61 } globus_gass_transfer_ftp_state_t;
62 
63 /* These mirror the GASS listener states exactly */
64 typedef enum
65 {
66  GLOBUS_GASS_TRANSFER_FTP_LISTENER_STARTING,
67  GLOBUS_GASS_TRANSFER_FTP_LISTENER_LISTENING,
68  GLOBUS_GASS_TRANSFER_FTP_LISTENER_READY,
69  GLOBUS_GASS_TRANSFER_FTP_LISTENER_ACCEPTING,
70  GLOBUS_GASS_TRANSFER_FTP_LISTENER_CLOSING1,
71  GLOBUS_GASS_TRANSFER_FTP_LISTENER_CLOSING2,
72  GLOBUS_GASS_TRANSFER_FTP_LISTENER_CLOSED
73 } globus_gass_transfer_listener_state_t;
74 typedef enum
75 {
76  GLOBUS_GASS_TRANSFER_FTP_RECV_STATE_UNTIL_EOF,
77  GLOBUS_GASS_TRANSFER_FTP_RECV_STATE_EOF,
78  GLOBUS_GASS_TRANSFER_FTP_RECV_STATE_ERROR
79 } globus_l_gass_transfer_ftp_recv_state_t;
80 
81 typedef struct
82 {
83  /* Standard "proto" elements */
88 
89  /* Begin internal ftp-specific proto state */
90  globus_gass_transfer_listener_t listener;
91  globus_ftp_client_handle_t handle;
92  globus_url_scheme_t url_scheme;
93 
94  globus_gass_transfer_listener_state_t state;
95  globus_bool_t destroy_called;
96 
97  struct globus_gass_transfer_ftp_request_proto_s * request;
98 } globus_gass_transfer_ftp_listener_proto_t;
99 
100 typedef struct globus_gass_transfer_ftp_request_proto_s
101 {
102  /* Standard "proto" elements */
105 
107 
111 
113 
114  /* Begin internal ftp-specific proto state */
115  globus_ftp_client_handle_t handle;
116  /* last data for sending, and EOF on receiving */
117 
118  volatile globus_bool_t oneshot_registered;
119  volatile globus_bool_t oneshot_active;
120 
121  volatile globus_gass_transfer_ftp_state_t state;
122 
124 
125  globus_bool_t failure_occurred;
126  globus_bool_t destroy_called;
127 
128  /* Flags from the request attributes */
129  globus_url_t proxy_url;
130  globus_bool_t text_mode;
131  globus_size_t block_size;
132 
133  /* Type and name of the requested resource */
134  globus_url_t url;
135  char * url_string;
137 
138  /*
139  * For the "send" case, a 4 item iovec array, containing
140  * the chunk header, body, and trailing CRLF, and a 0-length
141  * chunk + crlf
142  */
143  struct iovec iov[4];
144  /* Length and transfer encoding */
145  globus_size_t length;
146  globus_size_t handled;
147  globus_bool_t chunked;
148  /* sending-side: are we handling the last data block? */
149  globus_bool_t last_data;
150  /* sending-side, number of writes that have been issued, used to compute the offset */
151  /* globus_size_t num_writes_sent; */
152 
153  globus_bool_t client_side;
154  /* Amount of data from the current chunk still needs to
155  be given to the user */
156  globus_size_t chunk_left;
157  globus_l_gass_transfer_ftp_recv_state_t recv_state;
158  globus_bool_t eof_read;
159 
160  /* Used to parse/store responses from the FTP server */
161  globus_byte_t * response_buffer;
162  globus_size_t response_buflen;
163  globus_size_t response_offset;
164  globus_size_t parsed_offset;
165  int code;
166  char * reason;
167  globus_bool_t parse_error;
168 
169  /* Major/minor version of the FTP protocol we are using */
170  int major;
171  int minor;
172  /* FTP headers we've received */
173  globus_list_t * headers;
174 
175  /* Line mode of this particular file we are reading */
176 
177  /*
178  globus_gass_transfer_ftp_line_mode_t line_mode;
179  */
180  /*
181  * The buffer which was handed to the protocol module
182  * from GASS
183  */
184  globus_byte_t * user_buffer;
185  globus_size_t user_buflen;
186  globus_size_t user_offset;
187  globus_size_t user_waitlen;
188 
189  globus_gass_transfer_authorization_t authorization_mode;
190  char * authorized_subject;
191  char * connected_subject;
192 
193  /* For handling requests from client */
194  char * uri;
195  char * method;
196  globus_bool_t proxy_connect;
197  globus_bool_t got_response;
198  globus_bool_t waiting_for_response;
199 } globus_gass_transfer_ftp_request_proto_t;
200 
201 /******************************************************************************
202  Module specific Prototypes
203 ******************************************************************************/
204 #if !defined(GLOBUS_GASS_TRANSFER_FTP_PARSER_TEST)
205 static
206 void
207 globus_l_gass_transfer_ftp_send(
210  globus_byte_t * buffer,
211  globus_size_t buffer_length,
212  globus_bool_t last_data);
213 
214 static
215 void
216 globus_l_gass_transfer_ftp_receive(
219  globus_byte_t * buffer,
220  globus_size_t buffer_length,
221  globus_size_t wait_for_length);
222 
223 static
224 void
225 globus_l_gass_transfer_ftp_writev_callback(
226  void * callback_arg,
227  globus_io_handle_t * handle,
228  globus_result_t result,
229  struct iovec * iov,
230  globus_size_t iovcnt,
231  globus_size_t nbytes);
232 
233 
234 static
235 void
236 globus_l_gass_transfer_ftp_write_callback(
237  void * callback_arg,
238  globus_ftp_client_handle_t * handle,
239  globus_object_t * error,
240  globus_byte_t * bytes,
241  globus_size_t nbytes,
242  globus_off_t offset,
243  globus_bool_t eof);
244 
245 #ifdef TEMP_DEF
246 
247 static
248 void
249 globus_l_gass_transfer_ftp_write_response(
250  void * arg,
251  globus_io_handle_t * handle,
252  globus_result_t result,
253  globus_byte_t * buf,
254  globus_size_t nbytes);
255 
256 #endif
257 
258 static
259 void
260 globus_l_gass_transfer_ftp_proto_destroy(
261  globus_gass_transfer_ftp_request_proto_t * proto);
262 
263 static
264 void
265 globus_l_gass_transfer_ftp_read_callback(
266  void * callback_arg,
267  globus_ftp_client_handle_t * handle,
268  globus_object_t * error,
269  globus_byte_t * bytes,
270  globus_size_t nbytes,
271  globus_off_t offset,
272  globus_bool_t eof);
273 
274 void
275 globus_l_gass_transfer_ftp_get_done_callback(
276  void * callback_arg,
277  globus_ftp_client_handle_t * handle,
278  globus_object_t * error);
279 
280 void
281 globus_l_gass_transfer_ftp_put_done_callback(
282  void * callback_arg,
283  globus_ftp_client_handle_t * handle,
284  globus_object_t * error);
285 
286 #ifdef TEMP_DEF
287 static
288 void
289 globus_l_gass_transfer_ftp_read_buffered_callback(
290  void * callback_arg,
291  globus_io_handle_t * handle,
292  globus_result_t result,
293  globus_byte_t * buf,
294  globus_size_t nbytes);
295 
296 static
297 globus_bool_t
298 globus_l_gass_transfer_ftp_callback_read_buffered_callback(
299  globus_abstime_t * time_stop,
300  void * arg);
301 
302 static
303 globus_bool_t
304 globus_l_gass_transfer_ftp_callback_ready_callback(
305  globus_abstime_t * time_stop,
306  void * arg);
307 #endif
308 
309 static
310 void
311 globus_l_gass_transfer_ftp_fail(
314 
315 static
316 void
317 globus_l_gass_transfer_ftp_close_callback(
318  void * callback_arg,
319  globus_io_handle_t * handle,
320  globus_result_t result);
321 
322 #ifdef TEMP_DEF
323 static
324 void
325 globus_l_gass_transfer_ftp_accept_callback(
326  void * callback_arg,
327  globus_io_handle_t * handle,
328  globus_result_t result);
329 
330 #endif
331 
332 static
333 void
334 globus_l_gass_transfer_ftp_destroy(
337 
338 static
339 void
340 globus_l_gass_transfer_ftp_new_request(
342  globus_gass_transfer_requestattr_t * attr);
343 
344 static
345 globus_object_t *
346 globus_l_gass_transfer_ftp_new_requestattr(
347  char * url_scheme);
348 
349 #ifdef TEMP_DEF
350 static
351 globus_object_t *
352 globus_l_gass_transfer_ftp_new_listenerattr(
353  char * url_scheme);
354 
355 static
356 void
357 globus_l_gass_transfer_ftp_close_listener(
359  globus_gass_transfer_listener_t listener);
360 
361 static
362 void
363 globus_l_gass_transfer_ftp_listen(
365  globus_gass_transfer_listener_t listener);
366 
367 static
368 void
369 globus_l_gass_transfer_ftp_accept(
371  globus_gass_transfer_listener_t listener,
373  globus_gass_transfer_requestattr_t * attr);
374 
375 static
376 globus_bool_t
377 globus_l_gass_transfer_ftp_authorization_callback(
378  void * arg,
379  globus_io_handle_t * handle,
380  globus_result_t result,
381  char * identity,
382  gss_ctx_id_t * context_handle);
383 
384 static
385 void
386 globus_l_gass_transfer_ftp_listener_destroy(
388  globus_gass_transfer_listener_t listener);
389 
390 static
391 int
392 globus_l_gass_transfer_ftp_new_listener(
393  globus_gass_transfer_listener_t listener,
394  globus_gass_transfer_listenerattr_t * attr,
395  char * scheme,
396  char ** base_url,
398 
399 static
400 void
401 globus_l_gass_transfer_ftp_connect_callback(
402  void * arg,
403  globus_io_handle_t * handle,
404  globus_result_t result);
405 
406 static
407 void
408 globus_l_gass_transfer_ftp_command_callback(
409  void * arg,
410  globus_io_handle_t * handle,
411  globus_result_t result,
412  globus_byte_t * buf,
413  globus_size_t nbytes);
414 
415 static
416 void
417 globus_l_gass_transfer_ftp_response_callback(
418  void * arg,
419  globus_io_handle_t * handle,
420  globus_result_t result,
421  globus_byte_t * buf,
422  globus_size_t nbytes);
423 
424 static
425 void
426 globus_l_gass_transfer_ftp_listener_proto_destroy(
427  globus_gass_transfer_ftp_listener_proto_t *
428  proto);
429 static
430 globus_bool_t
431 globus_l_gass_transfer_ftp_callback_listen_callback(
432  globus_abstime_t * time_stop,
433  void * arg);
434 
435 static
436 void
437 globus_l_gass_transfer_ftp_listen_callback(
438  void * callback_arg,
439  globus_io_handle_t * handle,
440  globus_result_t result);
441 #endif
442 
443 static
444 globus_bool_t
445 globus_l_gass_transfer_ftp_find_crlf(
446  globus_byte_t * bytes,
447  globus_size_t len,
448  globus_size_t * crlf_offset);
449 
450 static
451 globus_bool_t
452 globus_l_gass_transfer_ftp_parse_headers(
453  globus_gass_transfer_ftp_request_proto_t * proto);
454 
455 static
456 globus_bool_t
457 globus_l_gass_transfer_ftp_parse_one_header(
458  globus_gass_transfer_ftp_request_proto_t * proto,
459  globus_bool_t * last_header);
460 
461 static
462 globus_bool_t
463 globus_l_gass_transfer_ftp_parse_status_line(
464  globus_gass_transfer_ftp_request_proto_t * proto);
465 
466 static
467 globus_bool_t
468 islws(
469  char byte);
470 
471 static
472 globus_bool_t
473 ischar(
474  char byte);
475 
476 static
477 globus_bool_t
478 istspecial(
479  char byte);
480 
481 static
482 globus_bool_t
483 globus_l_gass_transfer_ftp_callback_send_callback(
484  globus_abstime_t * time_stop,
485  void * arg);
486 #endif
487 
488 static
489 void
490 globus_l_gass_transfer_ftp_request_callback(
491  void * arg,
492  globus_io_handle_t * handle,
493  globus_result_t result,
494  globus_byte_t * buf,
495  globus_size_t nbytes);
496 
497 static
498 globus_result_t
499 globus_l_gass_transfer_ftp_register_read(
500  globus_gass_transfer_ftp_request_proto_t * proto);
501 
502 #ifdef TEMP_DEF
503 static
504 char *
505 globus_l_gass_transfer_ftp_construct_request(
506  globus_gass_transfer_ftp_request_proto_t * proto);
507 
508 static
509 globus_bool_t
510 globus_l_gass_transfer_ftp_handle_chunk(
511  globus_gass_transfer_ftp_request_proto_t * proto);
512 
513 static
514 globus_bool_t
515 globus_l_gass_transfer_ftp_parse_response(
516  globus_gass_transfer_ftp_request_proto_t * proto);
517 
518 static
519 globus_bool_t
520 globus_l_gass_transfer_ftp_parse_request(
521  globus_gass_transfer_ftp_request_proto_t * proto);
522 
523 static
524 globus_bool_t
525 globus_l_gass_transfer_ftp_parse_request_line(
526  globus_gass_transfer_ftp_request_proto_t * proto);
527 
528 static
529 void
530 globus_l_gass_transfer_ftp_extract_referral(
531  globus_gass_transfer_ftp_request_proto_t * proto,
532  char *** referral,
533  globus_size_t * referral_count);
534 #endif
535 
536 static
537 void
538 globus_l_gass_transfer_ftp_callback_denied(
539  void * arg);
540 
541 static
542 void
543 globus_l_gass_transfer_ftp_close(
544  globus_gass_transfer_ftp_request_proto_t * proto);
545 
546 static
547 void
548 globus_l_gass_transfer_ftp_register_close(
549  globus_gass_transfer_ftp_request_proto_t * proto);
550 
551 #ifdef TEMP_DEF
552 static
553 void
554 globus_l_gass_transfer_ftp_listener_close(
555  globus_gass_transfer_ftp_listener_proto_t * proto);
556 #endif
557 
558 #ifdef __cplusplus
559 }
560 #endif
561 
562 #endif /* GLOBUS_L_GASS_TRANSFER_FTP_H */
globus_gass_transfer_request_type_t
Definition: globus_gass_transfer.h:129
void(* globus_gass_transfer_proto_accept_t)(globus_gass_transfer_listener_proto_t *proto, globus_gass_transfer_listener_t listener, globus_gass_transfer_request_t request, globus_gass_transfer_requestattr_t *attr)
Definition: globus_gass_transfer_proto.h:342
void(* globus_gass_transfer_proto_receive_t)(globus_gass_transfer_request_proto_t *proto, globus_gass_transfer_request_t request, globus_byte_t *bytes, globus_size_t bytes_length, globus_size_t wait_for_length)
Definition: globus_gass_transfer_proto.h:147
globus_gass_transfer_proto_listener_t listen
Definition: globus_gass_transfer_proto.h:421
void(* globus_gass_transfer_proto_listener_t)(globus_gass_transfer_listener_proto_t *proto, globus_gass_transfer_listener_t listener)
Definition: globus_gass_transfer_proto.h:274
void(* globus_gass_transfer_proto_send_t)(globus_gass_transfer_request_proto_t *proto, globus_gass_transfer_request_t request, globus_byte_t *bytes, globus_size_t send_length, globus_bool_t last_data)
Definition: globus_gass_transfer_proto.h:107
Protocol module listener handling structure.
Definition: globus_gass_transfer_proto.h:416
void(* globus_gass_transfer_proto_func_t)(globus_gass_transfer_request_proto_t *proto, globus_gass_transfer_request_t request)
Definition: globus_gass_transfer_proto.h:174
globus_gass_transfer_proto_listener_t close_listener
Definition: globus_gass_transfer_proto.h:419
Protocol module request handling structure.
Definition: globus_gass_transfer_proto.h:370
globus_gass_transfer_proto_listener_t destroy
Definition: globus_gass_transfer_proto.h:425
globus_gass_transfer_proto_accept_t accept
Definition: globus_gass_transfer_proto.h:423