IHttpFunc.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef INCLUDE_HTTPFUNC_H_
  2. #define INCLUDE_HTTPFUNC_H_
  3. #pragma once
  4. #include <unordered_map>
  5. #include "RVCComm.h"
  6. using namespace std;
  7. #pragma pack(1)
  8. struct CHTTPReq{
  9. CHTTPReq():m_timeOut(30), m_bZip(false)
  10. #if defined(_MSC_VER)
  11. , m_bTransCode(true)
  12. #else
  13. , m_bTransCode(false)
  14. #endif //_MSC_VER
  15. ,m_printDbg(false), m_withToken(true){}
  16. virtual ~CHTTPReq(){}
  17. string m_url;
  18. int m_timeOut;
  19. bool m_bZip;
  20. bool m_bTransCode;
  21. bool m_printDbg;
  22. bool m_withToken;
  23. unordered_map<string, string> m_headers;
  24. virtual string ToJson() = 0;
  25. };
  26. struct CHTTPRet{
  27. virtual ~CHTTPRet(){}
  28. int m_sysCode;
  29. string m_userCode;
  30. string m_errMsg;
  31. unordered_map<string, string> m_headers;
  32. string m_resultData;
  33. virtual bool Parse(string strData) =0;
  34. };
  35. struct CHTTPUploadReq{
  36. CHTTPUploadReq()
  37. #if defined(_MSC_VER)
  38. : m_bTransCode(true)
  39. #else
  40. : m_bTransCode(false)
  41. #endif //_MSC_VER
  42. , fileContent(NULL), fileContentSize(0),m_timeOut(30),m_printDbg(false){}
  43. string url;
  44. string paramContent;
  45. string fileName;
  46. bool m_bTransCode;
  47. byte* fileContent;
  48. long fileContentSize;
  49. int m_timeOut;
  50. bool m_printDbg;
  51. };
  52. struct CHTTPUploadRet {
  53. long httpCode;
  54. string m_userCode;
  55. string m_errMsg;
  56. unordered_map<string, string> m_headers;
  57. string strBody;
  58. };
  59. #pragma pack()
  60. enum SettingsFlag
  61. {
  62. NO_FLAGS = 0x00,
  63. ENABLE_LOG = 0x01,
  64. VERIFY_PEER = 0x02,
  65. VERIFY_HOST = 0x04,
  66. ALL_FLAGS = 0xFF
  67. };
  68. struct fileContentArray
  69. {
  70. byte* copyPtr;
  71. int maxLen;
  72. int* curLen;
  73. };
  74. class IHttpFunc
  75. {
  76. public:
  77. virtual ~IHttpFunc() {}
  78. //销毁对象
  79. virtual void Destory() = 0;
  80. //get请求
  81. virtual const bool Get(CHTTPReq& req, CHTTPRet& ret) = 0;
  82. //post请求
  83. virtual const bool Post(CHTTPReq& req, CHTTPRet& ret) = 0;
  84. //文件块上传
  85. virtual const bool UploadFileBlock(CHTTPUploadReq& req, CHTTPUploadRet& ret) = 0;
  86. //文件块下载
  87. virtual const bool DownloadFileBlock(const char* url, const char* jsonReqStr, fileContentArray &content, long& httpCode, unordered_map<string, string>& responseHeaders, long timeout) = 0;
  88. };
  89. typedef void (*LogFnCallback)(const char*);
  90. RVCCOMM_API IHttpFunc* create_http(LogFnCallback oLogger);
  91. typedef void (*GetTokenCallBack)(std::string &, std::string &, std::string&, std::string&);
  92. RVCCOMM_API void SetTokenCallBack(GetTokenCallBack t_callBack);
  93. #endif