BBS2chProxyConnection.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. int serverPort;
  25. BBS2chProxyThreadCache *threadCache;
  26. std::string threadKey;
  27. pthread_mutex_t *mutex;
  28. static BBS2chProxyAuth auth;
  29. BBS2chProxyURL requestURL;
  30. public:
  31. int content_length;
  32. int status;
  33. bool isResponseChunked;
  34. bool force5ch;
  35. bool bbscgi;
  36. std::string responseHeaders;
  37. IBBS2chProxySocket *socketToClient;
  38. bool isClientChunked;
  39. bool isClientHttp1_0;
  40. CURL *curl;
  41. bool isHttps;
  42. std::string monaKeyForRequest;
  43. std::string userAgentForRequest;
  44. static BBS2chProxyKeyManager keyManager;
  45. public:
  46. BBS2chProxyConnection(int socket, int port, BBS2chProxyThreadCache *cache, pthread_mutex_t *m) :
  47. sock_c(socket), serverPort(port), threadCache(cache), mutex(m),
  48. content_length(0), status(0), isResponseChunked(false), force5ch(false), bbscgi(false),
  49. socketToClient(NULL), isClientChunked(false), isClientHttp1_0(false), curl(NULL), isHttps(false)
  50. {
  51. };
  52. ~BBS2chProxyConnection()
  53. {
  54. if (socketToClient) delete socketToClient;
  55. };
  56. void run(void * (*func)(void *));
  57. void connect(void);
  58. void setMonaKey(const std::string &key, int reason);
  59. static void compileRegex(void);
  60. private:
  61. int datProxy(const char *url, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
  62. int datProxyAPI(const char *url, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
  63. int bbsmenuProxy(const char *url, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
  64. int bbsCgiProxy(const char *url, BBS2chProxyHttpHeaders &requestHeaders, const char *requestBody);
  65. DataStorage *html2dat_old(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
  66. DataStorage *html2dat(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
  67. int tunnel(const char *addr, int port);
  68. std::string getMonaKey();
  69. };
  70. #if (defined(__clang__) && defined(_LIBCPP_VERSION)) || (__cplusplus >= 201103L)
  71. typedef std::shared_ptr<BBS2chProxyConnection> PBBS2chProxyConnection;
  72. #else
  73. typedef std::tr1::shared_ptr<BBS2chProxyConnection> PBBS2chProxyConnection;
  74. #endif