BBS2chProxyConnection.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include <string>
  3. #include <stdio.h>
  4. #include <time.h>
  5. #include <pthread.h>
  6. #include <sys/types.h>
  7. #include <regex.h>
  8. #include "DataStorage.h"
  9. #include "BBS2chProxyThreadInfo.h"
  10. #include "BBS2chProxyAuth.h"
  11. #include "IBBS2chProxySocket.h"
  12. #include "BBS2chProxyHttpHeaders.h"
  13. class BBS2chProxyConnection {
  14. private:
  15. int sock_c, sock_s;
  16. BBS2chProxyThreadCache *threadCache;
  17. std::string threadKey;
  18. pthread_mutex_t *mutex;
  19. BBS2chProxyAuth *auth;
  20. std::string monaKeyForRequest;
  21. public:
  22. int content_length;
  23. int status;
  24. bool chunked;
  25. bool force5ch;
  26. bool bbscgi;
  27. std::string responseHeaders;
  28. IBBS2chProxySocket *socketToClient;
  29. bool isClientChunked;
  30. public:
  31. BBS2chProxyConnection(int socket, BBS2chProxyThreadCache *cache, BBS2chProxyAuth *a, pthread_mutex_t *m) :
  32. sock_c(socket), threadCache(cache), auth(a), mutex(m),
  33. content_length(0), status(0), chunked(false), force5ch(false), bbscgi(false), socketToClient(NULL), isClientChunked(false)
  34. {
  35. };
  36. ~BBS2chProxyConnection()
  37. {
  38. if (socketToClient) delete socketToClient;
  39. };
  40. void run(void);
  41. void setMonaKey(const std::string &key, int reason);
  42. static void compileRegex(void);
  43. private:
  44. void connect(void);
  45. int datProxy(const char *url, const char *method);
  46. int datProxyAPI(const char *url, const char *method);
  47. int bbsmenuProxy(const char *url, const char *method);
  48. int bbsCgiProxy(const char *url, const char *protocol, BBS2chProxyHttpHeaders *requestHeaders, const char *requestBody);
  49. DataStorage *html2dat_old(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
  50. DataStorage *html2dat(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
  51. static void *launch(void *param);
  52. int tunnel(const char *addr, int port);
  53. static void *tunnel_c2s(void *param);
  54. static void *tunnel_s2c(void *param);
  55. std::string getMonaKey();
  56. };