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 #define STREAM_ERROR 1200
00057 #define STREAM_ERROR_INVALID_TYPE (STREAM_ERROR + 1)
00058 #define STREAM_ERROR_SOCKET_ERROR (STREAM_ERROR + 2)
00059 #define STREAM_ERROR_NO_CHUNK_SIZE (STREAM_ERROR + 3)
00060 #define STREAM_ERROR_WRONG_CHUNK_SIZE (STREAM_ERROR + 4)
00061
00064 typedef enum http_transfer_type
00065 {
00066 HTTP_TRANSFER_CONTENT_LENGTH,
00068 HTTP_TRANSFER_CHUNKED,
00070 HTTP_TRANSFER_CONNECTION_CLOSE,
00072 HTTP_TRANSFER_FILE
00075 } http_transfer_type_t;
00076
00079 struct http_input_stream_t
00080 {
00081 struct hsocket_t *sock;
00082 herror_t err;
00083 http_transfer_type_t type;
00084 int received;
00085 int content_length;
00086 int chunk_size;
00087 char connection_closed;
00088
00089
00090 FILE *fd;
00091 char filename[255];
00092 int deleteOnExit;
00093 };
00094
00097 struct http_output_stream_t
00098 {
00099 struct hsocket_t *sock;
00100 http_transfer_type_t type;
00101 int content_length;
00102 int sent;
00103 };
00104
00105 #ifdef __cplusplus
00106 extern "C" {
00107 #endif
00108
00122 extern struct http_input_stream_t *http_input_stream_new(struct hsocket_t *sock, hpair_t *header);
00123
00135 extern struct http_input_stream_t *http_input_stream_new_from_file(const char *filename);
00136
00142 extern void http_input_stream_free(struct http_input_stream_t * stream);
00143
00151 extern int http_input_stream_is_ready(struct http_input_stream_t * stream);
00152
00171 extern int http_input_stream_read(struct http_input_stream_t * stream, unsigned char *dest, int size);
00172
00185 extern struct http_output_stream_t *http_output_stream_new(struct hsocket_t *sock, hpair_t * header);
00186
00187
00193 extern void http_output_stream_free(struct http_output_stream_t *stream);
00194
00205 extern herror_t http_output_stream_write(struct http_output_stream_t *stream, const unsigned char *bytes, int size);
00206
00216 extern herror_t http_output_stream_write_string(struct http_output_stream_t *stream, const char *str);
00217
00227 extern herror_t http_output_stream_flush(struct http_output_stream_t *stream);
00228
00229 #ifdef __cplusplus
00230 }
00231 #endif
00232
00235 #endif