123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493 |
- #ifndef __PJLIB_UTIL_HTTP_CLIENT_H__
- #define __PJLIB_UTIL_HTTP_CLIENT_H__
- #include <pj/activesock.h>
- #include <pjlib-util/types.h>
- PJ_BEGIN_DECL
- typedef struct pj_http_req pj_http_req;
- #define PJ_HTTP_HEADER_SIZE 32
- typedef struct pj_http_header_elmt
- {
- pj_str_t name;
- pj_str_t value;
- } pj_http_header_elmt;
- typedef struct pj_http_headers
- {
-
- unsigned count;
-
- pj_http_header_elmt header[PJ_HTTP_HEADER_SIZE];
- } pj_http_headers;
- typedef struct pj_http_auth_cred
- {
-
- pj_str_t scheme;
-
- pj_str_t realm;
-
- pj_str_t username;
-
- unsigned data_type;
-
- pj_str_t data;
- } pj_http_auth_cred;
- typedef struct pj_http_req_param
- {
-
- int addr_family;
-
- pj_str_t method;
-
- pj_str_t version;
-
- pj_time_val timeout;
-
- void *user_data;
-
- pj_http_headers headers;
-
- struct pj_http_reqdata
- {
- void *data;
- pj_size_t size;
- pj_size_t total_size;
-
- } reqdata;
-
- pj_http_auth_cred auth_cred;
-
- pj_uint16_t source_port_range_start;
-
- pj_uint16_t source_port_range_size;
-
- pj_uint16_t max_retries;
- } pj_http_req_param;
- typedef struct pj_http_auth_chal
- {
- pj_str_t scheme;
- pj_str_t realm;
- pj_str_t domain;
- pj_str_t nonce;
- pj_str_t opaque;
- int stale;
- pj_str_t algorithm;
- pj_str_t qop;
- } pj_http_auth_chal;
- typedef struct pj_http_resp
- {
- pj_str_t version;
- pj_uint16_t status_code;
- pj_str_t reason;
- pj_http_headers headers;
- pj_http_auth_chal auth_chal;
- pj_int32_t content_length;
- void *data;
- pj_size_t size;
- } pj_http_resp;
- typedef struct pj_http_url
- {
- pj_str_t username;
- pj_str_t passwd;
- pj_str_t protocol;
- pj_str_t host;
- pj_uint16_t port;
- pj_str_t path;
- } pj_http_url;
- typedef struct pj_http_req_callback
- {
-
- void (*on_response)(pj_http_req *http_req, const pj_http_resp *resp);
-
- void (*on_send_data)(pj_http_req *http_req,
- void **data, pj_size_t *size);
-
- void (*on_data_read)(pj_http_req *http_req,
- void *data, pj_size_t size);
-
- void (*on_complete)(pj_http_req *http_req,
- pj_status_t status,
- const pj_http_resp *resp);
- } pj_http_req_callback;
- PJ_DECL(void) pj_http_req_param_default(pj_http_req_param *param);
- PJ_DECL(pj_status_t) pj_http_headers_add_elmt(pj_http_headers *headers,
- pj_str_t *name,
- pj_str_t *val);
- PJ_DECL(pj_status_t) pj_http_headers_add_elmt2(pj_http_headers *headers,
- char *name, char *val);
- PJ_DECL(pj_status_t) pj_http_req_parse_url(const pj_str_t *url,
- pj_http_url *hurl);
- PJ_DECL(pj_status_t) pj_http_req_create(pj_pool_t *pool,
- const pj_str_t *url,
- pj_timer_heap_t *timer,
- pj_ioqueue_t *ioqueue,
- const pj_http_req_param *param,
- const pj_http_req_callback *hcb,
- pj_http_req **http_req);
- PJ_DECL(void) pj_http_req_set_timeout(pj_http_req *http_req,
- const pj_time_val* timeout);
- PJ_DECL(pj_status_t) pj_http_req_start(pj_http_req *http_req);
- PJ_DECL(pj_status_t) pj_http_req_cancel(pj_http_req *http_req,
- pj_bool_t notify);
- PJ_DECL(pj_status_t) pj_http_req_destroy(pj_http_req *http_req);
- PJ_DECL(pj_bool_t) pj_http_req_is_running(const pj_http_req *http_req);
- PJ_DECL(void *) pj_http_req_get_user_data(pj_http_req *http_req);
- PJ_END_DECL
- #endif
|