00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __nanohttp_stream_h
00025 #define __nanohttp_stream_h
00026
00056
00062 #define STREAM_ERROR 1200
00063 #define STREAM_ERROR_INVALID_TYPE (STREAM_ERROR + 1)
00064 #define STREAM_ERROR_SOCKET_ERROR (STREAM_ERROR + 2)
00065 #define STREAM_ERROR_NO_CHUNK_SIZE (STREAM_ERROR + 3)
00066 #define STREAM_ERROR_WRONG_CHUNK_SIZE (STREAM_ERROR + 4)
00067
00076 typedef enum http_transfer_type
00077 {
00079 HTTP_TRANSFER_CONTENT_LENGTH,
00080
00082 HTTP_TRANSFER_CHUNKED,
00083
00085 HTTP_TRANSFER_CONNECTION_CLOSE,
00086
00088 HTTP_TRANSFER_FILE
00089 } http_transfer_type_t;
00090
00091
00098 struct http_input_stream_t
00099 {
00100 struct hsocket_t *sock;
00101 herror_t err;
00102 http_transfer_type_t type;
00103 int received;
00104 int content_length;
00105 int chunk_size;
00106 char connection_closed;
00107
00108
00109 FILE *fd;
00110 char filename[255];
00111 int deleteOnExit;
00112 };
00113
00120 struct http_output_stream_t
00121 {
00122 struct hsocket_t *sock;
00123 http_transfer_type_t type;
00124 int content_length;
00125 int sent;
00126 };
00127
00128
00129 #ifdef __cplusplus
00130 extern "C" {
00131 #endif
00132
00149 extern struct http_input_stream_t *http_input_stream_new(struct hsocket_t *sock, hpair_t *header);
00150
00164 extern struct http_input_stream_t *http_input_stream_new_from_file(const char *filename);
00165
00173 extern void http_input_stream_free(struct http_input_stream_t * stream);
00174
00184 extern int http_input_stream_is_ready(struct http_input_stream_t * stream);
00185
00207 extern int http_input_stream_read(struct http_input_stream_t * stream, unsigned char *dest, int size);
00208
00223 extern struct http_output_stream_t *http_output_stream_new(struct hsocket_t *sock, hpair_t * header);
00224
00225
00234 extern void http_output_stream_free(struct http_output_stream_t * stream);
00235
00249 extern herror_t http_output_stream_write(struct http_output_stream_t *stream, const unsigned char* bytes, int size);
00250
00263 extern herror_t http_output_stream_write_string(struct http_output_stream_t *stream, const char *str);
00264
00277 extern herror_t http_output_stream_flush(struct http_output_stream_t *stream);
00278
00279 #ifdef __cplusplus
00280 }
00281 #endif
00282
00283 #endif