Merge pull request #3 from tindy2013:master

This commit is contained in:
内核炸了啊对对队 2023-09-21 19:42:54 +08:00
parent a0b8b03357
commit d5d9fcf3b5
29 changed files with 1415 additions and 988 deletions

384
.github/workflows/docker.yml vendored Normal file
View File

@ -0,0 +1,384 @@
name: Publish Docker Image
on:
push:
branches: [ master ]
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
amd64_build:
name: Build AMD64 Image
runs-on: ubuntu-latest
steps:
- name: Checkout base
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get commit SHA
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Build and export
id: build
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v3
with:
platforms: linux/amd64
context: scripts/
tags: tindy2013/subconverter:latest
build-args: |
SHA=${{ steps.vars.outputs.sha_short }}
outputs: type=image,push=true
- name: Replace tag without `v`
if: startsWith(github.ref, 'refs/tags/')
uses: actions/github-script@v6
id: version
with:
script: |
return context.payload.ref.replace(/\/?refs\/tags\/v/, '')
result-encoding: string
- name: Build release and export
id: build_rel
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
platforms: linux/amd64
context: scripts/
tags: tindy2013/subconverter:${{steps.version.outputs.result}}
outputs: type=image,push=true
- name: Save digest
if: github.ref == 'refs/heads/master'
run: echo ${{ steps.build.outputs.digest }} > /tmp/digest.txt
- name: Save release digest
if: startsWith(github.ref, 'refs/tags/')
run: echo ${{ steps.build_rel.outputs.digest }} > /tmp/digest.txt
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: digest_amd64
path: /tmp/digest.txt
x86_build:
name: Build x86 Image
runs-on: ubuntu-latest
steps:
- name: Checkout base
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get commit SHA
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Build and export
id: build
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v3
with:
platforms: linux/386
context: scripts/
tags: tindy2013/subconverter:latest
build-args: |
SHA=${{ steps.vars.outputs.sha_short }}
outputs: type=image,push=true
- name: Replace tag without `v`
if: startsWith(github.ref, 'refs/tags/')
uses: actions/github-script@v6
id: version
with:
script: |
return context.payload.ref.replace(/\/?refs\/tags\/v/, '')
result-encoding: string
- name: Build release and export
id: build_rel
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
platforms: linux/386
context: scripts/
tags: tindy2013/subconverter:${{steps.version.outputs.result}}
outputs: type=image,push=true
- name: Save digest
if: github.ref == 'refs/heads/master'
run: echo ${{ steps.build.outputs.digest }} > /tmp/digest.txt
- name: Save release digest
if: startsWith(github.ref, 'refs/tags/')
run: echo ${{ steps.build_rel.outputs.digest }} > /tmp/digest.txt
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: digest_386
path: /tmp/digest.txt
armv7_build:
name: Build ARMv7 Image
runs-on: [self-hosted, linux, ARM64]
steps:
- name: Checkout base
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get commit SHA
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Build and export
id: build
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v3
with:
platforms: linux/arm/v7
context: scripts/
tags: tindy2013/subconverter:latest
build-args: |
SHA=${{ steps.vars.outputs.sha_short }}
THREADS=2
outputs: type=image,push=true
- name: Replace tag without `v`
if: startsWith(github.ref, 'refs/tags/')
uses: actions/github-script@v6
id: version
with:
script: |
return context.payload.ref.replace(/\/?refs\/tags\/v/, '')
result-encoding: string
- name: Build release and export
id: build_rel
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
platforms: linux/arm/v7
context: scripts/
tags: tindy2013/subconverter:${{steps.version.outputs.result}}
build-args: |
THREADS=2
outputs: type=image,push=true
- name: Save digest
if: github.ref == 'refs/heads/master'
run: echo ${{ steps.build.outputs.digest }} > /tmp/digest.txt
- name: Save release digest
if: startsWith(github.ref, 'refs/tags/')
run: echo ${{ steps.build_rel.outputs.digest }} > /tmp/digest.txt
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: digest_armv7
path: /tmp/digest.txt
arm64_build:
name: Build ARM64 Image
runs-on: [self-hosted, linux, ARM64]
steps:
- name: Checkout base
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get commit SHA
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Build and export
id: build
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v3
with:
platforms: linux/arm64
context: scripts/
tags: tindy2013/subconverter:latest
build-args: |
SHA=${{ steps.vars.outputs.sha_short }}
THREADS=2
outputs: type=image,push=true
- name: Replace tag without `v`
if: startsWith(github.ref, 'refs/tags/')
uses: actions/github-script@v6
id: version
with:
script: |
return context.payload.ref.replace(/\/?refs\/tags\/v/, '')
result-encoding: string
- name: Build release and export
id: build_rel
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
platforms: linux/arm64
context: scripts/
tags: tindy2013/subconverter:${{steps.version.outputs.result}}
build-args: |
THREADS=2
outputs: type=image,push=true
- name: Save digest
if: github.ref == 'refs/heads/master'
run: echo ${{ steps.build.outputs.digest }} > /tmp/digest.txt
- name: Save release digest
if: startsWith(github.ref, 'refs/tags/')
run: echo ${{ steps.build_rel.outputs.digest }} > /tmp/digest.txt
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: digest_arm64
path: /tmp/digest.txt
build:
name: Build
needs: [amd64_build, x86_build, armv7_build, arm64_build]
runs-on: ubuntu-latest
steps:
- name: Checkout base
uses: actions/checkout@v3
with:
fetch-depth: 0
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
config-inline: |
[worker.oci]
max-parallelism = 1
- name: Download artifact
uses: actions/download-artifact@v3
with:
path: /tmp/images/
# - name: Load image
# if: github.ref == 'refs/heads/master'
# run: |
# docker load --input /tmp/image_amd64/image_amd64.tar
# docker load --input /tmp/image_386/image_386.tar
# docker load --input /tmp/image_armv7/image_armv7.tar
# docker load --input /tmp/image_arm64/image_arm64.tar
# docker image ls -a
- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# - name: Get commit SHA
# id: vars
# run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
# - name: Docker buildx image and push on master branch
# if: github.ref == 'refs/heads/master'
# uses: docker/build-push-action@v3
# with:
# platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/386
# context: scripts/
# tags: tindy2013/subconverter:latest
# build-args: |
# SHA=${{ steps.vars.outputs.sha_short }}
# THREADS=1
# outputs: |
# type=image,push=true
- name: Replace tag without `v`
if: startsWith(github.ref, 'refs/tags/')
uses: actions/github-script@v6
id: version
with:
script: |
return context.payload.ref.replace(/\/?refs\/tags\/v/, '')
result-encoding: string
# - name: Load release image
# if: startsWith(github.ref, 'refs/tags/')
# run: |
# docker load --input /tmp/image_amd64/image_amd64_release.tar
# docker load --input /tmp/image_386/image_386_release.tar
# docker load --input /tmp/image_armv7/image_armv7_release.tar
# docker load --input /tmp/image_arm64/image_arm64_release.tar
# docker image ls -a
# - name: Docker buildx image and push on release
# if: startsWith(github.ref, 'refs/tags/')
# uses: docker/build-push-action@v3
# with:
# platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/386
# context: scripts/
# tags: tindy2013/subconverter:${{steps.version.outputs.result}}
# build-args: THREADS=1
# outputs: type=image,push=true
- name: Merge and push manifest on master branch
if: github.ref == 'refs/heads/master'
run: python scripts/merge_manifest.py
- name: Merge and push manifest on release
if: startsWith(github.ref, 'refs/tags/')
run: python scripts/merge_manifest.py ${{steps.version.outputs.result}}

