AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Types | Public Member Functions | Static Public Member Functions | List of all members
alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper Class Reference

#include <CurlEasyHandleWrapper.h>

Public Types

enum  TransferType { TransferType::kGET, TransferType::kPOST, TransferType::kPUT }
 
using CurlCallback = size_t(*)(char *buffer, size_t blockSize, size_t numBlocks, void *userData)
 
using CurlDebugCallback = int(*)(CURL *handle, curl_infotype infoType, char *buffer, size_t blockSize, void *userData)
 

Public Member Functions

 CurlEasyHandleWrapper (std::string id="")
 
 ~CurlEasyHandleWrapper ()
 
bool reset (std::string id="")
 
CURL * getCurlHandle ()
 
bool isValid ()
 
std::string getId () const
 
bool addHTTPHeader (const std::string &header)
 
bool addPostHeader (const std::string &header)
 
bool setURL (const std::string &url)
 
bool setTransferType (TransferType type)
 
bool setTransferTimeout (const long timeoutSeconds)
 
bool setPostData (const std::string &data)
 
bool setConnectionTimeout (const std::chrono::seconds timeoutSeconds)
 
bool setWriteCallback (CurlCallback callback, void *userData)
 
bool setHeaderCallback (CurlCallback callback, void *userData)
 
bool setReadCallback (CurlCallback callback, void *userData)
 
std::string urlEncode (const std::string &in) const
 
long getHTTPResponseCode ()
 
std::string getEffectiveUrl ()
 
CURLcode perform ()
 
CURLcode pause (int mask)
 
CurlEasyHandleWrapperOptionsSettingAdaptercurlOptionsSetter ()
 

Static Public Member Functions

static void setInterfaceName (const std::string &interfaceName)
 
static std::string getInterfaceName ()
 

Detailed Description

Class to allocate and configure a curl easy handle

Member Typedef Documentation

◆ CurlCallback

using alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::CurlCallback = size_t (*)(char* buffer, size_t blockSize, size_t numBlocks, void* userData)

Callbacks to libcurl typically follow the below pattern. size_t callback(char* buffer, size_t blockSize, size_t numBlocks, void* userData)

Parameters
bufferA pointer to the data buffer to either read or write to
blockSizeThe size of a "block" of data (ala fwrite)
numBlocksThe number of "blocks" to read or write
userDataSome user data passed in with CURLOPT_XDATA (where X = READ, WRITE, or HEADER)

◆ CurlDebugCallback

using alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::CurlDebugCallback = int (*)(CURL* handle, curl_infotype infoType, char* buffer, size_t blockSize, void* userData)

Debug Callbacks to libcurl typically follow the below pattern. size_t callback(CURL* handle, curl_infotype infoType, char *buffer, size_t blockSize, void *userData)

Parameters
handleThe CURL handle
handleThe CURL info type
bufferA pointer to the data buffer to either read or write to
blockSizeThe size of a "block" of data (ala fwrite)
userDataSome user data passed in with CURLOPT_DEBUGDATA

Member Enumeration Documentation

◆ TransferType

Definitions for HTTP action types

Enumerator
kGET 

HTTP GET.

kPOST 

HTTP POST.

kPUT 

HTTP PUT.

Constructor & Destructor Documentation

◆ CurlEasyHandleWrapper()

alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::CurlEasyHandleWrapper ( std::string  id = "")

Default constructor, optionally passing in an explicit Id.

Parameters
idname to use to identify this handle. If none provided, an automatically generated one will be assigned.

◆ ~CurlEasyHandleWrapper()

alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::~CurlEasyHandleWrapper ( )

Destructor

Member Function Documentation

◆ addHTTPHeader()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::addHTTPHeader ( const std::string &  header)

◆ addPostHeader()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::addPostHeader ( const std::string &  header)

◆ curlOptionsSetter()

CurlEasyHandleWrapperOptionsSettingAdapter& alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::curlOptionsSetter ( )

◆ getCurlHandle()

CURL* alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::getCurlHandle ( )

Used to get the underlying CURL easy handle. The handle returned may be a nullptr

Returns
The associated libcurl easy handle

◆ getEffectiveUrl()

std::string alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::getEffectiveUrl ( )

Get the effective URL.

