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_common_h
00025 #define __nanohttp_common_h
00026
00027 #define HEADER_CONTENT_ID "Content-Id"
00028 #define HEADER_CONTENT_TRANSFER_ENCODING "Content-Transfer-Encoding"
00029 #define TRANSFER_ENCODING_CHUNKED "chunked"
00030
00046
00058 #define HEADER_CACHE_CONTROL "Cache-Control"
00059
00067 #define HEADER_CONNECTION "Connection"
00068
00081 #define HEADER_DATE "Date"
00082
00092 #define HEADER_PRAGMA "Pragma"
00093
00100 #define HEADER_TRAILER "Trailer"
00101
00111 #define HEADER_TRANSFER_ENCODING "Transfer-Encoding"
00112
00122 #define HEADER_UPGRADE "Upgrade"
00123
00136 #define HEADER_VIA "Via"
00137
00147 #define HEADER_WARNING "Warning"
00148
00170 #define HEADER_ALLOW "Allow"
00171
00184 #define HEADER_CONTENT_ENCODING "Content-Encoding"
00185
00193 #define HEADER_CONTENT_LANGUAGE "Content-Language"
00194
00206 #define HEADER_CONTENT_LENGTH "Content-Length"
00207
00220 #define HEADER_CONTENT_LOCATION "Content-Location"
00221
00234 #define HEADER_CONTENT_MD5 "Content-MD5"
00235
00245 #define HEADER_CONTENT_RANGE "Content-Range"
00246
00254 #define HEADER_CONTENT_TYPE "Content-Type"
00255
00268 #define HEADER_EXPIRES "Expires"
00269
00276 #define HEADER_LAST_MODIFIED "Last-Modified"
00277
00285 #define NHTTP_ARG_CERT "-NHTTPcert"
00286 #define NHTTP_ARG_CERTPASS "-NHTTPcertpass"
00287 #define NHTTP_ARG_CA "-NHTTPCA"
00288
00289 #ifndef SAVE_STR
00290 #define SAVE_STR(str) ((str==0)?("(null)"):(str))
00291 #endif
00292
00293 #define BOUNDARY_LENGTH 18
00294
00295 #define MAX_HEADER_SIZE 4256
00296 #define MAX_FILE_BUFFER_SIZE 4256
00297
00298 #define REQUEST_MAX_PATH_SIZE 1024
00299 #define RESPONSE_MAX_DESC_SIZE 1024
00300
00306 typedef struct hpair hpair_t;
00307 struct hpair
00308 {
00309 char *key;
00310 char *value;
00311 hpair_t *next;
00312 };
00313
00319 typedef enum _http_version
00320 {
00321 HTTP_1_0,
00322 HTTP_1_1
00323 } http_version_t;
00324
00325
00339 typedef struct _content_type
00340 {
00341 char type[128];
00342 hpair_t *params;
00343 } content_type_t;
00344
00356 typedef enum _hreq_method
00357 {
00372 HTTP_REQUEST_POST,
00382 HTTP_REQUEST_GET,
00393 HTTP_REQUEST_OPTIONS,
00405 HTTP_REQUEST_HEAD,
00425 HTTP_REQUEST_PUT,
00438 HTTP_REQUEST_DELETE,
00449 HTTP_REQUEST_TRACE,
00456 HTTP_REQUEST_CONNECT,
00457 HTTP_REQUEST_UNKOWN
00458 } hreq_method_t;
00459
00565
00579 #define HTTP_STATUS_100_REASON_PHRASE "Continue"
00580
00595 #define HTTP_STATUS_101_REASON_PHRASE "Switching Protocols"
00596
00614 #define HTTP_STATUS_200_REASON_PHRASE "OK"
00615
00636 #define HTTP_STATUS_201_REASON_PHRASE "Created"
00637
00655 #define HTTP_STATUS_202_REASON_PHRASE "Accepted"
00656
00668 #define HTTP_STATUS_203_REASON_PHRASE "Non-Authoritative Information"
00669
00687 #define HTTP_STATUS_204_REASON_PHRASE "No Content"
00688
00699 #define HTTP_STATUS_205_REASON_PHRASE "Reset Content"
00700
00738 #define HTTP_STATUS_206_REASON_PHRASE "Partial Content"
00739
00761 #define HTTP_STATUS_300_REASON_PHRASE "Multiple Choices"
00762
00781 #define HTTP_STATUS_301_REASON_PHRASE "Moved Permanently"
00782
00807 #define HTTP_STATUS_302_REASON_PHRASE "Found"
00808
00828 #define HTTP_STATUS_303_REASON_PHRASE "See Other"
00829
00863 #define HTTP_STATUS_304_REASON_PHRASE "Not Modified"
00864
00877 #define HTTP_STATUS_305_REASON_PHRASE "Use Proxy"
00878
00899 #define HTTP_STATUS_307_REASON_PHRASE "Temporary Redirect"
00900
00907 #define HTTP_STATUS_400_REASON_PHRASE "Bad Request"
00908
00928 #define HTTP_STATUS_401_REASON_PHRASE "Unauthorized"
00929
00935 #define HTTP_STATUS_402_REASON_PHRASE "Payment Required"
00936
00947 #define HTTP_STATUS_403_REASON_PHRASE "Forbidden"
00948
00960 #define HTTP_STATUS_404_REASON_PHRASE "Not Found"
00961
00969 #define HTTP_STATUS_405_REASON_PHRASE "Method Not Allowed"
00970
00995 #define HTTP_STATUS_406_REASON_PHRASE "Not Acceptable"
00996
01011 #define HTTP_STATUS_407_REASON_PHRASE "Proxy Authentication Required"
01012
01020 #define HTTP_STATUS_408_REASON_PHRASE "Request Time-out"
01021
01041 #define HTTP_STATUS_409_REASON_PHRASE "Conflict"
01042
01063 #define HTTP_STATUS_410_REASON_PHRASE "Gone"
01064
01072 #define HTTP_STATUS_411_REASON_PHRASE "Length Required"
01073
01083 #define HTTP_STATUS_412_REASON_PHRASE "Precondition Failed"
01084
01096 #define HTTP_STATUS_413_REASON_PHRASE "Request Entity Too Large"
01097
01110 #define HTTP_STATUS_414_REASON_PHRASE "Request-URI Too Large"
01111
01119 #define HTTP_STATUS_415_REASON_PHRASE "Unsupported Media Type"
01120
01137 #define HTTP_STATUS_416_REASON_PHRASE "Requested range not satisfiable"
01138
01147 #define HTTP_STATUS_417_REASON_PHRASE "Expectation Failed"
01148
01155 #define HTTP_STATUS_500_REASON_PHRASE "Internal Server Error"
01156
01164 #define HTTP_STATUS_501_REASON_PHRASE "Not Implemented"
01165
01172 #define HTTP_STATUS_502_REASON_PHRASE "Bad Gateway"
01173
01188 #define HTTP_STATUS_503_REASON_PHRASE "Service Unavailable"
01189
01201 #define HTTP_STATUS_504_REASON_PHRASE "Gateway Time-out"
01202
01213 #define HTTP_STATUS_505_REASON_PHRASE "HTTP Version not supported"
01214
01222 struct part_t
01223 {
01224 char id[250];
01225 char location[250];
01226 hpair_t *header;
01227 char content_type[128];
01228 char transfer_encoding[128];
01229 char filename[250];
01230 struct part_t *next;
01231 int deleteOnExit;
01232 };
01233
01239 struct attachments_t
01240 {
01241 struct part_t *parts;
01242 struct part_t *last;
01243 struct part_t *root_part;
01244 };
01245
01246
01247 #ifdef __cplusplus
01248 extern "C" {
01249 #endif
01250
01264 extern hpair_t *hpairnode_new(const char *key, const char *value, hpair_t * next);
01265
01281 extern hpair_t *hpairnode_parse(const char *str, const char *delim, hpair_t * next);
01282
01290 extern void hpairnode_free(hpair_t * pair);
01291
01300 extern void hpairnode_free_deep(hpair_t * pair);
01301
01314 extern char *hpairnode_get(hpair_t * pair, const char *key);
01315
01329 extern char *hpairnode_get_ignore_case(hpair_t * pair, const char *key);
01330
01344 extern hpair_t *hpairnode_copy(const hpair_t * src);
01345
01357 extern hpair_t *hpairnode_copy_deep(const hpair_t *src);
01358
01366 extern void hpairnode_dump_deep(const hpair_t *pairs);
01367
01373 extern void hpairnode_dump(const hpair_t *pair);
01374
01388 extern content_type_t *content_type_new(const char *content_type_str);
01389
01395 extern void content_type_free(content_type_t * ct);
01396
01397 extern struct part_t *part_new(const char *id, const char *filename, const char *content_type, const char *transfer_encoding, struct part_t * next);
01398
01399 extern void part_free(struct part_t * part);
01400
01401
01402
01403 extern struct attachments_t *attachments_new(void);
01404
01412 extern void attachments_free(struct attachments_t * message);
01413 extern void attachments_add_part(struct attachments_t * attachments, struct part_t * part);
01414
01415 #ifdef __cplusplus
01416 }
01417 #endif
01418
01419 #endif