Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
HTTP client service

This module provides implementation of HTTP client 1.1 for WINC3400 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)

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_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)
 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 *domain_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.

#define HTTP_PROTO_NAME   "HTTP/1.1"

Protocol version string of HTTP client.

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.

Parameters
[in]module_instModule instance of HTTP client module.
[in]typeType of event.
[in]dataData structure of the event. http_client_data

A type of HTTP client callback.

Enumerator
HTTP_CLIENT_CALLBACK_SOCK_CONNECTED 

Socket was connected.

After received this event, try send request message to the server.

HTTP_CLIENT_CALLBACK_REQUESTED 

The request operation is completed.

HTTP_CLIENT_CALLBACK_RECV_RESPONSE 

Received HTTP response message.

HTTP_CLIENT_CALLBACK_RECV_CHUNKED_DATA 

Received Chunked data.

HTTP_CLIENT_CALLBACK_DISCONNECTED 

The session was closed.

A type of HTTP method.

Enumerator
HTTP_METHOD_GET 
HTTP_METHOD_POST 
HTTP_METHOD_DELETE 
HTTP_METHOD_PUT 
HTTP_METHOD_OPTIONS 
HTTP_METHOD_HEAD 

int http_client_deinit ( struct http_client_module *const  module)

Terminate HTTP client service.

Parameters
[in]moduleModule instance of HTTP client.
Returns
0 Function succeeded
-ENOENT No such address.
-EINVAL Invalid argument.
-ENOSPC No space left on device.
-EIO Device was occurred error due to unknown exception.
-EDESTADDRREQ Destination address required.
-ECONNRESET Connection reset by peer.
-EAGAIN Try again.
-EBUSY Device or resource busy.
-EADDRINUSE Address already in use.
-EALREADY Socket already connected.
-ENOTCONN Service in bad state.
-ECONNREFUSED Connection refused.
-EOVERFLOW Value too large for defined data type.
-EBADMSG Not a data message.
-ENOMEM Out of memory.
-ENOTSUP Unsupported operation.
void http_client_get_config_defaults ( struct http_client_config *const  config)

Get default configuration of HTTP client module.

Parameters
[in]configPointer of configuration structure which will be used in the module.

Referenced by configure_http_client().

int http_client_init ( struct http_client_module *const  module,
struct http_client_config config 
)

Initialize HTTP client service.

Parameters
[in]moduleModule instance of HTTP client module.
[in]configPointer of configuration structure which will be used in the module.
Returns
0 Function succeeded
-ENOENT No such address.
-EINVAL Invalid argument.
-ENOSPC No space left on device.
-EIO Device was occurred error due to unknown exception.
-EDESTADDRREQ Destination address required.
-ECONNRESET Connection reset by peer.
-EAGAIN Try again.
-EBUSY Device or resource busy.
-EADDRINUSE Address already in use.
-EALREADY Socket already connected.
-ENOTCONN Service in bad state.
-ECONNREFUSED Connection refused.
-EOVERFLOW Value too large for defined data type.
-EBADMSG Not a data message.
-ENOMEM Out of memory.

Referenced by configure_http_client().

int http_client_register_callback ( struct http_client_module *const  module,
http_client_callback_t  callback 
)

Register and enable the callback.

Parameters
[in]module_instInstance of HTTP client module.
[in]callbackCallback entry for the HTTP client module.
Returns
0 Function succeeded
-ENOENT No such address.
-EINVAL Invalid argument.
-ENOSPC No space left on device.
-EIO Device was occurred error due to unknown exception.
-EDESTADDRREQ Destination address required.
-ECONNRESET Connection reset by peer.
-EAGAIN Try again.
-EBUSY Device or resource busy.
-EADDRINUSE Address already in use.
-EALREADY Socket already connected.
-ENOTCONN Service in bad state.
-ECONNREFUSED Connection refused.
-EOVERFLOW Value too large for defined data type.
-EBADMSG Not a data message.
-ENOMEM Out of memory.
-ENOTSUP Unsupported operation.

Referenced by 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 
)

Event handler of gethostbyname.

Parameters
[in]module_instInstance of HTTP client module.
[in]urlURL of request.
[in]methodMethod of request.
[in]entityEntity of request. Entity is consist of Entity header and Entity body Please refer to http_entity.
Returns
0 Function succeeded
-ENOENT No such address.
-EINVAL Invalid argument.
-ENOSPC No space left on device.
-EIO Device was occurred error due to unknown exception.
-EDESTADDRREQ Destination address required.
-ECONNRESET Connection reset by peer.
-EAGAIN Try again.
-EBUSY Device or resource busy.
-EADDRINUSE Address already in use.
-EALREADY Socket already connected.
-ENOTCONN Service in bad state.
-ECONNREFUSED Connection refused.
-EOVERFLOW Value too large for defined data type.
-EBADMSG Not a data message.
-ENOMEM Out of memory.
-ENOTSUP Unsupported operation.

Referenced by http_client_callback(), and wifi_callback().

void http_client_socket_event_handler ( SOCKET  sock,
uint8_t  msg_type,
void *  msg_data 
)

Event handler of socket event.

Parameters
[in]sockSocket descriptor.
[in]msg_typeEvent type.
[in]msg_dataStructure of socket event.

Referenced by socket_event_handler().

void http_client_socket_resolve_handler ( uint8_t *  domain_name,
uint32_t  server_ip 
)

Event handler of gethostbyname.

Parameters
[in]domain_nameDomain name.
[in]server_ipServer IP.

Referenced by socket_resolve_handler().

int http_client_unregister_callback ( struct http_client_module *const  module)

Unregister callback.

Parameters
[in]module_instInstance of HTTP client module.
Returns
0 Function succeeded
-ENOENT No such address.
-EINVAL Invalid argument.
-ENOSPC No space left on device.
-EIO Device was occurred error due to unknown exception.
-EDESTADDRREQ Destination address required.
-ECONNRESET Connection reset by peer.
-EAGAIN Try again.
-EBUSY Device or resource busy.
-EADDRINUSE Address already in use.
-EALREADY Socket already connected.
-ENOTCONN Service in bad state.
-ECONNREFUSED Connection refused.
-EOVERFLOW Value too large for defined data type.
-EBADMSG Not a data message.
-ENOMEM Out of memory.
-ENOTSUP Unsupported operation.