BBS2chProxyConnection.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. class BBS2chProxyConnection {
  13. private:
  14. int sock_c, sock_s;
  15. BBS2chProxyThreadCache *threadCache;
  16. std::string threadKey;
  17. pthread_mutex_t *mutex;
  18. regex_t regex;
  19. regex_t regex_kako;
  20. regex_t regex_offlaw;
  21. BBS2chProxyAuth *auth;
  22. std::string monaKeyForRequest;
  23. public:
  24. int content_length;
  25. int status;
  26. bool chunked;
  27. bool force5ch;
  28. bool bbscgi;
  29. std::string responseHeaders;
  30. IBBS2chProxySocket *socketToClient;
  31. public:
  32. BBS2chProxyConnection(int socket, BBS2chProxyThreadCache *cache, BBS2chProxyAuth *a, pthread_mutex_t *m) :
  33. sock_c(socket), threadCache(cache), auth(a), mutex(m),
  34. content_length(0), status(0), chunked(false), force5ch(false), bbscgi(false), socketToClient(NULL)
  35. {
  36. regcomp(&regex, "^https?://([^:/.]+)\\.(2ch\\.net|5ch\\.net|bbspink\\.com)(:[0-9]+)?/([^/]+)/dat/([0-9]+)\\.dat", REG_EXTENDED|REG_ICASE);
  37. regcomp(&regex_kako, "^https?://([^:/.]+)\\.(2ch\\.net|5ch\\.net|bbspink\\.com)(:[0-9]+)?/([^/]+)/kako/[0-9]+/([0-9]+/)?([0-9]+)\\.dat", REG_EXTENDED|REG_ICASE);
  38. regcomp(&regex_offlaw, "^https?://([^:/.]+)\\.(2ch\\.net|5ch\\.net|bbspink\\.com)(:[0-9]+)?/test/offlaw2.so\\?.*bbs=([^&]+)", REG_EXTENDED|REG_ICASE);
  39. };
  40. ~BBS2chProxyConnection()
  41. {
  42. regfree(&regex);
  43. regfree(&regex_kako);
  44. regfree(&regex_offlaw);
  45. if (socketToClient) delete socketToClient;
  46. };
  47. void run(void);
  48. void setMonaKey(const std::string &key, int reason);
  49. private:
  50. void connect(void);
  51. int datProxy(const char *url, const char *method);
  52. int datProxyAPI(const char *url, const char *method);
  53. int bbsmenuProxy(const char *url, const char *method);
  54. int bbsCgiProxy(const char *url, const char *protocol, std::string &hostStr, void *requestHeaders, const char *requestBody);
  55. DataStorage *html2dat_old(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
  56. DataStorage *html2dat(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
  57. static void *launch(void *param);
  58. int tunnel(const char *addr, int port);
  59. static void *tunnel_c2s(void *param);
  60. static void *tunnel_s2c(void *param);
  61. std::string getMonaKey();
  62. };