BBS2chProxyConnection.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. std::string monaKeyForRequest;
  22. public:
  23. FILE *fpr;
  24. FILE *fpw;
  25. int content_length;
  26. int status;
  27. bool chunked;
  28. bool force5ch;
  29. bool bbscgi;
  30. std::string responseHeaders;
  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), fpr(NULL), fpw(NULL), force5ch(false), bbscgi(false)
  35. {
  36. regcomp(&regex, "^http://([^:/.]+)\\.(2ch\\.net|5ch\\.net|bbspink\\.com)(:[0-9]+)?/([^/]+)/dat/([0-9]+)\\.dat", REG_EXTENDED|REG_ICASE);
  37. regcomp(&regex_kako, "^http://([^:/.]+)\\.(2ch\\.net|5ch\\.net|bbspink\\.com)(:[0-9]+)?/([^/]+)/kako/[0-9]+/([0-9]+/)?([0-9]+)\\.dat", REG_EXTENDED|REG_ICASE);
  38. regcomp(&regex_offlaw, "^http://([^:/.]+)\\.(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. };
  46. void run(void);
  47. void setMonaKey(const std::string &key, int reason);
  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. int bbsCgiProxy(const char *url, const char *protocol, std::string &hostStr, void *requestHeaders, const char *requestBody);
  54. DataStorage *html2dat_old(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
  55. DataStorage *html2dat(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
  56. static void *launch(void *param);
  57. int tunnel(const char *addr, int port);
  58. static void *tunnel_c2s(void *param);
  59. static void *tunnel_s2c(void *param);
  60. std::string getMonaKey();
  61. };