BBS2chProxyHTML2Dat.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma once
  2. #include <string>
  3. #include <vector>
  4. #include <time.h>
  5. #include <curl/curl.h>
  6. #include "BBS2chProxyThreadInfo.h"
  7. #include "BBS2chProxyHttpHeaders.h"
  8. #include "parson/parson.h"
  9. class IBBS2chProxyHTML2Dat {
  10. protected:
  11. BBS2chProxyThreadCache *_threadCache;
  12. std::string _url;
  13. std::string _threadKey;
  14. std::string _userAgent;
  15. CURL *_curl;
  16. public:
  17. IBBS2chProxyHTML2Dat(BBS2chProxyThreadCache *cache, const BBS2chThreadIdentifier &identifier, CURL *curl)
  18. : _threadCache(cache), _curl(curl)
  19. {
  20. _threadKey = identifier.host;
  21. _threadKey += '/';
  22. _threadKey += identifier.board;
  23. _threadKey += '/';
  24. _threadKey += identifier.key;
  25. };
  26. virtual ~IBBS2chProxyHTML2Dat() {};
  27. virtual std::string generateDatFrom(int startFrom, time_t *lastModifiedOut, bool useCache, long *outStatusCode) = 0;
  28. void setRequestHeaders(BBS2chProxyHttpHeaders &headers);
  29. const std::string& getKey();
  30. protected:
  31. std::vector<char> getHtmlFromURL(const std::string &url, long *outStatusCode);
  32. };
  33. class BBS2chProxyHTML2Dat5ch : public IBBS2chProxyHTML2Dat {
  34. public:
  35. BBS2chProxyHTML2Dat5ch(BBS2chProxyThreadCache *cache, const BBS2chThreadIdentifier &identifier, bool useHttps, CURL *curl);
  36. ~BBS2chProxyHTML2Dat5ch() {};
  37. virtual std::string generateDatFrom(int startFrom, time_t *lastModifiedOut, bool useCache, long *outStatusCode);
  38. private:
  39. std::string html2dat_old(std::vector<char> &html, int startResNum, time_t *lastModified, bool useCache);
  40. std::string html2dat(std::vector<char> &html, int startResNum, time_t *lastModified, bool useCache);
  41. };
  42. class BBS2chProxyHTML2DatTalk : public IBBS2chProxyHTML2Dat {
  43. protected:
  44. JSON_Value *_cachedJson;
  45. public:
  46. BBS2chProxyHTML2DatTalk(BBS2chProxyThreadCache *cache, const BBS2chThreadIdentifier &identifier, CURL *curl);
  47. virtual ~BBS2chProxyHTML2DatTalk() {
  48. if (_cachedJson) json_value_free(_cachedJson);
  49. };
  50. virtual std::string generateDatFrom(int startFrom, time_t *lastModifiedOut, bool useCache, long *outStatusCode);
  51. protected:
  52. std::string json2dat(JSON_Value *json, int startFrom, time_t *lastModifiedOut, bool useCache);
  53. };
  54. class BBS2chProxyHTML2DatTalkHTML : public BBS2chProxyHTML2DatTalk {
  55. public:
  56. BBS2chProxyHTML2DatTalkHTML(BBS2chProxyThreadCache *cache, const BBS2chThreadIdentifier &identifier, CURL *curl);
  57. virtual ~BBS2chProxyHTML2DatTalkHTML() {};
  58. virtual std::string generateDatFrom(int startFrom, time_t *lastModifiedOut, bool useCache, long *outStatusCode);
  59. };
  60. class BBS2chProxyHTML2Dat5chItest : public BBS2chProxyHTML2DatTalk {
  61. protected:
  62. JSON_Value *_cachedJson;
  63. public:
  64. BBS2chProxyHTML2Dat5chItest(BBS2chProxyThreadCache *cache, const BBS2chThreadIdentifier &identifier, CURL *curl);
  65. virtual ~BBS2chProxyHTML2Dat5chItest() {};
  66. virtual std::string generateDatFrom(int startFrom, time_t *lastModifiedOut, bool useCache, long *outStatusCode);
  67. protected:
  68. std::string json2dat(JSON_Value *json, int startFrom, time_t *lastModifiedOut, bool useCache);
  69. };