NUGU SDK Linux  1.7.6
NuguHttp

HTTP request management. More...

+ Collaboration diagram for NuguHttp:

Classes

struct  _nugu_http_response
 HTTP Response object. More...
 

Typedefs

typedef int(* NuguHttpCallback) (NuguHttpRequest *req, const NuguHttpResponse *resp, void *user_data)
 Callback prototype for receiving async HTTP response. More...
 
typedef struct _nugu_http_header NuguHttpHeader
 HTTP Header object.
 
typedef struct _nugu_http_host NuguHttpHost
 HTTP Host object.
 
typedef int(* NuguHttpProgressCallback) (NuguHttpRequest *req, const NuguHttpResponse *resp, long long downloaded, long long total, void *user_data)
 Callback prototype for HTTP download progress.
 
typedef struct _nugu_http_request NuguHttpRequest
 HTTP Request object.
 
typedef struct _nugu_http_response NuguHttpResponse
 HTTP Response object.
 

Enumerations

enum  NuguHttpRequestType { NUGU_HTTP_REQUEST_GET , NUGU_HTTP_REQUEST_POST , NUGU_HTTP_REQUEST_PUT , NUGU_HTTP_REQUEST_DELETE }
 HTTP request types.
 

Functions

NUGU_API NuguHttpRequestnugu_http_delete (NuguHttpHost *host, const char *path, NuguHttpHeader *header, NuguHttpCallback callback, void *user_data)
 A convenient API for HTTP DELETE async requests. More...
 
NUGU_API NuguHttpRequestnugu_http_delete_sync (NuguHttpHost *host, const char *path, NuguHttpHeader *header)
 A convenient API for HTTP DELETE sync requests. More...
 
NUGU_API NuguHttpRequestnugu_http_download (NuguHttpHost *host, const char *path, const char *dest_path, NuguHttpHeader *header, NuguHttpCallback callback, NuguHttpProgressCallback progress_callback, void *user_data)
 A convenient API for HTTP file download async requests. More...
 
NUGU_API NuguHttpRequestnugu_http_get (NuguHttpHost *host, const char *path, NuguHttpHeader *header, NuguHttpCallback callback, void *user_data)
 A convenient API for HTTP GET async requests. More...
 
NUGU_API NuguHttpRequestnugu_http_get_sync (NuguHttpHost *host, const char *path, NuguHttpHeader *header)
 A convenient API for HTTP GET sync requests. More...
 
NUGU_API int nugu_http_header_add (NuguHttpHeader *header, const char *key, const char *value)
 Add a key-value string to header object. More...
 
NUGU_API NuguHttpHeadernugu_http_header_dup (const NuguHttpHeader *src_header)
 Duplicate the http header object. More...
 
NUGU_API const char * nugu_http_header_find (NuguHttpHeader *header, const char *key)
 Find value from header object. More...
 
NUGU_API void nugu_http_header_free (NuguHttpHeader *header)
 Destroy the header object. More...
 
NUGU_API int nugu_http_header_import (NuguHttpHeader *header, const NuguHttpHeader *from)
 Import header data from other header object. More...
 
NUGU_API NuguHttpHeadernugu_http_header_new (void)
 Create a new HTTP header object. More...
 
NUGU_API int nugu_http_header_remove (NuguHttpHeader *header, const char *key)
 Remove a key-value string from header object. More...
 
NUGU_API void nugu_http_host_free (NuguHttpHost *host)
 Destroy the host object. More...
 
NUGU_API NuguHttpHostnugu_http_host_new (const char *url)
 Create a new HTTP host object. More...
 
NUGU_API const char * nugu_http_host_peek_url (NuguHttpHost *host)
 Get url from HTTP host object. More...
 
NUGU_API void nugu_http_host_set_connection_timeout (NuguHttpHost *host, long msecs)
 Set connection timeout to host. More...
 
NUGU_API void nugu_http_host_set_timeout (NuguHttpHost *host, long msecs)
 Set timeout to host. More...
 
NUGU_API void nugu_http_init (void)
 Initialize HTTP module (curl_global_init)
 
