BBS2chProxyConnection.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. class BBS2chProxyConnection {
  21. private:
  22. int sock_c;
  23. BBS2chProxyThreadCache *threadCache;
  24. std::string threadKey;
  25. pthread_mutex_t *mutex;
  26. BBS2chProxyAuth *auth;
  27. std::string monaKeyForRequest;
  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. public:
  42. BBS2chProxyConnection(int socket, BBS2chProxyThreadCache *cache, BBS2chProxyAuth *a, pthread_mutex_t *m) :
  43. sock_c(socket), threadCache(cache), auth(a), mutex(m),
  44. content_length(0), status(0), isResponseChunked(false), force5ch(false), bbscgi(false),
  45. socketToClient(NULL), isClientChunked(false), isClientHttp1_0(false), curl(NULL), isHttps(false)
  46. {
  47. };
  48. ~BBS2chProxyConnection()
  49. {
  50. if (socketToClient) delete socketToClient;
  51. };
  52. void run(void * (*func)(void *));
  53. void connect(void);
  54. void setMonaKey(const std::string &key, int reason);
  55. static void compileRegex(void);
  56. private:
  57. int datProxy(const char *url, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
  58. int datProxyAPI(const char *url, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
  59. int bbsmenuProxy(const char *url, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
  60. int bbsCgiProxy(const char *url, BBS2chProxyHttpHeaders &requestHeaders, const char *requestBody);
  61. DataStorage *html2dat_old(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
  62. DataStorage *html2dat(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
  63. int tunnel(const char *addr, int port);
  64. std::string getMonaKey();
  65. };
  66. #if (defined(__clang__) && defined(_LIBCPP_VERSION)) || (__cplusplus >= 201103L)
  67. typedef std::shared_ptr<BBS2chProxyConnection> PBBS2chProxyConnection;
  68. #else
  69. typedef std::tr1::shared_ptr<BBS2chProxyConnection> PBBS2chProxyConnection;
  70. #endif