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