NUGU_API NuguHttpRequestnugu_http_post (NuguHttpHost *host, const char *path, NuguHttpHeader *header, const void *body, size_t body_len, NuguHttpCallback callback, void *user_data)
 A convenient API for HTTP POST async requests. More...
 
NUGU_API NuguHttpRequestnugu_http_post_sync (NuguHttpHost *host, const char *path, NuguHttpHeader *header, const void *body, size_t body_len)
 A convenient API for HTTP POST sync requests. More...
 
NUGU_API NuguHttpRequestnugu_http_put (NuguHttpHost *host, const char *path, NuguHttpHeader *header, const void *body, size_t body_len, NuguHttpCallback callback, void *user_data)
 A convenient API for HTTP PUT async requests. More...
 
NUGU_API NuguHttpRequestnugu_http_put_sync (NuguHttpHost *host, const char *path, NuguHttpHeader *header, const void *body, size_t body_len)
 A convenient API for HTTP PUT sync requests. More...
 
NUGU_API NuguHttpRequestnugu_http_request (enum NuguHttpRequestType type, NuguHttpHost *host, const char *path, NuguHttpHeader *header, const void *body, size_t body_len, NuguHttpCallback callback, void *user_data)
 HTTP async request. More...
 
NUGU_API void nugu_http_request_free (NuguHttpRequest *req)
 Destroy the HTTP request object. More...
 
NUGU_API const NuguHttpResponsenugu_http_request_response_get (NuguHttpRequest *req)
 Get the HTTP response from request object. More...
 
NUGU_API NuguHttpRequestnugu_http_request_sync (enum NuguHttpRequestType type, NuguHttpHost *host, const char *path, NuguHttpHeader *header, const void *body, size_t body_len)
 HTTP sync request. More...
 
NUGU_API NuguHttpResponsenugu_http_response_dup (const NuguHttpResponse *orig)
 Duplicate the HTTP response object. More...
 
NUGU_API void nugu_http_response_free (NuguHttpResponse *resp)
 Destroy the HTTP response object. More...
 

Detailed Description

HTTP request management.

The NuguHttp handles REST(GET/POST/PUT/DELETE) requests using HTTP.

Typedef Documentation

◆ NuguHttpCallback

typedef int(* NuguHttpCallback) (NuguHttpRequest *req, const NuguHttpResponse *resp, void *user_data)

Callback prototype for receiving async HTTP response.

Returns
Whether to automatically free memory for NuguHttpRequest
Return values
1automatically free memory after return the callback
0free the memory manually by the nugu_http_request_free().

Function Documentation

◆ nugu_http_host_new()

NUGU_API NuguHttpHost* nugu_http_host_new ( const char *  url)

Create a new HTTP host object.

Parameters
[in]urlhost url
Returns
HTTP host object
See also
nugu_http_host_free()
nugu_http_peek_url();

◆ nugu_http_host_set_timeout()

NUGU_API void nugu_http_host_set_timeout ( NuguHttpHost host,
long  msecs 
)

Set timeout to host.

Parameters
[in]hosthost object
[in]msecsmillisecond

◆ nugu_http_host_set_connection_timeout()

NUGU_API void nugu_http_host_set_connection_timeout ( NuguHttpHost host,
long  msecs 
)

Set connection timeout to host.

Parameters
[in]hosthost object
[in]msecsmillisecond

◆ nugu_http_host_peek_url()

NUGU_API const char* nugu_http_host_peek_url ( NuguHttpHost host)

Get url from HTTP host object.

Parameters
[in]hosthost object
Returns
url

◆ nugu_http_host_free()

NUGU_API void nugu_http_host_free ( NuguHttpHost host)

Destroy the host object.

Parameters
[in]hosthost object
See also
nugu_http_host_new()

◆ nugu_http_header_new()

NUGU_API NuguHttpHeader* nugu_http_header_new ( void  )

Create a new HTTP header object.

Returns
HTTP header object
See also
nugu_http_header_free()

◆ nugu_http_header_add()

NUGU_API int nugu_http_header_add ( NuguHttpHeader header,
const char *  key,
const char *  value 
)

Add a key-value string to header object.

