e0dcfa0c55
* Remove multiple newlines at the end of file * Remove the white space from the end of line
323 lines
10 KiB
C
323 lines
10 KiB
C
/****************************************************************************
|
|
* apps/include/netutils/curl4nx.h
|
|
*
|
|
* This file is part of the NuttX RTOS:
|
|
*
|
|
* Copyright (C) 2019 Sebastien Lorquet. All rights reserved.
|
|
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
* may be used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*
|
|
****************************************************************************/
|
|
|
|
#ifndef __APPS_INCLUDE_NETUTILS_CURL4NX_H
|
|
#define __APPS_INCLUDE_NETUTILS_CURL4NX_H
|
|
|
|
/****************************************************************************
|
|
* Included Files
|
|
****************************************************************************/
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
/****************************************************************************
|
|
* Public Defines
|
|
****************************************************************************/
|
|
|
|
enum curl4nxerrors_e
|
|
{
|
|
CURL4NXE_OK,
|
|
CURL4NXE_UNSUPPORTED_PROTOCOL,
|
|
CURL4NXE_FAILED_INIT,
|
|
CURL4NXE_URL_MALFORMAT,
|
|
CURL4NXE_NOT_BUILT_IN,
|
|
CURL4NXE_COULDNT_RESOLVE_HOST,
|
|
CURL4NXE_COULDNT_CONNECT,
|
|
CURL4NXE_HTTP2,
|
|
CURL4NXE_PARTIAL_FILE,
|
|
CURL4NXE_HTTP_RETURNED_ERROR,
|
|
CURL4NXE_WRITE_ERROR,
|
|
CURL4NXE_UPLOAD_FAILED,
|
|
CURL4NXE_READ_ERROR,
|
|
CURL4NXE_OUT_OF_MEMORY,
|
|
CURL4NXE_OPERATION_TIMEDOUT,
|
|
CURL4NXE_RANGE_ERROR,
|
|
CURL4NXE_HTTP_POST_ERROR,
|
|
CURL4NXE_SSL_CONNECT_ERROR,
|
|
CURL4NXE_BAD_DOWNLOAD_RESUME,
|
|
CURL4NXE_FUNCTION_NOT_FOUND,
|
|
CURL4NXE_ABORTED_BY_CALLBACK,
|
|
CURL4NXE_BAD_FUNCTION_ARGUMENT,
|
|
CURL4NXE_TOO_MANY_REDIRECTS,
|
|
CURL4NXE_UNKNOWN_OPTION,
|
|
CURL4NXE_GOT_NOTHING,
|
|
CURL4NXE_SEND_ERROR,
|
|
CURL4NXE_RECV_ERROR,
|
|
CURL4NXE_SSL_CERTPROBLEM,
|
|
CURL4NXE_SSL_CIPHER,
|
|
CURL4NXE_PEER_FAILED_VERIFICATION,
|
|
CURL4NXE_BAD_CONTENT_ENCODING,
|
|
CURL4NXE_LOGIN_DENIED,
|
|
CURL4NXE_REMOTE_DISK_FULL,
|
|
CURL4NXE_REMOTE_FILE_EXISTS,
|
|
CURL4NXE_SSL_CACERT_BADFILE,
|
|
CURL4NXE_REMOTE_FILE_NOT_FOUND,
|
|
CURL4NXE_AGAIN,
|
|
CURL4NXE_SSL_ISSUER_ERROR,
|
|
CURL4NXE_CHUNK_FAILED,
|
|
CURL4NXE_SSL_PINNEDPUBKEYNOTMATCH,
|
|
CURL4NXE_SSL_INVALIDCERTSTATUS,
|
|
CURL4NXE_HTTP2_STREAM,
|
|
CURL4NXE_RECURSIVE_API_CALL,
|
|
};
|
|
|
|
enum curl4nxopt_e
|
|
{
|
|
/* Options that are currently implemented */
|
|
|
|
CURL4NXOPT_URL,
|
|
CURL4NXOPT_PORT,
|
|
CURL4NXOPT_BUFFERSIZE,
|
|
CURL4NXOPT_HEADERFUNCTION,
|
|
CURL4NXOPT_HEADERDATA,
|
|
CURL4NXOPT_FAILONERROR,
|
|
CURL4NXOPT_FOLLOWLOCATION,
|
|
CURL4NXOPT_MAXREDIRS,
|
|
CURL4NXOPT_VERBOSE,
|
|
|
|
/* Options that will be implemented */
|
|
|
|
CURL4NXOPT_HEADER,
|
|
CURL4NXOPT_NOPROGRESS,
|
|
CURL4NXOPT_WRITEFUNCTION,
|
|
CURL4NXOPT_WRITEDATA,
|
|
CURL4NXOPT_READFUNCTION,
|
|
CURL4NXOPT_READDATA,
|
|
CURL4NXOPT_XFERINFOFUNCTION,
|
|
CURL4NXOPT_XFERINFODATA,
|
|
CURL4NXOPT_KEEP_SENDING_ON_ERROR,
|
|
CURL4NXOPT_PATH_AS_IS,
|
|
CURL4NXOPT_TCP_KEEPALIVE,
|
|
CURL4NXOPT_TCP_KEEPIDLE,
|
|
CURL4NXOPT_TCP_KEEPINTVL,
|
|
CURL4NXOPT_PUT,
|
|
CURL4NXOPT_POST,
|
|
CURL4NXOPT_POSTFIELDS,
|
|
CURL4NXOPT_POSTFIELDSIZE,
|
|
CURL4NXOPT_COPYPOSTFIELDS,
|
|
CURL4NXOPT_HTTPPOST,
|
|
CURL4NXOPT_REFERER,
|
|
CURL4NXOPT_USERAGENT,
|
|
CURL4NXOPT_HTTPHEADER,
|
|
CURL4NXOPT_HEADEROPT,
|
|
CURL4NXOPT_HTTPGET,
|
|
CURL4NXOPT_HTTP_VERSION,
|
|
|
|
/* Options that will be implemented later */
|
|
|
|
CURL4NXOPT_SSL_CTX_FUNCTION,
|
|
CURL4NXOPT_SSL_CTX_DATA,
|
|
CURL4NXOPT_USERNAME,
|
|
CURL4NXOPT_PASSWORD,
|
|
CURL4NXOPT_HTTPAUTH,
|
|
CURL4NXOPT_POSTREDIR,
|
|
CURL4NXOPT_COOKIE,
|
|
CURL4NXOPT_COOKIEFILE,
|
|
CURL4NXOPT_COOKIEJAR,
|
|
CURL4NXOPT_COOKIESESSION,
|
|
CURL4NXOPT_COOKIELIST,
|
|
CURL4NXOPT_IGNORE_CONTENT_LENGTH,
|
|
CURL4NXOPT_RANGE,
|
|
CURL4NXOPT_RESUME_FROM,
|
|
CURL4NXOPT_CUSTOMREQUEST,
|
|
CURL4NXOPT_UPLOAD,
|
|
CURL4NXOPT_UPLOAD_BUFFERSIZE,
|
|
CURL4NXOPT_TIMEOUT,
|
|
CURL4NXOPT_TIMEOUT_MS,
|
|
CURL4NXOPT_FRESH_CONNECT,
|
|
CURL4NXOPT_CONNECTTIMEOUT,
|
|
CURL4NXOPT_CONNECTTIMEOUT_MS,
|
|
CURL4NXOPT_USE_SSL,
|
|
CURL4NXOPT_SSLCERT,
|
|
CURL4NXOPT_SSLKEY,
|
|
CURL4NXOPT_KEYPASSWD,
|
|
CURL4NXOPT_SSLVERSION,
|
|
CURL4NXOPT_SSL_VERIFYHOST,
|
|
CURL4NXOPT_SSL_VERIFYPEER,
|
|
CURL4NXOPT_SSL_VERIFYSTATUS,
|
|
CURL4NXOPT_CAPATH,
|
|
CURL4NXOPT_PINNEDPUBLICKEY,
|
|
CURL4NXOPT_RANDOM_FILE,
|
|
CURL4NXOPT_SSL_CIPHER_LIST,
|
|
CURL4NXOPT_TLS13_CIPHERS,
|
|
CURL4NXOPT_SSL_OPTIONS,
|
|
};
|
|
|
|
/* For CURL4NXOPT_HTTP_VERSION */
|
|
|
|
#define CURL4NX_HTTP_VERSION_1_0 0x10
|
|
#define CURL4NX_HTTP_VERSION_1_1 0x11
|
|
#define CURL4NX_HTTP_VERSION_2_0 0x20 /* Unsupported! */
|
|
|
|
/****************************************************************************
|
|
* Public Types
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Name: curl4nx_iofunction_f
|
|
*
|
|
* Description: Type of the callback function used with
|
|
* CURL4NXOPT_WRITEFUNCTION and CURL4NXOPT_READFUNCTION.
|
|
*
|
|
****************************************************************************/
|
|
|
|
typedef size_t (*curl4nx_iofunc_f)(FAR char *ptr, size_t size,
|
|
size_t nmemb, FAR void *userdata);
|
|
|
|
/****************************************************************************
|
|
* Name: curl4nx_easy_strerror()
|
|
*
|
|
* Description: Return a textual description for an error code.
|
|
*
|
|
****************************************************************************/
|
|
|
|
typedef int (*curl4nx_xferinfofunc_f)(FAR void *clientp,
|
|
uint64_t dltotal, uint64_t dlnow,
|
|
uint64_t ultotal, uint64_t ulnow);
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
/****************************************************************************
|
|
* Public Function Prototypes
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Name: curl4nx_easy_strerror()
|
|
*
|
|
* Description: Return a textual description for an error code.
|
|
*
|
|
****************************************************************************/
|
|
|
|
FAR const char *curl4nx_easy_strerror(int errornum);
|
|
|
|
/****************************************************************************
|
|
* Name: curl4nx_easy_init()
|
|
*
|
|
* Description: Initialize a context for curl4nx operations.
|
|
*
|
|
****************************************************************************/
|
|
|
|
FAR struct curl4nx_s *curl4nx_easy_init(void);
|
|
|
|
/****************************************************************************
|
|
* Name: curl4nx_easy_escape()
|
|
*
|
|
* Description: Escape an URL to remove any forbidden character. Returned
|
|
* string MUST be released using free().
|
|
*
|
|
****************************************************************************/
|
|
|
|
FAR char *curl4nx_easy_escape(FAR struct curl4nx_s *handle,
|
|
FAR const char *string, int length);
|
|
|
|
/****************************************************************************
|
|
* Name: curl4nx_easy_unescape()
|
|
*
|
|
* Description: Unescape an escaped URL to replace all escaped characters.
|
|
* Returned string MUST be released using free().
|
|
*
|
|
****************************************************************************/
|
|
|
|
FAR char *curl4nx_easy_unescape(FAR struct curl4nx_s *handle,
|
|
FAR const char *url, int inlength,
|
|
FAR int *outlength);
|
|
|
|
/****************************************************************************
|
|
* Name: curl4nx_easy_setopt()
|
|
*
|
|
* Description: Define an option in the given curl4nx context.
|
|
*
|
|
****************************************************************************/
|
|
|
|
int curl4nx_easy_setopt(FAR struct curl4nx_s *handle, int option,
|
|
FAR void *optionptr);
|
|
|
|
/****************************************************************************
|
|
* Name: curl4nx_easy_reset()
|
|
*
|
|
* Description: Reset all operations that were set using curl4nx_easy_setopt()
|
|
* to their default values.
|
|
*
|
|
****************************************************************************/
|
|
|
|
void curl4nx_easy_reset(FAR struct curl4nx_s *handle);
|
|
|
|
/****************************************************************************
|
|
* Name: curl4nx_easy_duphandle()
|
|
*
|
|
* Description: Clone the current state of a handle.
|
|
*
|
|
****************************************************************************/
|
|
|
|
FAR struct curl4nx_s *curl4nx_easy_duphandle(FAR struct curl4nx_s *handle);
|
|
|
|
/****************************************************************************
|
|
* Name: curl4nx_easy_perform()
|
|
*
|
|
* Description: Perform the http operation that was set up in this curl4nx
|
|
* context.
|
|
*
|
|
****************************************************************************/
|
|
|
|
int curl4nx_easy_perform(FAR struct curl4nx_s *handle);
|
|
|
|
/****************************************************************************
|
|
* Name: curl4nx_easy_getinfo()
|
|
*
|
|
* Description: Get information about the current transfer.
|
|
*
|
|
****************************************************************************/
|
|
|
|
int curl4nx_easy_getinfo(FAR struct curl4nx_s *handle, int info,
|
|
FAR void *infoptr);
|
|
|
|
/****************************************************************************
|
|
* Name: curl4nx_easy_cleanup()
|
|
*
|
|
* Description: Cleanup any resource allocated within a curl4nx context.
|
|
*
|
|
****************************************************************************/
|
|
|
|
void curl4nx_easy_cleanup(FAR struct curl4nx_s *handle);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* __APPS_INCLUDE_NETUTILS_BASE64_H */
|