libcurl操作接口

///************************************************************************
/// <copyrigth>2018-2019 Corporation.All Rights Reserved</copyrigth>
/// <author>yimeng</author>
/// <contact>728297725@qq.com</contact>
/// <version>v1.0.0</version>
/// <describe>
/// Offer interfaces for http and ftp operation by curl
///</describe>
/// <date>2020/5/30</date>
///***********************************************************************
#ifndef ILIBCURL_H
#define ILIBCURL_H

#include <string>
#include <vector>

// It must be same as your dll file's name if you change your dll file name and change here,too
#define LIBCURL_DLL_NAME "LibCurl.dll"

typedef int(*UploadProgress)(void* pUserData,
    double TotalToUpload,
    double NowUpload);

typedef int(*DownLoadProgress)(void* pUserData,
    double TotalToDown,
    double NowDownload);

struct FileInfo
{
    // File path
    std::string strFilePath;

    // File name
    std::string strFileName;

    // Is directory or file
    bool bIsDirectory;

    // File permission
    std::string strFilePermission;
};

class ILibCurl
{
public:
    // Detructe the ILibCurl
    virtual ~ILibCurl() {    }

public:
    ///************************************************************************
    /// <summary>
    /// Set time out
    /// </summary>
    /// <param name=int iSeconds>Timeout(s)</param>
    /// <returns></returns>
    /// <remarks>
    /// Note: it is for one time curl request setting
    /// </remarks>
    ///***********************************************************************
    virtual void SetTimeout(int iSeconds = 60) = 0;

    ///************************************************************************
    /// <summary>
    /// Set try count
    /// </summary>
    /// <param name=int iCount>Try count if operation failed</param>
    /// <returns></returns>
    /// <remarks>
    /// Note: it is for one time curl request setting
    /// </remarks>
    ///***********************************************************************
    virtual void SetTryCount(int iCount = 3) = 0;

    ///************************************************************************
    /// <summary>
    /// Get the current libcurl version
    /// </summary>
    /// <returns></returns>
    /// <remarks>
    /// none
    /// </remarks>
    ///***********************************************************************
    virtual std::string GetCurVersion() = 0;

    ///************************************************************************
    /// <summary>
    /// Set upload callback function
    /// </summary>
    /// <param name=UploadProgress pUploadFunc>User callback funtion</param>
    /// <param name=void * pUserData>User's data</param>
    /// <returns></returns>
    /// <remarks>
    /// Note: you can get upload progress by this callback function
    /// </remarks>
    ///***********************************************************************
    virtual void SetUploadFunc(UploadProgress pUploadFunc = NULL, void* pUserData = NULL) = 0;

    ///************************************************************************
    /// <summary>
    /// Set download callback function
    /// </summary>
    /// <param name=UploadProgress pUploadFunc>User callback funtion</param>
    /// <param name=void * pUserData>User's data</param>
    /// <returns></returns>
    /// <remarks>
    /// Note: you can get download progress by this callback function
    /// </remarks>
    ///***********************************************************************
    virtual void SetDownloadFunc(DownLoadProgress pDownloadFunc = NULL, void* pUserData = NULL) = 0;

    ///************************************************************************
    /// <summary>
    /// Set head info for requesting
    /// </summary>
    /// <param name=std::string strHeadType></param>
    /// <param name=std::string strProtocol></param>
    /// <param name=std::string strEncodeType></param>
    /// <returns></returns>
    /// <remarks>
    /// none
    /// </remarks>
    ///***********************************************************************
    virtual void SetRequestHead(std::string strHeadType = "Content-Type",
        std::string strProtocol = "application/json",
        std::string strEncodeType = "charset=UTF-8") = 0;

    ///************************************************************************
    /// <summary>
    /// Get the error std::string
    /// </summary>
    /// <param name=int & iErrorCode>Error code</param>
    /// <param name=std::string & strErrorMsg>Error message</param>
    /// <returns></returns>
    /// <remarks>  
    /// none
    /// </remarks>
    ///***********************************************************************
    virtual void GetErrorInfo(int& iErrorCode, std::string& strErrorMsg) = 0;

    ///************************************************************************
    /// <summary>
    /// Post the request by http
    /// </summary>
    /// <param name=std::string strRequestUrl>Url</param>
    /// <param name=std::string strRequestData>Request data</param>
    /// <param name=std::string & strResponseData>Respond data</param>
    /// <returns></returns>
    /// <remarks>
    /// Note: Url should be UTF-8 encode
    /// </remarks>
    ///***********************************************************************
    virtual bool Post(std::string strRequestUrl,
        std::string strRequestData,
        std::string& strResponseData) = 0;