Parameters
[in]headerheader object
[in]keykey string, e.g. "Content-Type"
[in]valuevalue string, e.g. "application/json"
Returns
result
Return values
0success
-1failure
See also
nugu_http_header_remove()

◆ nugu_http_header_remove()

NUGU_API int nugu_http_header_remove ( NuguHttpHeader header,
const char *  key 
)

Remove a key-value string from header object.

Parameters
[in]headerheader object
[in]keykey string
Returns
result
Return values
0success
-1failure
See also
nugu_http_header_add()

◆ nugu_http_header_find()

NUGU_API const char* nugu_http_header_find ( NuguHttpHeader header,
const char *  key 
)

Find value from header object.

Parameters
[in]headerheader object
[in]keykey string
Returns
value string

◆ nugu_http_header_dup()

NUGU_API NuguHttpHeader* nugu_http_header_dup ( const NuguHttpHeader src_header)

Duplicate the http header object.

Parameters
[in]src_headersource header object
Returns
duplicated new header object
See also
nugu_http_header_new()

◆ nugu_http_header_import()

NUGU_API int nugu_http_header_import ( NuguHttpHeader header,
const NuguHttpHeader from 
)

Import header data from other header object.

Parameters
[in]headerheader object
[in]fromheader object to import
Returns
result
Return values
0success
-1failure

◆ nugu_http_header_free()

NUGU_API void nugu_http_header_free ( NuguHttpHeader header)

Destroy the header object.

Parameters
[in]headerheader object
See also
nugu_http_header_new()

◆ nugu_http_request()

NUGU_API NuguHttpRequest* nugu_http_request ( enum NuguHttpRequestType  type,
NuguHttpHost host,
const char *  path,
NuguHttpHeader header,
const void *  body,
size_t  body_len,
NuguHttpCallback  callback,
void *  user_data 
)

HTTP async request.

Parameters
[in]typerequest type
[in]hosthost object
[in]pathurl path
[in]headerheader object
[in]bodybody data to send
[in]body_lenlength of body data
[in]callbackcallback function to receive response
[in]user_datadata to pass to the user callback
Returns
HTTP request object
See also
nugu_http_request_free()

◆ nugu_http_request_sync()

NUGU_API NuguHttpRequest* nugu_http_request_sync ( enum NuguHttpRequestType  type,
NuguHttpHost host,
const char *  path,
NuguHttpHeader header,
const void *  body,
size_t  body_len 
)

HTTP sync request.

Parameters
[in]typerequest type
[in]hosthost object
[in]pathurl path
[in]headerheader object
[in]bodybody data to send
[in]body_lenlength of body data
Returns
HTTP request object
See also
nugu_http_request_free()
nugu_http_request_response_get()

◆ nugu_http_get()

NUGU_API NuguHttpRequest* nugu_http_get ( NuguHttpHost host,
const char *  path,
NuguHttpHeader header,
NuguHttpCallback  callback,
void *  user_data 
)

A convenient API for HTTP GET async requests.

Parameters
[in]hosthost object
[in]pathurl path
[in]headerheader object
[in]callbackcallback function to receive response
[in]user_datadata to pass to the user callback
Returns
HTTP request object
See also
nugu_http_request_free()

◆ nugu_http_get_sync()

NUGU_API NuguHttpRequest* nugu_http_get_sync ( NuguHttpHost host,
const char *  path,
NuguHttpHeader header 
)

A convenient API for HTTP GET sync requests.

Parameters
[in]hosthost object
[in]pathurl path
[in]headerheader object
Returns
HTTP request object
See also
nugu_http_request_free()
nugu_http_request_response_get()

◆ nugu_http_post()

NUGU_API NuguHttpRequest* nugu_http_post ( NuguHttpHost host,
const char *  path,
NuguHttpHeader header,
const void *  body,
size_t  body_len,
NuguHttpCallback  callback,
void *  user_data 
)

A convenient API for HTTP POST async requests.

Parameters
[in]hosthost object
[in]pathurl path
[in]headerheader object
[in]bodybody data to send
[in]body_lenlength of body data
[in]callbackcallback function to receive response
[in]user_datadata to pass to the user callback
Returns
HTTP request object
See also
nugu_http_request_free()

◆ nugu_http_post_sync()

