12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #pragma once
- #include <string>
- #include <stdio.h>
- #include <time.h>
- #include <pthread.h>
- #include <sys/types.h>
- #include <regex.h>
- #include "DataStorage.h"
- #include "BBS2chProxyThreadInfo.h"
- #include "BBS2chProxyAuth.h"
- #include "IBBS2chProxySocket.h"
- #include "BBS2chProxyHttpHeaders.h"
- class BBS2chProxyConnection {
- private:
- int sock_c, sock_s;
- BBS2chProxyThreadCache *threadCache;
- std::string threadKey;
- pthread_mutex_t *mutex;
- regex_t regex;
- regex_t regex_kako;
- regex_t regex_offlaw;
- BBS2chProxyAuth *auth;
- std::string monaKeyForRequest;
-
- public:
- int content_length;
- int status;
- bool chunked;
- bool force5ch;
- bool bbscgi;
- std::string responseHeaders;
- IBBS2chProxySocket *socketToClient;
-
- public:
- BBS2chProxyConnection(int socket, BBS2chProxyThreadCache *cache, BBS2chProxyAuth *a, pthread_mutex_t *m) :
- sock_c(socket), threadCache(cache), auth(a), mutex(m),
- content_length(0), status(0), chunked(false), force5ch(false), bbscgi(false), socketToClient(NULL)
- {
- regcomp(®ex, "^https?://([^:/.]+)\\.(2ch\\.net|5ch\\.net|bbspink\\.com)(:[0-9]+)?/([^/]+)/dat/([0-9]+)\\.dat", REG_EXTENDED|REG_ICASE);
- regcomp(®ex_kako, "^https?://([^:/.]+)\\.(2ch\\.net|5ch\\.net|bbspink\\.com)(:[0-9]+)?/([^/]+)/kako/[0-9]+/([0-9]+/)?([0-9]+)\\.dat", REG_EXTENDED|REG_ICASE);
- regcomp(®ex_offlaw, "^https?://([^:/.]+)\\.(2ch\\.net|5ch\\.net|bbspink\\.com)(:[0-9]+)?/test/offlaw2.so\\?.*bbs=([^&]+)", REG_EXTENDED|REG_ICASE);
- };
- ~BBS2chProxyConnection()
- {
- regfree(®ex);
- regfree(®ex_kako);
- regfree(®ex_offlaw);
- if (socketToClient) delete socketToClient;
- };
-
- void run(void);
- void setMonaKey(const std::string &key, int reason);
-
- private:
- void connect(void);
- int datProxy(const char *url, const char *method);
- int datProxyAPI(const char *url, const char *method);
- int bbsmenuProxy(const char *url, const char *method);
- int bbsCgiProxy(const char *url, const char *protocol, BBS2chProxyHttpHeaders *requestHeaders, const char *requestBody);
- DataStorage *html2dat_old(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
- DataStorage *html2dat(DataStorage *html, int startResNum, time_t *lastModified, bool useCache);
- static void *launch(void *param);
- int tunnel(const char *addr, int port);
- static void *tunnel_c2s(void *param);
- static void *tunnel_s2c(void *param);
- std::string getMonaKey();
- };
|