wirelessgateway/datatransfer/SH_Datatrans.hpp

109 lines
3.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef _DATATRANS_H_
#define _DATATRANS_H_
#include <stdio.h>
#include <string>
#include <curl/curl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
#include "../common/SH_global.h"
#include "../utility/SH_MySingleton.hpp"
#define BUFFER_SIZE 4096
#define IP "127.0.0.1"
#define PORT 12345
class DataTrans : public MySingleton<DataTrans>
{
public:
DataTrans();
~DataTrans();
/**
* @brief HTTP POST请求
* @param strUrl 输入参数,请求的Url地址,如:http://www.baidu.com
* @param strPost 输入参数,使用如下格式para1=val1¶2=val2&…
* @param strResponse 输出参数,返回的内容
* @return 返回是否Post成功
*/
int Post(const std::string & strUrl, const std::string & strPost, std::string & strResponse);
/**
* @brief HTTP GET请求
* @param strUrl 输入参数,请求的Url地址,如:http://www.baidu.com
* @param strResponse 输出参数,返回的内容
* @return 返回是否Post成功
*/
int Get(const std::string & strUrl, std::string & strResponse);
/**
* @brief HTTPS POST请求,无证书版本
* @param strUrl 输入参数,请求的Url地址,如:https://www.baidu.com
* @param strPost 输入参数,使用如下格式para1=val1¶2=val2&…
* @param strResponse 输出参数,返回的内容
* @param pCaPath 输入参数,为CA证书的路径.如果输入为NULL,则不验证服务器端证书的有效性.
* @return 返回是否Post成功
*/
int Posts(const std::string & strUrl, const std::string & strPost, std::string & strResponse, const char * pCaPath = NULL);
/**
* @brief HTTPS GET请求,无证书版本
* @param strUrl 输入参数,请求的Url地址,如:https://www.baidu.com
* @param strResponse 输出参数,返回的内容
* @param pCaPath 输入参数,为CA证书的路径.如果输入为NULL,则不验证服务器端证书的有效性.
* @return 返回是否Post成功
*/
int Gets(const std::string & strUrl, std::string & strResponse, const char * pCaPath = NULL);
/**
* @brief HTTP 上传文件
* @param strUrl 输入参数,请求的Url地址,如:http://localcast:8080/source
* @param strResponse 输出参数,返回的内容
* @param filename 文件的绝对地址,如/home/usr/cidw.log
* @return 函数返回0执行成功
*/
int upload_file(const std::string &strUrl, const std::string &filename, std::string &strResponse);
/**
* @brief 下载文件如果板子支持wget下载会方便很多接口保留待确认后在开发
* @param strUrl 输入参数,请求的Url地址,如:http://localcast:8080/source
* @param strResponse 输出参数,返回的内容
* @param filename 文件的绝对地址,如/home/usr/cidw.log
* @return 函数返回0执行成功
*/
// int download_file(const std::string &strUrl, const std::string &filename, std::string &strResponse);
/**
* @brief 通过socket发送文件
* @param filename 文件名
* @return 函数返回0执行成功
*/
int Send_file_socket(const std::string &filename);
/**
* @brief 通过socket发送文件夹下所有文件
* @param dirname 文件名
* @return 函数返回0执行成功
*/
int Send_Dir_socket(const char *dirname);
int download(char* pFilename,string& strUrl,string& strResponse,bool bDownload);
int dl_curl_post_req(const string &url, const string &postParams, string& filename);
public:
void SetDebug(bool bDebug);
private:
bool m_bDebug;
};
extern DataTrans *pDataTrans;
#endif