    ///************************************************************************
    /// <summary>
    /// Get the respond by http
    /// </summary>
    /// <param name=std::string strRequestUrl>Url</param>
    /// <param name=std::string strRequestData>Request data</param>
    /// <param name=std::string & strResponseData>Respond data</param>
    /// <returns></returns>
    /// <remarks>
    /// Note: Url should be UTF-8 encode
    /// </remarks>
    ///***********************************************************************
    virtual bool Get(std::string strRequestUrl,
        std::string strRequestData,
        std::string& strResponseData) = 0;

    ///************************************************************************
    /// <summary>
    /// Post the request by https
    /// </summary>
    /// <param name=std::string strRequestUrl>Url</param>
    /// <param name=std::string strRequestData>Request data</param>
    /// <param name=std::string & strResponseData>Respond data</param>
    /// <param name=const char * pCaPath>Certificatation path</param>
    /// <returns></returns>
    /// <remarks>
    /// Note: pCaPath==NULL : do not verify the certification on server
    /// </remarks>
    ///***********************************************************************
    virtual bool Posts(std::string strRequestUrl,
        std::string strRequestData,
        std::string& strResponseData,
        const char* pCaPath = NULL) = 0;

    ///************************************************************************
    /// <summary>
    /// Get the respond by https 
    /// </summary>
    /// <param name=std::string strRequestUrl>Url</param>
    /// <param name=std::string strRequestData>Request data</param>
    /// <param name=std::string & strResponseData>Respond data</param>
    /// <param name=const char * pCaPath>Certificatation path</param>
    /// <returns></returns>
    /// <remarks>
    /// Note: pCaPath==NULL : do not verify the certification on server
    /// </remarks>
    ///***********************************************************************
    virtual bool Gets(std::string strRequestUrl,
        std::string strRequestData,
        std::string& strResponseData,
        const char* pCaPath = NULL) = 0;

    ///************************************************************************
    /// <summary>
    /// Connect to FTP
    /// </summary>
    /// <param name=const std::string strRemoteIpAddr>FTP ip address</param>
    /// <param name=const std::string strUserName>Login user name</param>
    /// <param name=const std::string strPassword>Login password</param>
    /// <param name=const std::string strPortNo>FTP port no</param>
    /// <returns></returns>
    /// <remarks>
    /// Note: FTP's ip address such as 127.0.0.1 and it's portNo is 21 at the most time so you can keep it default.
    /// </remarks>
    ///***********************************************************************
    virtual bool FtpConnect(const std::string strRemoteIpAddr,
        const std::string strUserName,
        const std::string strPassword,
        const std::string strPortNo = "21") = 0;
 
    ///************************************************************************
    /// <summary>
    /// List all files under the directory
    /// </summary>
    /// <param name=const std::string strRemoteDirPath>FTP directory path</param>
    /// <param name=std::vector<FileInfo> & FileInfoTable>All files' info under the dir</param>
    /// <returns></returns>
    /// <remarks>
    /// Note: FTP directory path just like /Test/12/
    /// </remarks>
    ///***********************************************************************
    virtual bool FtpList(const std::string strRemoteDirPath, std::vector<FileInfo>& FileInfoTable) = 0;

    ///************************************************************************
    /// <summary>
    /// Upload file to the FTP
    /// </summary>
    /// <param name=const std::string strRemoteDirPath>FTP directory path</param>
    /// <param name=const std::string strLocalFilePath>Local file's full path</param>
    /// <returns></returns>
    /// <remarks>
    /// Note: strRemoteDirPath like /test
    /// </remarks>
    ///***********************************************************************
    virtual bool FtpUpload(const std::string strRemoteDirPath, const std::string strLocalFilePath) = 0;

    ///************************************************************************
    /// <summary>
    /// Download file from FTP
    /// </summary>
    /// <param name=const std::string strRemoteFilePath>FTP file's full path</param>
    /// <param name=const std::string strLocalDirPath>Local file's full path</param>
    /// <returns></returns>
    /// <remarks>
    /// none
    /// </remarks>
    ///***********************************************************************
    virtual bool FtpDownload(const std::string strRemoteFilePath, const std::string strLocalDirPath) = 0;

    ///************************************************************************
    /// <summary>
    /// Upload directory to FTP
    /// </summary>
    /// <param name=const std::string strRemoteDirPath>FTP directory path</param>
    /// <param name=const std::string strLocalDirPath>Local directory full path</param>
    /// <returns></returns>
    /// <remarks>
    /// none
    /// </remarks>
    ///***********************************************************************
    virtual bool FtpUploadDir(const std::string strRemoteDirPath,const std::string strLocalDirPath) = 0;

    ///************************************************************************
    /// <summary>
    /// Download directory from FTP
    /// </summary>
    /// <param name=const std::string strRemoteDirPath>FTP directory full path</param>
    /// <param name=const std::string strLocalDirPath>Local directory full path</param>
    /// <returns></returns>
    /// <remarks>
    /// none
    /// </remarks>
    ///***********************************************************************
    virtual bool FtpDownloadDir(const std::string strRemoteDirPath, const std::string strLocalDirPath) = 0;
};

#endif // ILIBCURL_H
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值