17 #ifndef GLOBUS_DONT_DOCUMENT_INTERNAL
26 #ifndef GLOBUS_L_GASS_TRANSFER_HTTP_H
27 #define GLOBUS_L_GASS_TRANSFER_HTTP_H
38 GLOBUS_L_DEFAULT_HTTP_PORT = 80,
39 GLOBUS_L_DEFAULT_HTTPS_PORT = 443,
40 GLOBUS_L_GASS_RESPONSE_LEN = 256
45 GLOBUS_L_LINE_MODE_UNKNOWN,
46 GLOBUS_L_LINE_MODE_CR,
47 GLOBUS_L_LINE_MODE_LF,
48 GLOBUS_L_LINE_MODE_CRLF
49 } globus_gass_transfer_http_line_mode_t;
56 const globus_gass_transfer_http_line_mode_t
57 globus_l_gass_transfer_http_line_mode =
58 #ifndef TARGET_ARCH_WIN32
59 GLOBUS_L_LINE_MODE_LF;
61 GLOBUS_L_LINE_MODE_CRLF;
67 #define GLOBUS_L_TEXT_BYTE(text) (text & 0x7f)
69 static globus_mutex_t globus_l_gass_transfer_http_mutex;
70 static globus_cond_t globus_l_gass_transfer_http_cond;
72 #define globus_l_gass_transfer_http_lock() \
73 globus_mutex_lock(&globus_l_gass_transfer_http_mutex) \
75 #define globus_l_gass_transfer_http_unlock() \
77 globus_mutex_unlock(&globus_l_gass_transfer_http_mutex)
78 #define globus_l_gass_transfer_http_wait() \
79 globus_cond_wait(&globus_l_gass_transfer_http_cond, \
80 &globus_l_gass_transfer_http_mutex)
81 #define globus_l_gass_transfer_http_signal() \
82 globus_cond_signal(&globus_l_gass_transfer_http_cond)
84 static char * globus_l_gass_transfer_http_subject_name;
89 #define CRLF "\015\012"
90 #define CR_STRING "\015"
91 #define LF_STRING "\012"
94 #define GLOBUS_GASS_HTTP_VERSION "Globus-GASS-HTTP/1.1.0"
96 #define GLOBUS_L_APPEND_URI "/globus-bins/GASSappend?"
98 #define GLOBUS_L_GET_COMMAND "GET %s HTTP/1.1" CRLF \
100 "Connection: close" CRLF \
101 "User-Agent: " GLOBUS_GASS_HTTP_VERSION CRLF
103 #define GLOBUS_L_PUT_COMMAND "PUT %s HTTP/1.1" CRLF \
105 "Connection: close" CRLF \
106 "User-Agent: " GLOBUS_GASS_HTTP_VERSION CRLF
108 #define GLOBUS_L_APPEND_COMMAND "POST " GLOBUS_L_APPEND_URI "%s " \
111 "Connection: close" CRLF \
112 "User-Agent: " GLOBUS_GASS_HTTP_VERSION CRLF
114 #define GLOBUS_L_REFER_RESPONSE "HTTP/1.1 302 Moved Temporarily" CRLF \
115 "Connection: close" CRLF \
116 "Server: " GLOBUS_GASS_HTTP_VERSION CRLF
118 #define GLOBUS_L_CONTINUE_RESPONSE "HTTP/1.1 100 Continue" CRLF
120 #define GLOBUS_L_GENERIC_RESPONSE "HTTP/1.%d %d %s" CRLF \
121 "Connection: close" CRLF \
122 "Server: " GLOBUS_GASS_HTTP_VERSION CRLF
123 #define GLOBUS_L_OK "Ok"
125 #define GLOBUS_L_DENIAL_RESPONSE "HTTP/1.1 %d %s" CRLF \
126 "Connection: close" CRLF \
127 "Server: " GLOBUS_GASS_HTTP_VERSION CRLF
129 #define GLOBUS_L_DEFAULT_DENIAL_MESSAGE "Internal Server Error"
131 #define GLOBUS_L_CONTENT_LENGTH_HEADER "Content-Length: %ld" CRLF
132 #define GLOBUS_L_CHUNKED_HEADER "Transfer-Encoding: chunked" CRLF
133 #define GLOBUS_L_BINARY_HEADER "Content-Type: " \
134 "application/octet-stream" CRLF
135 #define GLOBUS_L_TEXT_HEADER "Content-Type: text/plain" CRLF
136 #define GLOBUS_L_HTML_HEADER "Content-Type: text/html" CRLF
137 #define GLOBUS_L_HTML_REFERRAL_BODY_HEAD \
138 "<html><head><title>Document Moved</title></head><body>"
139 #define GLOBUS_L_HTML_REFERRAL_BODY_TAIL \
141 #define GLOBUS_L_HTML_DENIAL_BODY "<html><head><title>%d %s</title></head><body>" CRLF \
142 "<h1>%d %s</h1></body></html>" CRLF
143 #define GLOBUS_L_HTML_HREF "<a href=\"%s\">%s</a><br>"
144 #define GLOBUS_L_LOCATION_HEADER "Location: %s" CRLF
146 #define GLOBUS_L_DEFAULT_FAILURE_CODE 400
147 #define GLOBUS_L_DEFAULT_FAILURE_REASON "Bad Request"
150 #define GLOBUS_L_PROTOCOL_FAILURE_CODE 416
151 #define GLOBUS_L_PROTOCOL_FAILURE_REASON "Protocol Error"
153 #define GLOBUS_L_MALLOC_FAILURE_CODE 417
154 #define GLOBUS_L_MALLOC_FAILURE_REASON "Malloc Error"
162 GLOBUS_GASS_TRANSFER_HTTP_STATE_CONNECTING,
163 GLOBUS_GASS_TRANSFER_HTTP_STATE_REQUESTING,
164 GLOBUS_GASS_TRANSFER_HTTP_STATE_CLOSING,
165 GLOBUS_GASS_TRANSFER_HTTP_STATE_REFERRED,
166 GLOBUS_GASS_TRANSFER_HTTP_STATE_DENIED,
167 GLOBUS_GASS_TRANSFER_HTTP_STATE_RESPONDING,
169 GLOBUS_GASS_TRANSFER_HTTP_STATE_IDLE,
170 GLOBUS_GASS_TRANSFER_HTTP_STATE_DONE,
171 GLOBUS_GASS_TRANSFER_HTTP_STATE_PENDING
172 } globus_gass_transfer_http_state_t;
177 GLOBUS_GASS_TRANSFER_HTTP_LISTENER_STARTING,
178 GLOBUS_GASS_TRANSFER_HTTP_LISTENER_LISTENING,
179 GLOBUS_GASS_TRANSFER_HTTP_LISTENER_READY,
180 GLOBUS_GASS_TRANSFER_HTTP_LISTENER_ACCEPTING,
181 GLOBUS_GASS_TRANSFER_HTTP_LISTENER_CLOSING1,
182 GLOBUS_GASS_TRANSFER_HTTP_LISTENER_CLOSING2,
183 GLOBUS_GASS_TRANSFER_HTTP_LISTENER_CLOSED
184 } globus_gass_transfer_listener_state_t;
187 GLOBUS_GASS_TRANSFER_HTTP_RECV_STATE_CHUNK_SIZE,
188 GLOBUS_GASS_TRANSFER_HTTP_RECV_STATE_CHUNK_EXT,
189 GLOBUS_GASS_TRANSFER_HTTP_RECV_STATE_CHUNK_END_HEADER_CR,
190 GLOBUS_GASS_TRANSFER_HTTP_RECV_STATE_CHUNK_END_HEADER_LF,
191 GLOBUS_GASS_TRANSFER_HTTP_RECV_STATE_CHUNK_BODY,
192 GLOBUS_GASS_TRANSFER_HTTP_RECV_STATE_CHUNK_END_BODY_CR,
193 GLOBUS_GASS_TRANSFER_HTTP_RECV_STATE_CHUNK_END_BODY_LF,
194 GLOBUS_GASS_TRANSFER_HTTP_RECV_STATE_CHUNK_FOOTER,
195 GLOBUS_GASS_TRANSFER_HTTP_RECV_STATE_UNTIL_LENGTH,
196 GLOBUS_GASS_TRANSFER_HTTP_RECV_STATE_UNTIL_EOF,
197 GLOBUS_GASS_TRANSFER_HTTP_RECV_STATE_EOF,
198 GLOBUS_GASS_TRANSFER_HTTP_RECV_STATE_ERROR
199 } globus_l_gass_transfer_http_recv_state_t;
210 globus_gass_transfer_listener_t listener;
211 globus_io_handle_t handle;
212 globus_url_scheme_t url_scheme;
214 globus_gass_transfer_listener_state_t state;
215 globus_bool_t destroy_called;
217 struct globus_gass_transfer_http_request_proto_s * request;
218 } globus_gass_transfer_http_listener_proto_t;
220 typedef struct globus_gass_transfer_http_request_proto_s
235 globus_io_handle_t handle;
238 volatile globus_bool_t oneshot_registered;
239 volatile globus_bool_t oneshot_active;
241 volatile globus_gass_transfer_http_state_t state;
245 globus_bool_t failure_occurred;
246 globus_bool_t destroy_called;
249 globus_url_t proxy_url;
250 globus_bool_t text_mode;
251 globus_size_t block_size;
265 globus_size_t length;
266 globus_size_t handled;
267 globus_bool_t chunked;
269 globus_bool_t last_data;
271 globus_bool_t client_side;
274 globus_size_t chunk_left;
275 globus_l_gass_transfer_http_recv_state_t recv_state;
276 globus_bool_t eof_read;
279 globus_byte_t * response_buffer;
280 globus_size_t response_buflen;
281 globus_size_t response_offset;
282 globus_size_t parsed_offset;
285 globus_bool_t parse_error;
291 globus_list_t * headers;
294 globus_gass_transfer_http_line_mode_t line_mode;
299 globus_byte_t * user_buffer;
300 globus_size_t user_buflen;
301 globus_size_t user_offset;
302 globus_size_t user_waitlen;
304 globus_gass_transfer_authorization_t authorization_mode;
305 char * authorized_subject;
306 char * connected_subject;
311 globus_bool_t proxy_connect;
312 globus_bool_t got_response;
313 globus_bool_t waiting_for_response;
314 } globus_gass_transfer_http_request_proto_t;
319 #if !defined(GLOBUS_GASS_TRANSFER_HTTP_PARSER_TEST)
322 globus_l_gass_transfer_http_send(
325 globus_byte_t * buffer,
326 globus_size_t buffer_length,
327 globus_bool_t last_data);
331 globus_l_gass_transfer_http_receive(
334 globus_byte_t * buffer,
335 globus_size_t buffer_length,
336 globus_size_t wait_for_length);
340 globus_l_gass_transfer_http_writev_callback(
342 globus_io_handle_t * handle,
343 globus_result_t result,
345 globus_size_t iovcnt,
346 globus_size_t nbytes);
350 globus_l_gass_transfer_http_write_callback(
352 globus_io_handle_t * handle,
353 globus_result_t result,
355 globus_size_t nbytes);
359 globus_l_gass_transfer_http_write_response(
361 globus_io_handle_t * handle,
362 globus_result_t result,
364 globus_size_t nbytes);
368 globus_l_gass_transfer_http_proto_destroy(
369 globus_gass_transfer_http_request_proto_t * proto);
373 globus_l_gass_transfer_http_read_callback(
375 globus_io_handle_t * handle,
376 globus_result_t result,
378 globus_size_t nbytes);
382 globus_l_gass_transfer_http_read_buffered_callback(
384 globus_io_handle_t * handle,
385 globus_result_t result,
387 globus_size_t nbytes);
391 globus_l_gass_transfer_http_callback_read_buffered_callback(
396 globus_l_gass_transfer_http_callback_ready_callback(
399 globus_l_gass_transfer_http_copy_text_buffer(
400 globus_byte_t * output,
401 globus_byte_t * input,
402 globus_gass_transfer_http_line_mode_t * line_mode,
403 globus_size_t input_max_to_copy,
404 globus_size_t output_max_to_copy,
405 globus_size_t * input_copied,
406 globus_size_t * output_copied);
410 globus_l_gass_transfer_http_fail(
416 globus_l_gass_transfer_http_close_callback(
418 globus_io_handle_t * handle,
419 globus_result_t result);
423 globus_l_gass_transfer_http_accept_callback(
425 globus_io_handle_t * handle,
426 globus_result_t result);
431 globus_l_gass_transfer_http_destroy(
437 globus_l_gass_transfer_http_new_request(
439 globus_gass_transfer_requestattr_t * attr);
443 globus_l_gass_transfer_http_new_requestattr(
448 globus_l_gass_transfer_http_new_listenerattr(
453 globus_l_gass_transfer_http_close_listener(
455 globus_gass_transfer_listener_t listener);
459 globus_l_gass_transfer_http_listen(
461 globus_gass_transfer_listener_t listener);
465 globus_l_gass_transfer_http_accept(
467 globus_gass_transfer_listener_t listener,
469 globus_gass_transfer_requestattr_t * attr);
473 globus_l_gass_transfer_http_authorization_callback(
475 globus_io_handle_t * handle,
476 globus_result_t result,
478 gss_ctx_id_t context_handle);
482 globus_l_gass_transfer_http_listener_destroy(
484 globus_gass_transfer_listener_t listener);
488 globus_l_gass_transfer_http_new_listener(
489 globus_gass_transfer_listener_t listener,
490 globus_gass_transfer_listenerattr_t * attr,
497 globus_l_gass_transfer_http_connect_callback(
499 globus_io_handle_t * handle,
500 globus_result_t result);
504 globus_l_gass_transfer_http_command_callback(
506 globus_io_handle_t * handle,
507 globus_result_t result,
509 globus_size_t nbytes);
513 globus_l_gass_transfer_http_response_callback(
515 globus_io_handle_t * handle,
516 globus_result_t result,
518 globus_size_t nbytes);
522 globus_l_gass_transfer_http_listener_proto_destroy(
523 globus_gass_transfer_http_listener_proto_t *
527 globus_l_gass_transfer_http_callback_listen_callback(
532 globus_l_gass_transfer_http_listen_callback(
534 globus_io_handle_t * handle,
535 globus_result_t result);
540 globus_l_gass_transfer_http_find_crlf(
541 globus_byte_t * bytes,
543 globus_size_t * crlf_offset);
547 globus_l_gass_transfer_http_parse_headers(
548 globus_gass_transfer_http_request_proto_t * proto);
552 globus_l_gass_transfer_http_parse_one_header(
553 globus_gass_transfer_http_request_proto_t * proto,
554 globus_bool_t * last_header);
558 globus_l_gass_transfer_http_parse_status_line(
559 globus_gass_transfer_http_request_proto_t * proto);
578 globus_l_gass_transfer_http_callback_send_callback(
583 globus_l_gass_transfer_http_request_callback(
585 globus_io_handle_t * handle,
586 globus_result_t result,
588 globus_size_t nbytes);
592 globus_l_gass_transfer_http_register_read(
593 globus_gass_transfer_http_request_proto_t * proto);
597 globus_l_gass_transfer_http_construct_request(
598 globus_gass_transfer_http_request_proto_t * proto);
602 globus_l_gass_transfer_http_handle_chunk(
603 globus_gass_transfer_http_request_proto_t * proto);
607 globus_l_gass_transfer_http_parse_response(
608 globus_gass_transfer_http_request_proto_t * proto);
612 globus_l_gass_transfer_http_parse_request(
613 globus_gass_transfer_http_request_proto_t * proto);
617 globus_l_gass_transfer_http_parse_request_line(
618 globus_gass_transfer_http_request_proto_t * proto);
622 globus_l_gass_transfer_http_extract_referral(
623 globus_gass_transfer_http_request_proto_t * proto,
625 globus_size_t * referral_count);
629 globus_l_gass_transfer_http_callback_denied(
634 globus_l_gass_transfer_http_close(
635 globus_gass_transfer_http_request_proto_t * proto);
639 globus_l_gass_transfer_http_register_close(
640 globus_gass_transfer_http_request_proto_t * proto);
644 globus_l_gass_transfer_http_listener_close(
645 globus_gass_transfer_http_listener_proto_t * proto);
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:290
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:163
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:123
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:190
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:358
globus_gass_transfer_request_type_t
Definition: globus_gass_transfer.h:146
Protocol module listener handling structure.
Definition: globus_gass_transfer_proto.h:433
Protocol module request handling structure.
Definition: globus_gass_transfer_proto.h:387