View File

@ -10,6 +10,18 @@ docker run -d --restart=always -p 25500:25500 tindy2013/subconverter:latest
curl http://localhost:25500/version
# if you see `subconverter vx.x.x backend` then the container is up and running
```
Or run in docker-compose:
```yaml
---
version: '3'
services:
subconverter:
image: tindy2013/subconverter:latest
container_name: subconverter
ports:
- "15051:25500"
restart: always
```
If you want to update `pref` configuration inside the docker, you can use the following command:
```bash

View File

@ -1,6 +1,6 @@
find_path(QUICKJS_INCLUDE_DIRS quickjs/quickjs.h)
find_library(QUICKJS_LIBRARY quickjs)
find_library(QUICKJS_LIBRARY quickjs/libquickjs.a)
set(QUICKJS_LIBRARIES "${QUICKJS_LIBRARY}")

View File

@ -12,7 +12,8 @@ RUN apk add --no-cache --virtual .build-tools git g++ build-base linux-headers c
git submodule update --init && \
cmake -DCMAKE_BUILD_TYPE=Release . && \
make quickjs -j $THREADS && \
install -m644 quickjs/libquickjs.a /usr/lib && \
install -d /usr/lib/quickjs/ && \
install -m644 quickjs/libquickjs.a /usr/lib/quickjs/ && \
install -d /usr/include/quickjs/ && \
install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h /usr/include/quickjs/ && \
install -m644 quickjspp.hpp /usr/include && \

View File

@ -4,7 +4,7 @@ set -xe
apk add gcc g++ build-base linux-headers cmake make autoconf automake libtool python2
apk add mbedtls-dev mbedtls-static zlib-dev rapidjson-dev libevent-dev libevent-static zlib-static pcre2-dev
git clone https://github.com/curl/curl
git clone https://github.com/curl/curl --depth=1 --branch curl-7_88_1
cd curl
git checkout curl-7_88_0
cmake -DCURL_USE_MBEDTLS=ON -DHTTP_ONLY=ON -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_USE_LIBSSH2=OFF -DBUILD_CURL_EXE=OFF . > /dev/null
@ -21,7 +21,8 @@ git clone https://github.com/ftk/quickjspp --depth=1
cd quickjspp
cmake -DCMAKE_BUILD_TYPE=Release .
make quickjs -j2
install -m644 quickjs/libquickjs.a /usr/lib/
install -d /usr/lib/quickjs/
install -m644 quickjs/libquickjs.a /usr/lib/quickjs/
install -d /usr/include/quickjs/
install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h /usr/include/quickjs/
install -m644 quickjspp.hpp /usr/include/
@ -44,7 +45,7 @@ export PKG_CONFIG_PATH=/usr/lib64/pkgconfig
cmake -DCMAKE_BUILD_TYPE=Release .
make -j2
rm subconverter
g++ -o base/subconverter $(find CMakeFiles/subconverter.dir/src/ -name "*.o") -static -lpcre2-8 -levent -lyaml-cpp -L/usr/lib64 -lcurl -lmbedtls -lmbedcrypto -lmbedx509 -lz -lquickjs -llibcron -O3 -s
g++ -o base/subconverter $(find CMakeFiles/subconverter.dir/src/ -name "*.o") -static -lpcre2-8 -levent -lyaml-cpp -L/usr/lib64 -lcurl -lmbedtls -lmbedcrypto -lmbedx509 -lz -l:quickjs/libquickjs.a -llibcron -O3 -s
cd base
chmod +rx subconverter

View File

@ -3,7 +3,7 @@ set -xe
brew reinstall rapidjson libevent zlib pcre2 pkgconfig
#git clone https://github.com/curl/curl --depth=1
#git clone https://github.com/curl/curl --depth=1 --branch curl-7_88_1
#cd curl
#./buildconf > /dev/null
#./configure --with-ssl=/usr/local/opt/openssl@1.1 --without-mbedtls --disable-ldap --disable-ldaps --disable-rtsp --without-libidn2 > /dev/null
@ -21,7 +21,8 @@ git clone https://github.com/ftk/quickjspp --depth=1
cd quickjspp
cmake -DCMAKE_BUILD_TYPE=Release .
make quickjs -j8
install -m644 quickjs/libquickjs.a /usr/local/lib/
install -d /usr/local/lib/quickjs/
install -m644 quickjs/libquickjs.a /usr/local/lib/quickjs/
install -d /usr/local/include/quickjs/
install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h /usr/local/include/quickjs/
install -m644 quickjspp.hpp /usr/local/include/

View File

@ -1,7 +1,7 @@
#!/bin/bash
set -xe
git clone https://github.com/curl/curl --depth=1
git clone https://github.com/curl/curl --depth=1 --branch curl-7_88_1
cd curl
cmake -DCMAKE_BUILD_TYPE=Release -DCURL_USE_LIBSSH2=OFF -DHTTP_ONLY=ON -DCURL_USE_SCHANNEL=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" -DHAVE_LIBIDN2=OFF -DCURL_USE_LIBPSL=OFF .
make install -j4
@ -18,7 +18,8 @@ cd quickjspp
patch quickjs/quickjs-libc.c -i ../scripts/patches/0001-quickjs-libc-add-realpath-for-Windows.patch
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release .
make quickjs -j4
install -m644 quickjs/libquickjs.a "$MINGW_PREFIX/lib/"
install -d "$MINGW_PREFIX/lib/quickjs/"
install -m644 quickjs/libquickjs.a "$MINGW_PREFIX/lib/quickjs/"
install -d "$MINGW_PREFIX/include/quickjs"
install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h "$MINGW_PREFIX/include/quickjs/"
install -m644 quickjspp.hpp "$MINGW_PREFIX/include/"
@ -47,5 +48,5 @@ rm -f C:/Strawberry/perl/bin/pkg-config C:/Strawberry/perl/bin/pkg-config.bat
cmake -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" .
make -j4
rm subconverter.exe
g++ $(find CMakeFiles/subconverter.dir/src -name "*.obj") curl/lib/libcurl.a -o base/subconverter.exe -static -lbcrypt -levent -lpcre2-8 -lquickjs -llibcron -lyaml-cpp -liphlpapi -lcrypt32 -lws2_32 -lwsock32 -lz -s
g++ $(find CMakeFiles/subconverter.dir/src -name "*.obj") curl/lib/libcurl.a -o base/subconverter.exe -static -lbcrypt -levent -lpcre2-8 -l:quickjs/libquickjs.a -llibcron -lyaml-cpp -liphlpapi -lcrypt32 -lws2_32 -lwsock32 -lz -s
mv base subconverter

View File

@ -20,7 +20,8 @@ git clone https://github.com/ftk/quickjspp --depth=1
cd quickjspp
cmake -DCMAKE_BUILD_TYPE=Release .
make quickjs -j3
install -m644 quickjs/libquickjs.a $PREFIX/lib/
install -d $PREFIX/lib/quickjs/
install -m644 quickjs/libquickjs.a $PREFIX/lib/quickjs/
install -d $PREFIX/include/quickjs/
install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h $PREFIX/include/quickjs/
install -m644 quickjspp.hpp $PREFIX/include/

