12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #pragma once
- #include <string>
- #if (defined(__clang__) && defined(_LIBCPP_VERSION)) || (__cplusplus >= 201103L)
- #include <memory>
- #else
- #include <tr1/memory>
- #endif
- #include <stdio.h>
- #include <time.h>
- #include <pthread.h>
- #include <sys/types.h>
- #include <regex.h>
- #include <curl/curl.h>
- #include "DataStorage.h"
- #include "BBS2chProxyThreadInfo.h"
- #include "BBS2chProxyAuth.h"
- #include "IBBS2chProxySocket.h"
- #include "BBS2chProxyHttpHeaders.h"
- #include "BBS2chProxyURL.h"
- #include "BBS2chProxyKeyManager.h"
- struct BBS2chThreadIdentifier {
- std::string hostPrefix;
- std::string host;
- std::string board;
- std::string key;
- };
- class BBS2chProxyConnection {
- private:
- int sock_c;
- int serverPort;
- BBS2chProxyThreadCache *threadCache;
- std::string threadKey;
- pthread_mutex_t *mutex;
- static BBS2chProxyAuth auth;
- BBS2chProxyURL requestURL;
-
- public:
- int content_length;
- int status;
- bool isResponseChunked;
- bool force5ch;
- bool bbscgi;
- std::string responseHeaders;
- IBBS2chProxySocket *socketToClient;
- bool isClientChunked;
- bool isClientHttp1_0;
- CURL *curl;
- bool isHttps;
- std::string monaKeyForRequest;
- std::string userAgentForRequest;
- int directDatDownloading;
- static BBS2chProxyKeyManager keyManager;
-
- public:
- BBS2chProxyConnection(int socket, int port, BBS2chProxyThreadCache *cache, pthread_mutex_t *m) :
- sock_c(socket), serverPort(port), threadCache(cache), mutex(m),
- content_length(0), status(0), isResponseChunked(false), force5ch(false), bbscgi(false),
- socketToClient(NULL), isClientChunked(false), isClientHttp1_0(false), curl(NULL), isHttps(false), directDatDownloading(0)
- {
- };
- ~BBS2chProxyConnection()
- {
- if (socketToClient) delete socketToClient;
- };
-
- void run(void * (*func)(void *));
- void connect(void);
- void setMonaKey(const std::string &key, int reason);
- static void compileRegex(void);
-
- private:
- int datProxy(const char *url, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
- int datProxyAPI(const char *url, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
- int bbsmenuProxy(const char *url, const char *method, BBS2chProxyHttpHeaders &requestHeaders);
- int bbsCgiProxy(const char *url, 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);
- int tunnel(const char *addr, int port);
- std::string getMonaKey();
- BBS2chProxyURL getRawDatURLAndStatus(const BBS2chThreadIdentifier &threadIdentifier, BBS2chProxyHttpHeaders &requestHeaders, bool findKakologOnly, long *status, bool *foundAsKakolog);
- };
- #if (defined(__clang__) && defined(_LIBCPP_VERSION)) || (__cplusplus >= 201103L)
- typedef std::shared_ptr<BBS2chProxyConnection> PBBS2chProxyConnection;
- #else
- typedef std::tr1::shared_ptr<BBS2chProxyConnection> PBBS2chProxyConnection;
- #endif
|