Note
In cases where CURLOPT_FOLLOWLOCATION is used, CURL follows the url it receives in the location header of the response until it reaches a URL with no location header. This last used url is the effective URL.
Returns
The effective URL string.

◆ getHTTPResponseCode()

long alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::getHTTPResponseCode ( )

Get the HTTP response code.

Returns
The HTTP response code.

◆ getId()

std::string alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::getId ( ) const

Get the ID for this handle.

Returns
The ID for this handle.

◆ getInterfaceName()

static std::string alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::getInterfaceName ( )
static

Static function to get the network interface.

Returns
the current network interface, otherwise an empty string.

◆ isValid()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::isValid ( )

Used to check if curl is correctly initialized

Returns
true if curl handler is valid

◆ pause()

CURLcode alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::pause ( int  mask)

Call curl_easy_pause() for this handle.

Parameters
maskThe mask value to pass through to curl_easy_pause().
See also
https://curl.haxx.se/libcurl/c/curl_easy_pause.html
Returns
The CURL response code.

◆ perform()

CURLcode alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::perform ( )

Perform whatever has been setup in the handle.

Returns
The CURL response code.

◆ reset()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::reset ( std::string  id = "")

Resets an allocated easy handle for re-use in another transfer Calls curl_easy_reset on the curl easy handle Frees and sets the following members to nullptr:

  • HTTP headers
  • POST headers
  • CURL post form
Parameters
idname to use to identify this handle. If none provided, an automatically generated one will be assigned.
Returns
Whether the reset was successful

◆ setConnectionTimeout()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::setConnectionTimeout ( const std::chrono::seconds  timeoutSeconds)

Sets how long the stream should take, in seconds, to establish a connection. If not set explicitly there is no timeout.

Parameters
timeoutSecondsThe amount of time, in seconds, establishing a connection should take. Set to 0 to disable a timeout.
Returns
Whether setting the timeout was successful

◆ setHeaderCallback()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::setHeaderCallback ( CurlCallback  callback,
void *  userData 
)

Sets the callback to call when libcurl has HTTP header data available NOTE: Each header line is provided individually

Parameters
callbackA function pointer to the callback
userDataAny data to be passed to the callback
Returns
Whether the addition was successful

◆ setInterfaceName()

static void alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::setInterfaceName ( const std::string &  interfaceName)
static

Static function to set the network interface to be used for the curl connection.

Network interface provided will be used in preference over the value in provided in config. Set emtpy string to reset to default.

Note
The network interace set shall applied only to newly instantiated CurlEasyHandleWrapper objects.
Parameters
valueThe interface name as defined in CURLOPT_INTERFACE.

◆ setPostData()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::setPostData ( const std::string &  data)

Sets the data to be sent in the next POST operation.

Parameters
dataString buffer to the full data to send in a HTTP POST operation.
Returns
Whether the operation was successful.

◆ setReadCallback()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::setReadCallback ( CurlCallback  callback,
void *  userData 
)

Sets the callback to call when libcurl requires data to POST

Parameters
callbackA function pointer to the callback
userDataAny data to be passed to the callback
Returns
Whether the addition was successful

◆ setTransferTimeout()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::setTransferTimeout ( const long  timeoutSeconds)

Sets a timeout, in seconds, for how long the stream transfer is allowed to take. If not set explicitly, there will be no timeout.

Parameters
timeoutSecondsThe amount of time in seconds the stream can take. Set to 0 to disable a timeout.
Returns
Whether setting the timeout was succesful

◆ setTransferType()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::setTransferType ( TransferType  type)

Sets the HTTP action to perform.

Parameters
typeThe action to perform
Returns
true if the setting was successful

◆ setURL()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::setURL ( const std::string &  url)

Set the request URL. No validation is done at this stage

Parameters
urlThe required URL
Returns
true if setting was successful

◆ setWriteCallback()

bool alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::setWriteCallback ( CurlCallback  callback,
void *  userData 
)

Sets the callback to call when libcurl has response data to consume

Parameters
callbackA function pointer to the callback
userDataAny data to be passed to the callback
Returns
Whether the addition was successful

◆ urlEncode()

std::string alexaClientSDK::avsCommon::utils::libcurlUtils::CurlEasyHandleWrapper::urlEncode ( const std::string &  in) const

URL encode a string.

Parameters
inThe string to encode.
Returns
The encoded string.

The documentation for this class was generated from the following file:

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0