NUGU_API NuguHttpRequest* nugu_http_post_sync ( NuguHttpHost host,
const char *  path,
NuguHttpHeader header,
const void *  body,
size_t  body_len 
)

A convenient API for HTTP POST sync requests.

Parameters
[in]hosthost object
[in]pathurl path
[in]headerheader object
[in]bodybody data to send
[in]body_lenlength of body data
Returns
HTTP request object
See also
nugu_http_request_free()
nugu_http_request_response_get()

◆ nugu_http_put()

NUGU_API NuguHttpRequest* nugu_http_put ( NuguHttpHost host,
const char *  path,
NuguHttpHeader header,
const void *  body,
size_t  body_len,
NuguHttpCallback  callback,
void *  user_data 
)

A convenient API for HTTP PUT async requests.

Parameters
[in]hosthost object
[in]pathurl path
[in]headerheader object
[in]bodybody data to send
[in]body_lenlength of body data
[in]callbackcallback function to receive response
[in]user_datadata to pass to the user callback
Returns
HTTP request object
See also
nugu_http_request_free()

◆ nugu_http_put_sync()

NUGU_API NuguHttpRequest* nugu_http_put_sync ( NuguHttpHost host,
const char *  path,
NuguHttpHeader header,
const void *  body,
size_t  body_len 
)

A convenient API for HTTP PUT sync requests.

Parameters
[in]hosthost object
[in]pathurl path
[in]headerheader object
[in]bodybody data to send
[in]body_lenlength of body data
Returns
HTTP request object
See also
nugu_http_request_free()
nugu_http_request_response_get()

◆ nugu_http_delete()

NUGU_API NuguHttpRequest* nugu_http_delete ( NuguHttpHost host,
const char *  path,
NuguHttpHeader header,
NuguHttpCallback  callback,
void *  user_data 
)

A convenient API for HTTP DELETE async requests.

Parameters
[in]hosthost object
[in]pathurl path
[in]headerheader object
[in]callbackcallback function to receive response
[in]user_datadata to pass to the user callback
Returns
HTTP request object
See also
nugu_http_request_free()

◆ nugu_http_delete_sync()

NUGU_API NuguHttpRequest* nugu_http_delete_sync ( NuguHttpHost host,
const char *  path,
NuguHttpHeader header 
)

A convenient API for HTTP DELETE sync requests.

Parameters
[in]hosthost object
[in]pathurl path
[in]headerheader object
Returns
HTTP request object
See also
nugu_http_request_free()
nugu_http_request_response_get()

◆ nugu_http_download()

NUGU_API NuguHttpRequest* nugu_http_download ( NuguHttpHost host,
const char *  path,
const char *  dest_path,
NuguHttpHeader header,
NuguHttpCallback  callback,
NuguHttpProgressCallback  progress_callback,
void *  user_data 
)

A convenient API for HTTP file download async requests.

Parameters
[in]hosthost object
[in]pathurl path
[in]dest_pathpath to save the file
[in]headerheader object
[in]callbackcallback function to receive response
[in]progress_callbackcallback function to receive download progress
[in]user_datadata to pass to the user callback
Returns
HTTP request object
See also
nugu_http_request_free()

◆ nugu_http_request_free()

NUGU_API void nugu_http_request_free ( NuguHttpRequest req)

Destroy the HTTP request object.

Parameters
[in]reqrequest object
See also
nugu_http_request()
nugu_http_request_sync()

◆ nugu_http_response_dup()

NUGU_API NuguHttpResponse* nugu_http_response_dup ( const NuguHttpResponse orig)

Duplicate the HTTP response object.

Parameters
[in]origOriginal response object
Returns
HTTP response object
See also
nugu_http_response_free()

◆ nugu_http_response_free()

NUGU_API void nugu_http_response_free ( NuguHttpResponse resp)

Destroy the HTTP response object.

Parameters
[in]respresponse object
See also
nugu_http_response_dup()

◆ nugu_http_request_response_get()

NUGU_API const NuguHttpResponse* nugu_http_request_response_get ( NuguHttpRequest req)

Get the HTTP response from request object.

Parameters
[in]reqrequest object
Returns
HTTP response object