This module provides implementation of HTTP client 1.1 for WINC1500 board.
Detailed description of HTTP, please refer to the following documents.
http://tools.ietf.org/html/rfc2616
Revision history 2014/10/07 : Initial draft. (v1.0.0) 2014/12/17 : Add extension header and fix some issues. (v1.0.1) 2015/01/07 : Optimize the WINC driver 18.0 (v1.0.2)
Data Structures | |
struct | http_client_config |
HTTP client configuration structure. More... | |
union | http_client_data |
Structure of the HTTP client callback. More... | |
struct | http_client_data_disconnected |
Structure of the HTTP_CLIENT_CALLBACK_DISCONNECTED callback. More... | |
struct | http_client_data_recv_chunked_data |
Structure of the HTTP_CLIENT_CALLBACK_RECV_CHUNKED_DATA callback. More... | |
struct | http_client_data_recv_response |
Structure of the HTTP_CLIENT_CALLBACK_RECV_RESPONSE callback. More... | |
struct | http_client_data_requested |
Structure of the HTTP_CLIENT_CALLBACK_REQUESTED callback. More... | |
struct | http_client_data_sock_connected |
Structure of the HTTP_CLIENT_CALLBACK_SOCK_CONNECTED callback. More... | |
struct | http_client_module |
Structure of HTTP client connection instance. More... | |
struct | http_client_req |
HTTP client request instance. More... | |
struct | http_client_resp |
HTTP client response instance. More... | |
struct | http_entity |
A structure that the implementation of HTTP entity. More... | |
Macros | |
#define | HTTP_HEADER_ACCEPT ("Accept: ") |
#define | HTTP_HEADER_ACCEPT_CHARSET ("Accept-Charset: ") |
#define | HTTP_HEADER_ACCEPT_ENCODING ("Accept-Encoding: ") |
#define | HTTP_HEADER_ACCEPT_LANGUAGE ("Accept-Language: ") |
#define | HTTP_HEADER_ACCEPT_RANGES ("Accept-Ranges: ") |
#define | HTTP_HEADER_AGE ("Age: ") |
#define | HTTP_HEADER_ALLOW ("Allow: ") |
#define | HTTP_HEADER_AUTHORIZATION ("Authorization: ") |
#define | HTTP_HEADER_CACHE_CONTROL ("Cache-Control: ") |
#define | HTTP_HEADER_CONNECTION ("Connection: ") |
#define | HTTP_HEADER_CONTENT_ENCODING ("Content-Encoding: ") |
#define | HTTP_HEADER_CONTENT_LANGUAGE ("Content-Language: ") |
#define | HTTP_HEADER_CONTENT_LENGTH ("Content-Length: ") |
#define | HTTP_HEADER_CONTENT_LOCATION ("Content-Location: ") |
#define | HTTP_HEADER_CONTENT_MD5 ("Content-MD5: ") |
#define | HTTP_HEADER_CONTENT_RANGE ("Content-Range: ") |
#define | HTTP_HEADER_CONTENT_TYPE ("Content-Type: ") |
#define | HTTP_HEADER_DATE ("Date: ") |
#define | HTTP_HEADER_ETAG ("ETag: ") |
#define | HTTP_HEADER_EXPECT ("Expect: ") |
#define | HTTP_HEADER_EXPIRES ("Expires: ") |
#define | HTTP_HEADER_FROM ("From: ") |
#define | HTTP_HEADER_HOST ("Host: ") |
#define | HTTP_HEADER_IF_MATCH ("If-Match: ") |
#define | HTTP_HEADER_IF_MODIFIED_SINCE ("If-Modified-Since: ") |
#define | HTTP_HEADER_IF_NONE_MATCH ("If-None-Match: ") |
#define | HTTP_HEADER_IF_RANGE ("If-Range: ") |
#define | HTTP_HEADER_IF_UNMODIFIED_SINCE ("If-Unmodified-Since: ") |
#define | HTTP_HEADER_LAST_MODIFIED ("Last-Modified: ") |
#define | HTTP_HEADER_LOCATION ("Location: ") |
#define | HTTP_HEADER_MAX_FORWARDS ("Max-Forwards: ") |
#define | HTTP_HEADER_PRAGMA ("Pragma: ") |
#define | HTTP_HEADER_PROXY_AUTHENTICATE ("Proxy-Authenticate: ") |
#define | HTTP_HEADER_PROXY_AUTHORIZATION ("Proxy-Authorization: ") |
#define | HTTP_HEADER_RANGE ("Range: ") |
#define | HTTP_HEADER_REFERER ("Referer: ") |
#define | HTTP_HEADER_RETRY_AFTER ("Retry-After: ") |
#define | HTTP_HEADER_SERVER ("Server: ") |
#define | HTTP_HEADER_TE ("TE: ") |
#define | HTTP_HEADER_TRAILER ("Trailer: ") |
#define | HTTP_HEADER_TRANSFER_ENCODING ("Transfer-Encoding: ") |
#define | HTTP_HEADER_UPGRADE ("Upgrade: ") |
#define | HTTP_HEADER_USER_AGENT ("User-Agent: ") |
#define | HTTP_HEADER_VARY ("Vary: ") |
#define | HTTP_HEADER_VIA ("Via: ") |
#define | HTTP_HEADER_WARNING ("Warning: ") |
#define | HTTP_HEADER_WWW_AUTHENTICATE ("WWW-Authenticate: ") |
#define | HTTP_MAX_URI_LENGTH 64 |
Max size of URI. More... | |
#define | HTTP_PROTO_NAME "HTTP/1.1" |
Protocol version string of HTTP client. More... | |
Typedefs | |
typedef void(* | http_client_callback_t )(struct http_client_module *module_inst, int type, union http_client_data *data) |
Callback interface of HTTP client service. More... | |
Enumerations | |
enum | http_client_callback_type { HTTP_CLIENT_CALLBACK_SOCK_CONNECTED, HTTP_CLIENT_CALLBACK_REQUESTED, HTTP_CLIENT_CALLBACK_RECV_RESPONSE, HTTP_CLIENT_CALLBACK_RECV_CHUNKED_DATA, HTTP_CLIENT_CALLBACK_DISCONNECTED } |
A type of HTTP client callback. More... | |
enum | http_method { HTTP_METHOD_GET = 1, HTTP_METHOD_POST, HTTP_METHOD_DELETE, HTTP_METHOD_PUT, HTTP_METHOD_OPTIONS, HTTP_METHOD_HEAD } |
A type of HTTP method. More... | |
Functions | |
int | http_client_close (struct http_client_module *const module) |
Force close HTTP connection. More... | |
int | http_client_deinit (struct http_client_module *const module) |
Terminate HTTP client service. More... | |
void | http_client_get_config_defaults (struct http_client_config *const config) |
Get default configuration of HTTP client module. More... | |
int | http_client_init (struct http_client_module *const module, struct http_client_config *config) |
Initialize HTTP client service. More... | |
int | http_client_register_callback (struct http_client_module *const module, http_client_callback_t callback) |
Register and enable the callback. More... | |
int | http_client_send_request (struct http_client_module *const module, const char *url, enum http_method method, struct http_entity *const entity, const char *ext_header) |
Event handler of gethostbyname. More... | |
void | http_client_socket_event_handler (SOCKET sock, uint8_t msg_type, void *msg_data) |
Event handler of socket event. More... | |
void | http_client_socket_resolve_handler (uint8_t *doamin_name, uint32_t server_ip) |
Event handler of gethostbyname. More... | |
int | http_client_unregister_callback (struct http_client_module *const module) |
Unregister callback. More... | |
#define HTTP_HEADER_ACCEPT ("Accept: ") |
#define HTTP_HEADER_ACCEPT_CHARSET ("Accept-Charset: ") |
#define HTTP_HEADER_ACCEPT_ENCODING ("Accept-Encoding: ") |
#define HTTP_HEADER_ACCEPT_LANGUAGE ("Accept-Language: ") |
#define HTTP_HEADER_ACCEPT_RANGES ("Accept-Ranges: ") |
#define HTTP_HEADER_AGE ("Age: ") |
#define HTTP_HEADER_ALLOW ("Allow: ") |
#define HTTP_HEADER_AUTHORIZATION ("Authorization: ") |
#define HTTP_HEADER_CACHE_CONTROL ("Cache-Control: ") |
#define HTTP_HEADER_CONNECTION ("Connection: ") |
#define HTTP_HEADER_CONTENT_ENCODING ("Content-Encoding: ") |
#define HTTP_HEADER_CONTENT_LANGUAGE ("Content-Language: ") |
#define HTTP_HEADER_CONTENT_LENGTH ("Content-Length: ") |
#define HTTP_HEADER_CONTENT_LOCATION ("Content-Location: ") |
#define HTTP_HEADER_CONTENT_MD5 ("Content-MD5: ") |
#define HTTP_HEADER_CONTENT_RANGE ("Content-Range: ") |
#define HTTP_HEADER_CONTENT_TYPE ("Content-Type: ") |
#define HTTP_HEADER_DATE ("Date: ") |
#define HTTP_HEADER_ETAG ("ETag: ") |
#define HTTP_HEADER_EXPECT ("Expect: ") |
#define HTTP_HEADER_EXPIRES ("Expires: ") |
#define HTTP_HEADER_FROM ("From: ") |
#define HTTP_HEADER_HOST ("Host: ") |
#define HTTP_HEADER_IF_MATCH ("If-Match: ") |
#define HTTP_HEADER_IF_MODIFIED_SINCE ("If-Modified-Since: ") |
#define HTTP_HEADER_IF_NONE_MATCH ("If-None-Match: ") |
#define HTTP_HEADER_IF_RANGE ("If-Range: ") |
#define HTTP_HEADER_IF_UNMODIFIED_SINCE ("If-Unmodified-Since: ") |
#define HTTP_HEADER_LAST_MODIFIED ("Last-Modified: ") |
#define HTTP_HEADER_LOCATION ("Location: ") |
#define HTTP_HEADER_MAX_FORWARDS ("Max-Forwards: ") |
#define HTTP_HEADER_PRAGMA ("Pragma: ") |
#define HTTP_HEADER_PROXY_AUTHENTICATE ("Proxy-Authenticate: ") |
#define HTTP_HEADER_PROXY_AUTHORIZATION ("Proxy-Authorization: ") |
#define HTTP_HEADER_RANGE ("Range: ") |
#define HTTP_HEADER_REFERER ("Referer: ") |
#define HTTP_HEADER_RETRY_AFTER ("Retry-After: ") |
#define HTTP_HEADER_SERVER ("Server: ") |
#define HTTP_HEADER_TE ("TE: ") |
#define HTTP_HEADER_TRAILER ("Trailer: ") |
#define HTTP_HEADER_TRANSFER_ENCODING ("Transfer-Encoding: ") |
#define HTTP_HEADER_UPGRADE ("Upgrade: ") |
#define HTTP_HEADER_USER_AGENT ("User-Agent: ") |
#define HTTP_HEADER_VARY ("Vary: ") |
#define HTTP_HEADER_VIA ("Via: ") |
#define HTTP_HEADER_WARNING ("Warning: ") |
#define HTTP_HEADER_WWW_AUTHENTICATE ("WWW-Authenticate: ") |
#define HTTP_MAX_URI_LENGTH 64 |
Max size of URI.
Referenced by http_client_send_request().
#define HTTP_PROTO_NAME "HTTP/1.1" |
Protocol version string of HTTP client.
Referenced by _http_client_request().
typedef void(* http_client_callback_t)(struct http_client_module *module_inst, int type, union http_client_data *data) |
Callback interface of HTTP client service.
[in] | module_inst | Module instance of HTTP client module. |
[in] | type | Type of event. |
[in] | data | Data structure of the event. http_client_data |
A type of HTTP client callback.
enum http_method |
int http_client_close | ( | struct http_client_module *const | module | ) |
Force close HTTP connection.
[in] | module_inst | Instance of HTTP client module. |
References _http_client_clear_conn(), NULL, http_client_module::req, http_client_req::state, and STATE_SOCK_CONNECTED.
int http_client_deinit | ( | struct http_client_module *const | module | ) |
Terminate HTTP client service.
[in] | module | Module instance of HTTP client. |
References http_client_module::alloc_buffer, http_client_module::config, http_client_req::ext_header, NULL, http_client_config::recv_buffer, and http_client_module::req.
void http_client_get_config_defaults | ( | struct http_client_config *const | config | ) |
Get default configuration of HTTP client module.
[in] | config | Pointer of configuration structure which will be used in the module. |
References DEFAULT_USER_AGENT, MIN_SEND_BUFFER_SIZE, NULL, http_client_config::port, http_client_config::recv_buffer, http_client_config::recv_buffer_size, http_client_config::send_buffer_size, http_client_config::timeout, http_client_config::timer_inst, http_client_config::tls, and http_client_config::user_agent.
Referenced by _exosite_example_configure_http_client().
int http_client_init | ( | struct http_client_module *const | module, |
struct http_client_config * | config | ||
) |
Initialize HTTP client service.
[in] | module | Module instance of HTTP client module. |
[in] | config | Pointer of configuration structure which will be used in the module. |
References http_client_module::alloc_buffer, http_client_module::config, http_client_timer_callback(), MIN_SEND_BUFFER_SIZE, NULL, http_client_config::recv_buffer, http_client_config::recv_buffer_size, http_client_module::req, http_client_module::resp, http_client_config::send_buffer_size, http_client_req::state, http_client_resp::state, STATE_INIT, STATE_PARSE_HEADER, sw_timer_register_callback(), http_client_config::timeout, http_client_module::timer_id, and http_client_config::timer_inst.
Referenced by _exosite_example_configure_http_client().
int http_client_register_callback | ( | struct http_client_module *const | module, |
http_client_callback_t | callback | ||
) |
Register and enable the callback.
[in] | module_inst | Instance of HTTP client module. |
[in] | callback | Callback entry for the HTTP client module. |
References http_client_module::cb, and NULL.
Referenced by _exosite_example_configure_http_client().
int http_client_send_request | ( | struct http_client_module *const | module, |
const char * | url, | ||
enum http_method | method, | ||
struct http_entity *const | entity, | ||
const char * | ext_header | ||
) |
Event handler of gethostbyname.
[in] | module_inst | Instance of HTTP client module. |
[in] | url | URL of request. |
[in] | method | Method of request. |
[in] | entity | Entity of request. Entity is consist of Entity header and Entity body Please refer to http_entity. |
[in] | ext_header | Extension header of the request.It must ends with new line character( ). |
References _htons, _http_client_clear_conn(), _http_client_request(), _is_ip(), AF_INET, http_client_module::config, connect(), http_client_req::entity, http_client_req::ext_header, gethostbyname(), http_client_module::host, HTTP_MAX_URI_LENGTH, http_client_req::method, nmi_inet_addr(), NULL, http_client_config::port, http_client_module::recved_size, http_client_module::req, in_addr::s_addr, http_client_module::sending, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, http_client_module::sock, SOCK_STREAM, socket(), SOCKET_FLAGS_SSL, http_client_req::state, STATE_INIT, STATE_REQ_SEND_HEADER, STATE_SOCK_CONNECTED, STATE_TRY_SOCK_CONNECT, http_client_config::tls, and http_client_req::uri.
Referenced by exosite_example_activiate(), and exosite_example_read_and_write().
void http_client_socket_event_handler | ( | SOCKET | sock, |
uint8_t | msg_type, | ||
void * | msg_data | ||
) |
Event handler of socket event.
[in] | sock | Socket descriptor. |
[in] | msg_type | Event type. |
[in] | msg_data | Structure of socket event. |
References _http_client_clear_conn(), _http_client_recv_packet(), _http_client_recved_packet(), _http_client_request(), _hwerr_to_stderr(), http_client_module::cb, http_client_module::config, HTTP_CLIENT_CALLBACK_SOCK_CONNECTED, NULL, http_client_module::req, http_client_data_sock_connected::result, tstrSocketRecvMsg::s16BufferSize, tstrSocketConnectMsg::s8Error, http_client_module::sending, http_client_module::sock, http_client_data::sock_connected, SOCKET_MSG_CONNECT, SOCKET_MSG_RECV, SOCKET_MSG_SEND, http_client_req::state, STATE_REQ_SEND_HEADER, sw_timer_enable_callback(), http_client_config::timeout, http_client_module::timer_id, and http_client_config::timer_inst.
Referenced by main().
void http_client_socket_resolve_handler | ( | uint8_t * | doamin_name, |
uint32_t | server_ip | ||
) |
Event handler of gethostbyname.
[in] | doamin_name | Domain name. |
[in] | server_ip | Server IP. |
References _htons, _http_client_clear_conn(), AF_INET, http_client_module::config, connect(), http_client_module::host, NULL, http_client_config::port, http_client_module::req, in_addr::s_addr, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, http_client_module::sock, http_client_req::state, STATE_TRY_SOCK_CONNECT, and TCP_SOCK_MAX.
Referenced by main().
int http_client_unregister_callback | ( | struct http_client_module *const | module | ) |
Unregister callback.
[in] | module_inst | Instance of HTTP client module. |
References http_client_module::cb, and NULL.