mirror of
https://github.com/MetaCubeX/subconverter.git
synced 2025-11-04 18:19:42 +08:00
Optimize codes
This commit is contained in:
parent
4459dd7f6c
commit
372140c53b
@ -3,13 +3,13 @@ set -xe
|
||||
|
||||
git clone https://github.com/curl/curl --depth=1
|
||||
cd curl
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_USE_LIBSSH2=OFF -DHTTP_ONLY=ON -DCMAKE_USE_SCHANNEL=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DCMAKE_INSTALL_PREFIX=$MINGW_PREFIX -G "Unix Makefiles" .
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_USE_LIBSSH2=OFF -DHTTP_ONLY=ON -DCMAKE_USE_SCHANNEL=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" .
|
||||
make install -j4
|
||||
cd ..
|
||||
|
||||
git clone https://github.com/jbeder/yaml-cpp --depth=1
|
||||
cd yaml-cpp
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF -DCMAKE_INSTALL_PREFIX=$MINGW_PREFIX -G "Unix Makefiles" .
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" .
|
||||
make install -j4
|
||||
cd ..
|
||||
|
||||
@ -23,14 +23,14 @@ gcc -c -O3 -o duktape.o duktape.c
|
||||
gcc -c -O3 -o duk_module_node.o -I. ../extras/module-node/duk_module_node.c
|
||||
ar cr libduktape.a duktape.o
|
||||
ar cr libduktape_module.a duk_module_node.o
|
||||
install -m0644 ./*.a $MINGW_PREFIX/lib
|
||||
install -m0644 ./duk*.h $MINGW_PREFIX/include
|
||||
install -m0644 ../extras/module-node/duk_module_node.h $MINGW_PREFIX/include
|
||||
install -m0644 ./*.a "$MINGW_PREFIX/lib"
|
||||
install -m0644 ./duk*.h "$MINGW_PREFIX/include"
|
||||
install -m0644 ../extras/module-node/duk_module_node.h "$MINGW_PREFIX/include"
|
||||
cd ../../../..
|
||||
|
||||
git clone https://github.com/Tencent/rapidjson --depth=1
|
||||
cd rapidjson
|
||||
cmake -DRAPIDJSON_BUILD_DOC=OFF -DRAPIDJSON_BUILD_EXAMPLES=OFF -DRAPIDJSON_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=$MINGW_PREFIX -G "Unix Makefiles" .
|
||||
cmake -DRAPIDJSON_BUILD_DOC=OFF -DRAPIDJSON_BUILD_EXAMPLES=OFF -DRAPIDJSON_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" .
|
||||
make install -j4
|
||||
cd ..
|
||||
|
||||
|
||||
@ -335,7 +335,7 @@ void flushCache()
|
||||
//guarded_mutex guard(cache_rw_lock);
|
||||
cache_rw_lock.writeLock();
|
||||
defer(cache_rw_lock.writeUnlock();)
|
||||
operateFiles("cache", [](std::string file){ remove(("cache/" + file).data()); return 0; });
|
||||
operateFiles("cache", [](const std::string &file){ remove(("cache/" + file).data()); return 0; });
|
||||
}
|
||||
|
||||
int curlPost(const std::string &url, const std::string &data, const std::string &proxy, const string_array &request_headers, std::string *retData)
|
||||
|
||||
@ -57,7 +57,7 @@ bool matchSpaceSeparatedList(const std::string& source, const std::string &targe
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string checkMIMEType(const std::string filename)
|
||||
std::string checkMIMEType(const std::string &filename)
|
||||
{
|
||||
string_size name_begin = 0, name_end = 0;
|
||||
name_begin = filename.rfind('/');
|
||||
@ -102,6 +102,7 @@ const char *request_header_blacklist[] = {"host", "accept", "accept-encoding"};
|
||||
|
||||
static inline void buffer_cleanup(struct evbuffer *eb)
|
||||
{
|
||||
(void)eb;
|
||||
//evbuffer_free(eb);
|
||||
#ifdef MALLOC_TRIM
|
||||
malloc_trim(0);
|
||||
@ -121,7 +122,7 @@ static inline int process_request(Request &request, Response &response, std::str
|
||||
|
||||
for(responseRoute &x : responses)
|
||||
{
|
||||
if(request.method == "OPTIONS" && startsWith(request.postdata, x.method) && x.path == request.url)
|
||||
if(request.method == "OPTIONS" && matchSpaceSeparatedList(replace_all_distinct(request.postdata, ",", ""), x.method) && x.path == request.url)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@ -160,6 +161,7 @@ static inline int process_request(Request &request, Response &response, std::str
|
||||
|
||||
void OnReq(evhttp_request *req, void *args)
|
||||
{
|
||||
(void)args;
|
||||
const char *req_content_type = evhttp_find_header(req->input_headers, "Content-Type"), *req_ac_method = evhttp_find_header(req->input_headers, "Access-Control-Request-Method");
|
||||
const char *uri = req->uri, *internal_flag = evhttp_find_header(req->input_headers, "SubConverter-Request");
|
||||
|
||||
@ -193,6 +195,9 @@ void OnReq(evhttp_request *req, void *args)
|
||||
case EVHTTP_REQ_GET: request.method = "GET"; break;
|
||||
case EVHTTP_REQ_POST: request.method = "POST"; break;
|
||||
case EVHTTP_REQ_OPTIONS: request.method = "OPTIONS"; break;
|
||||
case EVHTTP_REQ_PUT: request.method = "PUT"; break;
|
||||
case EVHTTP_REQ_PATCH: request.method = "PATCH"; break;
|
||||
case EVHTTP_REQ_DELETE: request.method = "DELETE"; break;
|
||||
default: break;
|
||||
}
|
||||
request.url = uri;
|
||||
@ -276,7 +281,7 @@ int start_web_server(void *argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
evhttp_set_allowed_methods(Server.get(), EVHTTP_REQ_GET | EVHTTP_REQ_POST | EVHTTP_REQ_OPTIONS);
|
||||
evhttp_set_allowed_methods(Server.get(), EVHTTP_REQ_GET | EVHTTP_REQ_POST | EVHTTP_REQ_OPTIONS | EVHTTP_REQ_PUT | EVHTTP_REQ_PATCH | EVHTTP_REQ_DELETE);
|
||||
evhttp_set_gencb(Server.get(), OnReq, nullptr);
|
||||
evhttp_set_timeout(Server.get(), 30);
|
||||
if (event_dispatch() == -1)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user