BBS2chProxyConnection.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #include <string>
  3. #if (defined(__clang__) && defined(_LIBCPP_VERSION)) || (__cplusplus >= 201103L)
  4. #include <memory>
  5. #else
  6. #include <tr1/memory>
  7. #endif
  8. #include <stdio.h>
  9. #include <time.h>
  10. #include <pthread.h>
  11. #include <sys/types.h>
  12. #include <regex.h>
  13. #include <curl/curl.h>
  14. #include "DataStorage.h"
  15. #include "BBS2chProxyThreadInfo.h"
  16. #include "BBS2chProxyAuth.h"
  17. #include "IBBS2chProxySocket.h"
  18. #include "BBS2chProxyHttpHeaders.h"
  19. #include "BBS2chProxyURL.h"
  20. #include "BBS2chProxyKeyManager.h"
  21. class BBS2chProxyConnection {
  22. private:
  23. int sock_c;
  24. BBS2chProxyThreadCache *threadCache;
  25. std::string threadKey;
  26. pthread_mutex_t *mutex;
  27. static BBS2chProxyAuth auth;
  28. BBS2chProxyURL requestURL;
  29. public:
  30. int content_length;
  31. int status;
  32. bool isResponseChunked;
  33. bool force5ch;
  34. bool bbscgi;
  35. std::string responseHeaders;
  36. IBBS2chProxySocket *socketToClient;
  37. bool isClientChunked;
  38. bool isClientHttp1_0;
  39. CURL *curl;
  40. bool isHttps;
  41. std::string monaKeyForRequest;
  42. std::string userAgentForRequest;
  43. static BBS2chProxyKeyManager keyManager;
  44. public:
  45. BBS2chProxyConnection(int socket, BBS2chProxyThreadCache *cache, pthread_mutex_t *m) :
  46. sock_c(socket), threadCache(cache), mutex(m),
  47. content_length(0), status(0), isResponseChunked(false), force5ch(false), bbscgi(false),
  48. socketToClient(NULL), isClientChunked(false), isClientHttp1_0(false), curl(NULL), isHttps(false)
  49. {
  50. };
  51. ~BBS2chProxyConnection()
  52. {
  53. if (socketToClient) delete socketToClient;
  54. };
  55. void run(void * (*func)(void *));
  56. void connect(void);
  57. void setMonaKey(const std::string &key, int reason);
  58. static void compileRegex(void);
  59. private:
  60. int datProxy(const char *url, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
  61. int datProxyAPI(const char *url, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
  62. int bbsmenuProxy(const char *url, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
  63. int bbsCgiProxy(const char *url, BBS2chProxyHttpHeaders &requestHeaders, const char *requestBody);
  64. DataStorage *html2dat_old(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
  65. DataStorage *html2dat(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
  66. int tunnel(const char *addr, int port);
  67. std::string getMonaKey();
  68. };
  69. #if (defined(__clang__) && defined(_LIBCPP_VERSION)) || (__cplusplus >= 201103L)
  70. typedef std::shared_ptr<BBS2chProxyConnection> PBBS2chProxyConnection;
  71. #else
  72. typedef std::tr1::shared_ptr<BBS2chProxyConnection> PBBS2chProxyConnection;
  73. #endif