1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #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"
- 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:
- FILE *fpr;
- FILE *fpw;
- int content_length;
- int status;
- bool chunked;
- bool force5ch;
- bool bbscgi;
- std::string responseHeaders;
-
- 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), fpr(NULL), fpw(NULL), force5ch(false), bbscgi(false)
- {
- regcomp(®ex, "^http://([^:/.]+)\\.(2ch\\.net|5ch\\.net|bbspink\\.com)(:[0-9]+)?/([^/]+)/dat/([0-9]+)\\.dat", REG_EXTENDED|REG_ICASE);
- regcomp(®ex_kako, "^http://([^:/.]+)\\.(2ch\\.net|5ch\\.net|bbspink\\.com)(:[0-9]+)?/([^/]+)/kako/[0-9]+/([0-9]+/)?([0-9]+)\\.dat", REG_EXTENDED|REG_ICASE);
- regcomp(®ex_offlaw, "^http://([^:/.]+)\\.(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);
- };
-
- 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, std::string &hostStr, void *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();
- };
|