BBS2chProxyConnection.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include <stdio.h>
  3. #include <time.h>
  4. #include <pthread.h>
  5. #include <sys/types.h>
  6. #include <regex.h>
  7. #include "DataStorage.h"
  8. #include "BBS2chProxyThreadInfo.h"
  9. #include "BBS2chProxyAuth.h"
  10. class BBS2chProxyConnection {
  11. private:
  12. int sock_c, sock_s;
  13. BBS2chProxyThreadCache *threadCache;
  14. std::string threadKey;
  15. pthread_mutex_t *mutex;
  16. regex_t regex;
  17. regex_t regex_kako;
  18. regex_t regex_offlaw;
  19. BBS2chProxyAuth *auth;
  20. public:
  21. FILE *fpr;
  22. FILE *fpw;
  23. int content_length;
  24. int status;
  25. bool chunked;
  26. bool force5ch;
  27. public:
  28. BBS2chProxyConnection(int socket, BBS2chProxyThreadCache *cache, BBS2chProxyAuth *a, pthread_mutex_t *m) :
  29. sock_c(socket), threadCache(cache), auth(a), mutex(m),
  30. content_length(0), status(0), chunked(false), fpr(NULL), fpw(NULL), force5ch(false)
  31. {
  32. regcomp(&regex, "^http://([^:/.]+)\\.(2ch\\.net|5ch\\.net|bbspink\\.com)(:[0-9]+)?/([^/]+)/dat/([0-9]+)\\.dat", REG_EXTENDED|REG_ICASE);
  33. regcomp(&regex_kako, "^http://([^:/.]+)\\.(2ch\\.net|5ch\\.net|bbspink\\.com)(:[0-9]+)?/([^/]+)/kako/[0-9]+/([0-9]+/)?([0-9]+)\\.dat", REG_EXTENDED|REG_ICASE);
  34. regcomp(&regex_offlaw, "^http://([^:/.]+)\\.(2ch\\.net|5ch\\.net|bbspink\\.com)(:[0-9]+)?/test/offlaw2.so\\?.*bbs=([^&]+)", REG_EXTENDED|REG_ICASE);
  35. };
  36. ~BBS2chProxyConnection()
  37. {
  38. regfree(&regex);
  39. regfree(&regex_kako);
  40. regfree(&regex_offlaw);
  41. };
  42. void run(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. DataStorage *html2dat_old(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
  49. DataStorage *html2dat(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
  50. static void *launch(void *param);
  51. int tunnel(const char *addr, int port);
  52. static void *tunnel_c2s(void *param);
  53. static void *tunnel_s2c(void *param);
  54. };