HTTP Client Library: D:/CC3xxx/CC3100/CC3100 SDK/CC3100 1.1.0/sdk/netapps/http/client/httpcli.h Source File

TI HTTP Client Library

httpcli.h
1 /*
2  * Copyright (c) 2014, 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  */
32 
247 #ifndef _HTTPCli_H_
248 #define _HTTPCli_H_
249 
252 #ifdef __cplusplus
253 extern "C" {
254 #endif /* __cplusplus */
255 
256 #include <stdbool.h>
257 #include <http/client/httpstd.h>
258 #include <http/client/network.h>
259 #include <http/client/ssock.h>
260 
261 #ifndef HTTPCli_BUF_LEN
262 #define HTTPCli_BUF_LEN 128
263 #endif /* HTTPCLI_BUF_LEN */
264 
265 #ifndef HTTPCli_CERT_NAME_LEN
266 #define HTTPCli_CERT_NAME_LEN 16
267 #endif
268 
269 /* HTTP Client Error Codes */
273 #define HTTPCli_ESOCKETFAIL (-101)
274 
278 #define HTTPCli_ECONNECTFAIL (-102)
279 
283 #define HTTPCli_ESENDFAIL (-103)
284 
288 #define HTTPCli_ERECVFAIL (-104)
289 
293 #define HTTPCli_ETLSFAIL (-105)
294 
298 #define HTTPCli_EHOSTNAME (-106)
299 
303 #define HTTPCli_ESENDBUFSMALL (-107)
304 
308 #define HTTPCli_ERECVBUFSMALL (-108)
309 
313 #define HTTPCli_EASYNCMODE (-109)
314 
318 #define HTTPCli_ETHREADFAIL (-110)
319 
323 #define HTTPCli_EPROXYTUNNELFAIL (-111)
324 
328 #define HTTPCli_ERESPONSEINVALID (-112)
329 
333 #define HTTPCli_ECONTENTLENLARGE (-114)
334 
338 #define HTTPCli_EREDIRECTURILONG (-115)
339 
343 #define HTTPCli_ECONTENTTYPELONG (-116)
344 
348 #define HTTPCli_ENOCONTENTCALLBACK (-117)
349 
353 #define HTTPCli_ENOTCHUNKDATA (-118)
354 
358 #define HTTPCli_EINPROGRESS (-119)
359 
363 #define HTTPCli_EINTERNALBUFSMALL (-120)
364 
368 #define HTTPCli_ESETNOTIFYFAIL (-121)
369 
373 #define HTTPCli_EURILENLONG (-120)
374 
375 /* HTTP methods */
376 #define HTTPCli_METHOD_GET "GET"
377 #define HTTPCli_METHOD_POST "POST"
378 #define HTTPCli_METHOD_HEAD "HEAD"
379 #define HTTPCli_METHOD_OPTIONS "OPTIONS"
380 #define HTTPCli_METHOD_PUT "PUT"
381 #define HTTPCli_METHOD_DELETE "DELETE"
382 #define HTTPCli_METHOD_CONNECT "CONNECT"
383 
384 /* HTTP Request Field Name */
385 #define HTTPCli_FIELD_NAME_ACCEPT "Accept"
386 #define HTTPCli_FIELD_NAME_ACCEPT_CHARSET "Accept-Charset"
387 #define HTTPCli_FIELD_NAME_ACCEPT_ENCODING "Accept-Encoding"
388 #define HTTPCli_FIELD_NAME_ACCEPT_LANGUAGE "Accept-Language"
389 #define HTTPCli_FIELD_NAME_ACCEPT_RANGES "Accept-Ranges"
390 #define HTTPCli_FIELD_NAME_AGE "Age"
391 #define HTTPCli_FIELD_NAME_ALLOW "Allow"
392 #define HTTPCli_FIELD_NAME_AUTHORIZATION "Authorization"
393 #define HTTPCli_FIELD_NAME_CACHE_CONTROL "Cache-Control"
394 #define HTTPCli_FIELD_NAME_CONNECTION "Connection"
395 #define HTTPCli_FIELD_NAME_CONTENT_ENCODING "Content-Encoding"
396 #define HTTPCli_FIELD_NAME_CONTENT_LANGUAGE "Content-Language"
397 #define HTTPCli_FIELD_NAME_CONTENT_LENGTH "Content-Length"
398 #define HTTPCli_FIELD_NAME_CONTENT_LOCATION "Content-Location"
399 #define HTTPCli_FIELD_NAME_CONTENT_MD5 "Content-MD5"
400 #define HTTPCli_FIELD_NAME_CONTENT_RANGE "Content-Range"
401 #define HTTPCli_FIELD_NAME_CONTENT_TYPE "Content-Type"
402 #define HTTPCli_FIELD_NAME_COOKIE "Cookie"
403 #define HTTPCli_FIELD_NAME_DATE "Date"
404 #define HTTPCli_FIELD_NAME_ETAG "ETag"
405 #define HTTPCli_FIELD_NAME_EXPECT "Expect"
406 #define HTTPCli_FIELD_NAME_EXPIRES "Expires"
407 #define HTTPCli_FIELD_NAME_FROM "From"
408 #define HTTPCli_FIELD_NAME_HOST "Host"
409 #define HTTPCli_FIELD_NAME_IF_MATCH "If-Match"
410 #define HTTPCli_FIELD_NAME_IF_MODIFIED_SINCE "If-Modified-Since"
411 #define HTTPCli_FIELD_NAME_IF_NONE_MATCH "If-None-Match"
412 #define HTTPCli_FIELD_NAME_IF_RANGE "If-Range"
413 #define HTTPCli_FIELD_NAME_IF_UNMODIFIED_SINCE "If-Unmodified-Since"
414 #define HTTPCli_FIELD_NAME_LAST_MODIFIED "Last-Modified"
415 #define HTTPCli_FIELD_NAME_LOCATION "Location"
416 #define HTTPCli_FIELD_NAME_MAX_FORWARDS "Max-Forwards"
417 #define HTTPCli_FIELD_NAME_ORIGIN "Origin"
418 #define HTTPCli_FIELD_NAME_PRAGMA "Pragma"
419 #define HTTPCli_FIELD_NAME_PROXY_AUTHENTICATE "Proxy-Authenticate"
420 #define HTTPCli_FIELD_NAME_PROXY_AUTHORIZATION "Proxy-Authorization"
421 #define HTTPCli_FIELD_NAME_RANGE "Range"
422 #define HTTPCli_FIELD_NAME_REFERER "Referer"
423 #define HTTPCli_FIELD_NAME_RETRY_AFTER "Retry-After"
424 #define HTTPCli_FIELD_NAME_SERVER "Server"
425 #define HTTPCli_FIELD_NAME_TE "TE"
426 #define HTTPCli_FIELD_NAME_TRAILER "Trailer"
427 #define HTTPCli_FIELD_NAME_TRANSFER_ENCODING "Transfer-Encoding"
428 #define HTTPCli_FIELD_NAME_UPGRADE "Upgrade"
429 #define HTTPCli_FIELD_NAME_USER_AGENT "User-Agent"
430 #define HTTPCli_FIELD_NAME_VARY "Vary"
431 #define HTTPCli_FIELD_NAME_VIA "Via"
432 #define HTTPCli_FIELD_NAME_WWW_AUTHENTICATE "WWW-Authenticate"
433 #define HTTPCli_FIELD_NAME_WARNING "Warning"
434 #define HTTPCli_FIELD_NAME_X_FORWARDED_FOR "X-Forwarded-For"
435 
436 /* HTTP client instance configuration */
437 #define HTTPCli_TYPE_TLS (0x02)
438 #define HTTPCli_TYPE_IPV6 (0x04)
439 
440 /* HTTP client getResponseField() special return codes */
441 #define HTTPCli_FIELD_ID_DUMMY (-11)
442 #define HTTPCli_FIELD_ID_END (-12)
443 
447 typedef struct HTTPCli_Field {
448  const char *name;
449  const char *value;
450 } HTTPCli_Field;
451 
460 typedef void (*HTTPCli_StatusCallback)(void *cli, int status);
461 
465 typedef struct HTTPCli_StatusHandler {
470 
486 typedef int (*HTTPCli_ContentCallback)(void *cli, int status, char *body,
487  int len, bool moreFlag);
488 
492 typedef struct HTTPCli_ContentHandler {
493  char *contentType;
496 
506 typedef void (*HTTPCli_RedirectCallback)(void *cli, int status, char *uri);
507 
516 typedef void (*HTTPCli_Notify)(long skt, void *cli);
517 
521 typedef struct HTTPCli_Struct {
522  char **respFields;
523  unsigned int state;
524  unsigned long clen;
525  Ssock_Struct ssock;
526  HTTPCli_Field *fields;
527 
528  char buf[HTTPCli_BUF_LEN];
529  unsigned int buflen;
530  char *bufptr;
531 
532 #ifndef HTTPCli_LIBTYPE_MIN
533  HTTPCli_StatusHandler *shandle;
534  HTTPCli_ContentHandler *chandle;
535  HTTPCli_RedirectCallback rhandle;
536 #ifndef __linux__
537  unsigned int stackSize;
538  unsigned int priority;
539 #endif /* __linux__ */
540 #endif /* HTTPCli_LIBTYPE_MIN */
541 
543 
547 typedef struct HTTPCli_Params {
548 
549 #ifndef HTTPCli_LIBTYPE_MIN
550  HTTPCli_StatusHandler *shandle;
551  HTTPCli_ContentHandler *chandle;
552  HTTPCli_RedirectCallback rhandle;
553 #ifndef __linux__
554  unsigned int stackSize;
555  unsigned int priority;
556 #endif /* __linux__ */
557 #endif /* HTTPCli_LIBTYPE_MIN */
558 
559 #ifdef __SLP__
560  HTTPCli_Notify rnotify;
561  HTTPCli_Notify wnotify;
562  HTTPCli_Notify enotify;
563 #endif /* __SLP__ */
564 
565  int timeout;
569 
573 typedef struct HTTPCli_SecureParams {
574 #ifdef __CYASSL__
575  CYASSL_CTX *ctx; /* CYASSL context */
576 
577 #elif defined(__SL__) /* __CYASSL__ */
578  SlSockSecureMethod method;
579  SlSockSecureMask mask;
580  char cafile[HTTPCli_CERT_NAME_LEN];
582  char privkey[HTTPCli_CERT_NAME_LEN];
584  char cert[HTTPCli_CERT_NAME_LEN];
586  char dhkey[HTTPCli_CERT_NAME_LEN];
589 #else /* __CYASSL__ */
590  char s;
591 
592 #endif /* __CYASSL__ */
594 
596 
616 extern int HTTPCli_initSockAddr(struct sockaddr *addr, const char *uri,
617  int flags);
618 
624 extern void HTTPCli_construct(HTTPCli_Struct *cli);
625 
631 extern HTTPCli_Handle HTTPCli_create();
632 
648 extern int HTTPCli_connect(HTTPCli_Struct *cli, const struct sockaddr *addr,
649  int flags, const HTTPCli_Params *params);
650 
657 extern void HTTPCli_delete(HTTPCli_Handle cli);
658 
664 extern void HTTPCli_destruct(HTTPCli_Struct *cli);
665 
671 extern void HTTPCli_disconnect(HTTPCli_Struct *cli);
672 
686 extern HTTPCli_Field *HTTPCli_setRequestFields(HTTPCli_Handle cli,
687  const HTTPCli_Field *fields);
688 
702 extern char **HTTPCli_setResponseFields(HTTPCli_Handle cli,
703  const char *fields[]);
704 
728 extern int HTTPCli_sendRequest(HTTPCli_Handle cli, const char *method,
729  const char *requestURI, bool moreFlag);
730 
748 extern int HTTPCli_sendField(HTTPCli_Handle cli, const char *name,
749  const char *value, bool lastFlag);
750 
765 extern int HTTPCli_sendRequestBody(HTTPCli_Handle cli, const char *body,
766  int len);
767 
779 extern int HTTPCli_getResponseStatus(HTTPCli_Handle cli);
780 
804 extern int HTTPCli_getResponseField(HTTPCli_Handle cli, char *value,
805  int len, bool *moreFlag);
806 
827 extern int HTTPCli_readResponseBody(HTTPCli_Handle cli, char *body,
828  int len, bool *moreFlag);
829 
846 extern int HTTPCli_readRawResponseBody(HTTPCli_Handle cli, char *body, int len);
847 
853 extern void HTTPCli_setSecureParams(HTTPCli_SecureParams *sparams);
854 
860 extern void HTTPCli_setProxy(const struct sockaddr *addr);
861 
862 #ifdef __cplusplus
863 }
864 #endif /* __cplusplus */
865 
867 #endif /* _HTTPCli_H_ */
struct HTTPCli_Struct HTTPCli_Struct
HTTPCli instance type.
HTTPCli_ContentCallback handle
Definition: httpcli.h:494
HTTPCli secure parameters for TLS.
Definition: httpcli.h:573
void HTTPCli_construct(HTTPCli_Struct *cli)
Create a new instance object in the provided structure.
void HTTPCli_delete(HTTPCli_Handle cli)
Destory the HTTP client instance and free the previously allocated instance object.
Definition: httpcli.c:1374
struct HTTPCli_StatusHandler HTTPCli_StatusHandler
HTTPCli Response status code handlers.
int HTTPCli_initSockAddr(struct sockaddr *addr, const char *uri, int flags)
Initialize the socket address structure for the given URI. Supported URI formats are: "http://www...
Definition: httpcli.c:1072
HTTPCli Request Header Field.
Definition: httpcli.h:447
HTTPCli_StatusCallback handle1xx
Definition: httpcli.h:466
unsigned int priority
Definition: httpcli.h:555
HTTPCli Content Handler type.
Definition: httpcli.h:492
struct HTTPCli_SecureParams HTTPCli_SecureParams
HTTPCli secure parameters for TLS.
int HTTPCli_getResponseStatus(HTTPCli_Handle cli)
Process the response header from the HTTP server and return status.
Definition: httpcli.c:1568
struct HTTPCli_Params HTTPCli_Params
HTTPCli instance paramaters.
HTTPCli_Field * HTTPCli_setRequestFields(HTTPCli_Handle cli, const HTTPCli_Field *fields)
Set an array of header fields to be sent for every HTTP request.
Definition: httpcli.c:1429
int HTTPCli_sendRequestBody(HTTPCli_Handle cli, const char *body, int len)
Send the request message body to the HTTP server.
Definition: httpcli.c:1551
unsigned int stackSize
Definition: httpcli.h:554
int HTTPCli_readRawResponseBody(HTTPCli_Handle cli, char *body, int len)
Read the raw response message body from the HTTP server.
Definition: httpcli.c:1707
HTTPCli instance type.
Definition: httpcli.h:521
#define HTTPCli_BUF_LEN
Definition: httpcli.h:262
int(* HTTPCli_ContentCallback)(void *cli, int status, char *body, int len, bool moreFlag)
HTTPCli callback function prototype for content handling.
Definition: httpcli.h:486
Definition: ssock.h:63
int timeout
Definition: httpcli.h:565
int HTTPCli_sendRequest(HTTPCli_Handle cli, const char *method, const char *requestURI, bool moreFlag)
Make a HTTP 1.1 request to the HTTP server.
Definition: httpcli.c:1474
int HTTPCli_connect(HTTPCli_Struct *cli, const struct sockaddr *addr, int flags, const HTTPCli_Params *params)
Open a connection to a HTTP server.
Definition: httpcli.c:1174
struct HTTPCli_Field HTTPCli_Field
HTTPCli Request Header Field.
void(* HTTPCli_RedirectCallback)(void *cli, int status, char *uri)
HTTPCli callback function prototype for redirection handling.
Definition: httpcli.h:506
int HTTPCli_sendField(HTTPCli_Handle cli, const char *name, const char *value, bool lastFlag)
Send a header field to the HTTP server.
Definition: httpcli.c:1515
void HTTPCli_destruct(HTTPCli_Struct *cli)
Destory the HTTP client instance.
Definition: httpcli.c:1386
HTTPCli_StatusCallback handle2xx
Definition: httpcli.h:467
int HTTPCli_readResponseBody(HTTPCli_Handle cli, char *body, int len, bool *moreFlag)
Read the parsed response body data from the HTTP server.
Definition: httpcli.c:1677
void HTTPCli_setSecureParams(HTTPCli_SecureParams *sparams)
Set the secure communication paramaters.
Definition: httpcli.c:1464
char * contentType
Definition: httpcli.h:493
HTTPCli_StatusCallback handle4xx
Definition: httpcli.h:468
void HTTPCli_setProxy(const struct sockaddr *addr)
Set the proxy address.
Definition: httpcli.c:1725
char ** HTTPCli_setResponseFields(HTTPCli_Handle cli, const char *fields[])
Set the header fields to filter the response headers.
Definition: httpcli.c:1447
void(* HTTPCli_StatusCallback)(void *cli, int status)
HTTPCli callback function prototype for status handling.
Definition: httpcli.h:460
const char * value
Definition: httpcli.h:449
const char * name
Definition: httpcli.h:448
HTTPCli instance paramaters.
Definition: httpcli.h:547
struct HTTPCli_ContentHandler HTTPCli_ContentHandler
HTTPCli Content Handler type.
void HTTPCli_disconnect(HTTPCli_Struct *cli)
Disconnect from the HTTP server and destroy the HTTP client instance.
Definition: httpcli.c:1413
HTTPCli_Handle HTTPCli_create()
Allocate and initialize a new instance object and return its handle.
Definition: httpcli.c:1359
HTTPCli Response status code handlers.
Definition: httpcli.h:465
int HTTPCli_getResponseField(HTTPCli_Handle cli, char *value, int len, bool *moreFlag)
Process the response header from the HTTP server and return field.
Definition: httpcli.c:1588
void(* HTTPCli_Notify)(long skt, void *cli)
HTTPCli callback function prototype for asynchronous notify Supported for 6LoWPAN stack only...
Definition: httpcli.h:516
Generated on Tue Jan 13 2015 14:42:03 for HTTP Client Library by   doxygen 1.8.9.1