BBS2chProxyConnection.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "BBS2chProxyThreadInfo.h"
  15. #include "BBS2chProxyAuth.h"
  16. #include "IBBS2chProxySocket.h"
  17. #include "BBS2chProxyHttpHeaders.h"
  18. #include "BBS2chProxyURL.h"
  19. #include "BBS2chProxyKeyManager.h"
  20. #include "BBS2chProxyBoardManager.h"
  21. #include "BBS2chProxyHTML2Dat.h"
  22. #include "BBS2chProxyFormData.h"
  23. class BBS2chProxyConnection {
  24. private:
  25. int sock_c;
  26. BBS2chProxyThreadCache *threadCache;
  27. BBS2chProxyURL requestURL;
  28. static BBS2chProxyBoardManager boardManager;
  29. public:
  30. int content_length;
  31. int status;
  32. bool isResponseChunked;
  33. bool force5ch;
  34. bool bbscgi;
  35. IBBS2chProxySocket *socketToClient;
  36. bool isClientChunked;
  37. bool isClientHttp1_0;
  38. CURL *curl;
  39. bool isHttps;
  40. int directDatDownloading;
  41. int serverPort;
  42. static BBS2chProxyAuth auth;
  43. static BBS2chProxyKeyManager keyManager;
  44. public:
  45. BBS2chProxyConnection(int socket, int port, BBS2chProxyThreadCache *cache) :
  46. sock_c(socket), serverPort(port), threadCache(cache),
  47. content_length(0), status(0), isResponseChunked(false), force5ch(false), bbscgi(false),
  48. socketToClient(NULL), isClientChunked(false), isClientHttp1_0(false), curl(NULL), isHttps(false), directDatDownloading(0)
  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(IBBS2chProxyHTML2Dat &html2dat, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
  61. int datProxyAPI(const std::string &url, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
  62. int bbsmenuProxy(const std::string &url, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
  63. int bbsCgiProxy(BBS2chProxyURL &url, BBS2chProxyHttpHeaders &requestHeaders, BBS2chProxyFormData &requestBody, bool talkTo5ch);
  64. int subjectTxtProxy(BBS2chProxyURL &url, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
  65. int tunnel(const char *addr, int port);
  66. BBS2chProxyURL getRawDatURLAndStatus(const BBS2chThreadIdentifier &threadIdentifier, BBS2chProxyHttpHeaders &requestHeaders, bool findKakologOnly, long *status, bool *foundAsKakolog);
  67. };
  68. #if (defined(__clang__) && defined(_LIBCPP_VERSION)) || (__cplusplus >= 201103L)
  69. typedef std::shared_ptr<BBS2chProxyConnection> PBBS2chProxyConnection;
  70. #else
  71. typedef std::tr1::shared_ptr<BBS2chProxyConnection> PBBS2chProxyConnection;
  72. #endif