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
00053
00063 #define HEADER_CACHE_CONTROL "Cache-Control"
00064
00072 #define HEADER_CONNECTION "Connection"
00073
00086 #define HEADER_DATE "Date"
00087
00097 #define HEADER_PRAGMA "Pragma"
00098
00105 #define HEADER_TRAILER "Trailer"
00106
00116 #define HEADER_TRANSFER_ENCODING "Transfer-Encoding"
00117
00127 #define HEADER_UPGRADE "Upgrade"
00128
00141 #define HEADER_VIA "Via"
00142
00152 #define HEADER_WARNING "Warning"
00153
00175 #define HEADER_ALLOW "Allow"
00176
00189 #define HEADER_CONTENT_ENCODING "Content-Encoding"
00190
00198 #define HEADER_CONTENT_LANGUAGE "Content-Language"
00199
00211 #define HEADER_CONTENT_LENGTH "Content-Length"
00212
00225 #define HEADER_CONTENT_LOCATION "Content-Location"
00226
00239 #define HEADER_CONTENT_MD5 "Content-MD5"
00240
00250 #define HEADER_CONTENT_RANGE "Content-Range"
00251
00259 #define HEADER_CONTENT_TYPE "Content-Type"
00260
00273 #define HEADER_EXPIRES "Expires"
00274
00281 #define HEADER_LAST_MODIFIED "Last-Modified"
00282
00290 #define NHTTP_ARG_CERT "-NHTTPcert"
00291 #define NHTTP_ARG_CERTPASS "-NHTTPcertpass"
00292 #define NHTTP_ARG_CA "-NHTTPCA"
00293
00294 #ifndef SAVE_STR
00295 #define SAVE_STR(str) ((str==0)?("(null)"):(str))
00296 #endif
00297
00298 #define BOUNDARY_LENGTH 18
00299
00300 #define MAX_HEADER_SIZE 4256
00301 #define MAX_FILE_BUFFER_SIZE 4256
00302
00303 #define REQUEST_MAX_PATH_SIZE 1024
00304 #define RESPONSE_MAX_DESC_SIZE 1024
00305
00311 typedef struct hpair hpair_t;
00312 struct hpair
00313 {
00314 char *key;
00315 char *value;
00316 hpair_t *next;
00317 };
00318
00324 typedef enum _http_version
00325 {
00326 HTTP_1_0,
00327 HTTP_1_1
00328 } http_version_t;
00329
00330
00341 typedef struct _content_type
00342 {
00343 char type[128];
00344 hpair_t *params;
00345 } content_type_t;
00346
00356 typedef enum _hreq_method
00357 {
00370 HTTP_REQUEST_POST,
00378 HTTP_REQUEST_GET,
00387 HTTP_REQUEST_OPTIONS,
00397 HTTP_REQUEST_HEAD,
00415 HTTP_REQUEST_PUT,
00426 HTTP_REQUEST_DELETE,
00435 HTTP_REQUEST_TRACE,
00440 HTTP_REQUEST_CONNECT,
00441 HTTP_REQUEST_UNKOWN
00442 } hreq_method_t;
00443
00550
00562 #define HTTP_STATUS_100_REASON_PHRASE "Continue"
00563
00577 #define HTTP_STATUS_101_REASON_PHRASE "Switching Protocols"
00578
00590 #define HTTP_STATUS_200_REASON_PHRASE "OK"
00591
00610 #define HTTP_STATUS_201_REASON_PHRASE "Created"
00611
00627 #define HTTP_STATUS_202_REASON_PHRASE "Accepted"
00628
00637 #define HTTP_STATUS_203_REASON_PHRASE "Non-Authoritative Information"
00638
00653 #define HTTP_STATUS_204_REASON_PHRASE "No Content"
00654
00662 #define HTTP_STATUS_205_REASON_PHRASE "Reset Content"
00663
00698 #define HTTP_STATUS_206_REASON_PHRASE "Partial Content"
00699
00718 #define HTTP_STATUS_300_REASON_PHRASE "Multiple Choices"
00719
00735 #define HTTP_STATUS_301_REASON_PHRASE "Moved Permanently"
00736
00759 #define HTTP_STATUS_302_REASON_PHRASE "Found"
00760
00777 #define HTTP_STATUS_303_REASON_PHRASE "See Other"
00778
00809 #define HTTP_STATUS_304_REASON_PHRASE "Not Modified"
00810
00820 #define HTTP_STATUS_305_REASON_PHRASE "Use Proxy"
00821
00839 #define HTTP_STATUS_307_REASON_PHRASE "Temporary Redirect"
00840
00844 #define HTTP_STATUS_400_REASON_PHRASE "Bad Request"
00845
00862 #define HTTP_STATUS_401_REASON_PHRASE "Unauthorized"
00863
00866 #define HTTP_STATUS_402_REASON_PHRASE "Payment Required"
00867
00875 #define HTTP_STATUS_403_REASON_PHRASE "Forbidden"
00876
00885 #define HTTP_STATUS_404_REASON_PHRASE "Not Found"
00886
00891 #define HTTP_STATUS_405_REASON_PHRASE "Method Not Allowed"
00892
00914 #define HTTP_STATUS_406_REASON_PHRASE "Not Acceptable"
00915
00927 #define HTTP_STATUS_407_REASON_PHRASE "Proxy Authentication Required"
00928
00934 #define HTTP_STATUS_408_REASON_PHRASE "Request Time-out"
00935
00952 #define HTTP_STATUS_409_REASON_PHRASE "Conflict"
00953
00971 #define HTTP_STATUS_410_REASON_PHRASE "Gone"
00972
00977 #define HTTP_STATUS_411_REASON_PHRASE "Length Required"
00978
00985 #define HTTP_STATUS_412_REASON_PHRASE "Precondition Failed"
00986
00995 #define HTTP_STATUS_413_REASON_PHRASE "Request Entity Too Large"
00996
01007 #define HTTP_STATUS_414_REASON_PHRASE "Request-URI Too Large"
01008
01013 #define HTTP_STATUS_415_REASON_PHRASE "Unsupported Media Type"
01014
01028 #define HTTP_STATUS_416_REASON_PHRASE "Requested range not satisfiable"
01029
01035 #define HTTP_STATUS_417_REASON_PHRASE "Expectation Failed"
01036
01040 #define HTTP_STATUS_500_REASON_PHRASE "Internal Server Error"
01041
01046 #define HTTP_STATUS_501_REASON_PHRASE "Not Implemented"
01047
01051 #define HTTP_STATUS_502_REASON_PHRASE "Bad Gateway"
01052
01064 #define HTTP_STATUS_503_REASON_PHRASE "Service Unavailable"
01065
01074 #define HTTP_STATUS_504_REASON_PHRASE "Gateway Time-out"
01075
01083 #define HTTP_STATUS_505_REASON_PHRASE "HTTP Version not supported"
01084
01092 struct part_t
01093 {
01094 char id[250];
01095 char location[250];
01096 hpair_t *header;
01097 char content_type[128];
01098 char transfer_encoding[128];
01099 char filename[250];
01100 struct part_t *next;
01101 int deleteOnExit;
01102 };
01103
01109 struct attachments_t
01110 {
01111 struct part_t *parts;
01112 struct part_t *last;
01113 struct part_t *root_part;
01114 };
01115
01116
01117 #ifdef __cplusplus
01118 extern "C" {
01119 #endif
01120
01134 extern hpair_t *hpairnode_new(const char *key, const char *value, hpair_t * next);
01135
01151 extern hpair_t *hpairnode_parse(const char *str, const char *delim, hpair_t * next);
01152
01160 extern void hpairnode_free(hpair_t * pair);
01161
01170 extern void hpairnode_free_deep(hpair_t * pair);
01171
01184 extern char *hpairnode_get(hpair_t * pair, const char *key);
01185
01199 extern char *hpairnode_get_ignore_case(hpair_t * pair, const char *key);
01200
01214 extern hpair_t *hpairnode_copy(const hpair_t * src);
01215
01227 extern hpair_t *hpairnode_copy_deep(const hpair_t *src);
01228
01236 extern void hpairnode_dump_deep(const hpair_t *pairs);
01237
01243 extern void hpairnode_dump(const hpair_t *pair);
01244
01258 extern content_type_t *content_type_new(const char *content_type_str);
01259
01265 extern void content_type_free(content_type_t * ct);
01266
01267 extern struct part_t *part_new(const char *id, const char *filename, const char *content_type, const char *transfer_encoding, struct part_t * next);
01268
01269 extern void part_free(struct part_t * part);
01270
01271
01272
01273 extern struct attachments_t *attachments_new(void);
01274
01282 extern void attachments_free(struct attachments_t * message);
01283 extern void attachments_add_part(struct attachments_t * attachments, struct part_t * part);
01284
01285 #ifdef __cplusplus
01286 }
01287 #endif
01288
01291 #endif