BBS2chProxyConnection.h 2.2 KB

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