IHttpFunc.h 2.4 KB

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