View File

@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include <tuple>
#include <cstdint>
#include "../utils/string.h"
#include "../utils/tribool.h"

View File

@ -68,7 +68,7 @@ int addNodes(std::string link, std::vector<Proxy> &allNodes, int groupID, parse_
switch(args.size())
{
case 0:
link = parse(std::string(), string_array());
link = parse("", string_array());
break;
case 1:
link = parse(args[0], string_array());

View File

@ -177,7 +177,7 @@ std::string rulesetToClashStr(YAML::Node &base_rule, std::vector<RulesetContent>
if(!overwrite_original_rules && base_rule[field_name].IsDefined())
{
for(size_t i = 0; i < base_rule[field_name].size(); i++)
output_content += " - " + safe_as<std::string>(base_rule[field_name][i]) + "\n";
output_content += " - " + safe_as<std::string>(base_rule[field_name][i]) + "\n";
}
base_rule.remove(field_name);
@ -200,7 +200,7 @@ std::string rulesetToClashStr(YAML::Node &base_rule, std::vector<RulesetContent>
strLine += "," + rule_group;
if(count_least(strLine, ',', 3))
strLine = regReplace(strLine, "^(.*?,.*?)(,.*)(,.*)$", "$1$3$2");
output_content += " - " + strLine + "\n";
output_content += " - " + strLine + "\n";
total_rules++;
continue;
}
@ -228,7 +228,7 @@ std::string rulesetToClashStr(YAML::Node &base_rule, std::vector<RulesetContent>
strLine += "," + rule_group;
if(count_least(strLine, ',', 3))
strLine = regReplace(strLine, "^(.*?,.*?)(,.*)(,.*)$", "$1$3$2");
output_content += " - " + strLine + "\n";
output_content += " - " + strLine + "\n";
total_rules++;
}
}
@ -245,28 +245,28 @@ void rulesetToSurge(INIReader &base_rule, std::vector<RulesetContent> &ruleset_c
switch(surge_ver) //other version: -3 for Surfboard, -4 for Loon
{
case 0:
base_rule.SetCurrentSection("RoutingRule"); //Mellow
base_rule.set_current_section("RoutingRule"); //Mellow
break;
case -1:
base_rule.SetCurrentSection("filter_local"); //Quantumult X
base_rule.set_current_section("filter_local"); //Quantumult X
break;
case -2:
base_rule.SetCurrentSection("TCP"); //Quantumult
base_rule.set_current_section("TCP"); //Quantumult
break;
default:
base_rule.SetCurrentSection("Rule");
base_rule.set_current_section("Rule");
}
if(overwrite_original_rules)
{
base_rule.EraseSection();
base_rule.erase_section();
switch(surge_ver)
{
case -1:
base_rule.EraseSection("filter_remote");
base_rule.erase_section("filter_remote");
break;
case -4:
base_rule.EraseSection("Remote Rule");
base_rule.erase_section("Remote Rule");
break;
}
}
@ -308,7 +308,7 @@ void rulesetToSurge(INIReader &base_rule, std::vector<RulesetContent> &ruleset_c
if(surge_ver == -1 && x.rule_type == RULESET_QUANX && isLink(rule_path))
{
strLine = rule_path + ", tag=" + rule_group + ", force-policy=" + rule_group + ", enabled=true";
base_rule.Set("filter_remote", "{NONAME}", strLine);
base_rule.set("filter_remote", "{NONAME}", strLine);
continue;
}
if(fileExist(rule_path))
@ -325,13 +325,13 @@ void rulesetToSurge(INIReader &base_rule, std::vector<RulesetContent> &ruleset_c
{
strLine = remote_path_prefix + "/getruleset?type=2&url=" + urlSafeBase64Encode(rule_path_typed) + "&group=" + urlSafeBase64Encode(rule_group);
strLine += ", tag=" + rule_group + ", enabled=true";
base_rule.Set("filter_remote", "{NONAME}", strLine);
base_rule.set("filter_remote", "{NONAME}", strLine);
continue;
}
else if(surge_ver == -4 && remote_path_prefix.size())
{
strLine = remote_path_prefix + "/getruleset?type=1&url=" + urlSafeBase64Encode(rule_path_typed) + "," + rule_group;
base_rule.Set("Remote Rule", "{NONAME}", strLine);
base_rule.set("Remote Rule", "{NONAME}", strLine);
continue;
}
}
@ -359,13 +359,13 @@ void rulesetToSurge(INIReader &base_rule, std::vector<RulesetContent> &ruleset_c
{
strLine = remote_path_prefix + "/getruleset?type=2&url=" + urlSafeBase64Encode(rule_path_typed) + "&group=" + urlSafeBase64Encode(rule_group);
strLine += ", tag=" + rule_group + ", enabled=true";
base_rule.Set("filter_remote", "{NONAME}", strLine);
base_rule.set("filter_remote", "{NONAME}", strLine);
continue;
}
else if(surge_ver == -4)
{
strLine = rule_path + "," + rule_group;
base_rule.Set("Remote Rule", "{NONAME}", strLine);
base_rule.set("Remote Rule", "{NONAME}", strLine);
continue;
}
}
@ -450,6 +450,6 @@ void rulesetToSurge(INIReader &base_rule, std::vector<RulesetContent> &ruleset_c
for(std::string &x : allRules)
{
base_rule.Set("{NONAME}", x);
base_rule.set("{NONAME}", x);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -151,7 +151,7 @@ int render_template(const std::string &content, const template_args &vars, std::
{
std::string key = args.at(0)->get<std::string>(), value = args.at(1)->get<std::string>();
parse_json_pointer(data, key, value);
return std::string();
return "";
});
env.add_callback("split", 3, [&data](inja::Arguments &args)
{
@ -159,7 +159,7 @@ int render_template(const std::string &content, const template_args &vars, std::
string_array vArray = split(content, delim);
for(size_t index = 0; index < vArray.size(); index++)
parse_json_pointer(data, dest + "." + std::to_string(index), vArray[index]);
return std::string();
return "";
});
env.add_callback("append", 2, [&data](inja::Arguments &args)
{
@ -175,7 +175,7 @@ int render_template(const std::string &content, const template_args &vars, std::
}
output_content.append(value);
data[nlohmann::json::json_pointer(pointer)] = output_content;
return std::string();
return "";
});
env.add_callback("getLink", 1, [](inja::Arguments &args)
{

View File

@ -959,15 +959,15 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
base_content = fetchFile(url, proxy, global.cacheConfig);
if(ini.Parse(base_content) != INIREADER_EXCEPTION_NONE)
if(ini.parse(base_content) != INIREADER_EXCEPTION_NONE)
{
std::string errmsg = "Parsing Surge config failed! Reason: " + ini.GetLastError();
std::string errmsg = "Parsing Surge config failed! Reason: " + ini.get_last_error();
//std::cerr<<errmsg<<"\n";
writeLog(0, errmsg, LOG_LEVEL_ERROR);
*status_code = 400;
return errmsg;
}
if(!ini.SectionExist("Proxy") || !ini.SectionExist("Proxy Group") || !ini.SectionExist("Rule"))
if(!ini.section_exist("Proxy") || !ini.section_exist("Proxy Group") || !ini.section_exist("Rule"))
{
std::string errmsg = "Incomplete surge config! Missing critical sections!";
//std::cerr<<errmsg<<"\n";
@ -978,7 +978,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
//scan groups first, get potential policy-path
string_multimap section;
ini.GetItems("Proxy Group", section);
ini.get_items("Proxy Group", section);
std::string name, type, content;
string_array links;
links.emplace_back(url);
@ -1059,7 +1059,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
proxyToClash(nodes, clash, dummy_groups, false, ext);
section.clear();
ini.GetItems("Proxy", section);
ini.get_items("Proxy", section);
for(auto &x : section)
{
singlegroup.reset();
@ -1089,7 +1089,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
}
eraseElements(dummy_str_array);
ini.GetAll("Rule", "{NONAME}", dummy_str_array);
ini.get_all("Rule", "{NONAME}", dummy_str_array);
YAML::Node rule;
string_array strArray;
std::string strLine;
@ -1167,17 +1167,17 @@ std::string getProfile(RESPONSE_CALLBACK_ARGS)
//std::cerr<<"Trying to load profile '" + name + "'.\n";
writeLog(0, "Trying to load profile '" + name + "'.", LOG_LEVEL_INFO);
INIReader ini;
if(ini.Parse(profile_content) != INIREADER_EXCEPTION_NONE && !ini.SectionExist("Profile"))
if(ini.parse(profile_content) != INIREADER_EXCEPTION_NONE && !ini.section_exist("Profile"))
{
//std::cerr<<"Load profile failed! Reason: "<<ini.GetLastError()<<"\n";
writeLog(0, "Load profile failed! Reason: " + ini.GetLastError(), LOG_LEVEL_ERROR);
//std::cerr<<"Load profile failed! Reason: "<<ini.get_last_error()<<"\n";
writeLog(0, "Load profile failed! Reason: " + ini.get_last_error(), LOG_LEVEL_ERROR);
*status_code = 500;
return "Broken profile!";
}
//std::cerr<<"Trying to parse profile '" + name + "'.\n";
writeLog(0, "Trying to parse profile '" + name + "'.", LOG_LEVEL_INFO);
string_multimap contents;
ini.GetItems("Profile", contents);
ini.get_items("Profile", contents);
if(!contents.size())
{
//std::cerr<<"Load profile failed! Reason: Empty Profile section\n";
@ -1219,12 +1219,12 @@ std::string getProfile(RESPONSE_CALLBACK_ARGS)
writeLog(0, "Ignoring non-exist profile '" + name + "'...", LOG_LEVEL_WARNING);
continue;
}
if(ini.ParseFile(name) != INIREADER_EXCEPTION_NONE && !ini.SectionExist("Profile"))
if(ini.parse_file(name) != INIREADER_EXCEPTION_NONE && !ini.section_exist("Profile"))
{
writeLog(0, "Ignoring broken profile '" + name + "'...", LOG_LEVEL_WARNING);
continue;
}
url = ini.Get("Profile", "url");
url = ini.get("Profile", "url");
if(url.size())
{
all_urls += "|" + url;
@ -1309,16 +1309,16 @@ int simpleGenerator()
}
INIReader ini;
if(ini.Parse(config) != INIREADER_EXCEPTION_NONE)
if(ini.parse(config) != INIREADER_EXCEPTION_NONE)
{
//std::cerr<<"Generator configuration broken! Reason:"<<ini.GetLastError()<<"\n";
writeLog(0, "Generator configuration broken! Reason:" + ini.GetLastError(), LOG_LEVEL_ERROR);
//std::cerr<<"Generator configuration broken! Reason:"<<ini.get_last_error()<<"\n";
writeLog(0, "Generator configuration broken! Reason:" + ini.get_last_error(), LOG_LEVEL_ERROR);
return -2;
}
//std::cerr<<"Read generator configuration completed.\n\n";
writeLog(0, "Read generator configuration completed.\n", LOG_LEVEL_INFO);
string_array sections = ini.GetSections();
string_array sections = ini.get_section_names();
if(global.generateProfiles.size())
{
//std::cerr<<"Generating with specific artifacts: \""<<gen_profile<<"\"...\n";
@ -1353,26 +1353,26 @@ int simpleGenerator()
response.status_code = 200;
//std::cerr<<"Generating artifact '"<<x<<"'...\n";
writeLog(0, "Generating artifact '" + x + "'...", LOG_LEVEL_INFO);
ini.EnterSection(x);
if(ini.ItemExist("path"))
path = ini.Get("path");
ini.enter_section(x);
if(ini.item_exist("path"))
path = ini.get("path");
else
{
//std::cerr<<"Artifact '"<<x<<"' output path missing! Skipping...\n\n";
writeLog(0, "Artifact '" + x + "' output path missing! Skipping...\n", LOG_LEVEL_ERROR);
continue;
}
if(ini.ItemExist("profile"))
if(ini.item_exist("profile"))
{
profile = ini.Get("profile");
profile = ini.get("profile");
request.argument = "name=" + urlEncode(profile) + "&token=" + global.accessToken + "&expand=true";
content = getProfile(request, response);
}
else
{
if(ini.GetBool("direct") == true)
if(ini.get_bool("direct") == true)
{
std::string url = ini.Get("url");
std::string url = ini.get("url");
content = fetchFile(url, proxy, global.cacheSubscription);
if(content.empty())
{
@ -1385,7 +1385,7 @@ int simpleGenerator()
fileWrite(path, "\xEF\xBB\xBF" + content, true);
continue;
}
ini.GetItems(allItems);
ini.get_items(allItems);
allItems.emplace("expand", "true");
for(auto &y : allItems)
{

View File

@ -804,7 +804,7 @@ void readConf()
try
{
std::string prefdata = fileGet(global.prefPath, false);
if(prefdata.find("common:") != prefdata.npos)
if(prefdata.find("common:") != std::string::npos)
{
YAML::Node yaml = YAML::Load(prefdata);
if(yaml.size() && yaml["common"])
@ -830,69 +830,69 @@ void readConf()
INIReader ini;
ini.allow_dup_section_titles = true;
//ini.do_utf8_to_gbk = true;
int retVal = ini.ParseFile(global.prefPath);
int retVal = ini.parse_file(global.prefPath);
if(retVal != INIREADER_EXCEPTION_NONE)
{
writeLog(0, "Unable to load preference settings as INI. Reason: " + ini.GetLastError(), LOG_LEVEL_FATAL);
writeLog(0, "Unable to load preference settings as INI. Reason: " + ini.get_last_error(), LOG_LEVEL_FATAL);
return;
}
string_array tempArray;
ini.EnterSection("common");
ini.GetBoolIfExist("api_mode", global.APIMode);
ini.GetIfExist("api_access_token", global.accessToken);
ini.GetIfExist("default_url", global.defaultUrls);
global.enableInsert = ini.Get("enable_insert");
ini.GetIfExist("insert_url", global.insertUrls);
ini.GetBoolIfExist("prepend_insert_url", global.prependInsert);
if(ini.ItemPrefixExist("exclude_remarks"))
ini.GetAll("exclude_remarks", global.excludeRemarks);
if(ini.ItemPrefixExist("include_remarks"))
ini.GetAll("include_remarks", global.includeRemarks);
global.filterScript = ini.GetBool("enable_filter") ? ini.Get("filter_script"): "";
ini.GetIfExist("base_path", global.basePath);
ini.GetIfExist("clash_rule_base", global.clashBase);
ini.GetIfExist("surge_rule_base", global.surgeBase);
ini.GetIfExist("surfboard_rule_base", global.surfboardBase);
ini.GetIfExist("mellow_rule_base", global.mellowBase);
ini.GetIfExist("quan_rule_base", global.quanBase);
ini.GetIfExist("quanx_rule_base", global.quanXBase);
ini.GetIfExist("loon_rule_base", global.loonBase);
ini.GetIfExist("default_external_config", global.defaultExtConfig);
ini.GetBoolIfExist("append_proxy_type", global.appendType);
ini.GetIfExist("proxy_config", global.proxyConfig);
ini.GetIfExist("proxy_ruleset", global.proxyRuleset);
ini.GetIfExist("proxy_subscription", global.proxySubscription);
ini.enter_section("common");
ini.get_bool_if_exist("api_mode", global.APIMode);
ini.get_if_exist("api_access_token", global.accessToken);
ini.get_if_exist("default_url", global.defaultUrls);
global.enableInsert = ini.get("enable_insert");
ini.get_if_exist("insert_url", global.insertUrls);
ini.get_bool_if_exist("prepend_insert_url", global.prependInsert);
if(ini.item_prefix_exist("exclude_remarks"))
ini.get_all("exclude_remarks", global.excludeRemarks);
if(ini.item_prefix_exist("include_remarks"))
ini.get_all("include_remarks", global.includeRemarks);
global.filterScript = ini.get_bool("enable_filter") ? ini.get("filter_script") : "";
ini.get_if_exist("base_path", global.basePath);
ini.get_if_exist("clash_rule_base", global.clashBase);
ini.get_if_exist("surge_rule_base", global.surgeBase);
ini.get_if_exist("surfboard_rule_base", global.surfboardBase);
ini.get_if_exist("mellow_rule_base", global.mellowBase);
ini.get_if_exist("quan_rule_base", global.quanBase);
ini.get_if_exist("quanx_rule_base", global.quanXBase);
ini.get_if_exist("loon_rule_base", global.loonBase);
ini.get_if_exist("default_external_config", global.defaultExtConfig);
ini.get_bool_if_exist("append_proxy_type", global.appendType);
ini.get_if_exist("proxy_config", global.proxyConfig);
ini.get_if_exist("proxy_ruleset", global.proxyRuleset);
ini.get_if_exist("proxy_subscription", global.proxySubscription);
if(ini.SectionExist("surge_external_proxy"))
if(ini.section_exist("surge_external_proxy"))
{
ini.EnterSection("surge_external_proxy");
ini.GetIfExist("surge_ssr_path", global.surgeSSRPath);
ini.GetBoolIfExist("resolve_hostname", global.surgeResolveHostname);
ini.enter_section("surge_external_proxy");
ini.get_if_exist("surge_ssr_path", global.surgeSSRPath);
ini.get_bool_if_exist("resolve_hostname", global.surgeResolveHostname);
}
if(ini.SectionExist("node_pref"))
if(ini.section_exist("node_pref"))
{
ini.EnterSection("node_pref");
ini.enter_section("node_pref");
/*
ini.GetBoolIfExist("udp_flag", udp_flag);
ini.GetBoolIfExist("tcp_fast_open_flag", tfo_flag);
ini.GetBoolIfExist("skip_cert_verify_flag", scv_flag);
ini.get_bool_if_exist("tcp_fast_open_flag", tfo_flag);
ini.get_bool_if_exist("skip_cert_verify_flag", scv_flag);
*/
global.UDPFlag.set(ini.Get("udp_flag"));
global.TFOFlag.set(ini.Get("tcp_fast_open_flag"));
global.skipCertVerify.set(ini.Get("skip_cert_verify_flag"));
global.TLS13Flag.set(ini.Get("tls13_flag"));
ini.GetBoolIfExist("sort_flag", global.enableSort);
global.sortScript = ini.Get("sort_script");
ini.GetBoolIfExist("filter_deprecated_nodes", global.filterDeprecated);
ini.GetBoolIfExist("append_sub_userinfo", global.appendUserinfo);
ini.GetBoolIfExist("clash_use_new_field_name", global.clashUseNewField);
ini.GetIfExist("clash_proxies_style", global.clashProxiesStyle);
if(ini.ItemPrefixExist("rename_node"))
global.UDPFlag.set(ini.get("udp_flag"));
global.TFOFlag.set(ini.get("tcp_fast_open_flag"));
global.skipCertVerify.set(ini.get("skip_cert_verify_flag"));
global.TLS13Flag.set(ini.get("tls13_flag"));
ini.get_bool_if_exist("sort_flag", global.enableSort);
global.sortScript = ini.get("sort_script");
ini.get_bool_if_exist("filter_deprecated_nodes", global.filterDeprecated);
ini.get_bool_if_exist("append_sub_userinfo", global.appendUserinfo);
ini.get_bool_if_exist("clash_use_new_field_name", global.clashUseNewField);
ini.get_if_exist("clash_proxies_style", global.clashProxiesStyle);
if(ini.item_prefix_exist("rename_node"))
{
ini.GetAll("rename_node", tempArray);
ini.get_all("rename_node", tempArray);
importItems(tempArray, false);
auto configs = INIBinding::from<RegexMatchConfig>::from_ini(tempArray, "@");
safe_set_renames(configs);
@ -900,20 +900,20 @@ void readConf()
}
}
if(ini.SectionExist("userinfo"))
if(ini.section_exist("userinfo"))
{
ini.EnterSection("userinfo");
if(ini.ItemPrefixExist("stream_rule"))
ini.enter_section("userinfo");
if(ini.item_prefix_exist("stream_rule"))
{
ini.GetAll("stream_rule", tempArray);
ini.get_all("stream_rule", tempArray);
importItems(tempArray, false);
auto configs = INIBinding::from<RegexMatchConfig>::from_ini(tempArray, "|");
safe_set_streams(configs);
eraseElements(tempArray);
}
if(ini.ItemPrefixExist("time_rule"))
if(ini.item_prefix_exist("time_rule"))
{
ini.GetAll("time_rule", tempArray);
ini.get_all("time_rule", tempArray);
importItems(tempArray, false);
auto configs = INIBinding::from<RegexMatchConfig>::from_ini(tempArray, "|");
safe_set_times(configs);
@ -921,45 +921,45 @@ void readConf()
}
}
ini.EnterSection("managed_config");
ini.GetBoolIfExist("write_managed_config", global.writeManagedConfig);
ini.GetIfExist("managed_config_prefix", global.managedConfigPrefix);
ini.GetIntIfExist("config_update_interval", global.updateInterval);
ini.GetBoolIfExist("config_update_strict", global.updateStrict);
ini.GetIfExist("quanx_device_id", global.quanXDevID);
ini.enter_section("managed_config");
ini.get_bool_if_exist("write_managed_config", global.writeManagedConfig);
ini.get_if_exist("managed_config_prefix", global.managedConfigPrefix);
ini.get_int_if_exist("config_update_interval", global.updateInterval);
ini.get_bool_if_exist("config_update_strict", global.updateStrict);
ini.get_if_exist("quanx_device_id", global.quanXDevID);
ini.EnterSection("emojis");
ini.GetBoolIfExist("add_emoji", global.addEmoji);
ini.GetBoolIfExist("remove_old_emoji", global.removeEmoji);
if(ini.ItemPrefixExist("rule"))
ini.enter_section("emojis");
ini.get_bool_if_exist("add_emoji", global.addEmoji);
ini.get_bool_if_exist("remove_old_emoji", global.removeEmoji);
if(ini.item_prefix_exist("rule"))
{
ini.GetAll("rule", tempArray);
ini.get_all("rule", tempArray);
importItems(tempArray, false);
auto configs = INIBinding::from<RegexMatchConfig>::from_ini(tempArray, ",");
safe_set_emojis(configs);
eraseElements(tempArray);
}
if(ini.SectionExist("rulesets"))
ini.EnterSection("rulesets");
if(ini.section_exist("rulesets"))
ini.enter_section("rulesets");
else
ini.EnterSection("ruleset");
global.enableRuleGen = ini.GetBool("enabled");
ini.enter_section("ruleset");
global.enableRuleGen = ini.get_bool("enabled");
if(global.enableRuleGen)
{
ini.GetBoolIfExist("overwrite_original_rules", global.overwriteOriginalRules);
ini.GetBoolIfExist("update_ruleset_on_request", global.updateRulesetOnRequest);
if(ini.ItemPrefixExist("ruleset"))
ini.get_bool_if_exist("overwrite_original_rules", global.overwriteOriginalRules);
ini.get_bool_if_exist("update_ruleset_on_request", global.updateRulesetOnRequest);
if(ini.item_prefix_exist("ruleset"))
{
string_array vArray;
ini.GetAll("ruleset", vArray);
ini.get_all("ruleset", vArray);
importItems(vArray, false);
global.customRulesets = INIBinding::from<RulesetConfig>::from_ini(vArray);
}
else if(ini.ItemPrefixExist("surge_ruleset"))
else if(ini.item_prefix_exist("surge_ruleset"))
{
string_array vArray;
ini.GetAll("surge_ruleset", vArray);
ini.get_all("surge_ruleset", vArray);
importItems(vArray, false);
global.customRulesets = INIBinding::from<RulesetConfig>::from_ini(vArray);
}
@ -970,22 +970,22 @@ void readConf()
global.updateRulesetOnRequest = false;
}
if(ini.SectionExist("proxy_groups"))
ini.EnterSection("proxy_groups");
if(ini.section_exist("proxy_groups"))
ini.enter_section("proxy_groups");
else
ini.EnterSection("clash_proxy_group");
if(ini.ItemPrefixExist("custom_proxy_group"))
ini.enter_section("clash_proxy_group");
if(ini.item_prefix_exist("custom_proxy_group"))
{
string_array vArray;
ini.GetAll("custom_proxy_group", vArray);
ini.get_all("custom_proxy_group", vArray);
importItems(vArray, false);
global.customProxyGroups = INIBinding::from<ProxyGroupConfig>::from_ini(vArray);
}
ini.EnterSection("template");
ini.GetIfExist("template_path", global.templatePath);
ini.enter_section("template");
ini.get_if_exist("template_path", global.templatePath);
string_multimap tempmap;
ini.GetItems(tempmap);
ini.get_items(tempmap);
eraseElements(global.templateVars);
for(auto &x : tempmap)
{
@ -995,36 +995,36 @@ void readConf()
}
global.templateVars["managed_config_prefix"] = global.managedConfigPrefix;
if(ini.SectionExist("aliases"))
if(ini.section_exist("aliases"))
{
ini.EnterSection("aliases");
ini.GetItems(tempmap);
ini.enter_section("aliases");
ini.get_items(tempmap);
webServer.reset_redirect();
for(auto &x : tempmap)
webServer.append_redirect(x.first, x.second);
}
if(ini.SectionExist("tasks"))
if(ini.section_exist("tasks"))
{
string_array vArray;
ini.EnterSection("tasks");
ini.GetAll("task", vArray);
ini.enter_section("tasks");
ini.get_all("task", vArray);
importItems(vArray, false);
global.enableCron = !vArray.empty();
global.cronTasks = INIBinding::from<CronTaskConfig>::from_ini(vArray);
refresh_schedule();
}
ini.EnterSection("server");
ini.GetIfExist("listen", global.listenAddress);
ini.GetIntIfExist("port", global.listenPort);
webServer.serve_file_root = ini.Get("serve_file_root");
ini.enter_section("server");
ini.get_if_exist("listen", global.listenAddress);
ini.get_int_if_exist("port", global.listenPort);
webServer.serve_file_root = ini.get("serve_file_root");
webServer.serve_file = !webServer.serve_file_root.empty();
ini.EnterSection("advanced");
ini.enter_section("advanced");
std::string log_level;
ini.GetIfExist("log_level", log_level);
ini.GetBoolIfExist("print_debug_info", global.printDbgInfo);
ini.get_if_exist("log_level", log_level);
ini.get_bool_if_exist("print_debug_info", global.printDbgInfo);
if(global.printDbgInfo)
global.logLevel = LOG_LEVEL_VERBOSE;
else
@ -1050,19 +1050,19 @@ void readConf()
global.logLevel = LOG_LEVEL_INFO;
}
}
ini.GetIntIfExist("max_pending_connections", global.maxPendingConns);
ini.GetIntIfExist("max_concurrent_threads", global.maxConcurThreads);
ini.GetNumberIfExist("max_allowed_rulesets", global.maxAllowedRulesets);
ini.GetNumberIfExist("max_allowed_rules", global.maxAllowedRules);
ini.GetNumberIfExist("max_allowed_download_size", global.maxAllowedDownloadSize);
if(ini.ItemExist("enable_cache"))
ini.get_int_if_exist("max_pending_connections", global.maxPendingConns);
ini.get_int_if_exist("max_concurrent_threads", global.maxConcurThreads);
ini.get_number_if_exist("max_allowed_rulesets", global.maxAllowedRulesets);
ini.get_number_if_exist("max_allowed_rules", global.maxAllowedRules);
ini.get_number_if_exist("max_allowed_download_size", global.maxAllowedDownloadSize);
if(ini.item_exist("enable_cache"))
{
if(ini.GetBool("enable_cache"))
if(ini.get_bool("enable_cache"))
{
ini.GetIntIfExist("cache_subscription", global.cacheSubscription);
ini.GetIntIfExist("cache_config", global.cacheConfig);
ini.GetIntIfExist("cache_ruleset", global.cacheRuleset);
ini.GetBoolIfExist("serve_cache_on_fetch_fail", global.serveCacheOnFetchFail);
ini.get_int_if_exist("cache_subscription", global.cacheSubscription);
ini.get_int_if_exist("cache_config", global.cacheConfig);
ini.get_int_if_exist("cache_ruleset", global.cacheRuleset);
ini.get_bool_if_exist("serve_cache_on_fetch_fail", global.serveCacheOnFetchFail);
}
else
{
@ -1070,9 +1070,9 @@ void readConf()
global.serveCacheOnFetchFail = false;
}
}
ini.GetBoolIfExist("script_clean_context", global.scriptCleanContext);
ini.GetBoolIfExist("async_fetch_ruleset", global.asyncFetchRuleset);
ini.GetBoolIfExist("skip_failed_links", global.skipFailedLinks);
ini.get_bool_if_exist("script_clean_context", global.scriptCleanContext);
ini.get_bool_if_exist("async_fetch_ruleset", global.asyncFetchRuleset);
ini.get_bool_if_exist("skip_failed_links", global.skipFailedLinks);
writeLog(0, "Load preference settings in INI format completed.", LOG_LEVEL_INFO);
}
@ -1227,27 +1227,27 @@ int loadExternalConfig(std::string &path, ExternalConfig &ext)
INIReader ini;
ini.store_isolated_line = true;
ini.SetIsolatedItemsSection("custom");
if(ini.Parse(base_content) != INIREADER_EXCEPTION_NONE)
ini.set_isolated_items_section("custom");
if(ini.parse(base_content) != INIREADER_EXCEPTION_NONE)
{
//std::cerr<<"Load external configuration failed. Reason: "<<ini.GetLastError()<<"\n";
writeLog(0, "Load external configuration failed. Reason: " + ini.GetLastError(), LOG_LEVEL_ERROR);
//std::cerr<<"Load external configuration failed. Reason: "<<ini.get_last_error()<<"\n";
writeLog(0, "Load external configuration failed. Reason: " + ini.get_last_error(), LOG_LEVEL_ERROR);
return -1;
}
ini.EnterSection("custom");
if(ini.ItemPrefixExist("custom_proxy_group"))
ini.enter_section("custom");
if(ini.item_prefix_exist("custom_proxy_group"))
{
string_array vArray;
ini.GetAll("custom_proxy_group", vArray);
ini.get_all("custom_proxy_group", vArray);
importItems(vArray, global.APIMode);
ext.custom_proxy_group = INIBinding::from<ProxyGroupConfig>::from_ini(vArray);
}
std::string ruleset_name = ini.ItemPrefixExist("ruleset") ? "ruleset" : "surge_ruleset";
if(ini.ItemPrefixExist(ruleset_name))
std::string ruleset_name = ini.item_prefix_exist("ruleset") ? "ruleset" : "surge_ruleset";
if(ini.item_prefix_exist(ruleset_name))
{
string_array vArray;
ini.GetAll(ruleset_name, vArray);
ini.get_all(ruleset_name, vArray);
importItems(vArray, global.APIMode);
if(global.maxAllowedRulesets && vArray.size() > global.maxAllowedRulesets)
{
@ -1257,44 +1257,44 @@ int loadExternalConfig(std::string &path, ExternalConfig &ext)
ext.surge_ruleset = INIBinding::from<RulesetConfig>::from_ini(vArray);
}
ini.GetIfExist("clash_rule_base", ext.clash_rule_base);
ini.GetIfExist("surge_rule_base", ext.surge_rule_base);
ini.GetIfExist("surfboard_rule_base", ext.surfboard_rule_base);
ini.GetIfExist("mellow_rule_base", ext.mellow_rule_base);
ini.GetIfExist("quan_rule_base", ext.quan_rule_base);
ini.GetIfExist("quanx_rule_base", ext.quanx_rule_base);
ini.GetIfExist("loon_rule_base", ext.loon_rule_base);
ini.GetIfExist("sssub_rule_base", ext.sssub_rule_base);
ini.get_if_exist("clash_rule_base", ext.clash_rule_base);
ini.get_if_exist("surge_rule_base", ext.surge_rule_base);
ini.get_if_exist("surfboard_rule_base", ext.surfboard_rule_base);
ini.get_if_exist("mellow_rule_base", ext.mellow_rule_base);
ini.get_if_exist("quan_rule_base", ext.quan_rule_base);
ini.get_if_exist("quanx_rule_base", ext.quanx_rule_base);
ini.get_if_exist("loon_rule_base", ext.loon_rule_base);
ini.get_if_exist("sssub_rule_base", ext.sssub_rule_base);
ini.GetBoolIfExist("overwrite_original_rules", ext.overwrite_original_rules);
ini.GetBoolIfExist("enable_rule_generator", ext.enable_rule_generator);
ini.get_bool_if_exist("overwrite_original_rules", ext.overwrite_original_rules);
ini.get_bool_if_exist("enable_rule_generator", ext.enable_rule_generator);
if(ini.ItemPrefixExist("rename"))
if(ini.item_prefix_exist("rename"))
{
string_array vArray;
ini.GetAll("rename", vArray);
ini.get_all("rename", vArray);
importItems(vArray, global.APIMode);
ext.rename = INIBinding::from<RegexMatchConfig>::from_ini(vArray, "@");
}
ext.add_emoji = ini.Get("add_emoji");
ext.remove_old_emoji = ini.Get("remove_old_emoji");
if(ini.ItemPrefixExist("emoji"))
ext.add_emoji = ini.get("add_emoji");
ext.remove_old_emoji = ini.get("remove_old_emoji");
if(ini.item_prefix_exist("emoji"))
{
string_array vArray;
ini.GetAll("emoji", vArray);
ini.get_all("emoji", vArray);
importItems(vArray, global.APIMode);
ext.emoji = INIBinding::from<RegexMatchConfig>::from_ini(vArray, ",");
}
if(ini.ItemPrefixExist("include_remarks"))
ini.GetAll("include_remarks", ext.include);
if(ini.ItemPrefixExist("exclude_remarks"))
ini.GetAll("exclude_remarks", ext.exclude);
if(ini.item_prefix_exist("include_remarks"))
ini.get_all("include_remarks", ext.include);
if(ini.item_prefix_exist("exclude_remarks"))
ini.get_all("exclude_remarks", ext.exclude);
if(ini.SectionExist("template") && ext.tpl_args != nullptr)
if(ini.section_exist("template") && ext.tpl_args != nullptr)
{
ini.EnterSection("template");
ini.enter_section("template");
string_multimap tempmap;
ini.GetItems(tempmap);
ini.get_items(tempmap);
for(auto &x : tempmap)
ext.tpl_args->local_vars[x.first] = x.second;
}

View File

@ -41,15 +41,15 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
return -1;
}
ini.ParseFile("gistconf.ini");
if(ini.EnterSection("common") != 0)
ini.parse_file("gistconf.ini");
if(ini.enter_section("common") != 0)
{
//std::cerr<<"gistconf.ini has incorrect format. Skipping...\n";
writeLog(0, "gistconf.ini has incorrect format. Skipping...", LOG_LEVEL_ERROR);
return -1;
}
token = ini.Get("token");
token = ini.get("token");
if(!token.size())
{
//std::cerr<<"No token is provided. Skipping...\n";
@ -57,12 +57,12 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
return -1;
}
id = ini.Get("id");
username = ini.Get("username");
id = ini.get("id");
username = ini.get("username");
if(!path.size())
{
if(ini.ItemExist("path"))
path = ini.Get(name, "path");
if(ini.item_exist("path"))
path = ini.get(name, "path");
else
path = name;
}
@ -102,16 +102,16 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
//std::cerr<<"Writing to Gist success!\nGenerator: "<<name<<"\nPath: "<<path<<"\nRaw URL: "<<url<<"\nGist owner: "<<username<<"\n";
writeLog(0, "Writing to Gist success!\nGenerator: " + name + "\nPath: " + path + "\nRaw URL: " + url + "\nGist owner: " + username, LOG_LEVEL_INFO);
ini.EraseSection();
ini.Set("token", token);
ini.Set("id", id);
ini.Set("username", username);
ini.erase_section();
ini.set("token", token);
ini.set("id", id);
ini.set("username", username);
ini.SetCurrentSection(path);
ini.EraseSection();
ini.Set("type", name);
ini.Set("url", url);
ini.set_current_section(path);
ini.erase_section();
ini.set("type", name);
ini.set("url", url);
ini.ToFile("gistconf.ini");
ini.to_file("gistconf.ini");
return 0;
}

View File

@ -295,10 +295,10 @@ static int curlGet(const FetchArgument &argument, FetchResult &result)
static std::string dataGet(const std::string &url)
{
if (!startsWith(url, "data:"))
return std::string();
return "";
std::string::size_type comma = url.find(',');
if (comma == std::string::npos || comma == url.size() - 1)
return std::string();
return "";
std::string data = urlDecode(url.substr(comma + 1));
if (endsWith(url.substr(0, comma), ";base64")) {

View File

@ -4,4 +4,4 @@
Settings global;
bool fileExist(const std::string&, bool) { return false; }
std::string fileGet(const std::string&, bool) { return std::string(); }
std::string fileGet(const std::string&, bool) { return ""; }

View File

@ -174,9 +174,9 @@ int main(int argc, char *argv[])
std::string env_api_mode = getEnv("API_MODE"), env_managed_prefix = getEnv("MANAGED_PREFIX"), env_token = getEnv("API_TOKEN");
global.APIMode = tribool().parse(toLower(env_api_mode)).get(global.APIMode);
if(env_managed_prefix.size())
if(!env_managed_prefix.empty())
global.managedConfigPrefix = env_managed_prefix;
if(env_token.size())
if(!env_token.empty())
global.accessToken = env_token;
if(global.generatorMode)
@ -196,7 +196,7 @@ int main(int argc, char *argv[])
webServer.append_response("GET", "/refreshrules", "text/plain", [](RESPONSE_CALLBACK_ARGS) -> std::string
{
if(global.accessToken.size())
if(!global.accessToken.empty())
{
std::string token = getUrlArg(request.argument, "token");
if(token != global.accessToken)
@ -211,7 +211,7 @@ int main(int argc, char *argv[])
webServer.append_response("GET", "/readconf", "text/plain", [](RESPONSE_CALLBACK_ARGS) -> std::string
{
if(global.accessToken.size())
if(!global.accessToken.empty())
{
std::string token = getUrlArg(request.argument, "token");
if(token != global.accessToken)
@ -228,7 +228,7 @@ int main(int argc, char *argv[])
webServer.append_response("POST", "/updateconf", "text/plain", [](RESPONSE_CALLBACK_ARGS) -> std::string
{
if(global.accessToken.size())
if(!global.accessToken.empty())
{
std::string token = getUrlArg(request.argument, "token");
if(token != global.accessToken)

View File

@ -1539,17 +1539,17 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
ini.store_isolated_line = true;
ini.keep_empty_section = false;
ini.allow_dup_section_titles = true;
ini.SetIsolatedItemsSection("Proxy");
ini.IncludeSection("Proxy");
ini.AddDirectSaveSection("Proxy");
ini.set_isolated_items_section("Proxy");
ini.include_section("Proxy");
ini.add_direct_save_section("Proxy");
if(surge.find("[Proxy]") != surge.npos)
surge = regReplace(surge, "^[\\S\\s]*?\\[", "[", false);
ini.Parse(surge);
surge = regReplace(surge, R"(^[\S\s]*?\[)", "[", false);
ini.parse(surge);
if(!ini.SectionExist("Proxy"))
if(!ini.section_exist("Proxy"))
return false;
ini.EnterSection("Proxy");
ini.GetItems(proxies);
ini.enter_section("Proxy");
ini.get_items(proxies);
const std::string proxystr = "(.*?)\\s*=\\s*(.*)";

View File

@ -2,7 +2,7 @@
#include <fstream>
#include <sys/stat.h>
#include "string.h"
#include "utils/string.h"
bool isInScope(const std::string &path)
{
@ -22,7 +22,7 @@ std::string fileGet(const std::string &path, bool scope_limit)
std::string content;
if(scope_limit && !isInScope(path))
return std::string();
return "";
std::FILE *fp = std::fopen(path.c_str(), "rb");
if(fp)

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
#ifndef __MD5_H__
#define __MD5_H__
#include <cstdint>
/*
* Size of a standard MD5 signature in bytes. This definition is for
* external programs only. The MD5 routines themselves reference the

View File

@ -18,7 +18,7 @@ std::string hostnameToIPAddr(const std::string &host)
if(retVal != 0)
{
freeaddrinfo(retAddrInfo);
return std::string();
return "";
}
for(cur = retAddrInfo; cur != NULL; cur = cur->ai_next)

View File

@ -21,7 +21,7 @@ template <typename T> void exception_thrower(T e)
inline void operator >> (const rapidjson::Value& value, std::string& i)
{
if(value.IsNull())
i = std::string();
i = "";
else if(value.IsString())
i = std::string(value.GetString());
else if(value.IsInt64())
@ -31,7 +31,7 @@ inline void operator >> (const rapidjson::Value& value, std::string& i)
else if(value.IsDouble())
i = std::to_string(value.GetDouble());
else
i = std::string();
i = "";
}
inline void operator >> (const rapidjson::Value& value, int& i)

View File

@ -234,13 +234,13 @@ std::string trimWhitespace(const std::string &str, bool before, bool after)
{
epos = str.find_last_not_of(whitespaces);
if(epos == std::string::npos)
return std::string();
return "";
}
if(before)
{
bpos = str.find_first_not_of(whitespaces);
if(bpos == std::string::npos)
return std::string();
return "";
}
return str.substr(bpos, epos - bpos + 1);
}
@ -295,7 +295,7 @@ std::string getUrlArg(const std::string &url, const std::string &request)
break;
pos--;
}
return std::string();
return "";
}
std::string replaceAllDistinct(std::string str, const std::string &old_value, const std::string &new_value)

View File

@ -7,6 +7,7 @@
#include <vector>
#include <map>
using string = std::string;
using string_size = std::string::size_type;
using string_array = std::vector<std::string>;
using string_map = std::map<std::string, std::string>;

View File

@ -2,6 +2,7 @@
#define STRING_HASH_H_INCLUDED
#include <string>
#include <cstdint>
using hash_t = uint64_t;

View File

@ -50,7 +50,7 @@ std::string getSystemProxy()
if(ret != ERROR_SUCCESS)
{
//std::cout << "open failed: " << ret << std::endl;
return std::string();
return "";
}
DWORD values_count, max_value_name_len, max_value_len;
@ -59,7 +59,7 @@ std::string getSystemProxy()
if(ret != ERROR_SUCCESS)
{
//std::cout << "query failed" << std::endl;
return std::string();
return "";
}
std::vector<std::tuple<std::shared_ptr<char>, DWORD, std::shared_ptr<BYTE>>> values;
@ -103,7 +103,7 @@ std::string getSystemProxy()
}
*/
//return 0;
return std::string();
return "";
#else
string_array proxy_env = {"all_proxy", "ALL_PROXY", "http_proxy", "HTTP_PROXY", "https_proxy", "HTTPS_PROXY"};
for(std::string &x : proxy_env)
@ -112,6 +112,6 @@ std::string getSystemProxy()
if(proxy != NULL)
return std::string(proxy);
}
return std::string();
return "";
#endif // _WIN32
}