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