Network Services API  2.40.00.11
httpclient.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2018, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
56 #ifndef ti_net_http_HTTPClient__include
57 #define ti_net_http_HTTPClient__include
58 
61 
62 #include <stdbool.h>
63 
64 #include <ti/net/slnetsock.h>
65 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
70 #define HTTPClient_DOMAIN_BUFLEN (100)
71 
73 #define HTTPClient_RES_HFIELD_BUFFER_SIZE (300)
74 
76 #define HTTPClient_MIN_USER_WORKSPACE_SIZE (500)
77 #define HTTPClient_MAX_REDIRECTION_ATTEMPTS (3)
78 #define HTTPClient_MAX_REQUEST_ATTEMPTS (2)
79 #define HTTPClient_MAX_RESPONSE_HEADER_FILEDS (25)
80 
81 #define HTTPClient_PORT (80)
82 #define HTTPClient_SECURE_PORT (443)
83 
84 /* HTTP response header fields */
85 #define HTTPClient_HFIELD_RES_AGE (0)
86 #define HTTPClient_HFIELD_RES_ALLOW (1)
87 #define HTTPClient_HFIELD_RES_CACHE_CONTROL (2)
88 #define HTTPClient_HFIELD_RES_CONNECTION (3)
89 #define HTTPClient_HFIELD_RES_CONTENT_ENCODING (4)
90 #define HTTPClient_HFIELD_RES_CONTENT_LANGUAGE (5)
91 #define HTTPClient_HFIELD_RES_CONTENT_LENGTH (6)
92 #define HTTPClient_HFIELD_RES_CONTENT_LOCATION (7)
93 #define HTTPClient_HFIELD_RES_CONTENT_RANGE (8)
94 #define HTTPClient_HFIELD_RES_CONTENT_TYPE (9)
95 #define HTTPClient_HFIELD_RES_DATE (10)
96 #define HTTPClient_HFIELD_RES_ETAG (11)
97 #define HTTPClient_HFIELD_RES_EXPIRES (12)
98 #define HTTPClient_HFIELD_RES_LAST_MODIFIED (13)
99 #define HTTPClient_HFIELD_RES_LOCATION (14)
100 #define HTTPClient_HFIELD_RES_PROXY_AUTHENTICATE (15)
101 #define HTTPClient_HFIELD_RES_RETRY_AFTER (16)
102 #define HTTPClient_HFIELD_RES_SERVER (17)
103 #define HTTPClient_HFIELD_RES_SET_COOKIE (18)
104 #define HTTPClient_HFIELD_RES_TRAILER (19)
105 #define HTTPClient_HFIELD_RES_TRANSFER_ENCODING (20)
106 #define HTTPClient_HFIELD_RES_UPGRADE (21)
107 #define HTTPClient_HFIELD_RES_VARY (22)
108 #define HTTPClient_HFIELD_RES_VIA (23)
109 #define HTTPClient_HFIELD_RES_WWW_AUTHENTICATE (24)
110 #define HTTPClient_HFIELD_RES_WARNING (25)
111 
112 #define HTTPClient_REQUEST_HEADER_MASK (0x80000000)
113 
114 /* HTTP request header fields */
115 #define HTTPClient_HFIELD_REQ_ACCEPT (26 | HTTPClient_REQUEST_HEADER_MASK)
116 #define HTTPClient_HFIELD_REQ_ACCEPT_CHARSET (27 | HTTPClient_REQUEST_HEADER_MASK)
117 #define HTTPClient_HFIELD_REQ_ACCEPT_ENCODING (28 | HTTPClient_REQUEST_HEADER_MASK)
118 #define HTTPClient_HFIELD_REQ_ACCEPT_LANGUAGE (29 | HTTPClient_REQUEST_HEADER_MASK)
119 #define HTTPClient_HFIELD_REQ_ALLOW (HTTPClient_HFIELD_RES_ALLOW | HTTPClient_REQUEST_HEADER_MASK)
120 #define HTTPClient_HFIELD_REQ_AUTHORIZATION (30 | HTTPClient_REQUEST_HEADER_MASK)
121 #define HTTPClient_HFIELD_REQ_CACHE_CONTROL (HTTPClient_HFIELD_RES_CACHE_CONTROL | HTTPClient_REQUEST_HEADER_MASK)
122 #define HTTPClient_HFIELD_REQ_CONNECTION (HTTPClient_HFIELD_RES_CONNECTION | HTTPClient_REQUEST_HEADER_MASK)
123 #define HTTPClient_HFIELD_REQ_CONTENT_ENCODING (HTTPClient_HFIELD_RES_CONTENT_ENCODING | HTTPClient_REQUEST_HEADER_MASK)
124 #define HTTPClient_HFIELD_REQ_CONTENT_LANGUAGE (HTTPClient_HFIELD_RES_CONTENT_LANGUAGE | HTTPClient_REQUEST_HEADER_MASK)
125 #define HTTPClient_HFIELD_REQ_CONTENT_LOCATION (HTTPClient_HFIELD_RES_CONTENT_LOCATION | HTTPClient_REQUEST_HEADER_MASK)
126 #define HTTPClient_HFIELD_REQ_CONTENT_TYPE (HTTPClient_HFIELD_RES_CONTENT_TYPE | HTTPClient_REQUEST_HEADER_MASK)
127 #define HTTPClient_HFIELD_REQ_COOKIE (31 | HTTPClient_REQUEST_HEADER_MASK)
128 #define HTTPClient_HFIELD_REQ_DATE (HTTPClient_HFIELD_RES_DATE | HTTPClient_REQUEST_HEADER_MASK)
129 #define HTTPClient_HFIELD_REQ_EXPECT (32 | HTTPClient_REQUEST_HEADER_MASK)
130 #define HTTPClient_HFIELD_REQ_FORWARDED (33 | HTTPClient_REQUEST_HEADER_MASK)
131 #define HTTPClient_HFIELD_REQ_FROM (34 | HTTPClient_REQUEST_HEADER_MASK)
132 #define HTTPClient_HFIELD_REQ_HOST (35 | HTTPClient_REQUEST_HEADER_MASK)
133 #define HTTPClient_HFIELD_REQ_IF_MATCH (36 | HTTPClient_REQUEST_HEADER_MASK)
134 #define HTTPClient_HFIELD_REQ_IF_MODIFIED_SINCE (37 | HTTPClient_REQUEST_HEADER_MASK)
135 #define HTTPClient_HFIELD_REQ_IF_NONE_MATCH (38 | HTTPClient_REQUEST_HEADER_MASK)
136 #define HTTPClient_HFIELD_REQ_IF_RANGE (39 | HTTPClient_REQUEST_HEADER_MASK)
137 #define HTTPClient_HFIELD_REQ_IF_UNMODIFIED_SINCE (40 | HTTPClient_REQUEST_HEADER_MASK)
138 #define HTTPClient_HFIELD_REQ_ORIGIN (41 | HTTPClient_REQUEST_HEADER_MASK)
139 #define HTTPClient_HFIELD_REQ_PROXY_AUTHORIZATION (42 | HTTPClient_REQUEST_HEADER_MASK)
140 #define HTTPClient_HFIELD_REQ_RANGE (43 | HTTPClient_REQUEST_HEADER_MASK)
141 #define HTTPClient_HFIELD_REQ_TE (44 | HTTPClient_REQUEST_HEADER_MASK)
142 #define HTTPClient_HFIELD_REQ_TRANSFER_ENCODING (HTTPClient_HFIELD_RES_TRANSFER_ENCODING | HTTPClient_REQUEST_HEADER_MASK)
143 #define HTTPClient_HFIELD_REQ_UPGRADE (HTTPClient_HFIELD_RES_UPGRADE | HTTPClient_REQUEST_HEADER_MASK)
144 #define HTTPClient_HFIELD_REQ_USER_AGENT (45 | HTTPClient_REQUEST_HEADER_MASK)
145 #define HTTPClient_HFIELD_REQ_VIA (HTTPClient_HFIELD_RES_VIA | HTTPClient_REQUEST_HEADER_MASK)
146 #define HTTPClient_HFIELD_REQ_WARNING (HTTPClient_HFIELD_RES_WARNING | HTTPClient_REQUEST_HEADER_MASK)
147 
148 #define HTTPClient_MAX_NUMBER_OF_HEADER_FIELDS (46)
149 
150 /* SetOpt options */
152 #define HTTPClient_REDIRECT_FEATURE (48)
153 
155 #define HTTPClient_RESPONSE_FILTER_CLEAR (49)
156 
158 #define HTTPClient_REDIRECT_TLS_DOWNGRADE (50)
159 
164 #define HTTPClient_AUTHENTICATE_SERVER_CALLBACK (51)
165 
166 /* HTTP Client Error Codes */
167 
173 #define HTTPClient_ESENDBUFSMALL (-3001)
174 
178 #define HTTPClient_EGETOPTBUFSMALL (-3002)
179 
183 #define HTTPClient_ERESPONSEINVALID (-3003)
184 
188 #define HTTPClient_EINPROGRESS (-3004)
189 
197 #define HTTPClient_EDOMAINBUFSMALL (-3005)
198 
204 #define HTTPClient_ECBALLOCATIONFAILED (-3006)
205 
213 #define HTTPClient_EBODYBUFSMALL (-3008)
214 
220 #define HTTPClient_ENULLPOINTER (-3009)
221 
225 #define HTTPClient_EREQUESTHEADERALLOCFAILED (-3010)
226 
230 #define HTTPClient_EREQHEADERNOTFOUND (-3011)
231 
237 #define HTTPClient_EHOSTNOTFOUND (-3012)
238 
242 #define HTTPClient_ECLIENTALREADYCONNECTED (-3013)
243 
247 #define HTTPClient_ERESPONSEISNOTREDIRECTABLE (-3014)
248 
252 #define HTTPClient_ESENDERROR (-3015)
253 
263 #define HTTPClient_EREDIRECTLOCATIONFAIL (-3016)
264 
272 #define HTTPClient_ETLSDOWNGRADEISFORBIDDEN (-3017)
273 
279 #define HTTPClient_EWRONGAPIPARAMETER (-3018)
280 
288 #define HTTPClient_EHOSTHEADERALREADYEXIST (-3019)
289 
295 #define HTTPClient_ENOCONNECTION (-3020)
296 
303 #define HTTPClient_ENOTABSOLUTEURI (-3021)
304 
310 #define HTTPClient_ECANTCREATESECATTRIB (-3022)
311 
312  /* HTTP Status Codes */
317  HTTP_SC_OK = 200,
343  HTTP_SC_GONE = 410,
363 };
364 
365 
366 /* HTTPClient_connect flags */
368 #define HTTPClient_IGNORE_PROXY (0x01)
369 
370 /* If the user already added "Host:" header, set this flag */
371 #define HTTPClient_HOST_EXIST (0x02)
372 
373 /* HTTPClient_setHeader flags */
375 #define HTTPClient_HFIELD_NOT_PERSISTENT (0x01)
376 
378 #define HTTPClient_HFIELD_PERSISTENT (0x02)
379 
380 /* HTTPClient_sendRequest flags */
382 #define HTTPClient_CHUNK_START (0x01)
383 
385 #define HTTPClient_CHUNK_END (0x02)
386 
388 #define HTTPClient_DROP_BODY (0x04)
389 
390 
391 /* HTTP Request Methods */
392 extern const char *HTTP_METHOD_GET;
393 extern const char *HTTP_METHOD_POST;
394 extern const char *HTTP_METHOD_HEAD;
395 extern const char *HTTP_METHOD_OPTIONS;
396 extern const char *HTTP_METHOD_PUT;
397 extern const char *HTTP_METHOD_DELETE;
398 extern const char *HTTP_METHOD_CONNECT;
399 
400 /* structure user need to use for security */
402 {
403  const char *privateKey; /* Private key */
404  const char *clientCert; /* Client certificate */
405  const char *rootCa; /* Root CA */
407 
426 typedef int16_t (*HTTPClient_authenticationCallback)(const char *serverAuthBuff, uint32_t serverAuthLen, char *clientAuthBuff, uint32_t *clientAuthLen);
427 
428 typedef void *HTTPClient_Handle;
429 
440 HTTPClient_Handle HTTPClient_create(int16_t * status, void *params);
441 
450 int16_t HTTPClient_destroy(HTTPClient_Handle client);
451 
468 int16_t HTTPClient_connect(HTTPClient_Handle client, const char *hostName, HTTPClient_extSecParams *exSecParams, uint32_t flags);
469 
477 int16_t HTTPClient_disconnect(HTTPClient_Handle client);
478 
479 
520 int16_t HTTPClient_sendRequest(HTTPClient_Handle client, const char *method,const char *requestURI, const char *body, uint32_t bodyLen, uint32_t flags);
521 
543 int16_t HTTPClient_readResponseBody(HTTPClient_Handle client, char *body, uint32_t bodyLen, bool *moreDataFlag);
544 
569 int16_t HTTPClient_setHeader(HTTPClient_Handle client, uint32_t option, void *value, uint32_t len, uint32_t flags);
570 
600 int16_t HTTPClient_setHeaderByName(HTTPClient_Handle client, uint32_t option, const char *name, void *value, uint32_t len, uint32_t flags);
601 
621 int16_t HTTPClient_getHeader(HTTPClient_Handle client, uint32_t option, void *value, uint32_t *len, uint32_t flags);
622 
644 int16_t HTTPClient_setOpt(HTTPClient_Handle client, uint32_t option, void *value, uint32_t len, uint32_t flags);
645 
665 int16_t HTTPClient_getOpt(HTTPClient_Handle client, uint32_t option, void *value, uint32_t *len ,uint32_t flags);
666 
672 void HTTPClient_setProxy(const SlNetSock_Addr_t *addr);
673 
675 #ifdef __cplusplus
676 }
677 #endif
678 
679 #endif
Definition: httpclient.h:333
const char * HTTP_METHOD_HEAD
Definition: httpclient.h:338
const char * HTTP_METHOD_GET
Definition: httpclient.h:326
Definition: httpclient.h:319
int16_t HTTPClient_connect(HTTPClient_Handle client, const char *hostName, HTTPClient_extSecParams *exSecParams, uint32_t flags)
Open a connection to an HTTP server. A user can connect to a HTTP server using TLS,proxy or both.
Definition: httpclient.h:323
Definition: httpclient.h:339
Definition: httpclient.h:360
Definition: httpclient.h:329
int16_t HTTPClient_destroy(HTTPClient_Handle client)
Destroy the HTTP client instance and free the previously allocated instance object.
struct HTTPClient_extSecParams HTTPClient_extSecParams
int16_t HTTPClient_getOpt(HTTPClient_Handle client, uint32_t option, void *value, uint32_t *len, uint32_t flags)
Getting HTTP Client configurations.
Definition: httpclient.h:340
Definition: httpclient.h:324
Definition: httpclient.h:320
HTTP_STATUS_CODE
Definition: httpclient.h:313
int16_t HTTPClient_disconnect(HTTPClient_Handle client)
Disconnect from the HTTP server.
Definition: httpclient.h:335
Definition: httpclient.h:351
const char * HTTP_METHOD_OPTIONS
Definition: httpclient.h:322
Definition: httpclient.h:334
Definition: httpclient.h:358
IpV4 socket address.
Definition: slnetsock.h:653
Definition: httpclient.h:357
Definition: httpclient.h:321
int16_t HTTPClient_sendRequest(HTTPClient_Handle client, const char *method, const char *requestURI, const char *body, uint32_t bodyLen, uint32_t flags)
Make an HTTP request to the HTTP server.
int16_t HTTPClient_setOpt(HTTPClient_Handle client, uint32_t option, void *value, uint32_t len, uint32_t flags)
Setting HTTP Client configurations.
Definition: httpclient.h:341
const char * clientCert
Definition: httpclient.h:404
const char * HTTP_METHOD_CONNECT
Definition: httpclient.h:348
const char * HTTP_METHOD_DELETE
Definition: httpclient.h:328
Definition: httpclient.h:349
int16_t HTTPClient_getHeader(HTTPClient_Handle client, uint32_t option, void *value, uint32_t *len, uint32_t flags)
Getting HTTP Client Header-field configurations.
Definition: httpclient.h:362
Definition: httpclient.h:343
Definition: httpclient.h:318
Definition: httpclient.h:356
Definition: httpclient.h:317
void HTTPClient_setProxy(const SlNetSock_Addr_t *addr)
Set the proxy address.
int16_t HTTPClient_setHeaderByName(HTTPClient_Handle client, uint32_t option, const char *name, void *value, uint32_t len, uint32_t flags)
Setting HTTP Client Header-field configurations by header name. Both standard (as defined by the HTTP...
Definition: httpclient.h:350
void * HTTPClient_Handle
Definition: httpclient.h:428
Definition: httpclient.h:342
int16_t HTTPClient_setHeader(HTTPClient_Handle client, uint32_t option, void *value, uint32_t len, uint32_t flags)
Setting HTTP Client Header-field configurations.
Definition: httpclient.h:355
HTTPClient_Handle HTTPClient_create(int16_t *status, void *params)
Allocate and initialize a new HTTPClient instance object and return its handle.
int16_t HTTPClient_readResponseBody(HTTPClient_Handle client, char *body, uint32_t bodyLen, bool *moreDataFlag)
Read the response body data from the HTTP server The function handles both oneshot and chunked body r...
Definition: httpclient.h:331
const char * privateKey
Definition: httpclient.h:403
const char * rootCa
Definition: httpclient.h:405
Definition: httpclient.h:327
Definition: httpclient.h:346
Definition: httpclient.h:330
Definition: httpclient.h:314
const char * HTTP_METHOD_PUT
const char * HTTP_METHOD_POST
Definition: httpclient.h:352
Definition: httpclient.h:353
Definition: httpclient.h:401
Definition: httpclient.h:344
Definition: httpclient.h:359
Definition: httpclient.h:336
Definition: httpclient.h:315
Definition: httpclient.h:345
Definition: httpclient.h:347
Definition: httpclient.h:337
int16_t(* HTTPClient_authenticationCallback)(const char *serverAuthBuff, uint32_t serverAuthLen, char *clientAuthBuff, uint32_t *clientAuthLen)
HTTPClient callback for server authentication handling This function is responsible for generating th...
Definition: httpclient.h:426
© Copyright 1995-2018, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale