NUGU SDK Linux  1.7.6
nugu_http.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 SK Telecom Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __NUGU_HTTP_H__
18 #define __NUGU_HTTP_H__
19 
20 #include <stddef.h>
21 #include <nugu.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
41 typedef struct _nugu_http_host NuguHttpHost;
42 
46 typedef struct _nugu_http_header NuguHttpHeader;
47 
51 typedef struct _nugu_http_request NuguHttpRequest;
52 
57 
62  NUGU_HTTP_REQUEST_GET, /* GET Request */
63  NUGU_HTTP_REQUEST_POST, /* POST Request */
64  NUGU_HTTP_REQUEST_PUT, /* PUT Request */
65  NUGU_HTTP_REQUEST_DELETE, /* DELETE Request */
66 };
67 
73  const void *body; /* Response body */
74  size_t body_len; /* Response body length */
75  const void *header; /* Response header */
76  size_t header_len; /* Response header length */
77  long code; /* Response code (200, 404, ... -1) */
78 };
79 
86 typedef int (*NuguHttpCallback)(NuguHttpRequest *req,
87  const NuguHttpResponse *resp, void *user_data);
88 
93  const NuguHttpResponse *resp,
94  long long downloaded, long long total,
95  void *user_data);
96 
100 NUGU_API void nugu_http_init(void);
101 
109 NUGU_API NuguHttpHost *nugu_http_host_new(const char *url);
110 
116 NUGU_API void nugu_http_host_set_timeout(NuguHttpHost *host, long msecs);
117 
124  long msecs);
125 
131 NUGU_API const char *nugu_http_host_peek_url(NuguHttpHost *host);
132 
138 NUGU_API void nugu_http_host_free(NuguHttpHost *host);
139 
146 
157 NUGU_API int nugu_http_header_add(NuguHttpHeader *header, const char *key,
158  const char *value);
159 
169 NUGU_API int nugu_http_header_remove(NuguHttpHeader *header, const char *key);
170 
177 NUGU_API const char *nugu_http_header_find(NuguHttpHeader *header,
178  const char *key);
179 
187 
197  const NuguHttpHeader *from);
198 
204 NUGU_API void nugu_http_header_free(NuguHttpHeader *header);
205 
219 NUGU_API NuguHttpRequest *
221  const char *path, NuguHttpHeader *header, const void *body,
222  size_t body_len, NuguHttpCallback callback, void *user_data);
223 
236 NUGU_API NuguHttpRequest *
238  const char *path, NuguHttpHeader *header,
239  const void *body, size_t body_len);
240 
251 NUGU_API NuguHttpRequest *nugu_http_get(NuguHttpHost *host, const char *path,
252  NuguHttpHeader *header,
253  NuguHttpCallback callback,
254  void *user_data);
255 
266  const char *path,
267  NuguHttpHeader *header);
268 
281 NUGU_API NuguHttpRequest *nugu_http_post(NuguHttpHost *host, const char *path,
282  NuguHttpHeader *header,
283  const void *body, size_t body_len,
284  NuguHttpCallback callback,
285  void *user_data);
286 
298 NUGU_API NuguHttpRequest *
299 nugu_http_post_sync(NuguHttpHost *host, const char *path,
300  NuguHttpHeader *header, const void *body, size_t body_len);
301 
314 NUGU_API NuguHttpRequest *nugu_http_put(NuguHttpHost *host, const char *path,
315  NuguHttpHeader *header,
316  const void *body, size_t body_len,
317  NuguHttpCallback callback,
318  void *user_data);
319 
332  const char *path,
333  NuguHttpHeader *header,
334  const void *body, size_t body_len);
335 
346 NUGU_API NuguHttpRequest *nugu_http_delete(NuguHttpHost *host, const char *path,
347  NuguHttpHeader *header,
348  NuguHttpCallback callback,
349  void *user_data);
350 
361  const char *path,
362  NuguHttpHeader *header);
363 
376 NUGU_API NuguHttpRequest *
377 nugu_http_download(NuguHttpHost *host, const char *path, const char *dest_path,
378  NuguHttpHeader *header, NuguHttpCallback callback,
379  NuguHttpProgressCallback progress_callback, void *user_data);
380 
388 
396 
403 
409 NUGU_API const NuguHttpResponse *
411 
416 #ifdef __cplusplus
417 }
418 #endif
419 
420 #endif
struct _nugu_http_header NuguHttpHeader
HTTP Header object.
Definition: nugu_http.h:46
NUGU_API NuguHttpRequest * nugu_http_get_sync(NuguHttpHost *host, const char *path, NuguHttpHeader *header)
A convenient API for HTTP GET sync requests.
NuguHttpRequestType
HTTP request types.
Definition: nugu_http.h:61
NUGU_API NuguHttpHeader * nugu_http_header_dup(const NuguHttpHeader *src_header)
Duplicate the http header object.
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.
NUGU_API int nugu_http_header_add(NuguHttpHeader *header, const char *key, const char *value)
Add a key-value string to header object.
NUGU_API const char * nugu_http_header_find(NuguHttpHeader *header, const char *key)
Find value from header object.
NUGU_API NuguHttpHeader * nugu_http_header_new(void)
Create a new HTTP header object.
NUGU_API NuguHttpRequest * nugu_http_delete_sync(NuguHttpHost *host, const char *path, NuguHttpHeader *header)
A convenient API for HTTP DELETE sync requests.
NUGU_API int nugu_http_header_remove(NuguHttpHeader *header, const char *key)
Remove a key-value string from header object.
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.
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.
NUGU_API void nugu_http_request_free(NuguHttpRequest *req)
Destroy the HTTP request object.
NUGU_API void nugu_http_header_free(NuguHttpHeader *header)
Destroy the header object.
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.
NUGU_API NuguHttpResponse * nugu_http_response_dup(const NuguHttpResponse *orig)
Duplicate the HTTP response object.
int(* NuguHttpProgressCallback)(NuguHttpRequest *req, const NuguHttpResponse *resp, long long downloaded, long long total, void *user_data)
Callback prototype for HTTP download progress.
Definition: nugu_http.h:92
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.
NUGU_API void nugu_http_response_free(NuguHttpResponse *resp)
Destroy the HTTP response object.
struct _nugu_http_request NuguHttpRequest
HTTP Request object.
Definition: nugu_http.h:51
NUGU_API void nugu_http_host_free(NuguHttpHost *host)
Destroy the host object.
NUGU_API NuguHttpHost * nugu_http_host_new(const char *url)
Create a new HTTP host object.
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.
NUGU_API void nugu_http_host_set_timeout(NuguHttpHost *host, long msecs)
Set timeout to host.
NUGU_API void nugu_http_host_set_connection_timeout(NuguHttpHost *host, long msecs)
Set connection timeout to host.
int(* NuguHttpCallback)(NuguHttpRequest *req, const NuguHttpResponse *resp, void *user_data)
Callback prototype for receiving async HTTP response.
Definition: nugu_http.h:86
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.
struct _nugu_http_host NuguHttpHost
HTTP Host object.
Definition: nugu_http.h:41
NUGU_API void nugu_http_init(void)
Initialize HTTP module (curl_global_init)
NUGU_API const NuguHttpResponse * nugu_http_request_response_get(NuguHttpRequest *req)
Get the HTTP response from request object.
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.
NUGU_API int nugu_http_header_import(NuguHttpHeader *header, const NuguHttpHeader *from)
Import header data from other header object.
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.
NUGU_API const char * nugu_http_host_peek_url(NuguHttpHost *host)
Get url from HTTP host object.
HTTP Response object.
Definition: nugu_http.h:72