上传仓库
This commit is contained in:
parent
90b37ec64e
commit
9f8d9db33e
|
@ -0,0 +1,147 @@
|
||||||
|
# Generated from CLion Inspection settings
|
||||||
|
---
|
||||||
|
Checks: '-*,
|
||||||
|
bugprone-argument-comment,
|
||||||
|
bugprone-assert-side-effect,
|
||||||
|
bugprone-bad-signal-to-kill-thread,
|
||||||
|
bugprone-branch-clone,
|
||||||
|
bugprone-copy-constructor-init,
|
||||||
|
bugprone-dangling-handle,
|
||||||
|
bugprone-dynamic-static-initializers,
|
||||||
|
bugprone-fold-init-type,
|
||||||
|
bugprone-forward-declaration-namespace,
|
||||||
|
bugprone-forwarding-reference-overload,
|
||||||
|
bugprone-inaccurate-erase,
|
||||||
|
bugprone-incorrect-roundings,
|
||||||
|
bugprone-integer-division,
|
||||||
|
bugprone-lambda-function-name,
|
||||||
|
bugprone-macro-parentheses,
|
||||||
|
bugprone-macro-repeated-side-effects,
|
||||||
|
bugprone-misplaced-operator-in-strlen-in-alloc,
|
||||||
|
bugprone-misplaced-pointer-arithmetic-in-alloc,
|
||||||
|
bugprone-misplaced-widening-cast,
|
||||||
|
bugprone-move-forwarding-reference,
|
||||||
|
bugprone-multiple-statement-macro,
|
||||||
|
bugprone-no-escape,
|
||||||
|
bugprone-not-null-terminated-result,
|
||||||
|
bugprone-parent-virtual-call,
|
||||||
|
bugprone-posix-return,
|
||||||
|
bugprone-reserved-identifier,
|
||||||
|
bugprone-sizeof-container,
|
||||||
|
bugprone-sizeof-expression,
|
||||||
|
bugprone-spuriously-wake-up-functions,
|
||||||
|
bugprone-string-constructor,
|
||||||
|
bugprone-string-integer-assignment,
|
||||||
|
bugprone-string-literal-with-embedded-nul,
|
||||||
|
bugprone-suspicious-enum-usage,
|
||||||
|
bugprone-suspicious-include,
|
||||||
|
bugprone-suspicious-memory-comparison,
|
||||||
|
bugprone-suspicious-memset-usage,
|
||||||
|
bugprone-suspicious-missing-comma,
|
||||||
|
bugprone-suspicious-semicolon,
|
||||||
|
bugprone-suspicious-string-compare,
|
||||||
|
bugprone-swapped-arguments,
|
||||||
|
bugprone-terminating-continue,
|
||||||
|
bugprone-throw-keyword-missing,
|
||||||
|
bugprone-too-small-loop-variable,
|
||||||
|
bugprone-undefined-memory-manipulation,
|
||||||
|
bugprone-undelegated-constructor,
|
||||||
|
bugprone-unhandled-self-assignment,
|
||||||
|
bugprone-unused-raii,
|
||||||
|
bugprone-unused-return-value,
|
||||||
|
bugprone-use-after-move,
|
||||||
|
bugprone-virtual-near-miss,
|
||||||
|
cert-dcl21-cpp,
|
||||||
|
cert-dcl58-cpp,
|
||||||
|
cert-err34-c,
|
||||||
|
cert-err52-cpp,
|
||||||
|
cert-err60-cpp,
|
||||||
|
cert-flp30-c,
|
||||||
|
cert-msc50-cpp,
|
||||||
|
cert-msc51-cpp,
|
||||||
|
cert-str34-c,
|
||||||
|
cppcoreguidelines-interfaces-global-init,
|
||||||
|
cppcoreguidelines-narrowing-conversions,
|
||||||
|
cppcoreguidelines-pro-type-member-init,
|
||||||
|
cppcoreguidelines-pro-type-static-cast-downcast,
|
||||||
|
cppcoreguidelines-slicing,
|
||||||
|
google-default-arguments,
|
||||||
|
google-explicit-constructor,
|
||||||
|
google-runtime-operator,
|
||||||
|
hicpp-exception-baseclass,
|
||||||
|
hicpp-multiway-paths-covered,
|
||||||
|
misc-misplaced-const,
|
||||||
|
misc-new-delete-overloads,
|
||||||
|
misc-no-recursion,
|
||||||
|
misc-non-copyable-objects,
|
||||||
|
misc-throw-by-value-catch-by-reference,
|
||||||
|
misc-unconventional-assign-operator,
|
||||||
|
misc-uniqueptr-reset-release,
|
||||||
|
modernize-avoid-bind,
|
||||||
|
modernize-concat-nested-namespaces,
|
||||||
|
modernize-deprecated-headers,
|
||||||
|
modernize-deprecated-ios-base-aliases,
|
||||||
|
modernize-loop-convert,
|
||||||
|
modernize-make-shared,
|
||||||
|
modernize-make-unique,
|
||||||
|
modernize-pass-by-value,
|
||||||
|
modernize-raw-string-literal,
|
||||||
|
modernize-redundant-void-arg,
|
||||||
|
modernize-replace-auto-ptr,
|
||||||
|
modernize-replace-disallow-copy-and-assign-macro,
|
||||||
|
modernize-replace-random-shuffle,
|
||||||
|
modernize-return-braced-init-list,
|
||||||
|
modernize-shrink-to-fit,
|
||||||
|
modernize-unary-static-assert,
|
||||||
|
modernize-use-auto,
|
||||||
|
modernize-use-bool-literals,
|
||||||
|
modernize-use-emplace,
|
||||||
|
modernize-use-equals-default,
|
||||||
|
modernize-use-equals-delete,
|
||||||
|
modernize-use-nodiscard,
|
||||||
|
modernize-use-noexcept,
|
||||||
|
modernize-use-nullptr,
|
||||||
|
modernize-use-override,
|
||||||
|
modernize-use-transparent-functors,
|
||||||
|
modernize-use-uncaught-exceptions,
|
||||||
|
mpi-buffer-deref,
|
||||||
|
mpi-type-mismatch,
|
||||||
|
openmp-use-default-none,
|
||||||
|
performance-faster-string-find,
|
||||||
|
performance-for-range-copy,
|
||||||
|
performance-implicit-conversion-in-loop,
|
||||||
|
performance-inefficient-algorithm,
|
||||||
|
performance-inefficient-string-concatenation,
|
||||||
|
performance-inefficient-vector-operation,
|
||||||
|
performance-move-const-arg,
|
||||||
|
performance-move-constructor-init,
|
||||||
|
performance-no-automatic-move,
|
||||||
|
performance-noexcept-move-constructor,
|
||||||
|
performance-trivially-destructible,
|
||||||
|
performance-type-promotion-in-math-fn,
|
||||||
|
performance-unnecessary-copy-initialization,
|
||||||
|
performance-unnecessary-value-param,
|
||||||
|
portability-simd-intrinsics,
|
||||||
|
readability-avoid-const-params-in-decls,
|
||||||
|
readability-const-return-type,
|
||||||
|
readability-container-size-empty,
|
||||||
|
readability-convert-member-functions-to-static,
|
||||||
|
readability-delete-null-pointer,
|
||||||
|
readability-deleted-default,
|
||||||
|
readability-inconsistent-declaration-parameter-name,
|
||||||
|
readability-make-member-function-const,
|
||||||
|
readability-misleading-indentation,
|
||||||
|
readability-misplaced-array-index,
|
||||||
|
readability-non-const-parameter,
|
||||||
|
readability-redundant-control-flow,
|
||||||
|
readability-redundant-declaration,
|
||||||
|
readability-redundant-function-ptr-dereference,
|
||||||
|
readability-redundant-smartptr-get,
|
||||||
|
readability-redundant-string-cstr,
|
||||||
|
readability-redundant-string-init,
|
||||||
|
readability-simplify-subscript-expr,
|
||||||
|
readability-static-accessed-through-instance,
|
||||||
|
readability-static-definition-in-anonymous-namespace,
|
||||||
|
readability-string-compare,
|
||||||
|
readability-uniqueptr-delete-release,
|
||||||
|
readability-use-anyofallof'
|
|
@ -0,0 +1,34 @@
|
||||||
|
name: auto tag
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: main
|
||||||
|
jobs:
|
||||||
|
tag:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Create tag
|
||||||
|
uses: actions/github-script@v5
|
||||||
|
with:
|
||||||
|
github-token: ${{ github.token }}
|
||||||
|
script: |
|
||||||
|
if("${{github.event.head_commit.message}}".startsWith("v")){
|
||||||
|
github.rest.git.createTag({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
tag: "${{github.event.head_commit.message}}",
|
||||||
|
message: "${{github.event.head_commit.message}}",
|
||||||
|
object: "${{ github.sha }}",
|
||||||
|
type: "commit",
|
||||||
|
tagger: {
|
||||||
|
name: "Eritque arcus",
|
||||||
|
email: "eritque-arcus@eritque-arcus.tech"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
github.rest.git.createRef({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
ref: "refs/tags/${{github.event.head_commit.message}}",
|
||||||
|
sha: "${{ github.sha }}"
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
name: C++ CI in ubuntu & win
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- '*'
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
ubuntu-mingw:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: configure
|
||||||
|
env:
|
||||||
|
cc: gcc
|
||||||
|
cxx: g++
|
||||||
|
run: mkdir ./build && cd ./build && cmake ..
|
||||||
|
- name: build with gcc
|
||||||
|
run: cd ./build && make MiraiCPPlugin
|
||||||
|
windows-msvc-single:
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: configure
|
||||||
|
run: mkdir ./build && cd ./build && cmake ..
|
||||||
|
- name: build with msvc
|
||||||
|
run: cmake --build build --config Debug --target MiraiCPPlugin
|
||||||
|
windows-mingw:
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: configure
|
||||||
|
env:
|
||||||
|
cc: gcc
|
||||||
|
cxx: g++
|
||||||
|
run: mkdir ./build && cd ./build && cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" ..
|
||||||
|
- name: build with gcc
|
||||||
|
run: cmake --build build --config Debug --target MiraiCPPlugin
|
|
@ -0,0 +1,39 @@
|
||||||
|
# self defined
|
||||||
|
build/
|
||||||
|
lib/
|
||||||
|
cmake*/
|
||||||
|
|
||||||
|
# Prerequisites
|
||||||
|
*.d
|
||||||
|
|
||||||
|
# Compiled Object files
|
||||||
|
*.slo
|
||||||
|
*.lo
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
|
||||||
|
# Precompiled Headers
|
||||||
|
*.gch
|
||||||
|
*.pch
|
||||||
|
|
||||||
|
# Compiled Dynamic libraries
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
*.dll
|
||||||
|
|
||||||
|
# Fortran module files
|
||||||
|
*.mod
|
||||||
|
*.smod
|
||||||
|
|
||||||
|
# Compiled Static libraries
|
||||||
|
*.lai
|
||||||
|
*.la
|
||||||
|
*.a
|
||||||
|
*.lib
|
||||||
|
|
||||||
|
# Executables
|
||||||
|
*.exe
|
||||||
|
*.out
|
||||||
|
*.app
|
||||||
|
cmake-build-debug
|
||||||
|
.idea
|
|
@ -0,0 +1,49 @@
|
||||||
|
# 最低cmake版本
|
||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
|
# MSVC设置: 以utf8编译
|
||||||
|
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
|
||||||
|
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
|
||||||
|
|
||||||
|
# C++ 标准:17+
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# 声明C++项目
|
||||||
|
project(MiraiCPPlugin LANGUAGES CXX)
|
||||||
|
|
||||||
|
# 寻找库的头文件
|
||||||
|
set(SOURCE_HEADER_PATH
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/single_include/3rd_include
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/single_include/3rd_include/curl
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/single_include/3rd_include/utf8
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/single_include/3rd_include/utf8/utf8
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/single_include/MiraiCP
|
||||||
|
)
|
||||||
|
|
||||||
|
# 添加src目录下所有源文件(每次新增文件不要修改cmake,只需重新执行cmake命令)
|
||||||
|
file(GLOB PLUGIN_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
|
||||||
|
|
||||||
|
|
||||||
|
# 添加动态库编译目标
|
||||||
|
add_library(
|
||||||
|
MiraiCPPlugin
|
||||||
|
SHARED
|
||||||
|
single_include/MiraiCP/MiraiCP.cpp # MiraiCP 源文件
|
||||||
|
${PLUGIN_SOURCE_PATH})
|
||||||
|
|
||||||
|
# 引入全部头文件路径
|
||||||
|
target_include_directories(MiraiCPPlugin PUBLIC ${SOURCE_HEADER_PATH})
|
||||||
|
|
||||||
|
# 插件移植性
|
||||||
|
if (WIN32)
|
||||||
|
target_link_libraries(MiraiCPPlugin -static
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/libcurl.dll.a
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/libHttp.dll.a
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/libiconv.dll.a
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/libPerson.dll.a)
|
||||||
|
endif (WIN32)
|
||||||
|
if (UNIX)
|
||||||
|
target_link_libraries(MiraiCPPlugin -static-libstdc++ -static-libgcc)
|
||||||
|
endif (UNIX)
|
|
@ -0,0 +1,8 @@
|
||||||
|
cmake_minimum_required(VERSION 3.24)
|
||||||
|
project(Http)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
|
||||||
|
add_library(Http SHARED library.cpp)
|
||||||
|
target_link_libraries(Http ${CMAKE_CURRENT_SOURCE_DIR}/lib/libcurl.dll.a)
|
|
@ -0,0 +1 @@
|
||||||
|
请编译带有openssl和zlib的libcurl库,并将动态链接库放置在lib文件夹下
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Lucas' Bot.
|
||||||
|
*
|
||||||
|
* Lucas' Bot is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
|
||||||
|
Lucas' Bot is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along
|
||||||
|
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HTTP_LIBRARY_H
|
||||||
|
#define HTTP_LIBRARY_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Http {
|
||||||
|
class Request {
|
||||||
|
public:
|
||||||
|
Request();
|
||||||
|
~Request();
|
||||||
|
void setUrl(const std::string&);
|
||||||
|
void setMethod(const std::string&);
|
||||||
|
void setBody(const std::string&);
|
||||||
|
void setHeader(const std::string&);
|
||||||
|
void setVerbose(bool verbose);
|
||||||
|
std::string getResponse();
|
||||||
|
void send();
|
||||||
|
private:
|
||||||
|
std::string url;
|
||||||
|
std::string method;
|
||||||
|
std::string body;
|
||||||
|
std::string header;
|
||||||
|
std::string response;
|
||||||
|
bool verbose;
|
||||||
|
static size_t writeCallback(char *ptr, size_t size, size_t nmemb, void *userdata);
|
||||||
|
};
|
||||||
|
|
||||||
|
class FileUtilities {
|
||||||
|
public:
|
||||||
|
static std::string readFile(const std::string& path);
|
||||||
|
static void writeFile(const std::string& path, const std::string& content);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //HTTP_LIBRARY_H
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,79 @@
|
||||||
|
#ifndef CURLINC_CURLVER_H
|
||||||
|
#define CURLINC_CURLVER_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/* This header file contains nothing but libcurl version info, generated by
|
||||||
|
a script at release-time. This was made its own header file in 7.11.2 */
|
||||||
|
|
||||||
|
/* This is the global package copyright */
|
||||||
|
#define LIBCURL_COPYRIGHT "1996 - 2022 Daniel Stenberg, <daniel@haxx.se>."
|
||||||
|
|
||||||
|
/* This is the version number of the libcurl package from which this header
|
||||||
|
file origins: */
|
||||||
|
#define LIBCURL_VERSION "7.85.0"
|
||||||
|
|
||||||
|
/* The numeric version number is also available "in parts" by using these
|
||||||
|
defines: */
|
||||||
|
#define LIBCURL_VERSION_MAJOR 7
|
||||||
|
#define LIBCURL_VERSION_MINOR 85
|
||||||
|
#define LIBCURL_VERSION_PATCH 0
|
||||||
|
|
||||||
|
/* This is the numeric version of the libcurl version number, meant for easier
|
||||||
|
parsing and comparisons by programs. The LIBCURL_VERSION_NUM define will
|
||||||
|
always follow this syntax:
|
||||||
|
|
||||||
|
0xXXYYZZ
|
||||||
|
|
||||||
|
Where XX, YY and ZZ are the main version, release and patch numbers in
|
||||||
|
hexadecimal (using 8 bits each). All three numbers are always represented
|
||||||
|
using two digits. 1.2 would appear as "0x010200" while version 9.11.7
|
||||||
|
appears as "0x090b07".
|
||||||
|
|
||||||
|
This 6-digit (24 bits) hexadecimal number does not show pre-release number,
|
||||||
|
and it is always a greater number in a more recent release. It makes
|
||||||
|
comparisons with greater than and less than work.
|
||||||
|
|
||||||
|
Note: This define is the full hex number and _does not_ use the
|
||||||
|
CURL_VERSION_BITS() macro since curl's own configure script greps for it
|
||||||
|
and needs it to contain the full number.
|
||||||
|
*/
|
||||||
|
#define LIBCURL_VERSION_NUM 0x075500
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the date and time when the full source package was created. The
|
||||||
|
* timestamp is not stored in git, as the timestamp is properly set in the
|
||||||
|
* tarballs by the maketgz script.
|
||||||
|
*
|
||||||
|
* The format of the date follows this template:
|
||||||
|
*
|
||||||
|
* "2007-11-23"
|
||||||
|
*/
|
||||||
|
#define LIBCURL_TIMESTAMP "2022-08-31"
|
||||||
|
|
||||||
|
#define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|(z))
|
||||||
|
#define CURL_AT_LEAST_VERSION(x,y,z) \
|
||||||
|
(LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(x, y, z))
|
||||||
|
|
||||||
|
#endif /* CURLINC_CURLVER_H */
|
|
@ -0,0 +1,125 @@
|
||||||
|
#ifndef CURLINC_EASY_H
|
||||||
|
#define CURLINC_EASY_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Flag bits in the curl_blob struct: */
|
||||||
|
#define CURL_BLOB_COPY 1 /* tell libcurl to copy the data */
|
||||||
|
#define CURL_BLOB_NOCOPY 0 /* tell libcurl to NOT copy the data */
|
||||||
|
|
||||||
|
struct curl_blob {
|
||||||
|
void *data;
|
||||||
|
size_t len;
|
||||||
|
unsigned int flags; /* bit 0 is defined, the rest are reserved and should be
|
||||||
|
left zeroes */
|
||||||
|
};
|
||||||
|
|
||||||
|
CURL_EXTERN CURL *curl_easy_init(void);
|
||||||
|
CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...);
|
||||||
|
CURL_EXTERN CURLcode curl_easy_perform(CURL *curl);
|
||||||
|
CURL_EXTERN void curl_easy_cleanup(CURL *curl);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NAME curl_easy_getinfo()
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
*
|
||||||
|
* Request internal information from the curl session with this function. The
|
||||||
|
* third argument MUST be a pointer to a long, a pointer to a char * or a
|
||||||
|
* pointer to a double (as the documentation describes elsewhere). The data
|
||||||
|
* pointed to will be filled in accordingly and can be relied upon only if the
|
||||||
|
* function returns CURLE_OK. This function is intended to get used *AFTER* a
|
||||||
|
* performed transfer, all results from this function are undefined until the
|
||||||
|
* transfer is completed.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NAME curl_easy_duphandle()
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
*
|
||||||
|
* Creates a new curl session handle with the same options set for the handle
|
||||||
|
* passed in. Duplicating a handle could only be a matter of cloning data and
|
||||||
|
* options, internal state info and things like persistent connections cannot
|
||||||
|
* be transferred. It is useful in multithreaded applications when you can run
|
||||||
|
* curl_easy_duphandle() for each new thread to avoid a series of identical
|
||||||
|
* curl_easy_setopt() invokes in every thread.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURL *curl_easy_duphandle(CURL *curl);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NAME curl_easy_reset()
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
*
|
||||||
|
* Re-initializes a CURL handle to the default values. This puts back the
|
||||||
|
* handle to the same state as it was in when it was just created.
|
||||||
|
*
|
||||||
|
* It does keep: live connections, the Session ID cache, the DNS cache and the
|
||||||
|
* cookies.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN void curl_easy_reset(CURL *curl);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NAME curl_easy_recv()
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
*
|
||||||
|
* Receives data from the connected socket. Use after successful
|
||||||
|
* curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen,
|
||||||
|
size_t *n);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NAME curl_easy_send()
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
*
|
||||||
|
* Sends data over the connected socket. Use after successful
|
||||||
|
* curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer,
|
||||||
|
size_t buflen, size_t *n);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NAME curl_easy_upkeep()
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
*
|
||||||
|
* Performs connection upkeep for the given session handle.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLcode curl_easy_upkeep(CURL *curl);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,66 @@
|
||||||
|
#ifndef CURLINC_HEADER_H
|
||||||
|
#define CURLINC_HEADER_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
struct curl_header {
|
||||||
|
char *name; /* this might not use the same case */
|
||||||
|
char *value;
|
||||||
|
size_t amount; /* number of headers using this name */
|
||||||
|
size_t index; /* ... of this instance, 0 or higher */
|
||||||
|
unsigned int origin; /* see bits below */
|
||||||
|
void *anchor; /* handle privately used by libcurl */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 'origin' bits */
|
||||||
|
#define CURLH_HEADER (1<<0) /* plain server header */
|
||||||
|
#define CURLH_TRAILER (1<<1) /* trailers */
|
||||||
|
#define CURLH_CONNECT (1<<2) /* CONNECT headers */
|
||||||
|
#define CURLH_1XX (1<<3) /* 1xx headers */
|
||||||
|
#define CURLH_PSEUDO (1<<4) /* pseudo headers */
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CURLHE_OK,
|
||||||
|
CURLHE_BADINDEX, /* header exists but not with this index */
|
||||||
|
CURLHE_MISSING, /* no such header exists */
|
||||||
|
CURLHE_NOHEADERS, /* no headers at all exist (yet) */
|
||||||
|
CURLHE_NOREQUEST, /* no request with this number was used */
|
||||||
|
CURLHE_OUT_OF_MEMORY, /* out of memory while processing */
|
||||||
|
CURLHE_BAD_ARGUMENT, /* a function argument was not okay */
|
||||||
|
CURLHE_NOT_BUILT_IN /* if API was disabled in the build */
|
||||||
|
} CURLHcode;
|
||||||
|
|
||||||
|
CURL_EXTERN CURLHcode curl_easy_header(CURL *easy,
|
||||||
|
const char *name,
|
||||||
|
size_t index,
|
||||||
|
unsigned int origin,
|
||||||
|
int request,
|
||||||
|
struct curl_header **hout);
|
||||||
|
|
||||||
|
CURL_EXTERN struct curl_header *curl_easy_nextheader(CURL *easy,
|
||||||
|
unsigned int origin,
|
||||||
|
int request,
|
||||||
|
struct curl_header *prev);
|
||||||
|
|
||||||
|
#endif /* CURLINC_HEADER_H */
|
|
@ -0,0 +1,52 @@
|
||||||
|
#ifndef CURLINC_MPRINTF_H
|
||||||
|
#define CURLINC_MPRINTF_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h> /* needed for FILE */
|
||||||
|
#include "curl.h" /* for CURL_EXTERN */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CURL_EXTERN int curl_mprintf(const char *format, ...);
|
||||||
|
CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...);
|
||||||
|
CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...);
|
||||||
|
CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength,
|
||||||
|
const char *format, ...);
|
||||||
|
CURL_EXTERN int curl_mvprintf(const char *format, va_list args);
|
||||||
|
CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args);
|
||||||
|
CURL_EXTERN int curl_mvsprintf(char *buffer, const char *format, va_list args);
|
||||||
|
CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength,
|
||||||
|
const char *format, va_list args);
|
||||||
|
CURL_EXTERN char *curl_maprintf(const char *format, ...);
|
||||||
|
CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CURLINC_MPRINTF_H */
|
|
@ -0,0 +1,460 @@
|
||||||
|
#ifndef CURLINC_MULTI_H
|
||||||
|
#define CURLINC_MULTI_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
/*
|
||||||
|
This is an "external" header file. Don't give away any internals here!
|
||||||
|
|
||||||
|
GOALS
|
||||||
|
|
||||||
|
o Enable a "pull" interface. The application that uses libcurl decides where
|
||||||
|
and when to ask libcurl to get/send data.
|
||||||
|
|
||||||
|
o Enable multiple simultaneous transfers in the same thread without making it
|
||||||
|
complicated for the application.
|
||||||
|
|
||||||
|
o Enable the application to select() on its own file descriptors and curl's
|
||||||
|
file descriptors simultaneous easily.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This header file should not really need to include "curl.h" since curl.h
|
||||||
|
* itself includes this file and we expect user applications to do #include
|
||||||
|
* <curl/curl.h> without the need for especially including multi.h.
|
||||||
|
*
|
||||||
|
* For some reason we added this include here at one point, and rather than to
|
||||||
|
* break existing (wrongly written) libcurl applications, we leave it as-is
|
||||||
|
* but with this warning attached.
|
||||||
|
*/
|
||||||
|
#include "curl.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(BUILDING_LIBCURL) || defined(CURL_STRICTER)
|
||||||
|
typedef struct Curl_multi CURLM;
|
||||||
|
#else
|
||||||
|
typedef void CURLM;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or
|
||||||
|
curl_multi_socket*() soon */
|
||||||
|
CURLM_OK,
|
||||||
|
CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */
|
||||||
|
CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */
|
||||||
|
CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */
|
||||||
|
CURLM_INTERNAL_ERROR, /* this is a libcurl bug */
|
||||||
|
CURLM_BAD_SOCKET, /* the passed in socket argument did not match */
|
||||||
|
CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */
|
||||||
|
CURLM_ADDED_ALREADY, /* an easy handle already added to a multi handle was
|
||||||
|
attempted to get added - again */
|
||||||
|
CURLM_RECURSIVE_API_CALL, /* an api function was called from inside a
|
||||||
|
callback */
|
||||||
|
CURLM_WAKEUP_FAILURE, /* wakeup is unavailable or failed */
|
||||||
|
CURLM_BAD_FUNCTION_ARGUMENT, /* function called with a bad parameter */
|
||||||
|
CURLM_ABORTED_BY_CALLBACK,
|
||||||
|
CURLM_UNRECOVERABLE_POLL,
|
||||||
|
CURLM_LAST
|
||||||
|
} CURLMcode;
|
||||||
|
|
||||||
|
/* just to make code nicer when using curl_multi_socket() you can now check
|
||||||
|
for CURLM_CALL_MULTI_SOCKET too in the same style it works for
|
||||||
|
curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */
|
||||||
|
#define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM
|
||||||
|
|
||||||
|
/* bitmask bits for CURLMOPT_PIPELINING */
|
||||||
|
#define CURLPIPE_NOTHING 0L
|
||||||
|
#define CURLPIPE_HTTP1 1L
|
||||||
|
#define CURLPIPE_MULTIPLEX 2L
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CURLMSG_NONE, /* first, not used */
|
||||||
|
CURLMSG_DONE, /* This easy handle has completed. 'result' contains
|
||||||
|
the CURLcode of the transfer */
|
||||||
|
CURLMSG_LAST /* last, not used */
|
||||||
|
} CURLMSG;
|
||||||
|
|
||||||
|
struct CURLMsg {
|
||||||
|
CURLMSG msg; /* what this message means */
|
||||||
|
CURL *easy_handle; /* the handle it concerns */
|
||||||
|
union {
|
||||||
|
void *whatever; /* message-specific data */
|
||||||
|
CURLcode result; /* return code for transfer */
|
||||||
|
} data;
|
||||||
|
};
|
||||||
|
typedef struct CURLMsg CURLMsg;
|
||||||
|
|
||||||
|
/* Based on poll(2) structure and values.
|
||||||
|
* We don't use pollfd and POLL* constants explicitly
|
||||||
|
* to cover platforms without poll(). */
|
||||||
|
#define CURL_WAIT_POLLIN 0x0001
|
||||||
|
#define CURL_WAIT_POLLPRI 0x0002
|
||||||
|
#define CURL_WAIT_POLLOUT 0x0004
|
||||||
|
|
||||||
|
struct curl_waitfd {
|
||||||
|
curl_socket_t fd;
|
||||||
|
short events;
|
||||||
|
short revents; /* not supported yet */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_init()
|
||||||
|
*
|
||||||
|
* Desc: inititalize multi-style curl usage
|
||||||
|
*
|
||||||
|
* Returns: a new CURLM handle to use in all 'curl_multi' functions.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLM *curl_multi_init(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_add_handle()
|
||||||
|
*
|
||||||
|
* Desc: add a standard curl handle to the multi stack
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle,
|
||||||
|
CURL *curl_handle);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_remove_handle()
|
||||||
|
*
|
||||||
|
* Desc: removes a curl handle from the multi stack again
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
|
||||||
|
CURL *curl_handle);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_fdset()
|
||||||
|
*
|
||||||
|
* Desc: Ask curl for its fd_set sets. The app can use these to select() or
|
||||||
|
* poll() on. We want curl_multi_perform() called as soon as one of
|
||||||
|
* them are ready.
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle,
|
||||||
|
fd_set *read_fd_set,
|
||||||
|
fd_set *write_fd_set,
|
||||||
|
fd_set *exc_fd_set,
|
||||||
|
int *max_fd);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_wait()
|
||||||
|
*
|
||||||
|
* Desc: Poll on all fds within a CURLM set as well as any
|
||||||
|
* additional fds passed to the function.
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle,
|
||||||
|
struct curl_waitfd extra_fds[],
|
||||||
|
unsigned int extra_nfds,
|
||||||
|
int timeout_ms,
|
||||||
|
int *ret);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_poll()
|
||||||
|
*
|
||||||
|
* Desc: Poll on all fds within a CURLM set as well as any
|
||||||
|
* additional fds passed to the function.
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_poll(CURLM *multi_handle,
|
||||||
|
struct curl_waitfd extra_fds[],
|
||||||
|
unsigned int extra_nfds,
|
||||||
|
int timeout_ms,
|
||||||
|
int *ret);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_wakeup()
|
||||||
|
*
|
||||||
|
* Desc: wakes up a sleeping curl_multi_poll call.
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_wakeup(CURLM *multi_handle);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_perform()
|
||||||
|
*
|
||||||
|
* Desc: When the app thinks there's data available for curl it calls this
|
||||||
|
* function to read/write whatever there is right now. This returns
|
||||||
|
* as soon as the reads and writes are done. This function does not
|
||||||
|
* require that there actually is data available for reading or that
|
||||||
|
* data can be written, it can be called just in case. It returns
|
||||||
|
* the number of handles that still transfer data in the second
|
||||||
|
* argument's integer-pointer.
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code. *NOTE* that this only
|
||||||
|
* returns errors etc regarding the whole multi stack. There might
|
||||||
|
* still have occurred problems on individual transfers even when
|
||||||
|
* this returns OK.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle,
|
||||||
|
int *running_handles);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_cleanup()
|
||||||
|
*
|
||||||
|
* Desc: Cleans up and removes a whole multi stack. It does not free or
|
||||||
|
* touch any individual easy handles in any way. We need to define
|
||||||
|
* in what state those handles will be if this function is called
|
||||||
|
* in the middle of a transfer.
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_info_read()
|
||||||
|
*
|
||||||
|
* Desc: Ask the multi handle if there's any messages/informationals from
|
||||||
|
* the individual transfers. Messages include informationals such as
|
||||||
|
* error code from the transfer or just the fact that a transfer is
|
||||||
|
* completed. More details on these should be written down as well.
|
||||||
|
*
|
||||||
|
* Repeated calls to this function will return a new struct each
|
||||||
|
* time, until a special "end of msgs" struct is returned as a signal
|
||||||
|
* that there is no more to get at this point.
|
||||||
|
*
|
||||||
|
* The data the returned pointer points to will not survive calling
|
||||||
|
* curl_multi_cleanup().
|
||||||
|
*
|
||||||
|
* The 'CURLMsg' struct is meant to be very simple and only contain
|
||||||
|
* very basic information. If more involved information is wanted,
|
||||||
|
* we will provide the particular "transfer handle" in that struct
|
||||||
|
* and that should/could/would be used in subsequent
|
||||||
|
* curl_easy_getinfo() calls (or similar). The point being that we
|
||||||
|
* must never expose complex structs to applications, as then we'll
|
||||||
|
* undoubtably get backwards compatibility problems in the future.
|
||||||
|
*
|
||||||
|
* Returns: A pointer to a filled-in struct, or NULL if it failed or ran out
|
||||||
|
* of structs. It also writes the number of messages left in the
|
||||||
|
* queue (after this read) in the integer the second argument points
|
||||||
|
* to.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle,
|
||||||
|
int *msgs_in_queue);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_strerror()
|
||||||
|
*
|
||||||
|
* Desc: The curl_multi_strerror function may be used to turn a CURLMcode
|
||||||
|
* value into the equivalent human readable error string. This is
|
||||||
|
* useful for printing meaningful error messages.
|
||||||
|
*
|
||||||
|
* Returns: A pointer to a null-terminated error message.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN const char *curl_multi_strerror(CURLMcode);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_socket() and
|
||||||
|
* curl_multi_socket_all()
|
||||||
|
*
|
||||||
|
* Desc: An alternative version of curl_multi_perform() that allows the
|
||||||
|
* application to pass in one of the file descriptors that have been
|
||||||
|
* detected to have "action" on them and let libcurl perform.
|
||||||
|
* See man page for details.
|
||||||
|
*/
|
||||||
|
#define CURL_POLL_NONE 0
|
||||||
|
#define CURL_POLL_IN 1
|
||||||
|
#define CURL_POLL_OUT 2
|
||||||
|
#define CURL_POLL_INOUT 3
|
||||||
|
#define CURL_POLL_REMOVE 4
|
||||||
|
|
||||||
|
#define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD
|
||||||
|
|
||||||
|
#define CURL_CSELECT_IN 0x01
|
||||||
|
#define CURL_CSELECT_OUT 0x02
|
||||||
|
#define CURL_CSELECT_ERR 0x04
|
||||||
|
|
||||||
|
typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */
|
||||||
|
curl_socket_t s, /* socket */
|
||||||
|
int what, /* see above */
|
||||||
|
void *userp, /* private callback
|
||||||
|
pointer */
|
||||||
|
void *socketp); /* private socket
|
||||||
|
pointer */
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_timer_callback
|
||||||
|
*
|
||||||
|
* Desc: Called by libcurl whenever the library detects a change in the
|
||||||
|
* maximum number of milliseconds the app is allowed to wait before
|
||||||
|
* curl_multi_socket() or curl_multi_perform() must be called
|
||||||
|
* (to allow libcurl's timed events to take place).
|
||||||
|
*
|
||||||
|
* Returns: The callback should return zero.
|
||||||
|
*/
|
||||||
|
typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */
|
||||||
|
long timeout_ms, /* see above */
|
||||||
|
void *userp); /* private callback
|
||||||
|
pointer */
|
||||||
|
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s,
|
||||||
|
int *running_handles);
|
||||||
|
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle,
|
||||||
|
curl_socket_t s,
|
||||||
|
int ev_bitmask,
|
||||||
|
int *running_handles);
|
||||||
|
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle,
|
||||||
|
int *running_handles);
|
||||||
|
|
||||||
|
#ifndef CURL_ALLOW_OLD_MULTI_SOCKET
|
||||||
|
/* This macro below was added in 7.16.3 to push users who recompile to use
|
||||||
|
the new curl_multi_socket_action() instead of the old curl_multi_socket()
|
||||||
|
*/
|
||||||
|
#define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_timeout()
|
||||||
|
*
|
||||||
|
* Desc: Returns the maximum number of milliseconds the app is allowed to
|
||||||
|
* wait before curl_multi_socket() or curl_multi_perform() must be
|
||||||
|
* called (to allow libcurl's timed events to take place).
|
||||||
|
*
|
||||||
|
* Returns: CURLM error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle,
|
||||||
|
long *milliseconds);
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
/* This is the socket callback function pointer */
|
||||||
|
CURLOPT(CURLMOPT_SOCKETFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 1),
|
||||||
|
|
||||||
|
/* This is the argument passed to the socket callback */
|
||||||
|
CURLOPT(CURLMOPT_SOCKETDATA, CURLOPTTYPE_OBJECTPOINT, 2),
|
||||||
|
|
||||||
|
/* set to 1 to enable pipelining for this multi handle */
|
||||||
|
CURLOPT(CURLMOPT_PIPELINING, CURLOPTTYPE_LONG, 3),
|
||||||
|
|
||||||
|
/* This is the timer callback function pointer */
|
||||||
|
CURLOPT(CURLMOPT_TIMERFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 4),
|
||||||
|
|
||||||
|
/* This is the argument passed to the timer callback */
|
||||||
|
CURLOPT(CURLMOPT_TIMERDATA, CURLOPTTYPE_OBJECTPOINT, 5),
|
||||||
|
|
||||||
|
/* maximum number of entries in the connection cache */
|
||||||
|
CURLOPT(CURLMOPT_MAXCONNECTS, CURLOPTTYPE_LONG, 6),
|
||||||
|
|
||||||
|
/* maximum number of (pipelining) connections to one host */
|
||||||
|
CURLOPT(CURLMOPT_MAX_HOST_CONNECTIONS, CURLOPTTYPE_LONG, 7),
|
||||||
|
|
||||||
|
/* maximum number of requests in a pipeline */
|
||||||
|
CURLOPT(CURLMOPT_MAX_PIPELINE_LENGTH, CURLOPTTYPE_LONG, 8),
|
||||||
|
|
||||||
|
/* a connection with a content-length longer than this
|
||||||
|
will not be considered for pipelining */
|
||||||
|
CURLOPT(CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 9),
|
||||||
|
|
||||||
|
/* a connection with a chunk length longer than this
|
||||||
|
will not be considered for pipelining */
|
||||||
|
CURLOPT(CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 10),
|
||||||
|
|
||||||
|
/* a list of site names(+port) that are blocked from pipelining */
|
||||||
|
CURLOPT(CURLMOPT_PIPELINING_SITE_BL, CURLOPTTYPE_OBJECTPOINT, 11),
|
||||||
|
|
||||||
|
/* a list of server types that are blocked from pipelining */
|
||||||
|
CURLOPT(CURLMOPT_PIPELINING_SERVER_BL, CURLOPTTYPE_OBJECTPOINT, 12),
|
||||||
|
|
||||||
|
/* maximum number of open connections in total */
|
||||||
|
CURLOPT(CURLMOPT_MAX_TOTAL_CONNECTIONS, CURLOPTTYPE_LONG, 13),
|
||||||
|
|
||||||
|
/* This is the server push callback function pointer */
|
||||||
|
CURLOPT(CURLMOPT_PUSHFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 14),
|
||||||
|
|
||||||
|
/* This is the argument passed to the server push callback */
|
||||||
|
CURLOPT(CURLMOPT_PUSHDATA, CURLOPTTYPE_OBJECTPOINT, 15),
|
||||||
|
|
||||||
|
/* maximum number of concurrent streams to support on a connection */
|
||||||
|
CURLOPT(CURLMOPT_MAX_CONCURRENT_STREAMS, CURLOPTTYPE_LONG, 16),
|
||||||
|
|
||||||
|
CURLMOPT_LASTENTRY /* the last unused */
|
||||||
|
} CURLMoption;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_setopt()
|
||||||
|
*
|
||||||
|
* Desc: Sets options for the multi handle.
|
||||||
|
*
|
||||||
|
* Returns: CURLM error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle,
|
||||||
|
CURLMoption option, ...);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_assign()
|
||||||
|
*
|
||||||
|
* Desc: This function sets an association in the multi handle between the
|
||||||
|
* given socket and a private pointer of the application. This is
|
||||||
|
* (only) useful for curl_multi_socket uses.
|
||||||
|
*
|
||||||
|
* Returns: CURLM error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle,
|
||||||
|
curl_socket_t sockfd, void *sockp);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_push_callback
|
||||||
|
*
|
||||||
|
* Desc: This callback gets called when a new stream is being pushed by the
|
||||||
|
* server. It approves or denies the new stream. It can also decide
|
||||||
|
* to completely fail the connection.
|
||||||
|
*
|
||||||
|
* Returns: CURL_PUSH_OK, CURL_PUSH_DENY or CURL_PUSH_ERROROUT
|
||||||
|
*/
|
||||||
|
#define CURL_PUSH_OK 0
|
||||||
|
#define CURL_PUSH_DENY 1
|
||||||
|
#define CURL_PUSH_ERROROUT 2 /* added in 7.72.0 */
|
||||||
|
|
||||||
|
struct curl_pushheaders; /* forward declaration only */
|
||||||
|
|
||||||
|
CURL_EXTERN char *curl_pushheader_bynum(struct curl_pushheaders *h,
|
||||||
|
size_t num);
|
||||||
|
CURL_EXTERN char *curl_pushheader_byname(struct curl_pushheaders *h,
|
||||||
|
const char *name);
|
||||||
|
|
||||||
|
typedef int (*curl_push_callback)(CURL *parent,
|
||||||
|
CURL *easy,
|
||||||
|
size_t num_headers,
|
||||||
|
struct curl_pushheaders *headers,
|
||||||
|
void *userp);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* end of extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,70 @@
|
||||||
|
#ifndef CURLINC_OPTIONS_H
|
||||||
|
#define CURLINC_OPTIONS_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CURLOT_LONG, /* long (a range of values) */
|
||||||
|
CURLOT_VALUES, /* (a defined set or bitmask) */
|
||||||
|
CURLOT_OFF_T, /* curl_off_t (a range of values) */
|
||||||
|
CURLOT_OBJECT, /* pointer (void *) */
|
||||||
|
CURLOT_STRING, /* (char * to zero terminated buffer) */
|
||||||
|
CURLOT_SLIST, /* (struct curl_slist *) */
|
||||||
|
CURLOT_CBPTR, /* (void * passed as-is to a callback) */
|
||||||
|
CURLOT_BLOB, /* blob (struct curl_blob *) */
|
||||||
|
CURLOT_FUNCTION /* function pointer */
|
||||||
|
} curl_easytype;
|
||||||
|
|
||||||
|
/* Flag bits */
|
||||||
|
|
||||||
|
/* "alias" means it is provided for old programs to remain functional,
|
||||||
|
we prefer another name */
|
||||||
|
#define CURLOT_FLAG_ALIAS (1<<0)
|
||||||
|
|
||||||
|
/* The CURLOPTTYPE_* id ranges can still be used to figure out what type/size
|
||||||
|
to use for curl_easy_setopt() for the given id */
|
||||||
|
struct curl_easyoption {
|
||||||
|
const char *name;
|
||||||
|
CURLoption id;
|
||||||
|
curl_easytype type;
|
||||||
|
unsigned int flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
CURL_EXTERN const struct curl_easyoption *
|
||||||
|
curl_easy_option_by_name(const char *name);
|
||||||
|
|
||||||
|
CURL_EXTERN const struct curl_easyoption *
|
||||||
|
curl_easy_option_by_id(CURLoption id);
|
||||||
|
|
||||||
|
CURL_EXTERN const struct curl_easyoption *
|
||||||
|
curl_easy_option_next(const struct curl_easyoption *prev);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* end of extern "C" */
|
||||||
|
#endif
|
||||||
|
#endif /* CURLINC_OPTIONS_H */
|
|
@ -0,0 +1,35 @@
|
||||||
|
#ifndef CURLINC_STDCHEADERS_H
|
||||||
|
#define CURLINC_STDCHEADERS_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
size_t fread(void *, size_t, size_t, FILE *);
|
||||||
|
size_t fwrite(const void *, size_t, size_t, FILE *);
|
||||||
|
|
||||||
|
int strcasecmp(const char *, const char *);
|
||||||
|
int strncasecmp(const char *, const char *, size_t);
|
||||||
|
|
||||||
|
#endif /* CURLINC_STDCHEADERS_H */
|
|
@ -0,0 +1,490 @@
|
||||||
|
#ifndef CURLINC_SYSTEM_H
|
||||||
|
#define CURLINC_SYSTEM_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try to keep one section per platform, compiler and architecture, otherwise,
|
||||||
|
* if an existing section is reused for a different one and later on the
|
||||||
|
* original is adjusted, probably the piggybacking one can be adversely
|
||||||
|
* changed.
|
||||||
|
*
|
||||||
|
* In order to differentiate between platforms/compilers/architectures use
|
||||||
|
* only compiler built in predefined preprocessor symbols.
|
||||||
|
*
|
||||||
|
* curl_off_t
|
||||||
|
* ----------
|
||||||
|
*
|
||||||
|
* For any given platform/compiler curl_off_t must be typedef'ed to a 64-bit
|
||||||
|
* wide signed integral data type. The width of this data type must remain
|
||||||
|
* constant and independent of any possible large file support settings.
|
||||||
|
*
|
||||||
|
* As an exception to the above, curl_off_t shall be typedef'ed to a 32-bit
|
||||||
|
* wide signed integral data type if there is no 64-bit type.
|
||||||
|
*
|
||||||
|
* As a general rule, curl_off_t shall not be mapped to off_t. This rule shall
|
||||||
|
* only be violated if off_t is the only 64-bit data type available and the
|
||||||
|
* size of off_t is independent of large file support settings. Keep your
|
||||||
|
* build on the safe side avoiding an off_t gating. If you have a 64-bit
|
||||||
|
* off_t then take for sure that another 64-bit data type exists, dig deeper
|
||||||
|
* and you will find it.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(__DJGPP__) || defined(__GO32__)
|
||||||
|
# if defined(__DJGPP__) && (__DJGPP__ > 1)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(__SALFORDC__)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(__BORLANDC__)
|
||||||
|
# if (__BORLANDC__ < 0x520)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T __int64
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "I64d"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "I64u"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T i64
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ui64
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(__TURBOC__)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(__POCC__)
|
||||||
|
# if (__POCC__ < 280)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# elif defined(_MSC_VER)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T __int64
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "I64d"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "I64u"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T i64
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ui64
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(__LCC__)
|
||||||
|
# if defined(__MCST__) /* MCST eLbrus Compiler Collection */
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
# else /* Local (or Little) C Compiler */
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#elif defined(__SYMBIAN32__)
|
||||||
|
# if defined(__EABI__) /* Treat all ARM compilers equally */
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# elif defined(__CW32__)
|
||||||
|
# pragma longlong on
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# elif defined(__VC32__)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T __int64
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int
|
||||||
|
|
||||||
|
#elif defined(__MWERKS__)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(_WIN32_WCE)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T __int64
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "I64d"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "I64u"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T i64
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ui64
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(__MINGW32__)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "I64d"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "I64u"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_WS2TCPIP_H 1
|
||||||
|
|
||||||
|
#elif defined(__VMS)
|
||||||
|
# if defined(__VAX)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int
|
||||||
|
|
||||||
|
#elif defined(__OS400__)
|
||||||
|
# if defined(__ILEC400__)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#elif defined(__MVS__)
|
||||||
|
# if defined(__IBMC__) || defined(__IBMCPP__)
|
||||||
|
# if defined(_ILP32)
|
||||||
|
# elif defined(_LP64)
|
||||||
|
# endif
|
||||||
|
# if defined(_LONG_LONG)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# elif defined(_LP64)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#elif defined(__370__)
|
||||||
|
# if defined(__IBMC__) || defined(__IBMCPP__)
|
||||||
|
# if defined(_ILP32)
|
||||||
|
# elif defined(_LP64)
|
||||||
|
# endif
|
||||||
|
# if defined(_LONG_LONG)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# elif defined(_LP64)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#elif defined(TPF)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(__TINYC__) /* also known as tcc */
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
|
||||||
|
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* Oracle Solaris Studio */
|
||||||
|
# if !defined(__LP64) && (defined(__ILP32) || \
|
||||||
|
defined(__i386) || \
|
||||||
|
defined(__sparcv8) || \
|
||||||
|
defined(__sparcv8plus))
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# elif defined(__LP64) || \
|
||||||
|
defined(__amd64) || defined(__sparcv9)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
|
||||||
|
#elif defined(__xlc__) /* IBM xlc compiler */
|
||||||
|
# if !defined(_LP64)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
|
||||||
|
/* ===================================== */
|
||||||
|
/* KEEP MSVC THE PENULTIMATE ENTRY */
|
||||||
|
/* ===================================== */
|
||||||
|
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
# if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T __int64
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "I64d"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "I64u"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T i64
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ui64
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
/* ===================================== */
|
||||||
|
/* KEEP GENERIC GCC THE LAST ENTRY */
|
||||||
|
/* ===================================== */
|
||||||
|
|
||||||
|
#elif defined(__GNUC__) && !defined(_SCO_DS)
|
||||||
|
# if !defined(__LP64__) && \
|
||||||
|
(defined(__ILP32__) || defined(__i386__) || defined(__hppa__) || \
|
||||||
|
defined(__ppc__) || defined(__powerpc__) || defined(__arm__) || \
|
||||||
|
defined(__sparc__) || defined(__mips__) || defined(__sh__) || \
|
||||||
|
defined(__XTENSA__) || \
|
||||||
|
(defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ == 4) || \
|
||||||
|
(defined(__LONG_MAX__) && __LONG_MAX__ == 2147483647L))
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# elif defined(__LP64__) || \
|
||||||
|
defined(__x86_64__) || defined(__ppc64__) || defined(__sparc64__) || \
|
||||||
|
defined(__e2k__) || \
|
||||||
|
(defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ == 8) || \
|
||||||
|
(defined(__LONG_MAX__) && __LONG_MAX__ == 9223372036854775807L)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
|
||||||
|
#else
|
||||||
|
/* generic "safe guess" on old 32 bit style */
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _AIX
|
||||||
|
/* AIX needs <sys/poll.h> */
|
||||||
|
#define CURL_PULL_SYS_POLL_H
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* CURL_PULL_WS2TCPIP_H is defined above when inclusion of header file */
|
||||||
|
/* ws2tcpip.h is required here to properly make type definitions below. */
|
||||||
|
#ifdef CURL_PULL_WS2TCPIP_H
|
||||||
|
# include <winsock2.h>
|
||||||
|
# include <windows.h>
|
||||||
|
# include <ws2tcpip.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* CURL_PULL_SYS_TYPES_H is defined above when inclusion of header file */
|
||||||
|
/* sys/types.h is required here to properly make type definitions below. */
|
||||||
|
#ifdef CURL_PULL_SYS_TYPES_H
|
||||||
|
# include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* CURL_PULL_SYS_SOCKET_H is defined above when inclusion of header file */
|
||||||
|
/* sys/socket.h is required here to properly make type definitions below. */
|
||||||
|
#ifdef CURL_PULL_SYS_SOCKET_H
|
||||||
|
# include <sys/socket.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* CURL_PULL_SYS_POLL_H is defined above when inclusion of header file */
|
||||||
|
/* sys/poll.h is required here to properly make type definitions below. */
|
||||||
|
#ifdef CURL_PULL_SYS_POLL_H
|
||||||
|
# include <sys/poll.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Data type definition of curl_socklen_t. */
|
||||||
|
#ifdef CURL_TYPEOF_CURL_SOCKLEN_T
|
||||||
|
typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Data type definition of curl_off_t. */
|
||||||
|
|
||||||
|
#ifdef CURL_TYPEOF_CURL_OFF_T
|
||||||
|
typedef CURL_TYPEOF_CURL_OFF_T curl_off_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* CURL_ISOCPP and CURL_OFF_T_C definitions are done here in order to allow
|
||||||
|
* these to be visible and exported by the external libcurl interface API,
|
||||||
|
* while also making them visible to the library internals, simply including
|
||||||
|
* curl_setup.h, without actually needing to include curl.h internally.
|
||||||
|
* If some day this section would grow big enough, all this should be moved
|
||||||
|
* to its own header file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Figure out if we can use the ## preprocessor operator, which is supported
|
||||||
|
* by ISO/ANSI C and C++. Some compilers support it without setting __STDC__
|
||||||
|
* or __cplusplus so we need to carefully check for them too.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \
|
||||||
|
defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \
|
||||||
|
defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \
|
||||||
|
defined(__ILEC400__)
|
||||||
|
/* This compiler is believed to have an ISO compatible preprocessor */
|
||||||
|
#define CURL_ISOCPP
|
||||||
|
#else
|
||||||
|
/* This compiler is believed NOT to have an ISO compatible preprocessor */
|
||||||
|
#undef CURL_ISOCPP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Macros for minimum-width signed and unsigned curl_off_t integer constants.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(__BORLANDC__) && (__BORLANDC__ == 0x0551)
|
||||||
|
# define CURLINC_OFF_T_C_HLPR2(x) x
|
||||||
|
# define CURLINC_OFF_T_C_HLPR1(x) CURLINC_OFF_T_C_HLPR2(x)
|
||||||
|
# define CURL_OFF_T_C(Val) CURLINC_OFF_T_C_HLPR1(Val) ## \
|
||||||
|
CURLINC_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_T)
|
||||||
|
# define CURL_OFF_TU_C(Val) CURLINC_OFF_T_C_HLPR1(Val) ## \
|
||||||
|
CURLINC_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_TU)
|
||||||
|
#else
|
||||||
|
# ifdef CURL_ISOCPP
|
||||||
|
# define CURLINC_OFF_T_C_HLPR2(Val,Suffix) Val ## Suffix
|
||||||
|
# else
|
||||||
|
# define CURLINC_OFF_T_C_HLPR2(Val,Suffix) Val/**/Suffix
|
||||||
|
# endif
|
||||||
|
# define CURLINC_OFF_T_C_HLPR1(Val,Suffix) CURLINC_OFF_T_C_HLPR2(Val,Suffix)
|
||||||
|
# define CURL_OFF_T_C(Val) CURLINC_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_T)
|
||||||
|
# define CURL_OFF_TU_C(Val) CURLINC_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_TU)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CURLINC_SYSTEM_H */
|
|
@ -0,0 +1,712 @@
|
||||||
|
#ifndef CURLINC_TYPECHECK_GCC_H
|
||||||
|
#define CURLINC_TYPECHECK_GCC_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/* wraps curl_easy_setopt() with typechecking */
|
||||||
|
|
||||||
|
/* To add a new kind of warning, add an
|
||||||
|
* if(curlcheck_sometype_option(_curl_opt))
|
||||||
|
* if(!curlcheck_sometype(value))
|
||||||
|
* _curl_easy_setopt_err_sometype();
|
||||||
|
* block and define curlcheck_sometype_option, curlcheck_sometype and
|
||||||
|
* _curl_easy_setopt_err_sometype below
|
||||||
|
*
|
||||||
|
* NOTE: We use two nested 'if' statements here instead of the && operator, in
|
||||||
|
* order to work around gcc bug #32061. It affects only gcc 4.3.x/4.4.x
|
||||||
|
* when compiling with -Wlogical-op.
|
||||||
|
*
|
||||||
|
* To add an option that uses the same type as an existing option, you'll just
|
||||||
|
* need to extend the appropriate _curl_*_option macro
|
||||||
|
*/
|
||||||
|
#define curl_easy_setopt(handle, option, value) \
|
||||||
|
__extension__({ \
|
||||||
|
__typeof__(option) _curl_opt = option; \
|
||||||
|
if(__builtin_constant_p(_curl_opt)) { \
|
||||||
|
if(curlcheck_long_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_long(value)) \
|
||||||
|
_curl_easy_setopt_err_long(); \
|
||||||
|
if(curlcheck_off_t_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_off_t(value)) \
|
||||||
|
_curl_easy_setopt_err_curl_off_t(); \
|
||||||
|
if(curlcheck_string_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_string(value)) \
|
||||||
|
_curl_easy_setopt_err_string(); \
|
||||||
|
if(curlcheck_write_cb_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_write_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_write_callback(); \
|
||||||
|
if((_curl_opt) == CURLOPT_RESOLVER_START_FUNCTION) \
|
||||||
|
if(!curlcheck_resolver_start_callback(value)) \
|
||||||
|
_curl_easy_setopt_err_resolver_start_callback(); \
|
||||||
|
if((_curl_opt) == CURLOPT_READFUNCTION) \
|
||||||
|
if(!curlcheck_read_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_read_cb(); \
|
||||||
|
if((_curl_opt) == CURLOPT_IOCTLFUNCTION) \
|
||||||
|
if(!curlcheck_ioctl_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_ioctl_cb(); \
|
||||||
|
if((_curl_opt) == CURLOPT_SOCKOPTFUNCTION) \
|
||||||
|
if(!curlcheck_sockopt_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_sockopt_cb(); \
|
||||||
|
if((_curl_opt) == CURLOPT_OPENSOCKETFUNCTION) \
|
||||||
|
if(!curlcheck_opensocket_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_opensocket_cb(); \
|
||||||
|
if((_curl_opt) == CURLOPT_PROGRESSFUNCTION) \
|
||||||
|
if(!curlcheck_progress_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_progress_cb(); \
|
||||||
|
if((_curl_opt) == CURLOPT_DEBUGFUNCTION) \
|
||||||
|
if(!curlcheck_debug_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_debug_cb(); \
|
||||||
|
if((_curl_opt) == CURLOPT_SSL_CTX_FUNCTION) \
|
||||||
|
if(!curlcheck_ssl_ctx_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_ssl_ctx_cb(); \
|
||||||
|
if(curlcheck_conv_cb_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_conv_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_conv_cb(); \
|
||||||
|
if((_curl_opt) == CURLOPT_SEEKFUNCTION) \
|
||||||
|
if(!curlcheck_seek_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_seek_cb(); \
|
||||||
|
if(curlcheck_cb_data_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_cb_data(value)) \
|
||||||
|
_curl_easy_setopt_err_cb_data(); \
|
||||||
|
if((_curl_opt) == CURLOPT_ERRORBUFFER) \
|
||||||
|
if(!curlcheck_error_buffer(value)) \
|
||||||
|
_curl_easy_setopt_err_error_buffer(); \
|
||||||
|
if((_curl_opt) == CURLOPT_STDERR) \
|
||||||
|
if(!curlcheck_FILE(value)) \
|
||||||
|
_curl_easy_setopt_err_FILE(); \
|
||||||
|
if(curlcheck_postfields_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_postfields(value)) \
|
||||||
|
_curl_easy_setopt_err_postfields(); \
|
||||||
|
if((_curl_opt) == CURLOPT_HTTPPOST) \
|
||||||
|
if(!curlcheck_arr((value), struct curl_httppost)) \
|
||||||
|
_curl_easy_setopt_err_curl_httpost(); \
|
||||||
|
if((_curl_opt) == CURLOPT_MIMEPOST) \
|
||||||
|
if(!curlcheck_ptr((value), curl_mime)) \
|
||||||
|
_curl_easy_setopt_err_curl_mimepost(); \
|
||||||
|
if(curlcheck_slist_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_arr((value), struct curl_slist)) \
|
||||||
|
_curl_easy_setopt_err_curl_slist(); \
|
||||||
|
if((_curl_opt) == CURLOPT_SHARE) \
|
||||||
|
if(!curlcheck_ptr((value), CURLSH)) \
|
||||||
|
_curl_easy_setopt_err_CURLSH(); \
|
||||||
|
} \
|
||||||
|
curl_easy_setopt(handle, _curl_opt, value); \
|
||||||
|
})
|
||||||
|
|
||||||
|
/* wraps curl_easy_getinfo() with typechecking */
|
||||||
|
#define curl_easy_getinfo(handle, info, arg) \
|
||||||
|
__extension__({ \
|
||||||
|
__typeof__(info) _curl_info = info; \
|
||||||
|
if(__builtin_constant_p(_curl_info)) { \
|
||||||
|
if(curlcheck_string_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), char *)) \
|
||||||
|
_curl_easy_getinfo_err_string(); \
|
||||||
|
if(curlcheck_long_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), long)) \
|
||||||
|
_curl_easy_getinfo_err_long(); \
|
||||||
|
if(curlcheck_double_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), double)) \
|
||||||
|
_curl_easy_getinfo_err_double(); \
|
||||||
|
if(curlcheck_slist_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), struct curl_slist *)) \
|
||||||
|
_curl_easy_getinfo_err_curl_slist(); \
|
||||||
|
if(curlcheck_tlssessioninfo_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), struct curl_tlssessioninfo *)) \
|
||||||
|
_curl_easy_getinfo_err_curl_tlssesssioninfo(); \
|
||||||
|
if(curlcheck_certinfo_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), struct curl_certinfo *)) \
|
||||||
|
_curl_easy_getinfo_err_curl_certinfo(); \
|
||||||
|
if(curlcheck_socket_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), curl_socket_t)) \
|
||||||
|
_curl_easy_getinfo_err_curl_socket(); \
|
||||||
|
if(curlcheck_off_t_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), curl_off_t)) \
|
||||||
|
_curl_easy_getinfo_err_curl_off_t(); \
|
||||||
|
} \
|
||||||
|
curl_easy_getinfo(handle, _curl_info, arg); \
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For now, just make sure that the functions are called with three arguments
|
||||||
|
*/
|
||||||
|
#define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param)
|
||||||
|
#define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param)
|
||||||
|
|
||||||
|
|
||||||
|
/* the actual warnings, triggered by calling the _curl_easy_setopt_err*
|
||||||
|
* functions */
|
||||||
|
|
||||||
|
/* To define a new warning, use _CURL_WARNING(identifier, "message") */
|
||||||
|
#define CURLWARNING(id, message) \
|
||||||
|
static void __attribute__((__warning__(message))) \
|
||||||
|
__attribute__((__unused__)) __attribute__((__noinline__)) \
|
||||||
|
id(void) { __asm__(""); }
|
||||||
|
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_long,
|
||||||
|
"curl_easy_setopt expects a long argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_curl_off_t,
|
||||||
|
"curl_easy_setopt expects a curl_off_t argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_string,
|
||||||
|
"curl_easy_setopt expects a "
|
||||||
|
"string ('char *' or char[]) argument for this option"
|
||||||
|
)
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_write_callback,
|
||||||
|
"curl_easy_setopt expects a curl_write_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_resolver_start_callback,
|
||||||
|
"curl_easy_setopt expects a "
|
||||||
|
"curl_resolver_start_callback argument for this option"
|
||||||
|
)
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_read_cb,
|
||||||
|
"curl_easy_setopt expects a curl_read_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_ioctl_cb,
|
||||||
|
"curl_easy_setopt expects a curl_ioctl_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_sockopt_cb,
|
||||||
|
"curl_easy_setopt expects a curl_sockopt_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_opensocket_cb,
|
||||||
|
"curl_easy_setopt expects a "
|
||||||
|
"curl_opensocket_callback argument for this option"
|
||||||
|
)
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_progress_cb,
|
||||||
|
"curl_easy_setopt expects a curl_progress_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_debug_cb,
|
||||||
|
"curl_easy_setopt expects a curl_debug_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_ssl_ctx_cb,
|
||||||
|
"curl_easy_setopt expects a curl_ssl_ctx_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_conv_cb,
|
||||||
|
"curl_easy_setopt expects a curl_conv_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_seek_cb,
|
||||||
|
"curl_easy_setopt expects a curl_seek_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_cb_data,
|
||||||
|
"curl_easy_setopt expects a "
|
||||||
|
"private data pointer as argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_error_buffer,
|
||||||
|
"curl_easy_setopt expects a "
|
||||||
|
"char buffer of CURL_ERROR_SIZE as argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_FILE,
|
||||||
|
"curl_easy_setopt expects a 'FILE *' argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_postfields,
|
||||||
|
"curl_easy_setopt expects a 'void *' or 'char *' argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_curl_httpost,
|
||||||
|
"curl_easy_setopt expects a 'struct curl_httppost *' "
|
||||||
|
"argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_curl_mimepost,
|
||||||
|
"curl_easy_setopt expects a 'curl_mime *' "
|
||||||
|
"argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_curl_slist,
|
||||||
|
"curl_easy_setopt expects a 'struct curl_slist *' argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_CURLSH,
|
||||||
|
"curl_easy_setopt expects a CURLSH* argument for this option")
|
||||||
|
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_string,
|
||||||
|
"curl_easy_getinfo expects a pointer to 'char *' for this info")
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_long,
|
||||||
|
"curl_easy_getinfo expects a pointer to long for this info")
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_double,
|
||||||
|
"curl_easy_getinfo expects a pointer to double for this info")
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_curl_slist,
|
||||||
|
"curl_easy_getinfo expects a pointer to 'struct curl_slist *' for this info")
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_curl_tlssesssioninfo,
|
||||||
|
"curl_easy_getinfo expects a pointer to "
|
||||||
|
"'struct curl_tlssessioninfo *' for this info")
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_curl_certinfo,
|
||||||
|
"curl_easy_getinfo expects a pointer to "
|
||||||
|
"'struct curl_certinfo *' for this info")
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_curl_socket,
|
||||||
|
"curl_easy_getinfo expects a pointer to curl_socket_t for this info")
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_curl_off_t,
|
||||||
|
"curl_easy_getinfo expects a pointer to curl_off_t for this info")
|
||||||
|
|
||||||
|
/* groups of curl_easy_setops options that take the same type of argument */
|
||||||
|
|
||||||
|
/* To add a new option to one of the groups, just add
|
||||||
|
* (option) == CURLOPT_SOMETHING
|
||||||
|
* to the or-expression. If the option takes a long or curl_off_t, you don't
|
||||||
|
* have to do anything
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* evaluates to true if option takes a long argument */
|
||||||
|
#define curlcheck_long_option(option) \
|
||||||
|
(0 < (option) && (option) < CURLOPTTYPE_OBJECTPOINT)
|
||||||
|
|
||||||
|
#define curlcheck_off_t_option(option) \
|
||||||
|
(((option) > CURLOPTTYPE_OFF_T) && ((option) < CURLOPTTYPE_BLOB))
|
||||||
|
|
||||||
|
/* evaluates to true if option takes a char* argument */
|
||||||
|
#define curlcheck_string_option(option) \
|
||||||
|
((option) == CURLOPT_ABSTRACT_UNIX_SOCKET || \
|
||||||
|
(option) == CURLOPT_ACCEPT_ENCODING || \
|
||||||
|
(option) == CURLOPT_ALTSVC || \
|
||||||
|
(option) == CURLOPT_CAINFO || \
|
||||||
|
(option) == CURLOPT_CAPATH || \
|
||||||
|
(option) == CURLOPT_COOKIE || \
|
||||||
|
(option) == CURLOPT_COOKIEFILE || \
|
||||||
|
(option) == CURLOPT_COOKIEJAR || \
|
||||||
|
(option) == CURLOPT_COOKIELIST || \
|
||||||
|
(option) == CURLOPT_CRLFILE || \
|
||||||
|
(option) == CURLOPT_CUSTOMREQUEST || \
|
||||||
|
(option) == CURLOPT_DEFAULT_PROTOCOL || \
|
||||||
|
(option) == CURLOPT_DNS_INTERFACE || \
|
||||||
|
(option) == CURLOPT_DNS_LOCAL_IP4 || \
|
||||||
|
(option) == CURLOPT_DNS_LOCAL_IP6 || \
|
||||||
|
(option) == CURLOPT_DNS_SERVERS || \
|
||||||
|
(option) == CURLOPT_DOH_URL || \
|
||||||
|
(option) == CURLOPT_EGDSOCKET || \
|
||||||
|
(option) == CURLOPT_FTP_ACCOUNT || \
|
||||||
|
(option) == CURLOPT_FTP_ALTERNATIVE_TO_USER || \
|
||||||
|
(option) == CURLOPT_FTPPORT || \
|
||||||
|
(option) == CURLOPT_HSTS || \
|
||||||
|
(option) == CURLOPT_INTERFACE || \
|
||||||
|
(option) == CURLOPT_ISSUERCERT || \
|
||||||
|
(option) == CURLOPT_KEYPASSWD || \
|
||||||
|
(option) == CURLOPT_KRBLEVEL || \
|
||||||
|
(option) == CURLOPT_LOGIN_OPTIONS || \
|
||||||
|
(option) == CURLOPT_MAIL_AUTH || \
|
||||||
|
(option) == CURLOPT_MAIL_FROM || \
|
||||||
|
(option) == CURLOPT_NETRC_FILE || \
|
||||||
|
(option) == CURLOPT_NOPROXY || \
|
||||||
|
(option) == CURLOPT_PASSWORD || \
|
||||||
|
(option) == CURLOPT_PINNEDPUBLICKEY || \
|
||||||
|
(option) == CURLOPT_PRE_PROXY || \
|
||||||
|
(option) == CURLOPT_PROTOCOLS_STR || \
|
||||||
|
(option) == CURLOPT_PROXY || \
|
||||||
|
(option) == CURLOPT_PROXY_CAINFO || \
|
||||||
|
(option) == CURLOPT_PROXY_CAPATH || \
|
||||||
|
(option) == CURLOPT_PROXY_CRLFILE || \
|
||||||
|
(option) == CURLOPT_PROXY_ISSUERCERT || \
|
||||||
|
(option) == CURLOPT_PROXY_KEYPASSWD || \
|
||||||
|
(option) == CURLOPT_PROXY_PINNEDPUBLICKEY || \
|
||||||
|
(option) == CURLOPT_PROXY_SERVICE_NAME || \
|
||||||
|
(option) == CURLOPT_PROXY_SSL_CIPHER_LIST || \
|
||||||
|
(option) == CURLOPT_PROXY_SSLCERT || \
|
||||||
|
(option) == CURLOPT_PROXY_SSLCERTTYPE || \
|
||||||
|
(option) == CURLOPT_PROXY_SSLKEY || \
|
||||||
|
(option) == CURLOPT_PROXY_SSLKEYTYPE || \
|
||||||
|
(option) == CURLOPT_PROXY_TLS13_CIPHERS || \
|
||||||
|
(option) == CURLOPT_PROXY_TLSAUTH_PASSWORD || \
|
||||||
|
(option) == CURLOPT_PROXY_TLSAUTH_TYPE || \
|
||||||
|
(option) == CURLOPT_PROXY_TLSAUTH_USERNAME || \
|
||||||
|
(option) == CURLOPT_PROXYPASSWORD || \
|
||||||
|
(option) == CURLOPT_PROXYUSERNAME || \
|
||||||
|
(option) == CURLOPT_PROXYUSERPWD || \
|
||||||
|
(option) == CURLOPT_RANDOM_FILE || \
|
||||||
|
(option) == CURLOPT_RANGE || \
|
||||||
|
(option) == CURLOPT_REDIR_PROTOCOLS_STR || \
|
||||||
|
(option) == CURLOPT_REFERER || \
|
||||||
|
(option) == CURLOPT_REQUEST_TARGET || \
|
||||||
|
(option) == CURLOPT_RTSP_SESSION_ID || \
|
||||||
|
(option) == CURLOPT_RTSP_STREAM_URI || \
|
||||||
|
(option) == CURLOPT_RTSP_TRANSPORT || \
|
||||||
|
(option) == CURLOPT_SASL_AUTHZID || \
|
||||||
|
(option) == CURLOPT_SERVICE_NAME || \
|
||||||
|
(option) == CURLOPT_SOCKS5_GSSAPI_SERVICE || \
|
||||||
|
(option) == CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 || \
|
||||||
|
(option) == CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256 || \
|
||||||
|
(option) == CURLOPT_SSH_KNOWNHOSTS || \
|
||||||
|
(option) == CURLOPT_SSH_PRIVATE_KEYFILE || \
|
||||||
|
(option) == CURLOPT_SSH_PUBLIC_KEYFILE || \
|
||||||
|
(option) == CURLOPT_SSLCERT || \
|
||||||
|
(option) == CURLOPT_SSLCERTTYPE || \
|
||||||
|
(option) == CURLOPT_SSLENGINE || \
|
||||||
|
(option) == CURLOPT_SSLKEY || \
|
||||||
|
(option) == CURLOPT_SSLKEYTYPE || \
|
||||||
|
(option) == CURLOPT_SSL_CIPHER_LIST || \
|
||||||
|
(option) == CURLOPT_TLS13_CIPHERS || \
|
||||||
|
(option) == CURLOPT_TLSAUTH_PASSWORD || \
|
||||||
|
(option) == CURLOPT_TLSAUTH_TYPE || \
|
||||||
|
(option) == CURLOPT_TLSAUTH_USERNAME || \
|
||||||
|
(option) == CURLOPT_UNIX_SOCKET_PATH || \
|
||||||
|
(option) == CURLOPT_URL || \
|
||||||
|
(option) == CURLOPT_USERAGENT || \
|
||||||
|
(option) == CURLOPT_USERNAME || \
|
||||||
|
(option) == CURLOPT_AWS_SIGV4 || \
|
||||||
|
(option) == CURLOPT_USERPWD || \
|
||||||
|
(option) == CURLOPT_XOAUTH2_BEARER || \
|
||||||
|
(option) == CURLOPT_SSL_EC_CURVES || \
|
||||||
|
0)
|
||||||
|
|
||||||
|
/* evaluates to true if option takes a curl_write_callback argument */
|
||||||
|
#define curlcheck_write_cb_option(option) \
|
||||||
|
((option) == CURLOPT_HEADERFUNCTION || \
|
||||||
|
(option) == CURLOPT_WRITEFUNCTION)
|
||||||
|
|
||||||
|
/* evaluates to true if option takes a curl_conv_callback argument */
|
||||||
|
#define curlcheck_conv_cb_option(option) \
|
||||||
|
((option) == CURLOPT_CONV_TO_NETWORK_FUNCTION || \
|
||||||
|
(option) == CURLOPT_CONV_FROM_NETWORK_FUNCTION || \
|
||||||
|
(option) == CURLOPT_CONV_FROM_UTF8_FUNCTION)
|
||||||
|
|
||||||
|
/* evaluates to true if option takes a data argument to pass to a callback */
|
||||||
|
#define curlcheck_cb_data_option(option) \
|
||||||
|
((option) == CURLOPT_CHUNK_DATA || \
|
||||||
|
(option) == CURLOPT_CLOSESOCKETDATA || \
|
||||||
|
(option) == CURLOPT_DEBUGDATA || \
|
||||||
|
(option) == CURLOPT_FNMATCH_DATA || \
|
||||||
|
(option) == CURLOPT_HEADERDATA || \
|
||||||
|
(option) == CURLOPT_HSTSREADDATA || \
|
||||||
|
(option) == CURLOPT_HSTSWRITEDATA || \
|
||||||
|
(option) == CURLOPT_INTERLEAVEDATA || \
|
||||||
|
(option) == CURLOPT_IOCTLDATA || \
|
||||||
|
(option) == CURLOPT_OPENSOCKETDATA || \
|
||||||
|
(option) == CURLOPT_PREREQDATA || \
|
||||||
|
(option) == CURLOPT_PROGRESSDATA || \
|
||||||
|
(option) == CURLOPT_READDATA || \
|
||||||
|
(option) == CURLOPT_SEEKDATA || \
|
||||||
|
(option) == CURLOPT_SOCKOPTDATA || \
|
||||||
|
(option) == CURLOPT_SSH_KEYDATA || \
|
||||||
|
(option) == CURLOPT_SSL_CTX_DATA || \
|
||||||
|
(option) == CURLOPT_WRITEDATA || \
|
||||||
|
(option) == CURLOPT_RESOLVER_START_DATA || \
|
||||||
|
(option) == CURLOPT_TRAILERDATA || \
|
||||||
|
(option) == CURLOPT_SSH_HOSTKEYDATA || \
|
||||||
|
0)
|
||||||
|
|
||||||
|
/* evaluates to true if option takes a POST data argument (void* or char*) */
|
||||||
|
#define curlcheck_postfields_option(option) \
|
||||||
|
((option) == CURLOPT_POSTFIELDS || \
|
||||||
|
(option) == CURLOPT_COPYPOSTFIELDS || \
|
||||||
|
0)
|
||||||
|
|
||||||
|
/* evaluates to true if option takes a struct curl_slist * argument */
|
||||||
|
#define curlcheck_slist_option(option) \
|
||||||
|
((option) == CURLOPT_HTTP200ALIASES || \
|
||||||
|
(option) == CURLOPT_HTTPHEADER || \
|
||||||
|
(option) == CURLOPT_MAIL_RCPT || \
|
||||||
|
(option) == CURLOPT_POSTQUOTE || \
|
||||||
|
(option) == CURLOPT_PREQUOTE || \
|
||||||
|
(option) == CURLOPT_PROXYHEADER || \
|
||||||
|
(option) == CURLOPT_QUOTE || \
|
||||||
|
(option) == CURLOPT_RESOLVE || \
|
||||||
|
(option) == CURLOPT_TELNETOPTIONS || \
|
||||||
|
(option) == CURLOPT_CONNECT_TO || \
|
||||||
|
0)
|
||||||
|
|
||||||
|
/* groups of curl_easy_getinfo infos that take the same type of argument */
|
||||||
|
|
||||||
|
/* evaluates to true if info expects a pointer to char * argument */
|
||||||
|
#define curlcheck_string_info(info) \
|
||||||
|
(CURLINFO_STRING < (info) && (info) < CURLINFO_LONG && \
|
||||||
|
(info) != CURLINFO_PRIVATE)
|
||||||
|
|
||||||
|
/* evaluates to true if info expects a pointer to long argument */
|
||||||
|
#define curlcheck_long_info(info) \
|
||||||
|
(CURLINFO_LONG < (info) && (info) < CURLINFO_DOUBLE)
|
||||||
|
|
||||||
|
/* evaluates to true if info expects a pointer to double argument */
|
||||||
|
#define curlcheck_double_info(info) \
|
||||||
|
(CURLINFO_DOUBLE < (info) && (info) < CURLINFO_SLIST)
|
||||||
|
|
||||||
|
/* true if info expects a pointer to struct curl_slist * argument */
|
||||||
|
#define curlcheck_slist_info(info) \
|
||||||
|
(((info) == CURLINFO_SSL_ENGINES) || ((info) == CURLINFO_COOKIELIST))
|
||||||
|
|
||||||
|
/* true if info expects a pointer to struct curl_tlssessioninfo * argument */
|
||||||
|
#define curlcheck_tlssessioninfo_info(info) \
|
||||||
|
(((info) == CURLINFO_TLS_SSL_PTR) || ((info) == CURLINFO_TLS_SESSION))
|
||||||
|
|
||||||
|
/* true if info expects a pointer to struct curl_certinfo * argument */
|
||||||
|
#define curlcheck_certinfo_info(info) ((info) == CURLINFO_CERTINFO)
|
||||||
|
|
||||||
|
/* true if info expects a pointer to struct curl_socket_t argument */
|
||||||
|
#define curlcheck_socket_info(info) \
|
||||||
|
(CURLINFO_SOCKET < (info) && (info) < CURLINFO_OFF_T)
|
||||||
|
|
||||||
|
/* true if info expects a pointer to curl_off_t argument */
|
||||||
|
#define curlcheck_off_t_info(info) \
|
||||||
|
(CURLINFO_OFF_T < (info))
|
||||||
|
|
||||||
|
|
||||||
|
/* typecheck helpers -- check whether given expression has requested type*/
|
||||||
|
|
||||||
|
/* For pointers, you can use the curlcheck_ptr/curlcheck_arr macros,
|
||||||
|
* otherwise define a new macro. Search for __builtin_types_compatible_p
|
||||||
|
* in the GCC manual.
|
||||||
|
* NOTE: these macros MUST NOT EVALUATE their arguments! The argument is
|
||||||
|
* the actual expression passed to the curl_easy_setopt macro. This
|
||||||
|
* means that you can only apply the sizeof and __typeof__ operators, no
|
||||||
|
* == or whatsoever.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* XXX: should evaluate to true if expr is a pointer */
|
||||||
|
#define curlcheck_any_ptr(expr) \
|
||||||
|
(sizeof(expr) == sizeof(void *))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is NULL */
|
||||||
|
/* XXX: must not evaluate expr, so this check is not accurate */
|
||||||
|
#define curlcheck_NULL(expr) \
|
||||||
|
(__builtin_types_compatible_p(__typeof__(expr), __typeof__(NULL)))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is type*, const type* or NULL */
|
||||||
|
#define curlcheck_ptr(expr, type) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), type *) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), const type *))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is one of type[], type*, NULL or const type* */
|
||||||
|
#define curlcheck_arr(expr, type) \
|
||||||
|
(curlcheck_ptr((expr), type) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), type []))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is a string */
|
||||||
|
#define curlcheck_string(expr) \
|
||||||
|
(curlcheck_arr((expr), char) || \
|
||||||
|
curlcheck_arr((expr), signed char) || \
|
||||||
|
curlcheck_arr((expr), unsigned char))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is a long (no matter the signedness)
|
||||||
|
* XXX: for now, int is also accepted (and therefore short and char, which
|
||||||
|
* are promoted to int when passed to a variadic function) */
|
||||||
|
#define curlcheck_long(expr) \
|
||||||
|
(__builtin_types_compatible_p(__typeof__(expr), long) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), signed long) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), unsigned long) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), int) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), signed int) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), unsigned int) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), short) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), signed short) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), unsigned short) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), char) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), signed char) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), unsigned char))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_off_t */
|
||||||
|
#define curlcheck_off_t(expr) \
|
||||||
|
(__builtin_types_compatible_p(__typeof__(expr), curl_off_t))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is abuffer suitable for CURLOPT_ERRORBUFFER */
|
||||||
|
/* XXX: also check size of an char[] array? */
|
||||||
|
#define curlcheck_error_buffer(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), char *) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), char[]))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type (const) void* or (const) FILE* */
|
||||||
|
#if 0
|
||||||
|
#define curlcheck_cb_data(expr) \
|
||||||
|
(curlcheck_ptr((expr), void) || \
|
||||||
|
curlcheck_ptr((expr), FILE))
|
||||||
|
#else /* be less strict */
|
||||||
|
#define curlcheck_cb_data(expr) \
|
||||||
|
curlcheck_any_ptr(expr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type FILE* */
|
||||||
|
#define curlcheck_FILE(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
(__builtin_types_compatible_p(__typeof__(expr), FILE *)))
|
||||||
|
|
||||||
|
/* evaluates to true if expr can be passed as POST data (void* or char*) */
|
||||||
|
#define curlcheck_postfields(expr) \
|
||||||
|
(curlcheck_ptr((expr), void) || \
|
||||||
|
curlcheck_arr((expr), char) || \
|
||||||
|
curlcheck_arr((expr), unsigned char))
|
||||||
|
|
||||||
|
/* helper: __builtin_types_compatible_p distinguishes between functions and
|
||||||
|
* function pointers, hide it */
|
||||||
|
#define curlcheck_cb_compatible(func, type) \
|
||||||
|
(__builtin_types_compatible_p(__typeof__(func), type) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(func) *, type))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_resolver_start_callback */
|
||||||
|
#define curlcheck_resolver_start_callback(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_resolver_start_callback))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_read_callback or "similar" */
|
||||||
|
#define curlcheck_read_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), __typeof__(fread) *) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_read_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_read_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_read_callback2) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_read_callback3) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_read_callback4) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_read_callback5) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_read_callback6))
|
||||||
|
typedef size_t (*_curl_read_callback1)(char *, size_t, size_t, void *);
|
||||||
|
typedef size_t (*_curl_read_callback2)(char *, size_t, size_t, const void *);
|
||||||
|
typedef size_t (*_curl_read_callback3)(char *, size_t, size_t, FILE *);
|
||||||
|
typedef size_t (*_curl_read_callback4)(void *, size_t, size_t, void *);
|
||||||
|
typedef size_t (*_curl_read_callback5)(void *, size_t, size_t, const void *);
|
||||||
|
typedef size_t (*_curl_read_callback6)(void *, size_t, size_t, FILE *);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_write_callback or "similar" */
|
||||||
|
#define curlcheck_write_cb(expr) \
|
||||||
|
(curlcheck_read_cb(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), __typeof__(fwrite) *) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_write_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_write_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_write_callback2) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_write_callback3) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_write_callback4) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_write_callback5) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_write_callback6))
|
||||||
|
typedef size_t (*_curl_write_callback1)(const char *, size_t, size_t, void *);
|
||||||
|
typedef size_t (*_curl_write_callback2)(const char *, size_t, size_t,
|
||||||
|
const void *);
|
||||||
|
typedef size_t (*_curl_write_callback3)(const char *, size_t, size_t, FILE *);
|
||||||
|
typedef size_t (*_curl_write_callback4)(const void *, size_t, size_t, void *);
|
||||||
|
typedef size_t (*_curl_write_callback5)(const void *, size_t, size_t,
|
||||||
|
const void *);
|
||||||
|
typedef size_t (*_curl_write_callback6)(const void *, size_t, size_t, FILE *);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_ioctl_callback or "similar" */
|
||||||
|
#define curlcheck_ioctl_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_ioctl_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ioctl_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ioctl_callback2) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ioctl_callback3) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ioctl_callback4))
|
||||||
|
typedef curlioerr (*_curl_ioctl_callback1)(CURL *, int, void *);
|
||||||
|
typedef curlioerr (*_curl_ioctl_callback2)(CURL *, int, const void *);
|
||||||
|
typedef curlioerr (*_curl_ioctl_callback3)(CURL *, curliocmd, void *);
|
||||||
|
typedef curlioerr (*_curl_ioctl_callback4)(CURL *, curliocmd, const void *);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_sockopt_callback or "similar" */
|
||||||
|
#define curlcheck_sockopt_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_sockopt_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_sockopt_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_sockopt_callback2))
|
||||||
|
typedef int (*_curl_sockopt_callback1)(void *, curl_socket_t, curlsocktype);
|
||||||
|
typedef int (*_curl_sockopt_callback2)(const void *, curl_socket_t,
|
||||||
|
curlsocktype);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_opensocket_callback or
|
||||||
|
"similar" */
|
||||||
|
#define curlcheck_opensocket_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_opensocket_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_opensocket_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_opensocket_callback2) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_opensocket_callback3) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_opensocket_callback4))
|
||||||
|
typedef curl_socket_t (*_curl_opensocket_callback1)
|
||||||
|
(void *, curlsocktype, struct curl_sockaddr *);
|
||||||
|
typedef curl_socket_t (*_curl_opensocket_callback2)
|
||||||
|
(void *, curlsocktype, const struct curl_sockaddr *);
|
||||||
|
typedef curl_socket_t (*_curl_opensocket_callback3)
|
||||||
|
(const void *, curlsocktype, struct curl_sockaddr *);
|
||||||
|
typedef curl_socket_t (*_curl_opensocket_callback4)
|
||||||
|
(const void *, curlsocktype, const struct curl_sockaddr *);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_progress_callback or "similar" */
|
||||||
|
#define curlcheck_progress_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_progress_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_progress_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_progress_callback2))
|
||||||
|
typedef int (*_curl_progress_callback1)(void *,
|
||||||
|
double, double, double, double);
|
||||||
|
typedef int (*_curl_progress_callback2)(const void *,
|
||||||
|
double, double, double, double);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_debug_callback or "similar" */
|
||||||
|
#define curlcheck_debug_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_debug_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback2) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback3) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback4) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback5) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback6) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback7) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback8))
|
||||||
|
typedef int (*_curl_debug_callback1) (CURL *,
|
||||||
|
curl_infotype, char *, size_t, void *);
|
||||||
|
typedef int (*_curl_debug_callback2) (CURL *,
|
||||||
|
curl_infotype, char *, size_t, const void *);
|
||||||
|
typedef int (*_curl_debug_callback3) (CURL *,
|
||||||
|
curl_infotype, const char *, size_t, void *);
|
||||||
|
typedef int (*_curl_debug_callback4) (CURL *,
|
||||||
|
curl_infotype, const char *, size_t, const void *);
|
||||||
|
typedef int (*_curl_debug_callback5) (CURL *,
|
||||||
|
curl_infotype, unsigned char *, size_t, void *);
|
||||||
|
typedef int (*_curl_debug_callback6) (CURL *,
|
||||||
|
curl_infotype, unsigned char *, size_t, const void *);
|
||||||
|
typedef int (*_curl_debug_callback7) (CURL *,
|
||||||
|
curl_infotype, const unsigned char *, size_t, void *);
|
||||||
|
typedef int (*_curl_debug_callback8) (CURL *,
|
||||||
|
curl_infotype, const unsigned char *, size_t, const void *);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_ssl_ctx_callback or "similar" */
|
||||||
|
/* this is getting even messier... */
|
||||||
|
#define curlcheck_ssl_ctx_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_ssl_ctx_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback2) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback3) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback4) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback5) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback6) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback7) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback8))
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback1)(CURL *, void *, void *);
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback2)(CURL *, void *, const void *);
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback3)(CURL *, const void *, void *);
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback4)(CURL *, const void *,
|
||||||
|
const void *);
|
||||||
|
#ifdef HEADER_SSL_H
|
||||||
|
/* hack: if we included OpenSSL's ssl.h, we know about SSL_CTX
|
||||||
|
* this will of course break if we're included before OpenSSL headers...
|
||||||
|
*/
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback5)(CURL *, SSL_CTX *, void *);
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback6)(CURL *, SSL_CTX *, const void *);
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback7)(CURL *, const SSL_CTX *, void *);
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback8)(CURL *, const SSL_CTX *,
|
||||||
|
const void *);
|
||||||
|
#else
|
||||||
|
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback5;
|
||||||
|
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback6;
|
||||||
|
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback7;
|
||||||
|
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback8;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_conv_callback or "similar" */
|
||||||
|
#define curlcheck_conv_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_conv_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_conv_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_conv_callback2) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_conv_callback3) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_conv_callback4))
|
||||||
|
typedef CURLcode (*_curl_conv_callback1)(char *, size_t length);
|
||||||
|
typedef CURLcode (*_curl_conv_callback2)(const char *, size_t length);
|
||||||
|
typedef CURLcode (*_curl_conv_callback3)(void *, size_t length);
|
||||||
|
typedef CURLcode (*_curl_conv_callback4)(const void *, size_t length);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_seek_callback or "similar" */
|
||||||
|
#define curlcheck_seek_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_seek_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_seek_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_seek_callback2))
|
||||||
|
typedef CURLcode (*_curl_seek_callback1)(void *, curl_off_t, int);
|
||||||
|
typedef CURLcode (*_curl_seek_callback2)(const void *, curl_off_t, int);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* CURLINC_TYPECHECK_GCC_H */
|
|
@ -0,0 +1,147 @@
|
||||||
|
#ifndef CURLINC_URLAPI_H
|
||||||
|
#define CURLINC_URLAPI_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "curl.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* the error codes for the URL API */
|
||||||
|
typedef enum {
|
||||||
|
CURLUE_OK,
|
||||||
|
CURLUE_BAD_HANDLE, /* 1 */
|
||||||
|
CURLUE_BAD_PARTPOINTER, /* 2 */
|
||||||
|
CURLUE_MALFORMED_INPUT, /* 3 */
|
||||||
|
CURLUE_BAD_PORT_NUMBER, /* 4 */
|
||||||
|
CURLUE_UNSUPPORTED_SCHEME, /* 5 */
|
||||||
|
CURLUE_URLDECODE, /* 6 */
|
||||||
|
CURLUE_OUT_OF_MEMORY, /* 7 */
|
||||||
|
CURLUE_USER_NOT_ALLOWED, /* 8 */
|
||||||
|
CURLUE_UNKNOWN_PART, /* 9 */
|
||||||
|
CURLUE_NO_SCHEME, /* 10 */
|
||||||
|
CURLUE_NO_USER, /* 11 */
|
||||||
|
CURLUE_NO_PASSWORD, /* 12 */
|
||||||
|
CURLUE_NO_OPTIONS, /* 13 */
|
||||||
|
CURLUE_NO_HOST, /* 14 */
|
||||||
|
CURLUE_NO_PORT, /* 15 */
|
||||||
|
CURLUE_NO_QUERY, /* 16 */
|
||||||
|
CURLUE_NO_FRAGMENT, /* 17 */
|
||||||
|
CURLUE_NO_ZONEID, /* 18 */
|
||||||
|
CURLUE_BAD_FILE_URL, /* 19 */
|
||||||
|
CURLUE_BAD_FRAGMENT, /* 20 */
|
||||||
|
CURLUE_BAD_HOSTNAME, /* 21 */
|
||||||
|
CURLUE_BAD_IPV6, /* 22 */
|
||||||
|
CURLUE_BAD_LOGIN, /* 23 */
|
||||||
|
CURLUE_BAD_PASSWORD, /* 24 */
|
||||||
|
CURLUE_BAD_PATH, /* 25 */
|
||||||
|
CURLUE_BAD_QUERY, /* 26 */
|
||||||
|
CURLUE_BAD_SCHEME, /* 27 */
|
||||||
|
CURLUE_BAD_SLASHES, /* 28 */
|
||||||
|
CURLUE_BAD_USER, /* 29 */
|
||||||
|
CURLUE_LAST
|
||||||
|
} CURLUcode;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CURLUPART_URL,
|
||||||
|
CURLUPART_SCHEME,
|
||||||
|
CURLUPART_USER,
|
||||||
|
CURLUPART_PASSWORD,
|
||||||
|
CURLUPART_OPTIONS,
|
||||||
|
CURLUPART_HOST,
|
||||||
|
CURLUPART_PORT,
|
||||||
|
CURLUPART_PATH,
|
||||||
|
CURLUPART_QUERY,
|
||||||
|
CURLUPART_FRAGMENT,
|
||||||
|
CURLUPART_ZONEID /* added in 7.65.0 */
|
||||||
|
} CURLUPart;
|
||||||
|
|
||||||
|
#define CURLU_DEFAULT_PORT (1<<0) /* return default port number */
|
||||||
|
#define CURLU_NO_DEFAULT_PORT (1<<1) /* act as if no port number was set,
|
||||||
|
if the port number matches the
|
||||||
|
default for the scheme */
|
||||||
|
#define CURLU_DEFAULT_SCHEME (1<<2) /* return default scheme if
|
||||||
|
missing */
|
||||||
|
#define CURLU_NON_SUPPORT_SCHEME (1<<3) /* allow non-supported scheme */
|
||||||
|
#define CURLU_PATH_AS_IS (1<<4) /* leave dot sequences */
|
||||||
|
#define CURLU_DISALLOW_USER (1<<5) /* no user+password allowed */
|
||||||
|
#define CURLU_URLDECODE (1<<6) /* URL decode on get */
|
||||||
|
#define CURLU_URLENCODE (1<<7) /* URL encode on set */
|
||||||
|
#define CURLU_APPENDQUERY (1<<8) /* append a form style part */
|
||||||
|
#define CURLU_GUESS_SCHEME (1<<9) /* legacy curl-style guessing */
|
||||||
|
#define CURLU_NO_AUTHORITY (1<<10) /* Allow empty authority when the
|
||||||
|
scheme is unknown. */
|
||||||
|
#define CURLU_ALLOW_SPACE (1<<11) /* Allow spaces in the URL */
|
||||||
|
|
||||||
|
typedef struct Curl_URL CURLU;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* curl_url() creates a new CURLU handle and returns a pointer to it.
|
||||||
|
* Must be freed with curl_url_cleanup().
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLU *curl_url(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* curl_url_cleanup() frees the CURLU handle and related resources used for
|
||||||
|
* the URL parsing. It will not free strings previously returned with the URL
|
||||||
|
* API.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN void curl_url_cleanup(CURLU *handle);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* curl_url_dup() duplicates a CURLU handle and returns a new copy. The new
|
||||||
|
* handle must also be freed with curl_url_cleanup().
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLU *curl_url_dup(CURLU *in);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* curl_url_get() extracts a specific part of the URL from a CURLU
|
||||||
|
* handle. Returns error code. The returned pointer MUST be freed with
|
||||||
|
* curl_free() afterwards.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLUcode curl_url_get(CURLU *handle, CURLUPart what,
|
||||||
|
char **part, unsigned int flags);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* curl_url_set() sets a specific part of the URL in a CURLU handle. Returns
|
||||||
|
* error code. The passed in string will be copied. Passing a NULL instead of
|
||||||
|
* a part string, clears that part.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLUcode curl_url_set(CURLU *handle, CURLUPart what,
|
||||||
|
const char *part, unsigned int flags);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* curl_url_strerror() turns a CURLUcode value into the equivalent human
|
||||||
|
* readable error string. This is useful for printing meaningful error
|
||||||
|
* messages.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN const char *curl_url_strerror(CURLUcode);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* end of extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CURLINC_URLAPI_H */
|
|
@ -0,0 +1,103 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Lucas' Bot.
|
||||||
|
*
|
||||||
|
* Lucas' Bot is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
|
||||||
|
Lucas' Bot is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along
|
||||||
|
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "library.h"
|
||||||
|
|
||||||
|
#include "curl/curl.h"
|
||||||
|
#include <random>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace Http {
|
||||||
|
Request::Request() {
|
||||||
|
this->url = "";
|
||||||
|
this->method = "GET";
|
||||||
|
this->body = "";
|
||||||
|
this->header = "";
|
||||||
|
this->response = "";
|
||||||
|
this->verbose = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Request::~Request() = default;
|
||||||
|
|
||||||
|
void Request::setUrl(const std::string& theUrl) {
|
||||||
|
this->url = theUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Request::setMethod(const std::string& theMethod) {
|
||||||
|
this->method = theMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Request::setBody(const std::string& theBody) {
|
||||||
|
this->body = theBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Request::setHeader(const std::string& theHeader) {
|
||||||
|
this->header = theHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Request::setVerbose(bool theVerbose) {
|
||||||
|
this->verbose = theVerbose;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Request::getResponse() {
|
||||||
|
return this->response;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Request::send() {
|
||||||
|
CURL *curl;
|
||||||
|
CURLcode res;
|
||||||
|
curl = curl_easy_init();
|
||||||
|
if (curl) {
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, this->url.c_str());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, this->method.c_str());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, this->body.c_str());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Request::writeCallback);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &this->response);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, this->verbose);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
|
|
||||||
|
res = curl_easy_perform(curl);
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Request::writeCallback(char *ptr, size_t size, size_t nmemb, void *userdata) {
|
||||||
|
auto *response = static_cast<std::string *>(userdata);
|
||||||
|
response->append(ptr, size * nmemb);
|
||||||
|
return size * nmemb;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string FileUtilities::readFile(const std::string &path) {
|
||||||
|
std::ifstream file(path, std::ios::in | std::ios::binary | std::ios::ate);
|
||||||
|
std::stringstream buffer;
|
||||||
|
// read binary from path to the string
|
||||||
|
buffer << file.rdbuf();
|
||||||
|
return buffer.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileUtilities::writeFile(const std::string &path, const std::string &content) {
|
||||||
|
std::ofstream file(path, std::ios::out | std::ios::binary);
|
||||||
|
// write content to path in binary format
|
||||||
|
file.write(content.c_str(), content.size());
|
||||||
|
// Close
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
cmake_minimum_required(VERSION 3.24)
|
||||||
|
project(Person)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
|
add_library(Person SHARED Person.cpp PersonCollection.cpp)
|
|
@ -0,0 +1,142 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Lucas' Bot.
|
||||||
|
*
|
||||||
|
* Lucas' Bot is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
|
||||||
|
Lucas' Bot is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along
|
||||||
|
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Person.h"
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
bool Person::isSignOnToday() const {
|
||||||
|
// Get today's 12:00 A.M. time point
|
||||||
|
std::time_t now = std::time(nullptr);
|
||||||
|
std::tm* nowTm = std::localtime(&now);
|
||||||
|
nowTm->tm_hour = 0;
|
||||||
|
nowTm->tm_min = 0;
|
||||||
|
nowTm->tm_sec = 0;
|
||||||
|
std::time_t today = std::mktime(nowTm);
|
||||||
|
|
||||||
|
// Check last sign on time
|
||||||
|
// And compare it with today's 12:00 A.M.
|
||||||
|
// If last sign on time is before today's 12:00 A.M.,
|
||||||
|
// Then it is not sign on today
|
||||||
|
return lastSignOnTime >= today;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Person::signOn() {
|
||||||
|
if (isSignOnToday()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Check last sign-on date
|
||||||
|
// If it is yesterday, add 1 to signOnDays
|
||||||
|
// If it is not yesterday, reset signOnDays to 1
|
||||||
|
if (std::time(nullptr) - lastSignOnTime < 2 * 24 * 60 * 60) {
|
||||||
|
signOnDays++;
|
||||||
|
} else {
|
||||||
|
signOnDays = 1;
|
||||||
|
}
|
||||||
|
lastSignOnTime = std::time(nullptr);
|
||||||
|
// Increase Copper coin amount by random
|
||||||
|
// Range: 0-100
|
||||||
|
// Use Normal Distribution
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 gen(rd());
|
||||||
|
std::normal_distribution<> dis(50, 20);
|
||||||
|
copperCoin += static_cast<int>(dis(gen));
|
||||||
|
}
|
||||||
|
|
||||||
|
int Person::continuousSignOnDays() const {
|
||||||
|
// Check last sign-on date
|
||||||
|
// If it's not yesterday, return 0
|
||||||
|
// If it is yesterday or today, return signOnDays
|
||||||
|
|
||||||
|
// Get Yesterday's 12:00 A.M. Time Point
|
||||||
|
std::time_t now = std::time(nullptr);
|
||||||
|
std::tm* nowTm = std::localtime(&now);
|
||||||
|
nowTm->tm_hour = 0;
|
||||||
|
nowTm->tm_min = 0;
|
||||||
|
nowTm->tm_sec = 0;
|
||||||
|
std::time_t today = std::mktime(nowTm);
|
||||||
|
std::time_t yesterday = today - 24 * 60 * 60;
|
||||||
|
|
||||||
|
// Check last sign on time
|
||||||
|
// And compare it with yesterday's 12:00 A.M.
|
||||||
|
// If last sign on time is before yesterday's 12:00 A.M.,
|
||||||
|
// Then it is not sign on yesterday, returns zero
|
||||||
|
// and set signOnDays to 0
|
||||||
|
// else, returns signOnDays
|
||||||
|
if (lastSignOnTime < yesterday) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return signOnDays;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Person::willBeAttackNextTime() const {
|
||||||
|
static std::default_random_engine e(std::time(nullptr));
|
||||||
|
std::uniform_int_distribution<unsigned> u(0, 10000);
|
||||||
|
// u(e) divide 100 is the probability
|
||||||
|
switch (speakCount) {
|
||||||
|
// Case 0-73: the probability is 0.60%
|
||||||
|
case 0 ... 73:
|
||||||
|
return u(e) < 60;
|
||||||
|
// Case 74-90:
|
||||||
|
// The base probability is 6.60%
|
||||||
|
// Increase by 6% for each 1 times
|
||||||
|
// Max probability is 100%
|
||||||
|
case 74 ... 90:
|
||||||
|
return u(e) < 660 + 60 * (speakCount - 74);
|
||||||
|
// If speakCount > 90, the probability is 100%
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Person::resetAttackCount() {
|
||||||
|
speakCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Person::increaseSpeakCount() {
|
||||||
|
speakCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serialize to JSON
|
||||||
|
nlohmann::json Person::serializeToJSON() {
|
||||||
|
nlohmann::json j;
|
||||||
|
j["qqID"] = qqID;
|
||||||
|
j["lastSignOnTime"] = lastSignOnTime;
|
||||||
|
j["signOnDays"] = signOnDays;
|
||||||
|
j["speakCount"] = speakCount;
|
||||||
|
j["copperCoin"] = copperCoin;
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deserialize from JSON
|
||||||
|
Person::Person(const nlohmann::json &json) :
|
||||||
|
qqID(json["qqID"]),
|
||||||
|
lastSignOnTime(json["lastSignOnTime"]),
|
||||||
|
signOnDays(json["signOnDays"]),
|
||||||
|
speakCount(json["speakCount"]),
|
||||||
|
copperCoin(json["copperCoin"]) {}
|
||||||
|
|
||||||
|
int Person::getCopperCoin() const {
|
||||||
|
return copperCoin;
|
||||||
|
}
|
||||||
|
|
||||||
|
MiraiCP::QQID Person::getQQID() const {
|
||||||
|
return qqID;
|
||||||
|
}
|
||||||
|
|
||||||
|
Person::Person(MiraiCP::QQID id) :
|
||||||
|
qqID(id), lastSignOnTime(0), signOnDays(0), speakCount(0), copperCoin(0) {}
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Lucas' Bot.
|
||||||
|
*
|
||||||
|
* Lucas' Bot is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
|
||||||
|
Lucas' Bot is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along
|
||||||
|
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PERSON_DEMO_PERSON_H
|
||||||
|
#define PERSON_DEMO_PERSON_H
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
#include "json.hpp"
|
||||||
|
|
||||||
|
namespace MiraiCP {
|
||||||
|
using QQID = unsigned long long;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Person {
|
||||||
|
private:
|
||||||
|
MiraiCP::QQID qqID;
|
||||||
|
// 上次签到时间
|
||||||
|
std::time_t lastSignOnTime;
|
||||||
|
// 连续签到天数
|
||||||
|
int signOnDays;
|
||||||
|
// 发言未被攻击累计次数
|
||||||
|
int speakCount;
|
||||||
|
// 铜钱数量
|
||||||
|
int copperCoin;
|
||||||
|
public:
|
||||||
|
// Generate ctors and dtors
|
||||||
|
// assignment operators
|
||||||
|
Person() = default;
|
||||||
|
explicit Person(MiraiCP::QQID id);
|
||||||
|
|
||||||
|
// Deserialize from JSON
|
||||||
|
explicit Person(const nlohmann::json&);
|
||||||
|
~Person() = default;
|
||||||
|
Person(const Person&) = default;
|
||||||
|
Person& operator=(const Person&) = default;
|
||||||
|
Person(Person&&) = default;
|
||||||
|
Person& operator=(Person&&) = default;
|
||||||
|
|
||||||
|
[[nodiscard]] bool isSignOnToday() const;
|
||||||
|
void signOn();
|
||||||
|
[[nodiscard]] int continuousSignOnDays() const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool willBeAttackNextTime() const;
|
||||||
|
void resetAttackCount();
|
||||||
|
void increaseSpeakCount();
|
||||||
|
|
||||||
|
[[nodiscard]] int getCopperCoin() const;
|
||||||
|
nlohmann::json serializeToJSON();
|
||||||
|
|
||||||
|
[[nodiscard]] MiraiCP::QQID getQQID() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //PERSON_DEMO_PERSON_H
|
|
@ -0,0 +1,113 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Lucas' Bot.
|
||||||
|
*
|
||||||
|
* Lucas' Bot is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
|
||||||
|
Lucas' Bot is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along
|
||||||
|
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "PersonCollection.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
|
||||||
|
std::string localFilePath;
|
||||||
|
|
||||||
|
namespace PersonCollection {
|
||||||
|
|
||||||
|
std::unordered_map<MiraiCP::QQID, Person> personMap;
|
||||||
|
std::mutex personMapMutex;
|
||||||
|
bool initialized = false;
|
||||||
|
|
||||||
|
[[noreturn]]
|
||||||
|
void savePersonMapPeriodicallyWorker(const std::string &path);
|
||||||
|
|
||||||
|
// Refactoring:
|
||||||
|
// loadPersonMap and savePersonMap are now using
|
||||||
|
// globally defined localFilePath
|
||||||
|
void loadPersonMap() {
|
||||||
|
// If localFilePath is not defined
|
||||||
|
if (initialized || localFilePath.empty() || !std::filesystem::exists(localFilePath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::ifstream ifs(localFilePath);
|
||||||
|
nlohmann::json j;
|
||||||
|
// j is a json array containing person
|
||||||
|
ifs >> j;
|
||||||
|
// Lock the mutex
|
||||||
|
std::lock_guard<std::mutex> lock(personMapMutex);
|
||||||
|
for (auto &person : j) {
|
||||||
|
personMap[person["qqID"]] = Person(person);
|
||||||
|
}
|
||||||
|
// Start a thread to save the map periodically
|
||||||
|
std::thread t(savePersonMapPeriodicallyWorker, localFilePath);
|
||||||
|
t.detach();
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void savePersonMap() {
|
||||||
|
// If localFilePath is not defined
|
||||||
|
if (localFilePath.empty()) {
|
||||||
|
// Throw an exception
|
||||||
|
throw std::runtime_error("Local file path is not defined");
|
||||||
|
}
|
||||||
|
std::ofstream ofs(localFilePath);
|
||||||
|
if (!ofs.is_open()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nlohmann::json j;
|
||||||
|
{
|
||||||
|
// Lock the mutex
|
||||||
|
std::lock_guard<std::mutex> lock(personMapMutex);
|
||||||
|
for (auto &person : personMap) {
|
||||||
|
j.push_back(person.second.serializeToJSON());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ofs << j.dump(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void addPerson(MiraiCP::QQID id) {
|
||||||
|
// Lock the mutex
|
||||||
|
std::lock_guard<std::mutex> lock(personMapMutex);
|
||||||
|
personMap[id] = Person(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Person& getPerson(MiraiCP::QQID id) {
|
||||||
|
if (personMap.find(id) == personMap.end())
|
||||||
|
personMap.insert({id, Person(id)});
|
||||||
|
return personMap[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
void removePerson(MiraiCP::QQID id) {
|
||||||
|
// Lock the mutex
|
||||||
|
std::lock_guard<std::mutex> lock(personMapMutex);
|
||||||
|
personMap.erase(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void savePersonMapPeriodically(const std::string &path) {
|
||||||
|
std::thread t(savePersonMapPeriodicallyWorker, path);
|
||||||
|
t.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
void savePersonMapPeriodicallyWorker(const std::string &path) {
|
||||||
|
while (true) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::minutes(1));
|
||||||
|
savePersonMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void registerLocalFile(const std::string &path) {
|
||||||
|
localFilePath = path;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Lucas' Bot.
|
||||||
|
*
|
||||||
|
* Lucas' Bot is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
|
||||||
|
Lucas' Bot is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along
|
||||||
|
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PERSON_DEMO_PERSONCOLLECTION_H
|
||||||
|
#define PERSON_DEMO_PERSONCOLLECTION_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
#include "Person.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace PersonCollection {
|
||||||
|
void loadPersonMap();
|
||||||
|
void savePersonMap();
|
||||||
|
void addPerson(MiraiCP::QQID id);
|
||||||
|
Person& getPerson(MiraiCP::QQID id);
|
||||||
|
void removePerson(MiraiCP::QQID id);
|
||||||
|
void registerLocalFile(const std::string&);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif //PERSON_DEMO_PERSONCOLLECTION_H
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Lucas' Bot.
|
||||||
|
*
|
||||||
|
* Lucas' Bot is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
|
||||||
|
Lucas' Bot is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along
|
||||||
|
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#ifndef PERSON_DEMO_PERSON_H
|
||||||
|
#define PERSON_DEMO_PERSON_H
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
#include "json.hpp"
|
||||||
|
|
||||||
|
namespace MiraiCP {
|
||||||
|
using QQID = unsigned long long;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Person {
|
||||||
|
private:
|
||||||
|
MiraiCP::QQID qqID;
|
||||||
|
// 上次签到时间
|
||||||
|
std::time_t lastSignOnTime;
|
||||||
|
// 连续签到天数
|
||||||
|
int signOnDays;
|
||||||
|
// 发言未被攻击累计次数
|
||||||
|
int speakCount;
|
||||||
|
// 铜钱数量
|
||||||
|
int copperCoin;
|
||||||
|
public:
|
||||||
|
// Generate ctors and dtors
|
||||||
|
// assignment operators
|
||||||
|
Person() = default;
|
||||||
|
explicit Person(MiraiCP::QQID id);
|
||||||
|
|
||||||
|
// Deserialize from JSON
|
||||||
|
explicit Person(const nlohmann::json&);
|
||||||
|
~Person() = default;
|
||||||
|
Person(const Person&) = default;
|
||||||
|
Person& operator=(const Person&) = default;
|
||||||
|
Person(Person&&) = default;
|
||||||
|
Person& operator=(Person&&) = default;
|
||||||
|
|
||||||
|
[[nodiscard]] bool isSignOnToday() const;
|
||||||
|
void signOn();
|
||||||
|
[[nodiscard]] int continuousSignOnDays() const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool willBeAttackNextTime() const;
|
||||||
|
void resetAttackCount();
|
||||||
|
void increaseSpeakCount();
|
||||||
|
|
||||||
|
[[nodiscard]] int getCopperCoin() const;
|
||||||
|
nlohmann::json serializeToJSON();
|
||||||
|
|
||||||
|
[[nodiscard]] MiraiCP::QQID getQQID() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //PERSON_DEMO_PERSON_H
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Lucas' Bot.
|
||||||
|
*
|
||||||
|
* Lucas' Bot is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
|
||||||
|
Lucas' Bot is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along
|
||||||
|
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PERSON_DEMO_PERSONCOLLECTION_H
|
||||||
|
#define PERSON_DEMO_PERSONCOLLECTION_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
#include "Person.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace PersonCollection {
|
||||||
|
void loadPersonMap();
|
||||||
|
void savePersonMap();
|
||||||
|
void addPerson(MiraiCP::QQID id);
|
||||||
|
Person& getPerson(MiraiCP::QQID id);
|
||||||
|
void removePerson(MiraiCP::QQID id);
|
||||||
|
void registerLocalFile(const std::string&);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif //PERSON_DEMO_PERSONCOLLECTION_H
|
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Lucas' Bot.
|
||||||
|
*
|
||||||
|
* Lucas' Bot is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
|
||||||
|
Lucas' Bot is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along
|
||||||
|
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MIRAICPPLUGIN_RANDOM_LIBRARY_H
|
||||||
|
#define MIRAICPPLUGIN_RANDOM_LIBRARY_H
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace RandomLibrary {
|
||||||
|
|
||||||
|
std::default_random_engine e;
|
||||||
|
|
||||||
|
void initialize() {
|
||||||
|
static bool initialized = false;
|
||||||
|
if (initialized)
|
||||||
|
return;
|
||||||
|
e.seed(std::random_device{}());
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class RandomNumberType {
|
||||||
|
UniformDistribution,
|
||||||
|
NormalDistribution
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename TNum>
|
||||||
|
TNum getNextRandomNumber(RandomNumberType type, TNum lowerBound, TNum upperBound) {
|
||||||
|
static_assert(std::is_arithmetic_v<TNum>, "非算术类型不可用作本函数的参数!");
|
||||||
|
initialize();
|
||||||
|
if constexpr (std::is_integral_v<TNum>) {
|
||||||
|
std::uniform_int_distribution<TNum> u(lowerBound, upperBound);
|
||||||
|
return u(e);
|
||||||
|
} else {
|
||||||
|
if (type == RandomNumberType::UniformDistribution) {
|
||||||
|
std::uniform_real_distribution<TNum> u(lowerBound, upperBound);
|
||||||
|
return u(e);
|
||||||
|
} else {
|
||||||
|
std::normal_distribution<TNum> n(lowerBound, upperBound);
|
||||||
|
return n(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getNextBoolean(double probability) {
|
||||||
|
initialize();
|
||||||
|
std::bernoulli_distribution b(probability);
|
||||||
|
return b(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //MIRAICPPLUGIN_RANDOM_LIBRARY_H
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,79 @@
|
||||||
|
#ifndef CURLINC_CURLVER_H
|
||||||
|
#define CURLINC_CURLVER_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/* This header file contains nothing but libcurl version info, generated by
|
||||||
|
a script at release-time. This was made its own header file in 7.11.2 */
|
||||||
|
|
||||||
|
/* This is the global package copyright */
|
||||||
|
#define LIBCURL_COPYRIGHT "1996 - 2022 Daniel Stenberg, <daniel@haxx.se>."
|
||||||
|
|
||||||
|
/* This is the version number of the libcurl package from which this header
|
||||||
|
file origins: */
|
||||||
|
#define LIBCURL_VERSION "7.85.0"
|
||||||
|
|
||||||
|
/* The numeric version number is also available "in parts" by using these
|
||||||
|
defines: */
|
||||||
|
#define LIBCURL_VERSION_MAJOR 7
|
||||||
|
#define LIBCURL_VERSION_MINOR 85
|
||||||
|
#define LIBCURL_VERSION_PATCH 0
|
||||||
|
|
||||||
|
/* This is the numeric version of the libcurl version number, meant for easier
|
||||||
|
parsing and comparisons by programs. The LIBCURL_VERSION_NUM define will
|
||||||
|
always follow this syntax:
|
||||||
|
|
||||||
|
0xXXYYZZ
|
||||||
|
|
||||||
|
Where XX, YY and ZZ are the main version, release and patch numbers in
|
||||||
|
hexadecimal (using 8 bits each). All three numbers are always represented
|
||||||
|
using two digits. 1.2 would appear as "0x010200" while version 9.11.7
|
||||||
|
appears as "0x090b07".
|
||||||
|
|
||||||
|
This 6-digit (24 bits) hexadecimal number does not show pre-release number,
|
||||||
|
and it is always a greater number in a more recent release. It makes
|
||||||
|
comparisons with greater than and less than work.
|
||||||
|
|
||||||
|
Note: This define is the full hex number and _does not_ use the
|
||||||
|
CURL_VERSION_BITS() macro since curl's own configure script greps for it
|
||||||
|
and needs it to contain the full number.
|
||||||
|
*/
|
||||||
|
#define LIBCURL_VERSION_NUM 0x075500
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the date and time when the full source package was created. The
|
||||||
|
* timestamp is not stored in git, as the timestamp is properly set in the
|
||||||
|
* tarballs by the maketgz script.
|
||||||
|
*
|
||||||
|
* The format of the date follows this template:
|
||||||
|
*
|
||||||
|
* "2007-11-23"
|
||||||
|
*/
|
||||||
|
#define LIBCURL_TIMESTAMP "2022-08-31"
|
||||||
|
|
||||||
|
#define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|(z))
|
||||||
|
#define CURL_AT_LEAST_VERSION(x,y,z) \
|
||||||
|
(LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(x, y, z))
|
||||||
|
|
||||||
|
#endif /* CURLINC_CURLVER_H */
|
|
@ -0,0 +1,125 @@
|
||||||
|
#ifndef CURLINC_EASY_H
|
||||||
|
#define CURLINC_EASY_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Flag bits in the curl_blob struct: */
|
||||||
|
#define CURL_BLOB_COPY 1 /* tell libcurl to copy the data */
|
||||||
|
#define CURL_BLOB_NOCOPY 0 /* tell libcurl to NOT copy the data */
|
||||||
|
|
||||||
|
struct curl_blob {
|
||||||
|
void *data;
|
||||||
|
size_t len;
|
||||||
|
unsigned int flags; /* bit 0 is defined, the rest are reserved and should be
|
||||||
|
left zeroes */
|
||||||
|
};
|
||||||
|
|
||||||
|
CURL_EXTERN CURL *curl_easy_init(void);
|
||||||
|
CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...);
|
||||||
|
CURL_EXTERN CURLcode curl_easy_perform(CURL *curl);
|
||||||
|
CURL_EXTERN void curl_easy_cleanup(CURL *curl);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NAME curl_easy_getinfo()
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
*
|
||||||
|
* Request internal information from the curl session with this function. The
|
||||||
|
* third argument MUST be a pointer to a long, a pointer to a char * or a
|
||||||
|
* pointer to a double (as the documentation describes elsewhere). The data
|
||||||
|
* pointed to will be filled in accordingly and can be relied upon only if the
|
||||||
|
* function returns CURLE_OK. This function is intended to get used *AFTER* a
|
||||||
|
* performed transfer, all results from this function are undefined until the
|
||||||
|
* transfer is completed.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NAME curl_easy_duphandle()
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
*
|
||||||
|
* Creates a new curl session handle with the same options set for the handle
|
||||||
|
* passed in. Duplicating a handle could only be a matter of cloning data and
|
||||||
|
* options, internal state info and things like persistent connections cannot
|
||||||
|
* be transferred. It is useful in multithreaded applications when you can run
|
||||||
|
* curl_easy_duphandle() for each new thread to avoid a series of identical
|
||||||
|
* curl_easy_setopt() invokes in every thread.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURL *curl_easy_duphandle(CURL *curl);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NAME curl_easy_reset()
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
*
|
||||||
|
* Re-initializes a CURL handle to the default values. This puts back the
|
||||||
|
* handle to the same state as it was in when it was just created.
|
||||||
|
*
|
||||||
|
* It does keep: live connections, the Session ID cache, the DNS cache and the
|
||||||
|
* cookies.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN void curl_easy_reset(CURL *curl);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NAME curl_easy_recv()
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
*
|
||||||
|
* Receives data from the connected socket. Use after successful
|
||||||
|
* curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen,
|
||||||
|
size_t *n);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NAME curl_easy_send()
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
*
|
||||||
|
* Sends data over the connected socket. Use after successful
|
||||||
|
* curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer,
|
||||||
|
size_t buflen, size_t *n);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NAME curl_easy_upkeep()
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
*
|
||||||
|
* Performs connection upkeep for the given session handle.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLcode curl_easy_upkeep(CURL *curl);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,66 @@
|
||||||
|
#ifndef CURLINC_HEADER_H
|
||||||
|
#define CURLINC_HEADER_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
struct curl_header {
|
||||||
|
char *name; /* this might not use the same case */
|
||||||
|
char *value;
|
||||||
|
size_t amount; /* number of headers using this name */
|
||||||
|
size_t index; /* ... of this instance, 0 or higher */
|
||||||
|
unsigned int origin; /* see bits below */
|
||||||
|
void *anchor; /* handle privately used by libcurl */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* 'origin' bits */
|
||||||
|
#define CURLH_HEADER (1<<0) /* plain server header */
|
||||||
|
#define CURLH_TRAILER (1<<1) /* trailers */
|
||||||
|
#define CURLH_CONNECT (1<<2) /* CONNECT headers */
|
||||||
|
#define CURLH_1XX (1<<3) /* 1xx headers */
|
||||||
|
#define CURLH_PSEUDO (1<<4) /* pseudo headers */
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CURLHE_OK,
|
||||||
|
CURLHE_BADINDEX, /* header exists but not with this index */
|
||||||
|
CURLHE_MISSING, /* no such header exists */
|
||||||
|
CURLHE_NOHEADERS, /* no headers at all exist (yet) */
|
||||||
|
CURLHE_NOREQUEST, /* no request with this number was used */
|
||||||
|
CURLHE_OUT_OF_MEMORY, /* out of memory while processing */
|
||||||
|
CURLHE_BAD_ARGUMENT, /* a function argument was not okay */
|
||||||
|
CURLHE_NOT_BUILT_IN /* if API was disabled in the build */
|
||||||
|
} CURLHcode;
|
||||||
|
|
||||||
|
CURL_EXTERN CURLHcode curl_easy_header(CURL *easy,
|
||||||
|
const char *name,
|
||||||
|
size_t index,
|
||||||
|
unsigned int origin,
|
||||||
|
int request,
|
||||||
|
struct curl_header **hout);
|
||||||
|
|
||||||
|
CURL_EXTERN struct curl_header *curl_easy_nextheader(CURL *easy,
|
||||||
|
unsigned int origin,
|
||||||
|
int request,
|
||||||
|
struct curl_header *prev);
|
||||||
|
|
||||||
|
#endif /* CURLINC_HEADER_H */
|
|
@ -0,0 +1,52 @@
|
||||||
|
#ifndef CURLINC_MPRINTF_H
|
||||||
|
#define CURLINC_MPRINTF_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h> /* needed for FILE */
|
||||||
|
#include "curl.h" /* for CURL_EXTERN */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CURL_EXTERN int curl_mprintf(const char *format, ...);
|
||||||
|
CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...);
|
||||||
|
CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...);
|
||||||
|
CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength,
|
||||||
|
const char *format, ...);
|
||||||
|
CURL_EXTERN int curl_mvprintf(const char *format, va_list args);
|
||||||
|
CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args);
|
||||||
|
CURL_EXTERN int curl_mvsprintf(char *buffer, const char *format, va_list args);
|
||||||
|
CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength,
|
||||||
|
const char *format, va_list args);
|
||||||
|
CURL_EXTERN char *curl_maprintf(const char *format, ...);
|
||||||
|
CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CURLINC_MPRINTF_H */
|
|
@ -0,0 +1,460 @@
|
||||||
|
#ifndef CURLINC_MULTI_H
|
||||||
|
#define CURLINC_MULTI_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
/*
|
||||||
|
This is an "external" header file. Don't give away any internals here!
|
||||||
|
|
||||||
|
GOALS
|
||||||
|
|
||||||
|
o Enable a "pull" interface. The application that uses libcurl decides where
|
||||||
|
and when to ask libcurl to get/send data.
|
||||||
|
|
||||||
|
o Enable multiple simultaneous transfers in the same thread without making it
|
||||||
|
complicated for the application.
|
||||||
|
|
||||||
|
o Enable the application to select() on its own file descriptors and curl's
|
||||||
|
file descriptors simultaneous easily.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This header file should not really need to include "curl.h" since curl.h
|
||||||
|
* itself includes this file and we expect user applications to do #include
|
||||||
|
* <curl/curl.h> without the need for especially including multi.h.
|
||||||
|
*
|
||||||
|
* For some reason we added this include here at one point, and rather than to
|
||||||
|
* break existing (wrongly written) libcurl applications, we leave it as-is
|
||||||
|
* but with this warning attached.
|
||||||
|
*/
|
||||||
|
#include "curl.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(BUILDING_LIBCURL) || defined(CURL_STRICTER)
|
||||||
|
typedef struct Curl_multi CURLM;
|
||||||
|
#else
|
||||||
|
typedef void CURLM;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or
|
||||||
|
curl_multi_socket*() soon */
|
||||||
|
CURLM_OK,
|
||||||
|
CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */
|
||||||
|
CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */
|
||||||
|
CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */
|
||||||
|
CURLM_INTERNAL_ERROR, /* this is a libcurl bug */
|
||||||
|
CURLM_BAD_SOCKET, /* the passed in socket argument did not match */
|
||||||
|
CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */
|
||||||
|
CURLM_ADDED_ALREADY, /* an easy handle already added to a multi handle was
|
||||||
|
attempted to get added - again */
|
||||||
|
CURLM_RECURSIVE_API_CALL, /* an api function was called from inside a
|
||||||
|
callback */
|
||||||
|
CURLM_WAKEUP_FAILURE, /* wakeup is unavailable or failed */
|
||||||
|
CURLM_BAD_FUNCTION_ARGUMENT, /* function called with a bad parameter */
|
||||||
|
CURLM_ABORTED_BY_CALLBACK,
|
||||||
|
CURLM_UNRECOVERABLE_POLL,
|
||||||
|
CURLM_LAST
|
||||||
|
} CURLMcode;
|
||||||
|
|
||||||
|
/* just to make code nicer when using curl_multi_socket() you can now check
|
||||||
|
for CURLM_CALL_MULTI_SOCKET too in the same style it works for
|
||||||
|
curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */
|
||||||
|
#define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM
|
||||||
|
|
||||||
|
/* bitmask bits for CURLMOPT_PIPELINING */
|
||||||
|
#define CURLPIPE_NOTHING 0L
|
||||||
|
#define CURLPIPE_HTTP1 1L
|
||||||
|
#define CURLPIPE_MULTIPLEX 2L
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CURLMSG_NONE, /* first, not used */
|
||||||
|
CURLMSG_DONE, /* This easy handle has completed. 'result' contains
|
||||||
|
the CURLcode of the transfer */
|
||||||
|
CURLMSG_LAST /* last, not used */
|
||||||
|
} CURLMSG;
|
||||||
|
|
||||||
|
struct CURLMsg {
|
||||||
|
CURLMSG msg; /* what this message means */
|
||||||
|
CURL *easy_handle; /* the handle it concerns */
|
||||||
|
union {
|
||||||
|
void *whatever; /* message-specific data */
|
||||||
|
CURLcode result; /* return code for transfer */
|
||||||
|
} data;
|
||||||
|
};
|
||||||
|
typedef struct CURLMsg CURLMsg;
|
||||||
|
|
||||||
|
/* Based on poll(2) structure and values.
|
||||||
|
* We don't use pollfd and POLL* constants explicitly
|
||||||
|
* to cover platforms without poll(). */
|
||||||
|
#define CURL_WAIT_POLLIN 0x0001
|
||||||
|
#define CURL_WAIT_POLLPRI 0x0002
|
||||||
|
#define CURL_WAIT_POLLOUT 0x0004
|
||||||
|
|
||||||
|
struct curl_waitfd {
|
||||||
|
curl_socket_t fd;
|
||||||
|
short events;
|
||||||
|
short revents; /* not supported yet */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_init()
|
||||||
|
*
|
||||||
|
* Desc: inititalize multi-style curl usage
|
||||||
|
*
|
||||||
|
* Returns: a new CURLM handle to use in all 'curl_multi' functions.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLM *curl_multi_init(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_add_handle()
|
||||||
|
*
|
||||||
|
* Desc: add a standard curl handle to the multi stack
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle,
|
||||||
|
CURL *curl_handle);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_remove_handle()
|
||||||
|
*
|
||||||
|
* Desc: removes a curl handle from the multi stack again
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
|
||||||
|
CURL *curl_handle);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_fdset()
|
||||||
|
*
|
||||||
|
* Desc: Ask curl for its fd_set sets. The app can use these to select() or
|
||||||
|
* poll() on. We want curl_multi_perform() called as soon as one of
|
||||||
|
* them are ready.
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle,
|
||||||
|
fd_set *read_fd_set,
|
||||||
|
fd_set *write_fd_set,
|
||||||
|
fd_set *exc_fd_set,
|
||||||
|
int *max_fd);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_wait()
|
||||||
|
*
|
||||||
|
* Desc: Poll on all fds within a CURLM set as well as any
|
||||||
|
* additional fds passed to the function.
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle,
|
||||||
|
struct curl_waitfd extra_fds[],
|
||||||
|
unsigned int extra_nfds,
|
||||||
|
int timeout_ms,
|
||||||
|
int *ret);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_poll()
|
||||||
|
*
|
||||||
|
* Desc: Poll on all fds within a CURLM set as well as any
|
||||||
|
* additional fds passed to the function.
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_poll(CURLM *multi_handle,
|
||||||
|
struct curl_waitfd extra_fds[],
|
||||||
|
unsigned int extra_nfds,
|
||||||
|
int timeout_ms,
|
||||||
|
int *ret);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_wakeup()
|
||||||
|
*
|
||||||
|
* Desc: wakes up a sleeping curl_multi_poll call.
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_wakeup(CURLM *multi_handle);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_perform()
|
||||||
|
*
|
||||||
|
* Desc: When the app thinks there's data available for curl it calls this
|
||||||
|
* function to read/write whatever there is right now. This returns
|
||||||
|
* as soon as the reads and writes are done. This function does not
|
||||||
|
* require that there actually is data available for reading or that
|
||||||
|
* data can be written, it can be called just in case. It returns
|
||||||
|
* the number of handles that still transfer data in the second
|
||||||
|
* argument's integer-pointer.
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code. *NOTE* that this only
|
||||||
|
* returns errors etc regarding the whole multi stack. There might
|
||||||
|
* still have occurred problems on individual transfers even when
|
||||||
|
* this returns OK.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle,
|
||||||
|
int *running_handles);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_cleanup()
|
||||||
|
*
|
||||||
|
* Desc: Cleans up and removes a whole multi stack. It does not free or
|
||||||
|
* touch any individual easy handles in any way. We need to define
|
||||||
|
* in what state those handles will be if this function is called
|
||||||
|
* in the middle of a transfer.
|
||||||
|
*
|
||||||
|
* Returns: CURLMcode type, general multi error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_info_read()
|
||||||
|
*
|
||||||
|
* Desc: Ask the multi handle if there's any messages/informationals from
|
||||||
|
* the individual transfers. Messages include informationals such as
|
||||||
|
* error code from the transfer or just the fact that a transfer is
|
||||||
|
* completed. More details on these should be written down as well.
|
||||||
|
*
|
||||||
|
* Repeated calls to this function will return a new struct each
|
||||||
|
* time, until a special "end of msgs" struct is returned as a signal
|
||||||
|
* that there is no more to get at this point.
|
||||||
|
*
|
||||||
|
* The data the returned pointer points to will not survive calling
|
||||||
|
* curl_multi_cleanup().
|
||||||
|
*
|
||||||
|
* The 'CURLMsg' struct is meant to be very simple and only contain
|
||||||
|
* very basic information. If more involved information is wanted,
|
||||||
|
* we will provide the particular "transfer handle" in that struct
|
||||||
|
* and that should/could/would be used in subsequent
|
||||||
|
* curl_easy_getinfo() calls (or similar). The point being that we
|
||||||
|
* must never expose complex structs to applications, as then we'll
|
||||||
|
* undoubtably get backwards compatibility problems in the future.
|
||||||
|
*
|
||||||
|
* Returns: A pointer to a filled-in struct, or NULL if it failed or ran out
|
||||||
|
* of structs. It also writes the number of messages left in the
|
||||||
|
* queue (after this read) in the integer the second argument points
|
||||||
|
* to.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle,
|
||||||
|
int *msgs_in_queue);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_strerror()
|
||||||
|
*
|
||||||
|
* Desc: The curl_multi_strerror function may be used to turn a CURLMcode
|
||||||
|
* value into the equivalent human readable error string. This is
|
||||||
|
* useful for printing meaningful error messages.
|
||||||
|
*
|
||||||
|
* Returns: A pointer to a null-terminated error message.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN const char *curl_multi_strerror(CURLMcode);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_socket() and
|
||||||
|
* curl_multi_socket_all()
|
||||||
|
*
|
||||||
|
* Desc: An alternative version of curl_multi_perform() that allows the
|
||||||
|
* application to pass in one of the file descriptors that have been
|
||||||
|
* detected to have "action" on them and let libcurl perform.
|
||||||
|
* See man page for details.
|
||||||
|
*/
|
||||||
|
#define CURL_POLL_NONE 0
|
||||||
|
#define CURL_POLL_IN 1
|
||||||
|
#define CURL_POLL_OUT 2
|
||||||
|
#define CURL_POLL_INOUT 3
|
||||||
|
#define CURL_POLL_REMOVE 4
|
||||||
|
|
||||||
|
#define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD
|
||||||
|
|
||||||
|
#define CURL_CSELECT_IN 0x01
|
||||||
|
#define CURL_CSELECT_OUT 0x02
|
||||||
|
#define CURL_CSELECT_ERR 0x04
|
||||||
|
|
||||||
|
typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */
|
||||||
|
curl_socket_t s, /* socket */
|
||||||
|
int what, /* see above */
|
||||||
|
void *userp, /* private callback
|
||||||
|
pointer */
|
||||||
|
void *socketp); /* private socket
|
||||||
|
pointer */
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_timer_callback
|
||||||
|
*
|
||||||
|
* Desc: Called by libcurl whenever the library detects a change in the
|
||||||
|
* maximum number of milliseconds the app is allowed to wait before
|
||||||
|
* curl_multi_socket() or curl_multi_perform() must be called
|
||||||
|
* (to allow libcurl's timed events to take place).
|
||||||
|
*
|
||||||
|
* Returns: The callback should return zero.
|
||||||
|
*/
|
||||||
|
typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */
|
||||||
|
long timeout_ms, /* see above */
|
||||||
|
void *userp); /* private callback
|
||||||
|
pointer */
|
||||||
|
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s,
|
||||||
|
int *running_handles);
|
||||||
|
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle,
|
||||||
|
curl_socket_t s,
|
||||||
|
int ev_bitmask,
|
||||||
|
int *running_handles);
|
||||||
|
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle,
|
||||||
|
int *running_handles);
|
||||||
|
|
||||||
|
#ifndef CURL_ALLOW_OLD_MULTI_SOCKET
|
||||||
|
/* This macro below was added in 7.16.3 to push users who recompile to use
|
||||||
|
the new curl_multi_socket_action() instead of the old curl_multi_socket()
|
||||||
|
*/
|
||||||
|
#define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_timeout()
|
||||||
|
*
|
||||||
|
* Desc: Returns the maximum number of milliseconds the app is allowed to
|
||||||
|
* wait before curl_multi_socket() or curl_multi_perform() must be
|
||||||
|
* called (to allow libcurl's timed events to take place).
|
||||||
|
*
|
||||||
|
* Returns: CURLM error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle,
|
||||||
|
long *milliseconds);
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
/* This is the socket callback function pointer */
|
||||||
|
CURLOPT(CURLMOPT_SOCKETFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 1),
|
||||||
|
|
||||||
|
/* This is the argument passed to the socket callback */
|
||||||
|
CURLOPT(CURLMOPT_SOCKETDATA, CURLOPTTYPE_OBJECTPOINT, 2),
|
||||||
|
|
||||||
|
/* set to 1 to enable pipelining for this multi handle */
|
||||||
|
CURLOPT(CURLMOPT_PIPELINING, CURLOPTTYPE_LONG, 3),
|
||||||
|
|
||||||
|
/* This is the timer callback function pointer */
|
||||||
|
CURLOPT(CURLMOPT_TIMERFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 4),
|
||||||
|
|
||||||
|
/* This is the argument passed to the timer callback */
|
||||||
|
CURLOPT(CURLMOPT_TIMERDATA, CURLOPTTYPE_OBJECTPOINT, 5),
|
||||||
|
|
||||||
|
/* maximum number of entries in the connection cache */
|
||||||
|
CURLOPT(CURLMOPT_MAXCONNECTS, CURLOPTTYPE_LONG, 6),
|
||||||
|
|
||||||
|
/* maximum number of (pipelining) connections to one host */
|
||||||
|
CURLOPT(CURLMOPT_MAX_HOST_CONNECTIONS, CURLOPTTYPE_LONG, 7),
|
||||||
|
|
||||||
|
/* maximum number of requests in a pipeline */
|
||||||
|
CURLOPT(CURLMOPT_MAX_PIPELINE_LENGTH, CURLOPTTYPE_LONG, 8),
|
||||||
|
|
||||||
|
/* a connection with a content-length longer than this
|
||||||
|
will not be considered for pipelining */
|
||||||
|
CURLOPT(CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 9),
|
||||||
|
|
||||||
|
/* a connection with a chunk length longer than this
|
||||||
|
will not be considered for pipelining */
|
||||||
|
CURLOPT(CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 10),
|
||||||
|
|
||||||
|
/* a list of site names(+port) that are blocked from pipelining */
|
||||||
|
CURLOPT(CURLMOPT_PIPELINING_SITE_BL, CURLOPTTYPE_OBJECTPOINT, 11),
|
||||||
|
|
||||||
|
/* a list of server types that are blocked from pipelining */
|
||||||
|
CURLOPT(CURLMOPT_PIPELINING_SERVER_BL, CURLOPTTYPE_OBJECTPOINT, 12),
|
||||||
|
|
||||||
|
/* maximum number of open connections in total */
|
||||||
|
CURLOPT(CURLMOPT_MAX_TOTAL_CONNECTIONS, CURLOPTTYPE_LONG, 13),
|
||||||
|
|
||||||
|
/* This is the server push callback function pointer */
|
||||||
|
CURLOPT(CURLMOPT_PUSHFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 14),
|
||||||
|
|
||||||
|
/* This is the argument passed to the server push callback */
|
||||||
|
CURLOPT(CURLMOPT_PUSHDATA, CURLOPTTYPE_OBJECTPOINT, 15),
|
||||||
|
|
||||||
|
/* maximum number of concurrent streams to support on a connection */
|
||||||
|
CURLOPT(CURLMOPT_MAX_CONCURRENT_STREAMS, CURLOPTTYPE_LONG, 16),
|
||||||
|
|
||||||
|
CURLMOPT_LASTENTRY /* the last unused */
|
||||||
|
} CURLMoption;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_setopt()
|
||||||
|
*
|
||||||
|
* Desc: Sets options for the multi handle.
|
||||||
|
*
|
||||||
|
* Returns: CURLM error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle,
|
||||||
|
CURLMoption option, ...);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_multi_assign()
|
||||||
|
*
|
||||||
|
* Desc: This function sets an association in the multi handle between the
|
||||||
|
* given socket and a private pointer of the application. This is
|
||||||
|
* (only) useful for curl_multi_socket uses.
|
||||||
|
*
|
||||||
|
* Returns: CURLM error code.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle,
|
||||||
|
curl_socket_t sockfd, void *sockp);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: curl_push_callback
|
||||||
|
*
|
||||||
|
* Desc: This callback gets called when a new stream is being pushed by the
|
||||||
|
* server. It approves or denies the new stream. It can also decide
|
||||||
|
* to completely fail the connection.
|
||||||
|
*
|
||||||
|
* Returns: CURL_PUSH_OK, CURL_PUSH_DENY or CURL_PUSH_ERROROUT
|
||||||
|
*/
|
||||||
|
#define CURL_PUSH_OK 0
|
||||||
|
#define CURL_PUSH_DENY 1
|
||||||
|
#define CURL_PUSH_ERROROUT 2 /* added in 7.72.0 */
|
||||||
|
|
||||||
|
struct curl_pushheaders; /* forward declaration only */
|
||||||
|
|
||||||
|
CURL_EXTERN char *curl_pushheader_bynum(struct curl_pushheaders *h,
|
||||||
|
size_t num);
|
||||||
|
CURL_EXTERN char *curl_pushheader_byname(struct curl_pushheaders *h,
|
||||||
|
const char *name);
|
||||||
|
|
||||||
|
typedef int (*curl_push_callback)(CURL *parent,
|
||||||
|
CURL *easy,
|
||||||
|
size_t num_headers,
|
||||||
|
struct curl_pushheaders *headers,
|
||||||
|
void *userp);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* end of extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,70 @@
|
||||||
|
#ifndef CURLINC_OPTIONS_H
|
||||||
|
#define CURLINC_OPTIONS_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CURLOT_LONG, /* long (a range of values) */
|
||||||
|
CURLOT_VALUES, /* (a defined set or bitmask) */
|
||||||
|
CURLOT_OFF_T, /* curl_off_t (a range of values) */
|
||||||
|
CURLOT_OBJECT, /* pointer (void *) */
|
||||||
|
CURLOT_STRING, /* (char * to zero terminated buffer) */
|
||||||
|
CURLOT_SLIST, /* (struct curl_slist *) */
|
||||||
|
CURLOT_CBPTR, /* (void * passed as-is to a callback) */
|
||||||
|
CURLOT_BLOB, /* blob (struct curl_blob *) */
|
||||||
|
CURLOT_FUNCTION /* function pointer */
|
||||||
|
} curl_easytype;
|
||||||
|
|
||||||
|
/* Flag bits */
|
||||||
|
|
||||||
|
/* "alias" means it is provided for old programs to remain functional,
|
||||||
|
we prefer another name */
|
||||||
|
#define CURLOT_FLAG_ALIAS (1<<0)
|
||||||
|
|
||||||
|
/* The CURLOPTTYPE_* id ranges can still be used to figure out what type/size
|
||||||
|
to use for curl_easy_setopt() for the given id */
|
||||||
|
struct curl_easyoption {
|
||||||
|
const char *name;
|
||||||
|
CURLoption id;
|
||||||
|
curl_easytype type;
|
||||||
|
unsigned int flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
CURL_EXTERN const struct curl_easyoption *
|
||||||
|
curl_easy_option_by_name(const char *name);
|
||||||
|
|
||||||
|
CURL_EXTERN const struct curl_easyoption *
|
||||||
|
curl_easy_option_by_id(CURLoption id);
|
||||||
|
|
||||||
|
CURL_EXTERN const struct curl_easyoption *
|
||||||
|
curl_easy_option_next(const struct curl_easyoption *prev);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* end of extern "C" */
|
||||||
|
#endif
|
||||||
|
#endif /* CURLINC_OPTIONS_H */
|
|
@ -0,0 +1,35 @@
|
||||||
|
#ifndef CURLINC_STDCHEADERS_H
|
||||||
|
#define CURLINC_STDCHEADERS_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
size_t fread(void *, size_t, size_t, FILE *);
|
||||||
|
size_t fwrite(const void *, size_t, size_t, FILE *);
|
||||||
|
|
||||||
|
int strcasecmp(const char *, const char *);
|
||||||
|
int strncasecmp(const char *, const char *, size_t);
|
||||||
|
|
||||||
|
#endif /* CURLINC_STDCHEADERS_H */
|
|
@ -0,0 +1,490 @@
|
||||||
|
#ifndef CURLINC_SYSTEM_H
|
||||||
|
#define CURLINC_SYSTEM_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try to keep one section per platform, compiler and architecture, otherwise,
|
||||||
|
* if an existing section is reused for a different one and later on the
|
||||||
|
* original is adjusted, probably the piggybacking one can be adversely
|
||||||
|
* changed.
|
||||||
|
*
|
||||||
|
* In order to differentiate between platforms/compilers/architectures use
|
||||||
|
* only compiler built in predefined preprocessor symbols.
|
||||||
|
*
|
||||||
|
* curl_off_t
|
||||||
|
* ----------
|
||||||
|
*
|
||||||
|
* For any given platform/compiler curl_off_t must be typedef'ed to a 64-bit
|
||||||
|
* wide signed integral data type. The width of this data type must remain
|
||||||
|
* constant and independent of any possible large file support settings.
|
||||||
|
*
|
||||||
|
* As an exception to the above, curl_off_t shall be typedef'ed to a 32-bit
|
||||||
|
* wide signed integral data type if there is no 64-bit type.
|
||||||
|
*
|
||||||
|
* As a general rule, curl_off_t shall not be mapped to off_t. This rule shall
|
||||||
|
* only be violated if off_t is the only 64-bit data type available and the
|
||||||
|
* size of off_t is independent of large file support settings. Keep your
|
||||||
|
* build on the safe side avoiding an off_t gating. If you have a 64-bit
|
||||||
|
* off_t then take for sure that another 64-bit data type exists, dig deeper
|
||||||
|
* and you will find it.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(__DJGPP__) || defined(__GO32__)
|
||||||
|
# if defined(__DJGPP__) && (__DJGPP__ > 1)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(__SALFORDC__)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(__BORLANDC__)
|
||||||
|
# if (__BORLANDC__ < 0x520)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T __int64
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "I64d"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "I64u"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T i64
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ui64
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(__TURBOC__)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(__POCC__)
|
||||||
|
# if (__POCC__ < 280)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# elif defined(_MSC_VER)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T __int64
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "I64d"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "I64u"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T i64
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ui64
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(__LCC__)
|
||||||
|
# if defined(__MCST__) /* MCST eLbrus Compiler Collection */
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
# else /* Local (or Little) C Compiler */
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#elif defined(__SYMBIAN32__)
|
||||||
|
# if defined(__EABI__) /* Treat all ARM compilers equally */
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# elif defined(__CW32__)
|
||||||
|
# pragma longlong on
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# elif defined(__VC32__)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T __int64
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int
|
||||||
|
|
||||||
|
#elif defined(__MWERKS__)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(_WIN32_WCE)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T __int64
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "I64d"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "I64u"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T i64
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ui64
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(__MINGW32__)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "I64d"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "I64u"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_WS2TCPIP_H 1
|
||||||
|
|
||||||
|
#elif defined(__VMS)
|
||||||
|
# if defined(__VAX)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int
|
||||||
|
|
||||||
|
#elif defined(__OS400__)
|
||||||
|
# if defined(__ILEC400__)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#elif defined(__MVS__)
|
||||||
|
# if defined(__IBMC__) || defined(__IBMCPP__)
|
||||||
|
# if defined(_ILP32)
|
||||||
|
# elif defined(_LP64)
|
||||||
|
# endif
|
||||||
|
# if defined(_LONG_LONG)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# elif defined(_LP64)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#elif defined(__370__)
|
||||||
|
# if defined(__IBMC__) || defined(__IBMCPP__)
|
||||||
|
# if defined(_ILP32)
|
||||||
|
# elif defined(_LP64)
|
||||||
|
# endif
|
||||||
|
# if defined(_LONG_LONG)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# elif defined(_LP64)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#elif defined(TPF)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
#elif defined(__TINYC__) /* also known as tcc */
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
|
||||||
|
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* Oracle Solaris Studio */
|
||||||
|
# if !defined(__LP64) && (defined(__ILP32) || \
|
||||||
|
defined(__i386) || \
|
||||||
|
defined(__sparcv8) || \
|
||||||
|
defined(__sparcv8plus))
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# elif defined(__LP64) || \
|
||||||
|
defined(__amd64) || defined(__sparcv9)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
|
||||||
|
#elif defined(__xlc__) /* IBM xlc compiler */
|
||||||
|
# if !defined(_LP64)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
|
||||||
|
/* ===================================== */
|
||||||
|
/* KEEP MSVC THE PENULTIMATE ENTRY */
|
||||||
|
/* ===================================== */
|
||||||
|
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
# if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T __int64
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "I64d"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "I64u"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T i64
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ui64
|
||||||
|
# else
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
|
||||||
|
/* ===================================== */
|
||||||
|
/* KEEP GENERIC GCC THE LAST ENTRY */
|
||||||
|
/* ===================================== */
|
||||||
|
|
||||||
|
#elif defined(__GNUC__) && !defined(_SCO_DS)
|
||||||
|
# if !defined(__LP64__) && \
|
||||||
|
(defined(__ILP32__) || defined(__i386__) || defined(__hppa__) || \
|
||||||
|
defined(__ppc__) || defined(__powerpc__) || defined(__arm__) || \
|
||||||
|
defined(__sparc__) || defined(__mips__) || defined(__sh__) || \
|
||||||
|
defined(__XTENSA__) || \
|
||||||
|
(defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ == 4) || \
|
||||||
|
(defined(__LONG_MAX__) && __LONG_MAX__ == 2147483647L))
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "lld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "llu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T LL
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU ULL
|
||||||
|
# elif defined(__LP64__) || \
|
||||||
|
defined(__x86_64__) || defined(__ppc64__) || defined(__sparc64__) || \
|
||||||
|
defined(__e2k__) || \
|
||||||
|
(defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ == 8) || \
|
||||||
|
(defined(__LONG_MAX__) && __LONG_MAX__ == 9223372036854775807L)
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# endif
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
|
||||||
|
# define CURL_PULL_SYS_TYPES_H 1
|
||||||
|
# define CURL_PULL_SYS_SOCKET_H 1
|
||||||
|
|
||||||
|
#else
|
||||||
|
/* generic "safe guess" on old 32 bit style */
|
||||||
|
# define CURL_TYPEOF_CURL_OFF_T long
|
||||||
|
# define CURL_FORMAT_CURL_OFF_T "ld"
|
||||||
|
# define CURL_FORMAT_CURL_OFF_TU "lu"
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_T L
|
||||||
|
# define CURL_SUFFIX_CURL_OFF_TU UL
|
||||||
|
# define CURL_TYPEOF_CURL_SOCKLEN_T int
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _AIX
|
||||||
|
/* AIX needs <sys/poll.h> */
|
||||||
|
#define CURL_PULL_SYS_POLL_H
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* CURL_PULL_WS2TCPIP_H is defined above when inclusion of header file */
|
||||||
|
/* ws2tcpip.h is required here to properly make type definitions below. */
|
||||||
|
#ifdef CURL_PULL_WS2TCPIP_H
|
||||||
|
# include <winsock2.h>
|
||||||
|
# include <windows.h>
|
||||||
|
# include <ws2tcpip.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* CURL_PULL_SYS_TYPES_H is defined above when inclusion of header file */
|
||||||
|
/* sys/types.h is required here to properly make type definitions below. */
|
||||||
|
#ifdef CURL_PULL_SYS_TYPES_H
|
||||||
|
# include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* CURL_PULL_SYS_SOCKET_H is defined above when inclusion of header file */
|
||||||
|
/* sys/socket.h is required here to properly make type definitions below. */
|
||||||
|
#ifdef CURL_PULL_SYS_SOCKET_H
|
||||||
|
# include <sys/socket.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* CURL_PULL_SYS_POLL_H is defined above when inclusion of header file */
|
||||||
|
/* sys/poll.h is required here to properly make type definitions below. */
|
||||||
|
#ifdef CURL_PULL_SYS_POLL_H
|
||||||
|
# include <sys/poll.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Data type definition of curl_socklen_t. */
|
||||||
|
#ifdef CURL_TYPEOF_CURL_SOCKLEN_T
|
||||||
|
typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Data type definition of curl_off_t. */
|
||||||
|
|
||||||
|
#ifdef CURL_TYPEOF_CURL_OFF_T
|
||||||
|
typedef CURL_TYPEOF_CURL_OFF_T curl_off_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* CURL_ISOCPP and CURL_OFF_T_C definitions are done here in order to allow
|
||||||
|
* these to be visible and exported by the external libcurl interface API,
|
||||||
|
* while also making them visible to the library internals, simply including
|
||||||
|
* curl_setup.h, without actually needing to include curl.h internally.
|
||||||
|
* If some day this section would grow big enough, all this should be moved
|
||||||
|
* to its own header file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Figure out if we can use the ## preprocessor operator, which is supported
|
||||||
|
* by ISO/ANSI C and C++. Some compilers support it without setting __STDC__
|
||||||
|
* or __cplusplus so we need to carefully check for them too.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \
|
||||||
|
defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \
|
||||||
|
defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \
|
||||||
|
defined(__ILEC400__)
|
||||||
|
/* This compiler is believed to have an ISO compatible preprocessor */
|
||||||
|
#define CURL_ISOCPP
|
||||||
|
#else
|
||||||
|
/* This compiler is believed NOT to have an ISO compatible preprocessor */
|
||||||
|
#undef CURL_ISOCPP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Macros for minimum-width signed and unsigned curl_off_t integer constants.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(__BORLANDC__) && (__BORLANDC__ == 0x0551)
|
||||||
|
# define CURLINC_OFF_T_C_HLPR2(x) x
|
||||||
|
# define CURLINC_OFF_T_C_HLPR1(x) CURLINC_OFF_T_C_HLPR2(x)
|
||||||
|
# define CURL_OFF_T_C(Val) CURLINC_OFF_T_C_HLPR1(Val) ## \
|
||||||
|
CURLINC_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_T)
|
||||||
|
# define CURL_OFF_TU_C(Val) CURLINC_OFF_T_C_HLPR1(Val) ## \
|
||||||
|
CURLINC_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_TU)
|
||||||
|
#else
|
||||||
|
# ifdef CURL_ISOCPP
|
||||||
|
# define CURLINC_OFF_T_C_HLPR2(Val,Suffix) Val ## Suffix
|
||||||
|
# else
|
||||||
|
# define CURLINC_OFF_T_C_HLPR2(Val,Suffix) Val/**/Suffix
|
||||||
|
# endif
|
||||||
|
# define CURLINC_OFF_T_C_HLPR1(Val,Suffix) CURLINC_OFF_T_C_HLPR2(Val,Suffix)
|
||||||
|
# define CURL_OFF_T_C(Val) CURLINC_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_T)
|
||||||
|
# define CURL_OFF_TU_C(Val) CURLINC_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_TU)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CURLINC_SYSTEM_H */
|
|
@ -0,0 +1,712 @@
|
||||||
|
#ifndef CURLINC_TYPECHECK_GCC_H
|
||||||
|
#define CURLINC_TYPECHECK_GCC_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/* wraps curl_easy_setopt() with typechecking */
|
||||||
|
|
||||||
|
/* To add a new kind of warning, add an
|
||||||
|
* if(curlcheck_sometype_option(_curl_opt))
|
||||||
|
* if(!curlcheck_sometype(value))
|
||||||
|
* _curl_easy_setopt_err_sometype();
|
||||||
|
* block and define curlcheck_sometype_option, curlcheck_sometype and
|
||||||
|
* _curl_easy_setopt_err_sometype below
|
||||||
|
*
|
||||||
|
* NOTE: We use two nested 'if' statements here instead of the && operator, in
|
||||||
|
* order to work around gcc bug #32061. It affects only gcc 4.3.x/4.4.x
|
||||||
|
* when compiling with -Wlogical-op.
|
||||||
|
*
|
||||||
|
* To add an option that uses the same type as an existing option, you'll just
|
||||||
|
* need to extend the appropriate _curl_*_option macro
|
||||||
|
*/
|
||||||
|
#define curl_easy_setopt(handle, option, value) \
|
||||||
|
__extension__({ \
|
||||||
|
__typeof__(option) _curl_opt = option; \
|
||||||
|
if(__builtin_constant_p(_curl_opt)) { \
|
||||||
|
if(curlcheck_long_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_long(value)) \
|
||||||
|
_curl_easy_setopt_err_long(); \
|
||||||
|
if(curlcheck_off_t_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_off_t(value)) \
|
||||||
|
_curl_easy_setopt_err_curl_off_t(); \
|
||||||
|
if(curlcheck_string_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_string(value)) \
|
||||||
|
_curl_easy_setopt_err_string(); \
|
||||||
|
if(curlcheck_write_cb_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_write_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_write_callback(); \
|
||||||
|
if((_curl_opt) == CURLOPT_RESOLVER_START_FUNCTION) \
|
||||||
|
if(!curlcheck_resolver_start_callback(value)) \
|
||||||
|
_curl_easy_setopt_err_resolver_start_callback(); \
|
||||||
|
if((_curl_opt) == CURLOPT_READFUNCTION) \
|
||||||
|
if(!curlcheck_read_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_read_cb(); \
|
||||||
|
if((_curl_opt) == CURLOPT_IOCTLFUNCTION) \
|
||||||
|
if(!curlcheck_ioctl_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_ioctl_cb(); \
|
||||||
|
if((_curl_opt) == CURLOPT_SOCKOPTFUNCTION) \
|
||||||
|
if(!curlcheck_sockopt_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_sockopt_cb(); \
|
||||||
|
if((_curl_opt) == CURLOPT_OPENSOCKETFUNCTION) \
|
||||||
|
if(!curlcheck_opensocket_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_opensocket_cb(); \
|
||||||
|
if((_curl_opt) == CURLOPT_PROGRESSFUNCTION) \
|
||||||
|
if(!curlcheck_progress_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_progress_cb(); \
|
||||||
|
if((_curl_opt) == CURLOPT_DEBUGFUNCTION) \
|
||||||
|
if(!curlcheck_debug_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_debug_cb(); \
|
||||||
|
if((_curl_opt) == CURLOPT_SSL_CTX_FUNCTION) \
|
||||||
|
if(!curlcheck_ssl_ctx_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_ssl_ctx_cb(); \
|
||||||
|
if(curlcheck_conv_cb_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_conv_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_conv_cb(); \
|
||||||
|
if((_curl_opt) == CURLOPT_SEEKFUNCTION) \
|
||||||
|
if(!curlcheck_seek_cb(value)) \
|
||||||
|
_curl_easy_setopt_err_seek_cb(); \
|
||||||
|
if(curlcheck_cb_data_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_cb_data(value)) \
|
||||||
|
_curl_easy_setopt_err_cb_data(); \
|
||||||
|
if((_curl_opt) == CURLOPT_ERRORBUFFER) \
|
||||||
|
if(!curlcheck_error_buffer(value)) \
|
||||||
|
_curl_easy_setopt_err_error_buffer(); \
|
||||||
|
if((_curl_opt) == CURLOPT_STDERR) \
|
||||||
|
if(!curlcheck_FILE(value)) \
|
||||||
|
_curl_easy_setopt_err_FILE(); \
|
||||||
|
if(curlcheck_postfields_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_postfields(value)) \
|
||||||
|
_curl_easy_setopt_err_postfields(); \
|
||||||
|
if((_curl_opt) == CURLOPT_HTTPPOST) \
|
||||||
|
if(!curlcheck_arr((value), struct curl_httppost)) \
|
||||||
|
_curl_easy_setopt_err_curl_httpost(); \
|
||||||
|
if((_curl_opt) == CURLOPT_MIMEPOST) \
|
||||||
|
if(!curlcheck_ptr((value), curl_mime)) \
|
||||||
|
_curl_easy_setopt_err_curl_mimepost(); \
|
||||||
|
if(curlcheck_slist_option(_curl_opt)) \
|
||||||
|
if(!curlcheck_arr((value), struct curl_slist)) \
|
||||||
|
_curl_easy_setopt_err_curl_slist(); \
|
||||||
|
if((_curl_opt) == CURLOPT_SHARE) \
|
||||||
|
if(!curlcheck_ptr((value), CURLSH)) \
|
||||||
|
_curl_easy_setopt_err_CURLSH(); \
|
||||||
|
} \
|
||||||
|
curl_easy_setopt(handle, _curl_opt, value); \
|
||||||
|
})
|
||||||
|
|
||||||
|
/* wraps curl_easy_getinfo() with typechecking */
|
||||||
|
#define curl_easy_getinfo(handle, info, arg) \
|
||||||
|
__extension__({ \
|
||||||
|
__typeof__(info) _curl_info = info; \
|
||||||
|
if(__builtin_constant_p(_curl_info)) { \
|
||||||
|
if(curlcheck_string_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), char *)) \
|
||||||
|
_curl_easy_getinfo_err_string(); \
|
||||||
|
if(curlcheck_long_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), long)) \
|
||||||
|
_curl_easy_getinfo_err_long(); \
|
||||||
|
if(curlcheck_double_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), double)) \
|
||||||
|
_curl_easy_getinfo_err_double(); \
|
||||||
|
if(curlcheck_slist_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), struct curl_slist *)) \
|
||||||
|
_curl_easy_getinfo_err_curl_slist(); \
|
||||||
|
if(curlcheck_tlssessioninfo_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), struct curl_tlssessioninfo *)) \
|
||||||
|
_curl_easy_getinfo_err_curl_tlssesssioninfo(); \
|
||||||
|
if(curlcheck_certinfo_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), struct curl_certinfo *)) \
|
||||||
|
_curl_easy_getinfo_err_curl_certinfo(); \
|
||||||
|
if(curlcheck_socket_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), curl_socket_t)) \
|
||||||
|
_curl_easy_getinfo_err_curl_socket(); \
|
||||||
|
if(curlcheck_off_t_info(_curl_info)) \
|
||||||
|
if(!curlcheck_arr((arg), curl_off_t)) \
|
||||||
|
_curl_easy_getinfo_err_curl_off_t(); \
|
||||||
|
} \
|
||||||
|
curl_easy_getinfo(handle, _curl_info, arg); \
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For now, just make sure that the functions are called with three arguments
|
||||||
|
*/
|
||||||
|
#define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param)
|
||||||
|
#define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param)
|
||||||
|
|
||||||
|
|
||||||
|
/* the actual warnings, triggered by calling the _curl_easy_setopt_err*
|
||||||
|
* functions */
|
||||||
|
|
||||||
|
/* To define a new warning, use _CURL_WARNING(identifier, "message") */
|
||||||
|
#define CURLWARNING(id, message) \
|
||||||
|
static void __attribute__((__warning__(message))) \
|
||||||
|
__attribute__((__unused__)) __attribute__((__noinline__)) \
|
||||||
|
id(void) { __asm__(""); }
|
||||||
|
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_long,
|
||||||
|
"curl_easy_setopt expects a long argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_curl_off_t,
|
||||||
|
"curl_easy_setopt expects a curl_off_t argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_string,
|
||||||
|
"curl_easy_setopt expects a "
|
||||||
|
"string ('char *' or char[]) argument for this option"
|
||||||
|
)
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_write_callback,
|
||||||
|
"curl_easy_setopt expects a curl_write_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_resolver_start_callback,
|
||||||
|
"curl_easy_setopt expects a "
|
||||||
|
"curl_resolver_start_callback argument for this option"
|
||||||
|
)
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_read_cb,
|
||||||
|
"curl_easy_setopt expects a curl_read_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_ioctl_cb,
|
||||||
|
"curl_easy_setopt expects a curl_ioctl_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_sockopt_cb,
|
||||||
|
"curl_easy_setopt expects a curl_sockopt_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_opensocket_cb,
|
||||||
|
"curl_easy_setopt expects a "
|
||||||
|
"curl_opensocket_callback argument for this option"
|
||||||
|
)
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_progress_cb,
|
||||||
|
"curl_easy_setopt expects a curl_progress_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_debug_cb,
|
||||||
|
"curl_easy_setopt expects a curl_debug_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_ssl_ctx_cb,
|
||||||
|
"curl_easy_setopt expects a curl_ssl_ctx_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_conv_cb,
|
||||||
|
"curl_easy_setopt expects a curl_conv_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_seek_cb,
|
||||||
|
"curl_easy_setopt expects a curl_seek_callback argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_cb_data,
|
||||||
|
"curl_easy_setopt expects a "
|
||||||
|
"private data pointer as argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_error_buffer,
|
||||||
|
"curl_easy_setopt expects a "
|
||||||
|
"char buffer of CURL_ERROR_SIZE as argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_FILE,
|
||||||
|
"curl_easy_setopt expects a 'FILE *' argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_postfields,
|
||||||
|
"curl_easy_setopt expects a 'void *' or 'char *' argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_curl_httpost,
|
||||||
|
"curl_easy_setopt expects a 'struct curl_httppost *' "
|
||||||
|
"argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_curl_mimepost,
|
||||||
|
"curl_easy_setopt expects a 'curl_mime *' "
|
||||||
|
"argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_curl_slist,
|
||||||
|
"curl_easy_setopt expects a 'struct curl_slist *' argument for this option")
|
||||||
|
CURLWARNING(_curl_easy_setopt_err_CURLSH,
|
||||||
|
"curl_easy_setopt expects a CURLSH* argument for this option")
|
||||||
|
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_string,
|
||||||
|
"curl_easy_getinfo expects a pointer to 'char *' for this info")
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_long,
|
||||||
|
"curl_easy_getinfo expects a pointer to long for this info")
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_double,
|
||||||
|
"curl_easy_getinfo expects a pointer to double for this info")
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_curl_slist,
|
||||||
|
"curl_easy_getinfo expects a pointer to 'struct curl_slist *' for this info")
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_curl_tlssesssioninfo,
|
||||||
|
"curl_easy_getinfo expects a pointer to "
|
||||||
|
"'struct curl_tlssessioninfo *' for this info")
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_curl_certinfo,
|
||||||
|
"curl_easy_getinfo expects a pointer to "
|
||||||
|
"'struct curl_certinfo *' for this info")
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_curl_socket,
|
||||||
|
"curl_easy_getinfo expects a pointer to curl_socket_t for this info")
|
||||||
|
CURLWARNING(_curl_easy_getinfo_err_curl_off_t,
|
||||||
|
"curl_easy_getinfo expects a pointer to curl_off_t for this info")
|
||||||
|
|
||||||
|
/* groups of curl_easy_setops options that take the same type of argument */
|
||||||
|
|
||||||
|
/* To add a new option to one of the groups, just add
|
||||||
|
* (option) == CURLOPT_SOMETHING
|
||||||
|
* to the or-expression. If the option takes a long or curl_off_t, you don't
|
||||||
|
* have to do anything
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* evaluates to true if option takes a long argument */
|
||||||
|
#define curlcheck_long_option(option) \
|
||||||
|
(0 < (option) && (option) < CURLOPTTYPE_OBJECTPOINT)
|
||||||
|
|
||||||
|
#define curlcheck_off_t_option(option) \
|
||||||
|
(((option) > CURLOPTTYPE_OFF_T) && ((option) < CURLOPTTYPE_BLOB))
|
||||||
|
|
||||||
|
/* evaluates to true if option takes a char* argument */
|
||||||
|
#define curlcheck_string_option(option) \
|
||||||
|
((option) == CURLOPT_ABSTRACT_UNIX_SOCKET || \
|
||||||
|
(option) == CURLOPT_ACCEPT_ENCODING || \
|
||||||
|
(option) == CURLOPT_ALTSVC || \
|
||||||
|
(option) == CURLOPT_CAINFO || \
|
||||||
|
(option) == CURLOPT_CAPATH || \
|
||||||
|
(option) == CURLOPT_COOKIE || \
|
||||||
|
(option) == CURLOPT_COOKIEFILE || \
|
||||||
|
(option) == CURLOPT_COOKIEJAR || \
|
||||||
|
(option) == CURLOPT_COOKIELIST || \
|
||||||
|
(option) == CURLOPT_CRLFILE || \
|
||||||
|
(option) == CURLOPT_CUSTOMREQUEST || \
|
||||||
|
(option) == CURLOPT_DEFAULT_PROTOCOL || \
|
||||||
|
(option) == CURLOPT_DNS_INTERFACE || \
|
||||||
|
(option) == CURLOPT_DNS_LOCAL_IP4 || \
|
||||||
|
(option) == CURLOPT_DNS_LOCAL_IP6 || \
|
||||||
|
(option) == CURLOPT_DNS_SERVERS || \
|
||||||
|
(option) == CURLOPT_DOH_URL || \
|
||||||
|
(option) == CURLOPT_EGDSOCKET || \
|
||||||
|
(option) == CURLOPT_FTP_ACCOUNT || \
|
||||||
|
(option) == CURLOPT_FTP_ALTERNATIVE_TO_USER || \
|
||||||
|
(option) == CURLOPT_FTPPORT || \
|
||||||
|
(option) == CURLOPT_HSTS || \
|
||||||
|
(option) == CURLOPT_INTERFACE || \
|
||||||
|
(option) == CURLOPT_ISSUERCERT || \
|
||||||
|
(option) == CURLOPT_KEYPASSWD || \
|
||||||
|
(option) == CURLOPT_KRBLEVEL || \
|
||||||
|
(option) == CURLOPT_LOGIN_OPTIONS || \
|
||||||
|
(option) == CURLOPT_MAIL_AUTH || \
|
||||||
|
(option) == CURLOPT_MAIL_FROM || \
|
||||||
|
(option) == CURLOPT_NETRC_FILE || \
|
||||||
|
(option) == CURLOPT_NOPROXY || \
|
||||||
|
(option) == CURLOPT_PASSWORD || \
|
||||||
|
(option) == CURLOPT_PINNEDPUBLICKEY || \
|
||||||
|
(option) == CURLOPT_PRE_PROXY || \
|
||||||
|
(option) == CURLOPT_PROTOCOLS_STR || \
|
||||||
|
(option) == CURLOPT_PROXY || \
|
||||||
|
(option) == CURLOPT_PROXY_CAINFO || \
|
||||||
|
(option) == CURLOPT_PROXY_CAPATH || \
|
||||||
|
(option) == CURLOPT_PROXY_CRLFILE || \
|
||||||
|
(option) == CURLOPT_PROXY_ISSUERCERT || \
|
||||||
|
(option) == CURLOPT_PROXY_KEYPASSWD || \
|
||||||
|
(option) == CURLOPT_PROXY_PINNEDPUBLICKEY || \
|
||||||
|
(option) == CURLOPT_PROXY_SERVICE_NAME || \
|
||||||
|
(option) == CURLOPT_PROXY_SSL_CIPHER_LIST || \
|
||||||
|
(option) == CURLOPT_PROXY_SSLCERT || \
|
||||||
|
(option) == CURLOPT_PROXY_SSLCERTTYPE || \
|
||||||
|
(option) == CURLOPT_PROXY_SSLKEY || \
|
||||||
|
(option) == CURLOPT_PROXY_SSLKEYTYPE || \
|
||||||
|
(option) == CURLOPT_PROXY_TLS13_CIPHERS || \
|
||||||
|
(option) == CURLOPT_PROXY_TLSAUTH_PASSWORD || \
|
||||||
|
(option) == CURLOPT_PROXY_TLSAUTH_TYPE || \
|
||||||
|
(option) == CURLOPT_PROXY_TLSAUTH_USERNAME || \
|
||||||
|
(option) == CURLOPT_PROXYPASSWORD || \
|
||||||
|
(option) == CURLOPT_PROXYUSERNAME || \
|
||||||
|
(option) == CURLOPT_PROXYUSERPWD || \
|
||||||
|
(option) == CURLOPT_RANDOM_FILE || \
|
||||||
|
(option) == CURLOPT_RANGE || \
|
||||||
|
(option) == CURLOPT_REDIR_PROTOCOLS_STR || \
|
||||||
|
(option) == CURLOPT_REFERER || \
|
||||||
|
(option) == CURLOPT_REQUEST_TARGET || \
|
||||||
|
(option) == CURLOPT_RTSP_SESSION_ID || \
|
||||||
|
(option) == CURLOPT_RTSP_STREAM_URI || \
|
||||||
|
(option) == CURLOPT_RTSP_TRANSPORT || \
|
||||||
|
(option) == CURLOPT_SASL_AUTHZID || \
|
||||||
|
(option) == CURLOPT_SERVICE_NAME || \
|
||||||
|
(option) == CURLOPT_SOCKS5_GSSAPI_SERVICE || \
|
||||||
|
(option) == CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 || \
|
||||||
|
(option) == CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256 || \
|
||||||
|
(option) == CURLOPT_SSH_KNOWNHOSTS || \
|
||||||
|
(option) == CURLOPT_SSH_PRIVATE_KEYFILE || \
|
||||||
|
(option) == CURLOPT_SSH_PUBLIC_KEYFILE || \
|
||||||
|
(option) == CURLOPT_SSLCERT || \
|
||||||
|
(option) == CURLOPT_SSLCERTTYPE || \
|
||||||
|
(option) == CURLOPT_SSLENGINE || \
|
||||||
|
(option) == CURLOPT_SSLKEY || \
|
||||||
|
(option) == CURLOPT_SSLKEYTYPE || \
|
||||||
|
(option) == CURLOPT_SSL_CIPHER_LIST || \
|
||||||
|
(option) == CURLOPT_TLS13_CIPHERS || \
|
||||||
|
(option) == CURLOPT_TLSAUTH_PASSWORD || \
|
||||||
|
(option) == CURLOPT_TLSAUTH_TYPE || \
|
||||||
|
(option) == CURLOPT_TLSAUTH_USERNAME || \
|
||||||
|
(option) == CURLOPT_UNIX_SOCKET_PATH || \
|
||||||
|
(option) == CURLOPT_URL || \
|
||||||
|
(option) == CURLOPT_USERAGENT || \
|
||||||
|
(option) == CURLOPT_USERNAME || \
|
||||||
|
(option) == CURLOPT_AWS_SIGV4 || \
|
||||||
|
(option) == CURLOPT_USERPWD || \
|
||||||
|
(option) == CURLOPT_XOAUTH2_BEARER || \
|
||||||
|
(option) == CURLOPT_SSL_EC_CURVES || \
|
||||||
|
0)
|
||||||
|
|
||||||
|
/* evaluates to true if option takes a curl_write_callback argument */
|
||||||
|
#define curlcheck_write_cb_option(option) \
|
||||||
|
((option) == CURLOPT_HEADERFUNCTION || \
|
||||||
|
(option) == CURLOPT_WRITEFUNCTION)
|
||||||
|
|
||||||
|
/* evaluates to true if option takes a curl_conv_callback argument */
|
||||||
|
#define curlcheck_conv_cb_option(option) \
|
||||||
|
((option) == CURLOPT_CONV_TO_NETWORK_FUNCTION || \
|
||||||
|
(option) == CURLOPT_CONV_FROM_NETWORK_FUNCTION || \
|
||||||
|
(option) == CURLOPT_CONV_FROM_UTF8_FUNCTION)
|
||||||
|
|
||||||
|
/* evaluates to true if option takes a data argument to pass to a callback */
|
||||||
|
#define curlcheck_cb_data_option(option) \
|
||||||
|
((option) == CURLOPT_CHUNK_DATA || \
|
||||||
|
(option) == CURLOPT_CLOSESOCKETDATA || \
|
||||||
|
(option) == CURLOPT_DEBUGDATA || \
|
||||||
|
(option) == CURLOPT_FNMATCH_DATA || \
|
||||||
|
(option) == CURLOPT_HEADERDATA || \
|
||||||
|
(option) == CURLOPT_HSTSREADDATA || \
|
||||||
|
(option) == CURLOPT_HSTSWRITEDATA || \
|
||||||
|
(option) == CURLOPT_INTERLEAVEDATA || \
|
||||||
|
(option) == CURLOPT_IOCTLDATA || \
|
||||||
|
(option) == CURLOPT_OPENSOCKETDATA || \
|
||||||
|
(option) == CURLOPT_PREREQDATA || \
|
||||||
|
(option) == CURLOPT_PROGRESSDATA || \
|
||||||
|
(option) == CURLOPT_READDATA || \
|
||||||
|
(option) == CURLOPT_SEEKDATA || \
|
||||||
|
(option) == CURLOPT_SOCKOPTDATA || \
|
||||||
|
(option) == CURLOPT_SSH_KEYDATA || \
|
||||||
|
(option) == CURLOPT_SSL_CTX_DATA || \
|
||||||
|
(option) == CURLOPT_WRITEDATA || \
|
||||||
|
(option) == CURLOPT_RESOLVER_START_DATA || \
|
||||||
|
(option) == CURLOPT_TRAILERDATA || \
|
||||||
|
(option) == CURLOPT_SSH_HOSTKEYDATA || \
|
||||||
|
0)
|
||||||
|
|
||||||
|
/* evaluates to true if option takes a POST data argument (void* or char*) */
|
||||||
|
#define curlcheck_postfields_option(option) \
|
||||||
|
((option) == CURLOPT_POSTFIELDS || \
|
||||||
|
(option) == CURLOPT_COPYPOSTFIELDS || \
|
||||||
|
0)
|
||||||
|
|
||||||
|
/* evaluates to true if option takes a struct curl_slist * argument */
|
||||||
|
#define curlcheck_slist_option(option) \
|
||||||
|
((option) == CURLOPT_HTTP200ALIASES || \
|
||||||
|
(option) == CURLOPT_HTTPHEADER || \
|
||||||
|
(option) == CURLOPT_MAIL_RCPT || \
|
||||||
|
(option) == CURLOPT_POSTQUOTE || \
|
||||||
|
(option) == CURLOPT_PREQUOTE || \
|
||||||
|
(option) == CURLOPT_PROXYHEADER || \
|
||||||
|
(option) == CURLOPT_QUOTE || \
|
||||||
|
(option) == CURLOPT_RESOLVE || \
|
||||||
|
(option) == CURLOPT_TELNETOPTIONS || \
|
||||||
|
(option) == CURLOPT_CONNECT_TO || \
|
||||||
|
0)
|
||||||
|
|
||||||
|
/* groups of curl_easy_getinfo infos that take the same type of argument */
|
||||||
|
|
||||||
|
/* evaluates to true if info expects a pointer to char * argument */
|
||||||
|
#define curlcheck_string_info(info) \
|
||||||
|
(CURLINFO_STRING < (info) && (info) < CURLINFO_LONG && \
|
||||||
|
(info) != CURLINFO_PRIVATE)
|
||||||
|
|
||||||
|
/* evaluates to true if info expects a pointer to long argument */
|
||||||
|
#define curlcheck_long_info(info) \
|
||||||
|
(CURLINFO_LONG < (info) && (info) < CURLINFO_DOUBLE)
|
||||||
|
|
||||||
|
/* evaluates to true if info expects a pointer to double argument */
|
||||||
|
#define curlcheck_double_info(info) \
|
||||||
|
(CURLINFO_DOUBLE < (info) && (info) < CURLINFO_SLIST)
|
||||||
|
|
||||||
|
/* true if info expects a pointer to struct curl_slist * argument */
|
||||||
|
#define curlcheck_slist_info(info) \
|
||||||
|
(((info) == CURLINFO_SSL_ENGINES) || ((info) == CURLINFO_COOKIELIST))
|
||||||
|
|
||||||
|
/* true if info expects a pointer to struct curl_tlssessioninfo * argument */
|
||||||
|
#define curlcheck_tlssessioninfo_info(info) \
|
||||||
|
(((info) == CURLINFO_TLS_SSL_PTR) || ((info) == CURLINFO_TLS_SESSION))
|
||||||
|
|
||||||
|
/* true if info expects a pointer to struct curl_certinfo * argument */
|
||||||
|
#define curlcheck_certinfo_info(info) ((info) == CURLINFO_CERTINFO)
|
||||||
|
|
||||||
|
/* true if info expects a pointer to struct curl_socket_t argument */
|
||||||
|
#define curlcheck_socket_info(info) \
|
||||||
|
(CURLINFO_SOCKET < (info) && (info) < CURLINFO_OFF_T)
|
||||||
|
|
||||||
|
/* true if info expects a pointer to curl_off_t argument */
|
||||||
|
#define curlcheck_off_t_info(info) \
|
||||||
|
(CURLINFO_OFF_T < (info))
|
||||||
|
|
||||||
|
|
||||||
|
/* typecheck helpers -- check whether given expression has requested type*/
|
||||||
|
|
||||||
|
/* For pointers, you can use the curlcheck_ptr/curlcheck_arr macros,
|
||||||
|
* otherwise define a new macro. Search for __builtin_types_compatible_p
|
||||||
|
* in the GCC manual.
|
||||||
|
* NOTE: these macros MUST NOT EVALUATE their arguments! The argument is
|
||||||
|
* the actual expression passed to the curl_easy_setopt macro. This
|
||||||
|
* means that you can only apply the sizeof and __typeof__ operators, no
|
||||||
|
* == or whatsoever.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* XXX: should evaluate to true if expr is a pointer */
|
||||||
|
#define curlcheck_any_ptr(expr) \
|
||||||
|
(sizeof(expr) == sizeof(void *))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is NULL */
|
||||||
|
/* XXX: must not evaluate expr, so this check is not accurate */
|
||||||
|
#define curlcheck_NULL(expr) \
|
||||||
|
(__builtin_types_compatible_p(__typeof__(expr), __typeof__(NULL)))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is type*, const type* or NULL */
|
||||||
|
#define curlcheck_ptr(expr, type) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), type *) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), const type *))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is one of type[], type*, NULL or const type* */
|
||||||
|
#define curlcheck_arr(expr, type) \
|
||||||
|
(curlcheck_ptr((expr), type) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), type []))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is a string */
|
||||||
|
#define curlcheck_string(expr) \
|
||||||
|
(curlcheck_arr((expr), char) || \
|
||||||
|
curlcheck_arr((expr), signed char) || \
|
||||||
|
curlcheck_arr((expr), unsigned char))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is a long (no matter the signedness)
|
||||||
|
* XXX: for now, int is also accepted (and therefore short and char, which
|
||||||
|
* are promoted to int when passed to a variadic function) */
|
||||||
|
#define curlcheck_long(expr) \
|
||||||
|
(__builtin_types_compatible_p(__typeof__(expr), long) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), signed long) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), unsigned long) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), int) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), signed int) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), unsigned int) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), short) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), signed short) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), unsigned short) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), char) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), signed char) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), unsigned char))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_off_t */
|
||||||
|
#define curlcheck_off_t(expr) \
|
||||||
|
(__builtin_types_compatible_p(__typeof__(expr), curl_off_t))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is abuffer suitable for CURLOPT_ERRORBUFFER */
|
||||||
|
/* XXX: also check size of an char[] array? */
|
||||||
|
#define curlcheck_error_buffer(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), char *) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(expr), char[]))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type (const) void* or (const) FILE* */
|
||||||
|
#if 0
|
||||||
|
#define curlcheck_cb_data(expr) \
|
||||||
|
(curlcheck_ptr((expr), void) || \
|
||||||
|
curlcheck_ptr((expr), FILE))
|
||||||
|
#else /* be less strict */
|
||||||
|
#define curlcheck_cb_data(expr) \
|
||||||
|
curlcheck_any_ptr(expr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type FILE* */
|
||||||
|
#define curlcheck_FILE(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
(__builtin_types_compatible_p(__typeof__(expr), FILE *)))
|
||||||
|
|
||||||
|
/* evaluates to true if expr can be passed as POST data (void* or char*) */
|
||||||
|
#define curlcheck_postfields(expr) \
|
||||||
|
(curlcheck_ptr((expr), void) || \
|
||||||
|
curlcheck_arr((expr), char) || \
|
||||||
|
curlcheck_arr((expr), unsigned char))
|
||||||
|
|
||||||
|
/* helper: __builtin_types_compatible_p distinguishes between functions and
|
||||||
|
* function pointers, hide it */
|
||||||
|
#define curlcheck_cb_compatible(func, type) \
|
||||||
|
(__builtin_types_compatible_p(__typeof__(func), type) || \
|
||||||
|
__builtin_types_compatible_p(__typeof__(func) *, type))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_resolver_start_callback */
|
||||||
|
#define curlcheck_resolver_start_callback(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_resolver_start_callback))
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_read_callback or "similar" */
|
||||||
|
#define curlcheck_read_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), __typeof__(fread) *) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_read_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_read_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_read_callback2) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_read_callback3) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_read_callback4) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_read_callback5) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_read_callback6))
|
||||||
|
typedef size_t (*_curl_read_callback1)(char *, size_t, size_t, void *);
|
||||||
|
typedef size_t (*_curl_read_callback2)(char *, size_t, size_t, const void *);
|
||||||
|
typedef size_t (*_curl_read_callback3)(char *, size_t, size_t, FILE *);
|
||||||
|
typedef size_t (*_curl_read_callback4)(void *, size_t, size_t, void *);
|
||||||
|
typedef size_t (*_curl_read_callback5)(void *, size_t, size_t, const void *);
|
||||||
|
typedef size_t (*_curl_read_callback6)(void *, size_t, size_t, FILE *);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_write_callback or "similar" */
|
||||||
|
#define curlcheck_write_cb(expr) \
|
||||||
|
(curlcheck_read_cb(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), __typeof__(fwrite) *) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_write_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_write_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_write_callback2) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_write_callback3) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_write_callback4) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_write_callback5) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_write_callback6))
|
||||||
|
typedef size_t (*_curl_write_callback1)(const char *, size_t, size_t, void *);
|
||||||
|
typedef size_t (*_curl_write_callback2)(const char *, size_t, size_t,
|
||||||
|
const void *);
|
||||||
|
typedef size_t (*_curl_write_callback3)(const char *, size_t, size_t, FILE *);
|
||||||
|
typedef size_t (*_curl_write_callback4)(const void *, size_t, size_t, void *);
|
||||||
|
typedef size_t (*_curl_write_callback5)(const void *, size_t, size_t,
|
||||||
|
const void *);
|
||||||
|
typedef size_t (*_curl_write_callback6)(const void *, size_t, size_t, FILE *);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_ioctl_callback or "similar" */
|
||||||
|
#define curlcheck_ioctl_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_ioctl_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ioctl_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ioctl_callback2) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ioctl_callback3) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ioctl_callback4))
|
||||||
|
typedef curlioerr (*_curl_ioctl_callback1)(CURL *, int, void *);
|
||||||
|
typedef curlioerr (*_curl_ioctl_callback2)(CURL *, int, const void *);
|
||||||
|
typedef curlioerr (*_curl_ioctl_callback3)(CURL *, curliocmd, void *);
|
||||||
|
typedef curlioerr (*_curl_ioctl_callback4)(CURL *, curliocmd, const void *);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_sockopt_callback or "similar" */
|
||||||
|
#define curlcheck_sockopt_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_sockopt_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_sockopt_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_sockopt_callback2))
|
||||||
|
typedef int (*_curl_sockopt_callback1)(void *, curl_socket_t, curlsocktype);
|
||||||
|
typedef int (*_curl_sockopt_callback2)(const void *, curl_socket_t,
|
||||||
|
curlsocktype);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_opensocket_callback or
|
||||||
|
"similar" */
|
||||||
|
#define curlcheck_opensocket_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_opensocket_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_opensocket_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_opensocket_callback2) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_opensocket_callback3) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_opensocket_callback4))
|
||||||
|
typedef curl_socket_t (*_curl_opensocket_callback1)
|
||||||
|
(void *, curlsocktype, struct curl_sockaddr *);
|
||||||
|
typedef curl_socket_t (*_curl_opensocket_callback2)
|
||||||
|
(void *, curlsocktype, const struct curl_sockaddr *);
|
||||||
|
typedef curl_socket_t (*_curl_opensocket_callback3)
|
||||||
|
(const void *, curlsocktype, struct curl_sockaddr *);
|
||||||
|
typedef curl_socket_t (*_curl_opensocket_callback4)
|
||||||
|
(const void *, curlsocktype, const struct curl_sockaddr *);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_progress_callback or "similar" */
|
||||||
|
#define curlcheck_progress_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_progress_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_progress_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_progress_callback2))
|
||||||
|
typedef int (*_curl_progress_callback1)(void *,
|
||||||
|
double, double, double, double);
|
||||||
|
typedef int (*_curl_progress_callback2)(const void *,
|
||||||
|
double, double, double, double);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_debug_callback or "similar" */
|
||||||
|
#define curlcheck_debug_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_debug_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback2) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback3) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback4) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback5) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback6) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback7) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_debug_callback8))
|
||||||
|
typedef int (*_curl_debug_callback1) (CURL *,
|
||||||
|
curl_infotype, char *, size_t, void *);
|
||||||
|
typedef int (*_curl_debug_callback2) (CURL *,
|
||||||
|
curl_infotype, char *, size_t, const void *);
|
||||||
|
typedef int (*_curl_debug_callback3) (CURL *,
|
||||||
|
curl_infotype, const char *, size_t, void *);
|
||||||
|
typedef int (*_curl_debug_callback4) (CURL *,
|
||||||
|
curl_infotype, const char *, size_t, const void *);
|
||||||
|
typedef int (*_curl_debug_callback5) (CURL *,
|
||||||
|
curl_infotype, unsigned char *, size_t, void *);
|
||||||
|
typedef int (*_curl_debug_callback6) (CURL *,
|
||||||
|
curl_infotype, unsigned char *, size_t, const void *);
|
||||||
|
typedef int (*_curl_debug_callback7) (CURL *,
|
||||||
|
curl_infotype, const unsigned char *, size_t, void *);
|
||||||
|
typedef int (*_curl_debug_callback8) (CURL *,
|
||||||
|
curl_infotype, const unsigned char *, size_t, const void *);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_ssl_ctx_callback or "similar" */
|
||||||
|
/* this is getting even messier... */
|
||||||
|
#define curlcheck_ssl_ctx_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_ssl_ctx_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback2) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback3) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback4) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback5) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback6) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback7) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback8))
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback1)(CURL *, void *, void *);
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback2)(CURL *, void *, const void *);
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback3)(CURL *, const void *, void *);
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback4)(CURL *, const void *,
|
||||||
|
const void *);
|
||||||
|
#ifdef HEADER_SSL_H
|
||||||
|
/* hack: if we included OpenSSL's ssl.h, we know about SSL_CTX
|
||||||
|
* this will of course break if we're included before OpenSSL headers...
|
||||||
|
*/
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback5)(CURL *, SSL_CTX *, void *);
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback6)(CURL *, SSL_CTX *, const void *);
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback7)(CURL *, const SSL_CTX *, void *);
|
||||||
|
typedef CURLcode (*_curl_ssl_ctx_callback8)(CURL *, const SSL_CTX *,
|
||||||
|
const void *);
|
||||||
|
#else
|
||||||
|
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback5;
|
||||||
|
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback6;
|
||||||
|
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback7;
|
||||||
|
typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback8;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_conv_callback or "similar" */
|
||||||
|
#define curlcheck_conv_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_conv_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_conv_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_conv_callback2) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_conv_callback3) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_conv_callback4))
|
||||||
|
typedef CURLcode (*_curl_conv_callback1)(char *, size_t length);
|
||||||
|
typedef CURLcode (*_curl_conv_callback2)(const char *, size_t length);
|
||||||
|
typedef CURLcode (*_curl_conv_callback3)(void *, size_t length);
|
||||||
|
typedef CURLcode (*_curl_conv_callback4)(const void *, size_t length);
|
||||||
|
|
||||||
|
/* evaluates to true if expr is of type curl_seek_callback or "similar" */
|
||||||
|
#define curlcheck_seek_cb(expr) \
|
||||||
|
(curlcheck_NULL(expr) || \
|
||||||
|
curlcheck_cb_compatible((expr), curl_seek_callback) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_seek_callback1) || \
|
||||||
|
curlcheck_cb_compatible((expr), _curl_seek_callback2))
|
||||||
|
typedef CURLcode (*_curl_seek_callback1)(void *, curl_off_t, int);
|
||||||
|
typedef CURLcode (*_curl_seek_callback2)(const void *, curl_off_t, int);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* CURLINC_TYPECHECK_GCC_H */
|
|
@ -0,0 +1,147 @@
|
||||||
|
#ifndef CURLINC_URLAPI_H
|
||||||
|
#define CURLINC_URLAPI_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: curl
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "curl.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* the error codes for the URL API */
|
||||||
|
typedef enum {
|
||||||
|
CURLUE_OK,
|
||||||
|
CURLUE_BAD_HANDLE, /* 1 */
|
||||||
|
CURLUE_BAD_PARTPOINTER, /* 2 */
|
||||||
|
CURLUE_MALFORMED_INPUT, /* 3 */
|
||||||
|
CURLUE_BAD_PORT_NUMBER, /* 4 */
|
||||||
|
CURLUE_UNSUPPORTED_SCHEME, /* 5 */
|
||||||
|
CURLUE_URLDECODE, /* 6 */
|
||||||
|
CURLUE_OUT_OF_MEMORY, /* 7 */
|
||||||
|
CURLUE_USER_NOT_ALLOWED, /* 8 */
|
||||||
|
CURLUE_UNKNOWN_PART, /* 9 */
|
||||||
|
CURLUE_NO_SCHEME, /* 10 */
|
||||||
|
CURLUE_NO_USER, /* 11 */
|
||||||
|
CURLUE_NO_PASSWORD, /* 12 */
|
||||||
|
CURLUE_NO_OPTIONS, /* 13 */
|
||||||
|
CURLUE_NO_HOST, /* 14 */
|
||||||
|
CURLUE_NO_PORT, /* 15 */
|
||||||
|
CURLUE_NO_QUERY, /* 16 */
|
||||||
|
CURLUE_NO_FRAGMENT, /* 17 */
|
||||||
|
CURLUE_NO_ZONEID, /* 18 */
|
||||||
|
CURLUE_BAD_FILE_URL, /* 19 */
|
||||||
|
CURLUE_BAD_FRAGMENT, /* 20 */
|
||||||
|
CURLUE_BAD_HOSTNAME, /* 21 */
|
||||||
|
CURLUE_BAD_IPV6, /* 22 */
|
||||||
|
CURLUE_BAD_LOGIN, /* 23 */
|
||||||
|
CURLUE_BAD_PASSWORD, /* 24 */
|
||||||
|
CURLUE_BAD_PATH, /* 25 */
|
||||||
|
CURLUE_BAD_QUERY, /* 26 */
|
||||||
|
CURLUE_BAD_SCHEME, /* 27 */
|
||||||
|
CURLUE_BAD_SLASHES, /* 28 */
|
||||||
|
CURLUE_BAD_USER, /* 29 */
|
||||||
|
CURLUE_LAST
|
||||||
|
} CURLUcode;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CURLUPART_URL,
|
||||||
|
CURLUPART_SCHEME,
|
||||||
|
CURLUPART_USER,
|
||||||
|
CURLUPART_PASSWORD,
|
||||||
|
CURLUPART_OPTIONS,
|
||||||
|
CURLUPART_HOST,
|
||||||
|
CURLUPART_PORT,
|
||||||
|
CURLUPART_PATH,
|
||||||
|
CURLUPART_QUERY,
|
||||||
|
CURLUPART_FRAGMENT,
|
||||||
|
CURLUPART_ZONEID /* added in 7.65.0 */
|
||||||
|
} CURLUPart;
|
||||||
|
|
||||||
|
#define CURLU_DEFAULT_PORT (1<<0) /* return default port number */
|
||||||
|
#define CURLU_NO_DEFAULT_PORT (1<<1) /* act as if no port number was set,
|
||||||
|
if the port number matches the
|
||||||
|
default for the scheme */
|
||||||
|
#define CURLU_DEFAULT_SCHEME (1<<2) /* return default scheme if
|
||||||
|
missing */
|
||||||
|
#define CURLU_NON_SUPPORT_SCHEME (1<<3) /* allow non-supported scheme */
|
||||||
|
#define CURLU_PATH_AS_IS (1<<4) /* leave dot sequences */
|
||||||
|
#define CURLU_DISALLOW_USER (1<<5) /* no user+password allowed */
|
||||||
|
#define CURLU_URLDECODE (1<<6) /* URL decode on get */
|
||||||
|
#define CURLU_URLENCODE (1<<7) /* URL encode on set */
|
||||||
|
#define CURLU_APPENDQUERY (1<<8) /* append a form style part */
|
||||||
|
#define CURLU_GUESS_SCHEME (1<<9) /* legacy curl-style guessing */
|
||||||
|
#define CURLU_NO_AUTHORITY (1<<10) /* Allow empty authority when the
|
||||||
|
scheme is unknown. */
|
||||||
|
#define CURLU_ALLOW_SPACE (1<<11) /* Allow spaces in the URL */
|
||||||
|
|
||||||
|
typedef struct Curl_URL CURLU;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* curl_url() creates a new CURLU handle and returns a pointer to it.
|
||||||
|
* Must be freed with curl_url_cleanup().
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLU *curl_url(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* curl_url_cleanup() frees the CURLU handle and related resources used for
|
||||||
|
* the URL parsing. It will not free strings previously returned with the URL
|
||||||
|
* API.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN void curl_url_cleanup(CURLU *handle);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* curl_url_dup() duplicates a CURLU handle and returns a new copy. The new
|
||||||
|
* handle must also be freed with curl_url_cleanup().
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLU *curl_url_dup(CURLU *in);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* curl_url_get() extracts a specific part of the URL from a CURLU
|
||||||
|
* handle. Returns error code. The returned pointer MUST be freed with
|
||||||
|
* curl_free() afterwards.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLUcode curl_url_get(CURLU *handle, CURLUPart what,
|
||||||
|
char **part, unsigned int flags);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* curl_url_set() sets a specific part of the URL in a CURLU handle. Returns
|
||||||
|
* error code. The passed in string will be copied. Passing a NULL instead of
|
||||||
|
* a part string, clears that part.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN CURLUcode curl_url_set(CURLU *handle, CURLUPart what,
|
||||||
|
const char *part, unsigned int flags);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* curl_url_strerror() turns a CURLUcode value into the equivalent human
|
||||||
|
* readable error string. This is useful for printing meaningful error
|
||||||
|
* messages.
|
||||||
|
*/
|
||||||
|
CURL_EXTERN const char *curl_url_strerror(CURLUcode);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* end of extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CURLINC_URLAPI_H */
|
|
@ -0,0 +1,35 @@
|
||||||
|
#ifndef HTTP_LIBRARY_H
|
||||||
|
#define HTTP_LIBRARY_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Http {
|
||||||
|
class Request {
|
||||||
|
public:
|
||||||
|
Request();
|
||||||
|
~Request();
|
||||||
|
void setUrl(const std::string&);
|
||||||
|
void setMethod(const std::string&);
|
||||||
|
void setBody(const std::string&);
|
||||||
|
void setHeader(const std::string&);
|
||||||
|
void setVerbose(bool verbose);
|
||||||
|
std::string getResponse();
|
||||||
|
void send();
|
||||||
|
private:
|
||||||
|
std::string url;
|
||||||
|
std::string method;
|
||||||
|
std::string body;
|
||||||
|
std::string header;
|
||||||
|
std::string response;
|
||||||
|
bool verbose;
|
||||||
|
static size_t writeCallback(char *ptr, size_t size, size_t nmemb, void *userdata);
|
||||||
|
};
|
||||||
|
|
||||||
|
class FileUtilities {
|
||||||
|
public:
|
||||||
|
static std::string readFile(const std::string& path);
|
||||||
|
static void writeFile(const std::string& path, const std::string& content);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //HTTP_LIBRARY_H
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright 2006 Nemanja Trifunovic
|
||||||
|
|
||||||
|
/*
|
||||||
|
Permission is hereby granted, free of charge, to any person or organization
|
||||||
|
obtaining a copy of the software and accompanying documentation covered by
|
||||||
|
this license (the "Software") to use, reproduce, display, distribute,
|
||||||
|
execute, and transmit the Software, and to prepare derivative works of the
|
||||||
|
Software, and to permit third-parties to whom the Software is furnished to
|
||||||
|
do so, all subject to the following:
|
||||||
|
|
||||||
|
The copyright notices in the Software and this entire statement, including
|
||||||
|
the above license grant, this restriction and the following disclaimer,
|
||||||
|
must be included in all copies of the Software, in whole or in part, and
|
||||||
|
all derivative works of the Software, unless such copies or derivative
|
||||||
|
works are solely in the form of machine-executable object code generated by
|
||||||
|
a source language processor.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
|
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
|
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||||
|
#define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||||
|
|
||||||
|
#include "utf8/checked.h"
|
||||||
|
#include "utf8/unchecked.h"
|
||||||
|
|
||||||
|
#endif // header guard
|
|
@ -0,0 +1,335 @@
|
||||||
|
// Copyright 2006-2016 Nemanja Trifunovic
|
||||||
|
|
||||||
|
/*
|
||||||
|
Permission is hereby granted, free of charge, to any person or organization
|
||||||
|
obtaining a copy of the software and accompanying documentation covered by
|
||||||
|
this license (the "Software") to use, reproduce, display, distribute,
|
||||||
|
execute, and transmit the Software, and to prepare derivative works of the
|
||||||
|
Software, and to permit third-parties to whom the Software is furnished to
|
||||||
|
do so, all subject to the following:
|
||||||
|
|
||||||
|
The copyright notices in the Software and this entire statement, including
|
||||||
|
the above license grant, this restriction and the following disclaimer,
|
||||||
|
must be included in all copies of the Software, in whole or in part, and
|
||||||
|
all derivative works of the Software, unless such copies or derivative
|
||||||
|
works are solely in the form of machine-executable object code generated by
|
||||||
|
a source language processor.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
|
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
|
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||||
|
#define UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||||
|
|
||||||
|
#include "core.h"
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace utf8
|
||||||
|
{
|
||||||
|
// Base for the exceptions that may be thrown from the library
|
||||||
|
class exception : public ::std::exception {
|
||||||
|
};
|
||||||
|
|
||||||
|
// Exceptions that may be thrown from the library functions.
|
||||||
|
class invalid_code_point : public exception {
|
||||||
|
uint32_t cp;
|
||||||
|
public:
|
||||||
|
invalid_code_point(uint32_t codepoint) : cp(codepoint) {}
|
||||||
|
virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return "Invalid code point"; }
|
||||||
|
uint32_t code_point() const {return cp;}
|
||||||
|
};
|
||||||
|
|
||||||
|
class invalid_utf8 : public exception {
|
||||||
|
uint8_t u8;
|
||||||
|
public:
|
||||||
|
invalid_utf8 (uint8_t u) : u8(u) {}
|
||||||
|
virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return "Invalid UTF-8"; }
|
||||||
|
uint8_t utf8_octet() const {return u8;}
|
||||||
|
};
|
||||||
|
|
||||||
|
class invalid_utf16 : public exception {
|
||||||
|
uint16_t u16;
|
||||||
|
public:
|
||||||
|
invalid_utf16 (uint16_t u) : u16(u) {}
|
||||||
|
virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return "Invalid UTF-16"; }
|
||||||
|
uint16_t utf16_word() const {return u16;}
|
||||||
|
};
|
||||||
|
|
||||||
|
class not_enough_room : public exception {
|
||||||
|
public:
|
||||||
|
virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return "Not enough space"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
/// The library API - functions intended to be called by the users
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
octet_iterator append(uint32_t cp, octet_iterator result)
|
||||||
|
{
|
||||||
|
if (!utf8::internal::is_code_point_valid(cp))
|
||||||
|
throw invalid_code_point(cp);
|
||||||
|
|
||||||
|
if (cp < 0x80) // one octet
|
||||||
|
*(result++) = static_cast<uint8_t>(cp);
|
||||||
|
else if (cp < 0x800) { // two octets
|
||||||
|
*(result++) = static_cast<uint8_t>((cp >> 6) | 0xc0);
|
||||||
|
*(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
|
||||||
|
}
|
||||||
|
else if (cp < 0x10000) { // three octets
|
||||||
|
*(result++) = static_cast<uint8_t>((cp >> 12) | 0xe0);
|
||||||
|
*(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f) | 0x80);
|
||||||
|
*(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
|
||||||
|
}
|
||||||
|
else { // four octets
|
||||||
|
*(result++) = static_cast<uint8_t>((cp >> 18) | 0xf0);
|
||||||
|
*(result++) = static_cast<uint8_t>(((cp >> 12) & 0x3f) | 0x80);
|
||||||
|
*(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f) | 0x80);
|
||||||
|
*(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator, typename output_iterator>
|
||||||
|
output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, uint32_t replacement)
|
||||||
|
{
|
||||||
|
while (start != end) {
|
||||||
|
octet_iterator sequence_start = start;
|
||||||
|
internal::utf_error err_code = utf8::internal::validate_next(start, end);
|
||||||
|
switch (err_code) {
|
||||||
|
case internal::UTF8_OK :
|
||||||
|
for (octet_iterator it = sequence_start; it != start; ++it)
|
||||||
|
*out++ = *it;
|
||||||
|
break;
|
||||||
|
case internal::NOT_ENOUGH_ROOM:
|
||||||
|
out = utf8::append (replacement, out);
|
||||||
|
start = end;
|
||||||
|
break;
|
||||||
|
case internal::INVALID_LEAD:
|
||||||
|
out = utf8::append (replacement, out);
|
||||||
|
++start;
|
||||||
|
break;
|
||||||
|
case internal::INCOMPLETE_SEQUENCE:
|
||||||
|
case internal::OVERLONG_SEQUENCE:
|
||||||
|
case internal::INVALID_CODE_POINT:
|
||||||
|
out = utf8::append (replacement, out);
|
||||||
|
++start;
|
||||||
|
// just one replacement mark for the sequence
|
||||||
|
while (start != end && utf8::internal::is_trail(*start))
|
||||||
|
++start;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator, typename output_iterator>
|
||||||
|
inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out)
|
||||||
|
{
|
||||||
|
static const uint32_t replacement_marker = utf8::internal::mask16(0xfffd);
|
||||||
|
return utf8::replace_invalid(start, end, out, replacement_marker);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
uint32_t next(octet_iterator& it, octet_iterator end)
|
||||||
|
{
|
||||||
|
uint32_t cp = 0;
|
||||||
|
internal::utf_error err_code = utf8::internal::validate_next(it, end, cp);
|
||||||
|
switch (err_code) {
|
||||||
|
case internal::UTF8_OK :
|
||||||
|
break;
|
||||||
|
case internal::NOT_ENOUGH_ROOM :
|
||||||
|
throw not_enough_room();
|
||||||
|
case internal::INVALID_LEAD :
|
||||||
|
case internal::INCOMPLETE_SEQUENCE :
|
||||||
|
case internal::OVERLONG_SEQUENCE :
|
||||||
|
throw invalid_utf8(*it);
|
||||||
|
case internal::INVALID_CODE_POINT :
|
||||||
|
throw invalid_code_point(cp);
|
||||||
|
}
|
||||||
|
return cp;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
uint32_t peek_next(octet_iterator it, octet_iterator end)
|
||||||
|
{
|
||||||
|
return utf8::next(it, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
uint32_t prior(octet_iterator& it, octet_iterator start)
|
||||||
|
{
|
||||||
|
// can't do much if it == start
|
||||||
|
if (it == start)
|
||||||
|
throw not_enough_room();
|
||||||
|
|
||||||
|
octet_iterator end = it;
|
||||||
|
// Go back until we hit either a lead octet or start
|
||||||
|
while (utf8::internal::is_trail(*(--it)))
|
||||||
|
if (it == start)
|
||||||
|
throw invalid_utf8(*it); // error - no lead byte in the sequence
|
||||||
|
return utf8::peek_next(it, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator, typename distance_type>
|
||||||
|
void advance (octet_iterator& it, distance_type n, octet_iterator end)
|
||||||
|
{
|
||||||
|
const distance_type zero(0);
|
||||||
|
if (n < zero) {
|
||||||
|
// backward
|
||||||
|
for (distance_type i = n; i < zero; ++i)
|
||||||
|
utf8::prior(it, end);
|
||||||
|
} else {
|
||||||
|
// forward
|
||||||
|
for (distance_type i = zero; i < n; ++i)
|
||||||
|
utf8::next(it, end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
typename std::iterator_traits<octet_iterator>::difference_type
|
||||||
|
distance (octet_iterator first, octet_iterator last)
|
||||||
|
{
|
||||||
|
typename std::iterator_traits<octet_iterator>::difference_type dist;
|
||||||
|
for (dist = 0; first < last; ++dist)
|
||||||
|
utf8::next(first, last);
|
||||||
|
return dist;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename u16bit_iterator, typename octet_iterator>
|
||||||
|
octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result)
|
||||||
|
{
|
||||||
|
while (start != end) {
|
||||||
|
uint32_t cp = utf8::internal::mask16(*start++);
|
||||||
|
// Take care of surrogate pairs first
|
||||||
|
if (utf8::internal::is_lead_surrogate(cp)) {
|
||||||
|
if (start != end) {
|
||||||
|
uint32_t trail_surrogate = utf8::internal::mask16(*start++);
|
||||||
|
if (utf8::internal::is_trail_surrogate(trail_surrogate))
|
||||||
|
cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET;
|
||||||
|
else
|
||||||
|
throw invalid_utf16(static_cast<uint16_t>(trail_surrogate));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw invalid_utf16(static_cast<uint16_t>(cp));
|
||||||
|
|
||||||
|
}
|
||||||
|
// Lone trail surrogate
|
||||||
|
else if (utf8::internal::is_trail_surrogate(cp))
|
||||||
|
throw invalid_utf16(static_cast<uint16_t>(cp));
|
||||||
|
|
||||||
|
result = utf8::append(cp, result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename u16bit_iterator, typename octet_iterator>
|
||||||
|
u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)
|
||||||
|
{
|
||||||
|
while (start < end) {
|
||||||
|
uint32_t cp = utf8::next(start, end);
|
||||||
|
if (cp > 0xffff) { //make a surrogate pair
|
||||||
|
*result++ = static_cast<uint16_t>((cp >> 10) + internal::LEAD_OFFSET);
|
||||||
|
*result++ = static_cast<uint16_t>((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*result++ = static_cast<uint16_t>(cp);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator, typename u32bit_iterator>
|
||||||
|
octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result)
|
||||||
|
{
|
||||||
|
while (start != end)
|
||||||
|
result = utf8::append(*(start++), result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator, typename u32bit_iterator>
|
||||||
|
u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
|
||||||
|
{
|
||||||
|
while (start < end)
|
||||||
|
(*result++) = utf8::next(start, end);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The iterator class
|
||||||
|
template <typename octet_iterator>
|
||||||
|
class iterator {
|
||||||
|
octet_iterator it;
|
||||||
|
octet_iterator range_start;
|
||||||
|
octet_iterator range_end;
|
||||||
|
public:
|
||||||
|
typedef uint32_t value_type;
|
||||||
|
typedef uint32_t* pointer;
|
||||||
|
typedef uint32_t& reference;
|
||||||
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
typedef std::bidirectional_iterator_tag iterator_category;
|
||||||
|
iterator () {}
|
||||||
|
explicit iterator (const octet_iterator& octet_it,
|
||||||
|
const octet_iterator& rangestart,
|
||||||
|
const octet_iterator& rangeend) :
|
||||||
|
it(octet_it), range_start(rangestart), range_end(rangeend)
|
||||||
|
{
|
||||||
|
if (it < range_start || it > range_end)
|
||||||
|
throw std::out_of_range("Invalid utf-8 iterator position");
|
||||||
|
}
|
||||||
|
// the default "big three" are OK
|
||||||
|
octet_iterator base () const { return it; }
|
||||||
|
uint32_t operator * () const
|
||||||
|
{
|
||||||
|
octet_iterator temp = it;
|
||||||
|
return utf8::next(temp, range_end);
|
||||||
|
}
|
||||||
|
bool operator == (const iterator& rhs) const
|
||||||
|
{
|
||||||
|
if (range_start != rhs.range_start || range_end != rhs.range_end)
|
||||||
|
throw std::logic_error("Comparing utf-8 iterators defined with different ranges");
|
||||||
|
return (it == rhs.it);
|
||||||
|
}
|
||||||
|
bool operator != (const iterator& rhs) const
|
||||||
|
{
|
||||||
|
return !(operator == (rhs));
|
||||||
|
}
|
||||||
|
iterator& operator ++ ()
|
||||||
|
{
|
||||||
|
utf8::next(it, range_end);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
iterator operator ++ (int)
|
||||||
|
{
|
||||||
|
iterator temp = *this;
|
||||||
|
utf8::next(it, range_end);
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
iterator& operator -- ()
|
||||||
|
{
|
||||||
|
utf8::prior(it, range_start);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
iterator operator -- (int)
|
||||||
|
{
|
||||||
|
iterator temp = *this;
|
||||||
|
utf8::prior(it, range_start);
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
}; // class iterator
|
||||||
|
|
||||||
|
} // namespace utf8
|
||||||
|
|
||||||
|
#if UTF_CPP_CPLUSPLUS >= 201703L // C++ 17 or later
|
||||||
|
#include "cpp17.h"
|
||||||
|
#elif UTF_CPP_CPLUSPLUS >= 201103L // C++ 11 or later
|
||||||
|
#include "cpp11.h"
|
||||||
|
#endif // C++ 11 or later
|
||||||
|
|
||||||
|
#endif //header guard
|
||||||
|
|
|
@ -0,0 +1,338 @@
|
||||||
|
// Copyright 2006 Nemanja Trifunovic
|
||||||
|
|
||||||
|
/*
|
||||||
|
Permission is hereby granted, free of charge, to any person or organization
|
||||||
|
obtaining a copy of the software and accompanying documentation covered by
|
||||||
|
this license (the "Software") to use, reproduce, display, distribute,
|
||||||
|
execute, and transmit the Software, and to prepare derivative works of the
|
||||||
|
Software, and to permit third-parties to whom the Software is furnished to
|
||||||
|
do so, all subject to the following:
|
||||||
|
|
||||||
|
The copyright notices in the Software and this entire statement, including
|
||||||
|
the above license grant, this restriction and the following disclaimer,
|
||||||
|
must be included in all copies of the Software, in whole or in part, and
|
||||||
|
all derivative works of the Software, unless such copies or derivative
|
||||||
|
works are solely in the form of machine-executable object code generated by
|
||||||
|
a source language processor.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
|
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
|
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||||
|
#define UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||||
|
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
// Determine the C++ standard version.
|
||||||
|
// If the user defines UTF_CPP_CPLUSPLUS, use that.
|
||||||
|
// Otherwise, trust the unreliable predefined macro __cplusplus
|
||||||
|
|
||||||
|
#if !defined UTF_CPP_CPLUSPLUS
|
||||||
|
#define UTF_CPP_CPLUSPLUS __cplusplus
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if UTF_CPP_CPLUSPLUS >= 201103L // C++ 11 or later
|
||||||
|
#define UTF_CPP_OVERRIDE override
|
||||||
|
#define UTF_CPP_NOEXCEPT noexcept
|
||||||
|
#else // C++ 98/03
|
||||||
|
#define UTF_CPP_OVERRIDE
|
||||||
|
#define UTF_CPP_NOEXCEPT throw()
|
||||||
|
#endif // C++ 11 or later
|
||||||
|
|
||||||
|
|
||||||
|
namespace utf8
|
||||||
|
{
|
||||||
|
// The typedefs for 8-bit, 16-bit and 32-bit unsigned integers
|
||||||
|
// You may need to change them to match your system.
|
||||||
|
// These typedefs have the same names as ones from cstdint, or boost/cstdint
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
typedef unsigned short uint16_t;
|
||||||
|
typedef unsigned int uint32_t;
|
||||||
|
|
||||||
|
// Helper code - not intended to be directly called by the library users. May be changed at any time
|
||||||
|
namespace internal
|
||||||
|
{
|
||||||
|
// Unicode constants
|
||||||
|
// Leading (high) surrogates: 0xd800 - 0xdbff
|
||||||
|
// Trailing (low) surrogates: 0xdc00 - 0xdfff
|
||||||
|
const uint16_t LEAD_SURROGATE_MIN = 0xd800u;
|
||||||
|
const uint16_t LEAD_SURROGATE_MAX = 0xdbffu;
|
||||||
|
const uint16_t TRAIL_SURROGATE_MIN = 0xdc00u;
|
||||||
|
const uint16_t TRAIL_SURROGATE_MAX = 0xdfffu;
|
||||||
|
const uint16_t LEAD_OFFSET = 0xd7c0u; // LEAD_SURROGATE_MIN - (0x10000 >> 10)
|
||||||
|
const uint32_t SURROGATE_OFFSET = 0xfca02400u; // 0x10000u - (LEAD_SURROGATE_MIN << 10) - TRAIL_SURROGATE_MIN
|
||||||
|
|
||||||
|
// Maximum valid value for a Unicode code point
|
||||||
|
const uint32_t CODE_POINT_MAX = 0x0010ffffu;
|
||||||
|
|
||||||
|
template<typename octet_type>
|
||||||
|
inline uint8_t mask8(octet_type oc)
|
||||||
|
{
|
||||||
|
return static_cast<uint8_t>(0xff & oc);
|
||||||
|
}
|
||||||
|
template<typename u16_type>
|
||||||
|
inline uint16_t mask16(u16_type oc)
|
||||||
|
{
|
||||||
|
return static_cast<uint16_t>(0xffff & oc);
|
||||||
|
}
|
||||||
|
template<typename octet_type>
|
||||||
|
inline bool is_trail(octet_type oc)
|
||||||
|
{
|
||||||
|
return ((utf8::internal::mask8(oc) >> 6) == 0x2);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename u16>
|
||||||
|
inline bool is_lead_surrogate(u16 cp)
|
||||||
|
{
|
||||||
|
return (cp >= LEAD_SURROGATE_MIN && cp <= LEAD_SURROGATE_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename u16>
|
||||||
|
inline bool is_trail_surrogate(u16 cp)
|
||||||
|
{
|
||||||
|
return (cp >= TRAIL_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename u16>
|
||||||
|
inline bool is_surrogate(u16 cp)
|
||||||
|
{
|
||||||
|
return (cp >= LEAD_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename u32>
|
||||||
|
inline bool is_code_point_valid(u32 cp)
|
||||||
|
{
|
||||||
|
return (cp <= CODE_POINT_MAX && !utf8::internal::is_surrogate(cp));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
inline typename std::iterator_traits<octet_iterator>::difference_type
|
||||||
|
sequence_length(octet_iterator lead_it)
|
||||||
|
{
|
||||||
|
uint8_t lead = utf8::internal::mask8(*lead_it);
|
||||||
|
if (lead < 0x80)
|
||||||
|
return 1;
|
||||||
|
else if ((lead >> 5) == 0x6)
|
||||||
|
return 2;
|
||||||
|
else if ((lead >> 4) == 0xe)
|
||||||
|
return 3;
|
||||||
|
else if ((lead >> 3) == 0x1e)
|
||||||
|
return 4;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_difference_type>
|
||||||
|
inline bool is_overlong_sequence(uint32_t cp, octet_difference_type length)
|
||||||
|
{
|
||||||
|
if (cp < 0x80) {
|
||||||
|
if (length != 1)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (cp < 0x800) {
|
||||||
|
if (length != 2)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (cp < 0x10000) {
|
||||||
|
if (length != 3)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum utf_error {UTF8_OK, NOT_ENOUGH_ROOM, INVALID_LEAD, INCOMPLETE_SEQUENCE, OVERLONG_SEQUENCE, INVALID_CODE_POINT};
|
||||||
|
|
||||||
|
/// Helper for get_sequence_x
|
||||||
|
template <typename octet_iterator>
|
||||||
|
utf_error increase_safely(octet_iterator& it, octet_iterator end)
|
||||||
|
{
|
||||||
|
if (++it == end)
|
||||||
|
return NOT_ENOUGH_ROOM;
|
||||||
|
|
||||||
|
if (!utf8::internal::is_trail(*it))
|
||||||
|
return INCOMPLETE_SEQUENCE;
|
||||||
|
|
||||||
|
return UTF8_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(IT, END) {utf_error ret = increase_safely(IT, END); if (ret != UTF8_OK) return ret;}
|
||||||
|
|
||||||
|
/// get_sequence_x functions decode utf-8 sequences of the length x
|
||||||
|
template <typename octet_iterator>
|
||||||
|
utf_error get_sequence_1(octet_iterator& it, octet_iterator end, uint32_t& code_point)
|
||||||
|
{
|
||||||
|
if (it == end)
|
||||||
|
return NOT_ENOUGH_ROOM;
|
||||||
|
|
||||||
|
code_point = utf8::internal::mask8(*it);
|
||||||
|
|
||||||
|
return UTF8_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
utf_error get_sequence_2(octet_iterator& it, octet_iterator end, uint32_t& code_point)
|
||||||
|
{
|
||||||
|
if (it == end)
|
||||||
|
return NOT_ENOUGH_ROOM;
|
||||||
|
|
||||||
|
code_point = utf8::internal::mask8(*it);
|
||||||
|
|
||||||
|
UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
|
||||||
|
|
||||||
|
code_point = ((code_point << 6) & 0x7ff) + ((*it) & 0x3f);
|
||||||
|
|
||||||
|
return UTF8_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
utf_error get_sequence_3(octet_iterator& it, octet_iterator end, uint32_t& code_point)
|
||||||
|
{
|
||||||
|
if (it == end)
|
||||||
|
return NOT_ENOUGH_ROOM;
|
||||||
|
|
||||||
|
code_point = utf8::internal::mask8(*it);
|
||||||
|
|
||||||
|
UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
|
||||||
|
|
||||||
|
code_point = ((code_point << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff);
|
||||||
|
|
||||||
|
UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
|
||||||
|
|
||||||
|
code_point += (*it) & 0x3f;
|
||||||
|
|
||||||
|
return UTF8_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
utf_error get_sequence_4(octet_iterator& it, octet_iterator end, uint32_t& code_point)
|
||||||
|
{
|
||||||
|
if (it == end)
|
||||||
|
return NOT_ENOUGH_ROOM;
|
||||||
|
|
||||||
|
code_point = utf8::internal::mask8(*it);
|
||||||
|
|
||||||
|
UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
|
||||||
|
|
||||||
|
code_point = ((code_point << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff);
|
||||||
|
|
||||||
|
UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
|
||||||
|
|
||||||
|
code_point += (utf8::internal::mask8(*it) << 6) & 0xfff;
|
||||||
|
|
||||||
|
UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
|
||||||
|
|
||||||
|
code_point += (*it) & 0x3f;
|
||||||
|
|
||||||
|
return UTF8_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
utf_error validate_next(octet_iterator& it, octet_iterator end, uint32_t& code_point)
|
||||||
|
{
|
||||||
|
if (it == end)
|
||||||
|
return NOT_ENOUGH_ROOM;
|
||||||
|
|
||||||
|
// Save the original value of it so we can go back in case of failure
|
||||||
|
// Of course, it does not make much sense with i.e. stream iterators
|
||||||
|
octet_iterator original_it = it;
|
||||||
|
|
||||||
|
uint32_t cp = 0;
|
||||||
|
// Determine the sequence length based on the lead octet
|
||||||
|
typedef typename std::iterator_traits<octet_iterator>::difference_type octet_difference_type;
|
||||||
|
const octet_difference_type length = utf8::internal::sequence_length(it);
|
||||||
|
|
||||||
|
// Get trail octets and calculate the code point
|
||||||
|
utf_error err = UTF8_OK;
|
||||||
|
switch (length) {
|
||||||
|
case 0:
|
||||||
|
return INVALID_LEAD;
|
||||||
|
case 1:
|
||||||
|
err = utf8::internal::get_sequence_1(it, end, cp);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
err = utf8::internal::get_sequence_2(it, end, cp);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
err = utf8::internal::get_sequence_3(it, end, cp);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
err = utf8::internal::get_sequence_4(it, end, cp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err == UTF8_OK) {
|
||||||
|
// Decoding succeeded. Now, security checks...
|
||||||
|
if (utf8::internal::is_code_point_valid(cp)) {
|
||||||
|
if (!utf8::internal::is_overlong_sequence(cp, length)){
|
||||||
|
// Passed! Return here.
|
||||||
|
code_point = cp;
|
||||||
|
++it;
|
||||||
|
return UTF8_OK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
err = OVERLONG_SEQUENCE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
err = INVALID_CODE_POINT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Failure branch - restore the original value of the iterator
|
||||||
|
it = original_it;
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
inline utf_error validate_next(octet_iterator& it, octet_iterator end) {
|
||||||
|
uint32_t ignored;
|
||||||
|
return utf8::internal::validate_next(it, end, ignored);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
/// The library API - functions intended to be called by the users
|
||||||
|
|
||||||
|
// Byte order mark
|
||||||
|
const uint8_t bom[] = {0xef, 0xbb, 0xbf};
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
octet_iterator find_invalid(octet_iterator start, octet_iterator end)
|
||||||
|
{
|
||||||
|
octet_iterator result = start;
|
||||||
|
while (result != end) {
|
||||||
|
utf8::internal::utf_error err_code = utf8::internal::validate_next(result, end);
|
||||||
|
if (err_code != internal::UTF8_OK)
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
inline bool is_valid(octet_iterator start, octet_iterator end)
|
||||||
|
{
|
||||||
|
return (utf8::find_invalid(start, end) == end);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
inline bool starts_with_bom (octet_iterator it, octet_iterator end)
|
||||||
|
{
|
||||||
|
return (
|
||||||
|
((it != end) && (utf8::internal::mask8(*it++)) == bom[0]) &&
|
||||||
|
((it != end) && (utf8::internal::mask8(*it++)) == bom[1]) &&
|
||||||
|
((it != end) && (utf8::internal::mask8(*it)) == bom[2])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} // namespace utf8
|
||||||
|
|
||||||
|
#endif // header guard
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
// Copyright 2018 Nemanja Trifunovic
|
||||||
|
|
||||||
|
/*
|
||||||
|
Permission is hereby granted, free of charge, to any person or organization
|
||||||
|
obtaining a copy of the software and accompanying documentation covered by
|
||||||
|
this license (the "Software") to use, reproduce, display, distribute,
|
||||||
|
execute, and transmit the Software, and to prepare derivative works of the
|
||||||
|
Software, and to permit third-parties to whom the Software is furnished to
|
||||||
|
do so, all subject to the following:
|
||||||
|
|
||||||
|
The copyright notices in the Software and this entire statement, including
|
||||||
|
the above license grant, this restriction and the following disclaimer,
|
||||||
|
must be included in all copies of the Software, in whole or in part, and
|
||||||
|
all derivative works of the Software, unless such copies or derivative
|
||||||
|
works are solely in the form of machine-executable object code generated by
|
||||||
|
a source language processor.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
|
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
|
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef UTF8_FOR_CPP_a184c22c_d012_11e8_a8d5_f2801f1b9fd1
|
||||||
|
#define UTF8_FOR_CPP_a184c22c_d012_11e8_a8d5_f2801f1b9fd1
|
||||||
|
|
||||||
|
#include "checked.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace utf8
|
||||||
|
{
|
||||||
|
|
||||||
|
inline void append(char32_t cp, std::string& s)
|
||||||
|
{
|
||||||
|
append(uint32_t(cp), std::back_inserter(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string utf16to8(const std::u16string& s)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
utf16to8(s.begin(), s.end(), std::back_inserter(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::u16string utf8to16(const std::string& s)
|
||||||
|
{
|
||||||
|
std::u16string result;
|
||||||
|
utf8to16(s.begin(), s.end(), std::back_inserter(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string utf32to8(const std::u32string& s)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
utf32to8(s.begin(), s.end(), std::back_inserter(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::u32string utf8to32(const std::string& s)
|
||||||
|
{
|
||||||
|
std::u32string result;
|
||||||
|
utf8to32(s.begin(), s.end(), std::back_inserter(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::size_t find_invalid(const std::string& s)
|
||||||
|
{
|
||||||
|
std::string::const_iterator invalid = find_invalid(s.begin(), s.end());
|
||||||
|
return (invalid == s.end()) ? std::string::npos : (invalid - s.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool is_valid(const std::string& s)
|
||||||
|
{
|
||||||
|
return is_valid(s.begin(), s.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string replace_invalid(const std::string& s, char32_t replacement)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
replace_invalid(s.begin(), s.end(), std::back_inserter(result), replacement);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string replace_invalid(const std::string& s)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
replace_invalid(s.begin(), s.end(), std::back_inserter(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool starts_with_bom(const std::string& s)
|
||||||
|
{
|
||||||
|
return starts_with_bom(s.begin(), s.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace utf8
|
||||||
|
|
||||||
|
#endif // header guard
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
// Copyright 2018 Nemanja Trifunovic
|
||||||
|
|
||||||
|
/*
|
||||||
|
Permission is hereby granted, free of charge, to any person or organization
|
||||||
|
obtaining a copy of the software and accompanying documentation covered by
|
||||||
|
this license (the "Software") to use, reproduce, display, distribute,
|
||||||
|
execute, and transmit the Software, and to prepare derivative works of the
|
||||||
|
Software, and to permit third-parties to whom the Software is furnished to
|
||||||
|
do so, all subject to the following:
|
||||||
|
|
||||||
|
The copyright notices in the Software and this entire statement, including
|
||||||
|
the above license grant, this restriction and the following disclaimer,
|
||||||
|
must be included in all copies of the Software, in whole or in part, and
|
||||||
|
all derivative works of the Software, unless such copies or derivative
|
||||||
|
works are solely in the form of machine-executable object code generated by
|
||||||
|
a source language processor.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
|
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
|
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef UTF8_FOR_CPP_7e906c01_03a3_4daf_b420_ea7ea952b3c9
|
||||||
|
#define UTF8_FOR_CPP_7e906c01_03a3_4daf_b420_ea7ea952b3c9
|
||||||
|
|
||||||
|
#include "checked.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace utf8
|
||||||
|
{
|
||||||
|
|
||||||
|
inline void append(char32_t cp, std::string& s)
|
||||||
|
{
|
||||||
|
append(uint32_t(cp), std::back_inserter(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string utf16to8(std::u16string_view s)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
utf16to8(s.begin(), s.end(), std::back_inserter(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::u16string utf8to16(std::string_view s)
|
||||||
|
{
|
||||||
|
std::u16string result;
|
||||||
|
utf8to16(s.begin(), s.end(), std::back_inserter(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string utf32to8(std::u32string_view s)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
utf32to8(s.begin(), s.end(), std::back_inserter(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::u32string utf8to32(std::string_view s)
|
||||||
|
{
|
||||||
|
std::u32string result;
|
||||||
|
utf8to32(s.begin(), s.end(), std::back_inserter(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::size_t find_invalid(std::string_view s)
|
||||||
|
{
|
||||||
|
std::string_view::const_iterator invalid = find_invalid(s.begin(), s.end());
|
||||||
|
return (invalid == s.end()) ? std::string_view::npos : (invalid - s.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool is_valid(std::string_view s)
|
||||||
|
{
|
||||||
|
return is_valid(s.begin(), s.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string replace_invalid(std::string_view s, char32_t replacement)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
replace_invalid(s.begin(), s.end(), std::back_inserter(result), replacement);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string replace_invalid(std::string_view s)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
replace_invalid(s.begin(), s.end(), std::back_inserter(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool starts_with_bom(std::string_view s)
|
||||||
|
{
|
||||||
|
return starts_with_bom(s.begin(), s.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace utf8
|
||||||
|
|
||||||
|
#endif // header guard
|
||||||
|
|
|
@ -0,0 +1,274 @@
|
||||||
|
// Copyright 2006 Nemanja Trifunovic
|
||||||
|
|
||||||
|
/*
|
||||||
|
Permission is hereby granted, free of charge, to any person or organization
|
||||||
|
obtaining a copy of the software and accompanying documentation covered by
|
||||||
|
this license (the "Software") to use, reproduce, display, distribute,
|
||||||
|
execute, and transmit the Software, and to prepare derivative works of the
|
||||||
|
Software, and to permit third-parties to whom the Software is furnished to
|
||||||
|
do so, all subject to the following:
|
||||||
|
|
||||||
|
The copyright notices in the Software and this entire statement, including
|
||||||
|
the above license grant, this restriction and the following disclaimer,
|
||||||
|
must be included in all copies of the Software, in whole or in part, and
|
||||||
|
all derivative works of the Software, unless such copies or derivative
|
||||||
|
works are solely in the form of machine-executable object code generated by
|
||||||
|
a source language processor.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
|
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
|
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||||
|
#define UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||||
|
|
||||||
|
#include "core.h"
|
||||||
|
|
||||||
|
namespace utf8
|
||||||
|
{
|
||||||
|
namespace unchecked
|
||||||
|
{
|
||||||
|
template <typename octet_iterator>
|
||||||
|
octet_iterator append(uint32_t cp, octet_iterator result)
|
||||||
|
{
|
||||||
|
if (cp < 0x80) // one octet
|
||||||
|
*(result++) = static_cast<uint8_t>(cp);
|
||||||
|
else if (cp < 0x800) { // two octets
|
||||||
|
*(result++) = static_cast<uint8_t>((cp >> 6) | 0xc0);
|
||||||
|
*(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
|
||||||
|
}
|
||||||
|
else if (cp < 0x10000) { // three octets
|
||||||
|
*(result++) = static_cast<uint8_t>((cp >> 12) | 0xe0);
|
||||||
|
*(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f) | 0x80);
|
||||||
|
*(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
|
||||||
|
}
|
||||||
|
else { // four octets
|
||||||
|
*(result++) = static_cast<uint8_t>((cp >> 18) | 0xf0);
|
||||||
|
*(result++) = static_cast<uint8_t>(((cp >> 12) & 0x3f)| 0x80);
|
||||||
|
*(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f) | 0x80);
|
||||||
|
*(result++) = static_cast<uint8_t>((cp & 0x3f) | 0x80);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator, typename output_iterator>
|
||||||
|
output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, uint32_t replacement)
|
||||||
|
{
|
||||||
|
while (start != end) {
|
||||||
|
octet_iterator sequence_start = start;
|
||||||
|
internal::utf_error err_code = utf8::internal::validate_next(start, end);
|
||||||
|
switch (err_code) {
|
||||||
|
case internal::UTF8_OK :
|
||||||
|
for (octet_iterator it = sequence_start; it != start; ++it)
|
||||||
|
*out++ = *it;
|
||||||
|
break;
|
||||||
|
case internal::NOT_ENOUGH_ROOM:
|
||||||
|
out = utf8::unchecked::append (replacement, out);
|
||||||
|
start = end;
|
||||||
|
break;
|
||||||
|
case internal::INVALID_LEAD:
|
||||||
|
out = utf8::unchecked::append (replacement, out);
|
||||||
|
++start;
|
||||||
|
break;
|
||||||
|
case internal::INCOMPLETE_SEQUENCE:
|
||||||
|
case internal::OVERLONG_SEQUENCE:
|
||||||
|
case internal::INVALID_CODE_POINT:
|
||||||
|
out = utf8::unchecked::append (replacement, out);
|
||||||
|
++start;
|
||||||
|
// just one replacement mark for the sequence
|
||||||
|
while (start != end && utf8::internal::is_trail(*start))
|
||||||
|
++start;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator, typename output_iterator>
|
||||||
|
inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out)
|
||||||
|
{
|
||||||
|
static const uint32_t replacement_marker = utf8::internal::mask16(0xfffd);
|
||||||
|
return utf8::unchecked::replace_invalid(start, end, out, replacement_marker);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
uint32_t next(octet_iterator& it)
|
||||||
|
{
|
||||||
|
uint32_t cp = utf8::internal::mask8(*it);
|
||||||
|
typename std::iterator_traits<octet_iterator>::difference_type length = utf8::internal::sequence_length(it);
|
||||||
|
switch (length) {
|
||||||
|
case 1:
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
it++;
|
||||||
|
cp = ((cp << 6) & 0x7ff) + ((*it) & 0x3f);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
++it;
|
||||||
|
cp = ((cp << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff);
|
||||||
|
++it;
|
||||||
|
cp += (*it) & 0x3f;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
++it;
|
||||||
|
cp = ((cp << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff);
|
||||||
|
++it;
|
||||||
|
cp += (utf8::internal::mask8(*it) << 6) & 0xfff;
|
||||||
|
++it;
|
||||||
|
cp += (*it) & 0x3f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++it;
|
||||||
|
return cp;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
uint32_t peek_next(octet_iterator it)
|
||||||
|
{
|
||||||
|
return utf8::unchecked::next(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
uint32_t prior(octet_iterator& it)
|
||||||
|
{
|
||||||
|
while (utf8::internal::is_trail(*(--it))) ;
|
||||||
|
octet_iterator temp = it;
|
||||||
|
return utf8::unchecked::next(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator, typename distance_type>
|
||||||
|
void advance (octet_iterator& it, distance_type n)
|
||||||
|
{
|
||||||
|
const distance_type zero(0);
|
||||||
|
if (n < zero) {
|
||||||
|
// backward
|
||||||
|
for (distance_type i = n; i < zero; ++i)
|
||||||
|
utf8::unchecked::prior(it);
|
||||||
|
} else {
|
||||||
|
// forward
|
||||||
|
for (distance_type i = zero; i < n; ++i)
|
||||||
|
utf8::unchecked::next(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator>
|
||||||
|
typename std::iterator_traits<octet_iterator>::difference_type
|
||||||
|
distance (octet_iterator first, octet_iterator last)
|
||||||
|
{
|
||||||
|
typename std::iterator_traits<octet_iterator>::difference_type dist;
|
||||||
|
for (dist = 0; first < last; ++dist)
|
||||||
|
utf8::unchecked::next(first);
|
||||||
|
return dist;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename u16bit_iterator, typename octet_iterator>
|
||||||
|
octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result)
|
||||||
|
{
|
||||||
|
while (start != end) {
|
||||||
|
uint32_t cp = utf8::internal::mask16(*start++);
|
||||||
|
// Take care of surrogate pairs first
|
||||||
|
if (utf8::internal::is_lead_surrogate(cp)) {
|
||||||
|
uint32_t trail_surrogate = utf8::internal::mask16(*start++);
|
||||||
|
cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET;
|
||||||
|
}
|
||||||
|
result = utf8::unchecked::append(cp, result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename u16bit_iterator, typename octet_iterator>
|
||||||
|
u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)
|
||||||
|
{
|
||||||
|
while (start < end) {
|
||||||
|
uint32_t cp = utf8::unchecked::next(start);
|
||||||
|
if (cp > 0xffff) { //make a surrogate pair
|
||||||
|
*result++ = static_cast<uint16_t>((cp >> 10) + internal::LEAD_OFFSET);
|
||||||
|
*result++ = static_cast<uint16_t>((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*result++ = static_cast<uint16_t>(cp);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator, typename u32bit_iterator>
|
||||||
|
octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result)
|
||||||
|
{
|
||||||
|
while (start != end)
|
||||||
|
result = utf8::unchecked::append(*(start++), result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename octet_iterator, typename u32bit_iterator>
|
||||||
|
u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
|
||||||
|
{
|
||||||
|
while (start < end)
|
||||||
|
(*result++) = utf8::unchecked::next(start);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The iterator class
|
||||||
|
template <typename octet_iterator>
|
||||||
|
class iterator {
|
||||||
|
octet_iterator it;
|
||||||
|
public:
|
||||||
|
typedef uint32_t value_type;
|
||||||
|
typedef uint32_t* pointer;
|
||||||
|
typedef uint32_t& reference;
|
||||||
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
typedef std::bidirectional_iterator_tag iterator_category;
|
||||||
|
iterator () {}
|
||||||
|
explicit iterator (const octet_iterator& octet_it): it(octet_it) {}
|
||||||
|
// the default "big three" are OK
|
||||||
|
octet_iterator base () const { return it; }
|
||||||
|
uint32_t operator * () const
|
||||||
|
{
|
||||||
|
octet_iterator temp = it;
|
||||||
|
return utf8::unchecked::next(temp);
|
||||||
|
}
|
||||||
|
bool operator == (const iterator& rhs) const
|
||||||
|
{
|
||||||
|
return (it == rhs.it);
|
||||||
|
}
|
||||||
|
bool operator != (const iterator& rhs) const
|
||||||
|
{
|
||||||
|
return !(operator == (rhs));
|
||||||
|
}
|
||||||
|
iterator& operator ++ ()
|
||||||
|
{
|
||||||
|
::std::advance(it, utf8::internal::sequence_length(it));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
iterator operator ++ (int)
|
||||||
|
{
|
||||||
|
iterator temp = *this;
|
||||||
|
::std::advance(it, utf8::internal::sequence_length(it));
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
iterator& operator -- ()
|
||||||
|
{
|
||||||
|
utf8::unchecked::prior(it);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
iterator operator -- (int)
|
||||||
|
{
|
||||||
|
iterator temp = *this;
|
||||||
|
utf8::unchecked::prior(it);
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
}; // class iterator
|
||||||
|
|
||||||
|
} // namespace utf8::unchecked
|
||||||
|
} // namespace utf8
|
||||||
|
|
||||||
|
|
||||||
|
#endif // header guard
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,322 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Lucas' Bot.
|
||||||
|
*
|
||||||
|
* Lucas' Bot is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
|
||||||
|
Lucas' Bot is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along
|
||||||
|
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <MiraiCP.hpp>
|
||||||
|
#include "InstructionProcessor.h"
|
||||||
|
#include "PersonCollection.h"
|
||||||
|
#include <http.h>
|
||||||
|
#include <regex>
|
||||||
|
#include <RandomLibrary.h>
|
||||||
|
#include <windef.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取临时文件名
|
||||||
|
* @param suffix 文件后缀
|
||||||
|
* @return 包含临时文件名的字符串
|
||||||
|
*/
|
||||||
|
std::string getTemporaryFileName(const std::string &suffix) {
|
||||||
|
char s[1024];
|
||||||
|
// Windows 系统逻辑
|
||||||
|
#ifdef WIN32
|
||||||
|
// 获得临时文件的目录
|
||||||
|
FILE *fp = _popen("echo %temp%", "r");
|
||||||
|
fscanf(fp, "%s", s);
|
||||||
|
_pclose(fp);
|
||||||
|
// 将临时文件名附加在目录上,然后返回
|
||||||
|
sprintf(s, "%s\\%d.%s", s, RandomLibrary::getNextRandomNumber(
|
||||||
|
RandomLibrary::RandomNumberType::UniformDistribution,
|
||||||
|
0, RAND_MAX), suffix.c_str());
|
||||||
|
#else
|
||||||
|
// 类UNIX系统逻辑,类似于Windows系统
|
||||||
|
FILE *fp = popen("echo $TMPDIR", "r");
|
||||||
|
fscanf(fp, "%s", s);
|
||||||
|
pclose(fp);
|
||||||
|
sprintf(s, "%s/%d.%s", s, RandomLibrary::getNextRandomNumber(
|
||||||
|
RandomLibrary::RandomNumberType::UniformDistribution,
|
||||||
|
0, RAND_MAX), suffix.c_str());
|
||||||
|
#endif
|
||||||
|
return std::string{s};
|
||||||
|
}
|
||||||
|
|
||||||
|
void InstructionProcessor::repeat(const MessageDispatcher::SingleInstruction &instruction) {
|
||||||
|
// 获得消息来源所在QQ群
|
||||||
|
auto group = instruction.event.group;
|
||||||
|
// 如果参数为空,则提醒用户输入参数
|
||||||
|
if (instruction.arguments.empty()) {
|
||||||
|
group.quoteAndSendMessage(MiraiCP::PlainText("复读什么呢?"),
|
||||||
|
instruction.event.message.source.value());
|
||||||
|
} else {
|
||||||
|
// 连接参数vector中所有字符串为长字符串
|
||||||
|
// 使用空格分隔
|
||||||
|
std::string message;
|
||||||
|
for (const auto &argument : instruction.arguments) {
|
||||||
|
message += argument;
|
||||||
|
message += " ";
|
||||||
|
}
|
||||||
|
// 去除末尾空格
|
||||||
|
message.pop_back();
|
||||||
|
// 复读
|
||||||
|
group.sendMessage(MiraiCP::PlainText(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InstructionProcessor::commercialAccount(const MessageDispatcher::SingleInstruction &instruction) {
|
||||||
|
char s[1024];
|
||||||
|
auto group = instruction.event.group;
|
||||||
|
if (instruction.arguments.empty()) {
|
||||||
|
group.sendMessage(MiraiCP::PlainText("请输入事物"));
|
||||||
|
} else {
|
||||||
|
switch (instruction.arguments.size()) {
|
||||||
|
case 1:
|
||||||
|
sprintf(s, "大家好,这里是琪露诺看世界,今天小编带大家了解%s。%s是怎么一回事?"
|
||||||
|
"%s是什么梗?%s最近为什么这么火呢?\n"
|
||||||
|
" 大家都知道,%s最近很火,究竟是为什么很火呢?%s到底是什么梗?"
|
||||||
|
"相信大家对%s都很熟悉,%s就是我们每天都会经常遇到的,但是%s是怎么回事呢?"
|
||||||
|
"今天小编就带大家来看看究竟是怎么一回事。\n"
|
||||||
|
" %s最近能火,其实就是%s受到了大家的关注。大家可能会感到很惊讶,%s为什么是这样的?"
|
||||||
|
"%s究竟为什么火起来了呢?但事实就是这样,小编也感到非常惊讶。\n"
|
||||||
|
" 希望小编精心整理的这篇内容能够帮助到你,本期教学结束了,希望这篇文章能对你有所帮助,大家有什么想法,可以在下方评论区给小编留言。",
|
||||||
|
instruction.arguments[0].c_str(), instruction.arguments[0].c_str(),
|
||||||
|
instruction.arguments[0].c_str(), instruction.arguments[0].c_str(),
|
||||||
|
instruction.arguments[0].c_str(), instruction.arguments[0].c_str(),
|
||||||
|
instruction.arguments[0].c_str(), instruction.arguments[0].c_str(), instruction.arguments[0].c_str(),
|
||||||
|
instruction.arguments[0].c_str(),instruction.arguments[0].c_str(), instruction.arguments[0].c_str(),
|
||||||
|
instruction.arguments[0].c_str());
|
||||||
|
group.sendMessage(MiraiCP::PlainText(std::string{s}));
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
sprintf(s, " 大家好,这里是琪露诺看世界,今天小编带大家了解%s。%s到底是怎么一回事呢?让我们一起来看看吧。\n"
|
||||||
|
" 说起%s,相信大家一定很熟悉,但%s是什么呢?就让小编带大家一起了解吧。\n"
|
||||||
|
" 其实,%s就是%s,"
|
||||||
|
"大家可能会惊讶,%s竟然就是%s!\n"
|
||||||
|
" 这就是今天关于%s的全部内容了,不知道大家有什么想法呢?欢迎在屏幕下方留言哦",
|
||||||
|
instruction.arguments[0].c_str(), instruction.arguments[0].c_str(),
|
||||||
|
instruction.arguments[0].c_str(), instruction.arguments[1].c_str(),
|
||||||
|
instruction.arguments[0].c_str(), instruction.arguments[1].c_str(),
|
||||||
|
instruction.arguments[0].c_str(), instruction.arguments[1].c_str(),
|
||||||
|
instruction.arguments[0].c_str());
|
||||||
|
group.sendMessage(MiraiCP::PlainText(std::string{s}));
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
sprintf(s, " 大家好,这里是琪露诺看世界,今天小编带大家了解%s%s,"
|
||||||
|
"%s%s是怎么回事呢?"
|
||||||
|
"%s相信大家都很熟悉,但是%s%s是怎么回事呢,下面就让小编带大家一起了解吧。\n"
|
||||||
|
" %s%s,其实就是%s,"
|
||||||
|
"大家可能会很惊讶%s怎么会%s?但事实就是这样,小编也感到非常惊讶。\n"
|
||||||
|
" 这就是关于%s%s的事情了,大家有什么想法呢,欢迎在评论区告诉小编一起讨论哦!",
|
||||||
|
instruction.arguments[0].c_str(), instruction.arguments[1].c_str(),
|
||||||
|
instruction.arguments[0].c_str(), instruction.arguments[1].c_str(),
|
||||||
|
instruction.arguments[0].c_str(), instruction.arguments[0].c_str(), instruction.arguments[1].c_str(),
|
||||||
|
instruction.arguments[0].c_str(), instruction.arguments[1].c_str(), instruction.arguments[2].c_str(),
|
||||||
|
instruction.arguments[0].c_str(), instruction.arguments[1].c_str(),
|
||||||
|
instruction.arguments[0].c_str(), instruction.arguments[1].c_str());
|
||||||
|
group.sendMessage(MiraiCP::PlainText(std::string{s}));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
group.sendMessage(MiraiCP::PlainText("参数过多\n"
|
||||||
|
"请输入 [.菜单] 查看指令用法"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InstructionProcessor::uselessParagraph(const MessageDispatcher::SingleInstruction &instruction) {
|
||||||
|
auto group = instruction.event.group;
|
||||||
|
if (instruction.arguments.empty()) {
|
||||||
|
group.sendMessage(MiraiCP::PlainText{std::string{"请输入主题"}});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto& topic = instruction.arguments[0];
|
||||||
|
std::string url = "https://api.edwiv.com/bzsy/gen.php?event=" + topic +"&length=800&counterType=0&isWritten=0";
|
||||||
|
Http::Request request;
|
||||||
|
request.setVerbose(true);
|
||||||
|
request.setUrl(url);
|
||||||
|
request.send();
|
||||||
|
auto response = request.getResponse();
|
||||||
|
std::regex reg("<[^>]*>");
|
||||||
|
response = std::regex_replace(response, reg, "");
|
||||||
|
group.sendMessage( MiraiCP::PlainText(response));
|
||||||
|
}
|
||||||
|
|
||||||
|
void InstructionProcessor::trash(const MessageDispatcher::SingleInstruction &instruction) {
|
||||||
|
auto group = instruction.event.group;
|
||||||
|
static std::vector<std::string> trashes = {
|
||||||
|
"差不多得了[流汗][流汗]这么大的事都不拐上原神,原神一招你惹你了,二干了伤天害理的事情,都把你这样了你还不无脑抹黑,米哈游每天费尽心思的文化让路送出中国文化,你这种米孝子只会在网上敲键盘包庇无良公司,中国游戏的未来就是被你这种人毁掉的[流汗][流汗]",
|
||||||
|
|
||||||
|
"原神为什么是神?在谈论这个问题之前,我想先说说其他开放性世界游戏相较于原神究竟差在了哪里\n"
|
||||||
|
" 首先是犯下傲慢之罪的塞尔达传说\n"
|
||||||
|
" 塞尔达传说只是靠着一记mc评分(开放世界游戏评分)取得第一就开始沾沾自喜,这种傲慢的游戏注定走不长远,事实也是如此,靠着一个阴险的mc评分赢了神之后一直在走上坡路,最终泯然众人。与之相比神就很谦卑,不做买断制的都是神留给凡人的慈悲,神不是不会,只是不想通过太完美的表现让玩家绝望所以故意做,可笑有些人不理解神的良苦用心,竟然还用这些事来讥讽神,我劝你们好自为之。\n"
|
||||||
|
" 接着是犯下懒惰之罪荒野大镖客2\n"
|
||||||
|
" 自以为拿下mc评分前20就了不起了。另外大家有所不知,其实在进行评比的时候,r星的人闭上眼睛做冥想的时候,其脑海中看见的画面,正是站在光芒之中的原神,那时神告诉他:“你只可到这里,不可越过(指手机游戏榜)。”然而,神的劝说不但没有让荒野大镖客迷途知返,竟然还敢在mc评分里挤出原神的位置伙同正面挑战神的威严,于是神降下了他的惩罚,荒野大镖客在评分身败名裂,手机玩家没人记得,从此成为了众人口中的大表哥",
|
||||||
|
|
||||||
|
"差不多得了楼主,非抓住uzi没有s冠来黑,他的季后赛亚运会冠军直接无视是吧?人家任天堂都承认原神是原创了,还在这里揪着不放。鸿蒙除了不能用谷歌商店可以说哪里都比ios和安卓好用,就ios那个充电速度和像素别碰瓷mate系列了。丁真他至少带动家乡发展了,人家还是国企员工,你个键盘侠干什么了?\n"
|
||||||
|
"抛开事实不谈,明明是女人生的孩子凭什么要随父姓?想随父姓你至少得结扎啊,古圣拿那么多钱肯定是她有实力的,太好看了冰墩墩,王源抽烟都已经道歉了你还在说什么,小黑子能不能闭嘴?你凭什么诋毁嘉然,人家taffy不搞rsq你连认识她的机会都没有,他都是汉利安超人了被20mm口径的钢管暴打怎么就有问题了?\n"
|
||||||
|
"我看你就是五十万,你还不感恩自己有饭吃是吧?知不知道59a的重量,没有造过粉药的东西,承认自己是个雏草姬的事实很难是吧?天天就懂得米线米线,你见过凌晨四点的深圳吗?九九六有什么不好的,再努力一点你就可以再努力一点了,这就是电子厂给我的骄傲的资本 我介绍一些有意义的image_emoticon24 丁真为什么抽电子烟\n"
|
||||||
|
"①理塘海拔高,传统香烟燃烧慢,烟雾小,使用口感较差\n"
|
||||||
|
"②当地经济落后,传统香烟易造成当地居民资金不足问题\n"
|
||||||
|
"③传统与变革碰撞,随着科技和经济发展,电子烟越来越受年轻人青睐\n"
|
||||||
|
"④电子烟属于科技产品,能带动理塘高新技术产业发展\n"
|
||||||
|
"⑤因此,丁真爱抽电子烟 王源为什么抽传统香烟\n"
|
||||||
|
"①重庆市位于四川盆地边缘,海拔低,空气较稠密,利于传统香烟燃烧\n"
|
||||||
|
"②重庆市位于亚热带季风气候区,夏季多洪涝灾害,易停电,电子香烟无法保证夏季续航\n"
|
||||||
|
"③重庆多丘陵,地形崎岖,利于种植烟草\n"
|
||||||
|
"④重庆市60岁以上人口约占重庆市总人口的22%,人口老龄化严重,当地人思想较保守,所以当地人爱抽传统香烟\n"
|
||||||
|
"⑤因此,王源爱抽传统香烟丁真为什么抽电子烟\n"
|
||||||
|
"①理塘海拔高,传统香烟燃烧慢,烟雾小,使用口感较差\n"
|
||||||
|
"②当地经济落后,传统香烟易造成当地居民资金不足问题\n"
|
||||||
|
"③传统与变革碰撞,随着科技和经济发展,电子烟越来越受年轻人青睐\n"
|
||||||
|
"④电子烟属于科技产品,能带动理塘高新技术产业发展\n"
|
||||||
|
"⑤因此,丁真爱抽电子烟 王源为什么抽传统香烟 ①重庆市位于四川盆地边缘,海拔低,空气较稠密,利于传统香烟燃烧\n"
|
||||||
|
"②重庆市位于亚热带季风气候区,夏季多洪涝灾害,易停电,电子香烟无法保证夏季续航\n"
|
||||||
|
"③重庆多丘陵,地形崎岖,利于种植烟草\n"
|
||||||
|
"④重庆市60岁以上人口约占重庆市总人口的22%,人口老龄化严重,当地人思想较保守,所以当地人爱抽传统香烟\n"
|
||||||
|
"⑤因此,王源爱抽传统香烟",
|
||||||
|
|
||||||
|
"上次在公交车爱心座上玩Phigros,突然听到有人叫我臀批,因为我是c语言大佬,所以我直接用程序黑了他的手机,他发现他手机被黑后气急败坏,顺手拿起一根20cm粗的钢管打我,但我由于打小就挨揍,抗性直接拉满,他打了我半个小时,把钢管硬生生打断了,只有点皮外伤,然后我把他打得青一块紫一块的,让他住了好几天院,后来他出院了,给我赔礼道歉,请我喝了杯白水,我一喝,好家伙,原来是硫酸,那钻心的疼让我一生难忘,然后我看到前面有一团红色,以为是鞭炮,准备吓一吓他,好家伙,原来是核弹,还好我和他都是体育生,跑得快,腿脚还利落,只是手被炸断了,在医院,医生测量了下我的体温,好家伙一百多度,本来是不疼的,结果庸医误诊说修养就好了,然后我拖着断手过了一周,疼得受不了了,才去复诊,打了仨月石膏。。。然而我现在还躺在病床上,令人感叹",
|
||||||
|
"你说的对,但是《理论值》是由005自主研发的一款科幻游戏。游戏发生在一个被称作「Arcaea」的幻想世界,在这里,被void和星熊南巫选中的人将被授予「ipad pro2018」,导引616之力。你将扮演一位名为「洞洞五」的神秘角色,在自由的旅行中拯救性格各异、能力独特的歌曲们,和他们一起达成理论值,找回失散的鸡蛋饼。成长为两周炸船、五天杀半球、十六天杀BB的音游大神,并消灭里SIGMA、亚斯塔禄等邪恶份子——同时,逐步发掘「Testify Beyond难度」的真相,以此击溃韵律源点的阴谋,夺回疯狂星期四的食用权。",
|
||||||
|
|
||||||
|
|
||||||
|
"你说的对,但是《Phigros》是由米哈游自主研发的一款全新开放世界冒险音乐游戏。游戏发生在一个被称作「Arcaea」的幻想世界,在这里,被凯尔希选中的人将被授予「荣耀王者」,导引三相之力。你将扮演一位名为「生日快乐是个呆瓜」的神秘角色,在自由的旅行中拯救性格各异、能力独特的英灵们,和他们一起击败整合运动,找回失散的ek鲁比——同时,逐步发掘「水滴」的真相。《Phigros》是由米哈游同哔哩哔哩合作研发的一款全新开放世界冒险音乐rpg游戏。游戏发生在一个被称作「Arcaea」的出生世界,在这里,被嘉然选中的人将被授予「逼三狼」,导引宗师之力。你将扮演一位名为「生日快乐是个呆瓜」的神秘角色,在危机合约中拯救性格各异、能力独特的英灵们,和他们一起击败名为otto的魔王,找回失散的ek鲁比——同时,逐步发掘「三国杀」的真相,游戏拥有强大的枪械系统,高度自由的3d沙盒活动,以及抽卡养成玩法,凯尔希、美羊羊、东雪莲等强力角色等你获得,更有屠龙宝刀一刀999,金色大翅膀+99。游戏采用全新元宇宙玩法,支持vr、3d以及二次元画风,期待玩家同我们一起蒸蒸日上。你说的对,但是《Phigros》是由米哈游自主研发的一款全新开放世界冒险音乐游戏。游戏发生在一个被称作「Arcaea」的幻想世界,在这里,被凯尔希选中的人将被授予「荣耀王者」,导引三相之力。你将扮演一位名为「生日快乐是个呆瓜」的神秘角色,在自由的旅行中拯救性格各异、能力独特的英灵们,和他们一起击败整合运动,找回失散的ek鲁比——同时,逐步发掘「水滴」的真相。而且我是个楠酮你说的对,但是《Phigros》是由米哈游自主研发的一款全新开放世界冒险音乐游戏。游戏发生在一个被称作「Arcaea」的幻想世界,在这里,被凯尔希选中的人将被授予「荣耀王者」,导引三相之力。你将扮演一位名为「生日快乐是个呆瓜」的神秘角色,在自由的旅行中拯救性格各异、能力独特的英灵们,和他们一起击败整合运动,找回失散的ek鲁比——同时,逐步发掘「水滴」的真相。你说的对,所以你愿意来玩Phigros吗?《Phigros》是由米哈游和peroperogames一起研发的一款全新开放世界冒险音乐游戏。游戏发生在一个被称作「Arcaea」的幻想世界,在这里,被神选中的人将被授予「旅行者徽章」,导引音矿之力。你将扮演一位名为「乙姬」的神秘角色,在自由的旅行中邂逅性格各异、能力独特的领航员们,和她们一起击败中二企鹅,找回失散的Ivy——同时,逐步发掘「奏坂学院」的真相。尊敬的各位b友、各位初升、各位[星瞳_发癫][永雏塔菲_亲嘴]和UP主的粉丝:\n"
|
||||||
|
"今天我们怀着奥利安费的心情,来恭喜@_Karasu_ 电棍:国玉的战争在2022年8月2日晚8点53分,达到了1000w播放量。在此,我衷心地感谢大家,在百忙之中来到这里,与我们共同分担这份喜悦。\n"
|
||||||
|
"祝你越走越远,电棍:国玉的战我们永远喜欢你!\n"
|
||||||
|
"最后,让我们大声的喊出那句传世经典:尊尼↑获↓加是你↑爸↑↓↑\n"
|
||||||
|
"同时也祝贺三位U卩(三拖四)主受到古神哈姆的保佑,事业也会越来越好!",
|
||||||
|
|
||||||
|
"请复制粘贴下去\n"
|
||||||
|
"继续支持原神。\n"
|
||||||
|
"敌人的目的是把原神搞垮掉,我们就是要帮原神顶起来。\n"
|
||||||
|
"它们想通过举报让米哈游被迫改衣服,从而让玩家生气上头,引起和mhy的对立甚至退坑。\n"
|
||||||
|
"可我就不退坑,我还要声援。哪怕米哈游所有角色都裹上大棉袄变成隐形人,我也逼着自己玩下去。\n"
|
||||||
|
"不管我们要面对的敌人是谁,我们的格局不应该只限制在一个游戏上,我们要看到这场风波背后那些人。\n"
|
||||||
|
"往小了说是**搞鬼,往中了说是tx网易,往大了说,就是内鬼在______\n"
|
||||||
|
"云堇在国际影响力多大?关注外网的都知道,为啥这节奏早不来晚不来,偏偏2.4的时候来?\n"
|
||||||
|
"为啥唐氏少年这种垃圾还能被力推?\n"
|
||||||
|
"大家好好想想吧,目前玩家内讧加冲米哈游是最蠢的事情,我们自己力量都分散,怎么斗得过潜在的在暗处的那些牛鬼蛇神?\n"
|
||||||
|
"团结,团结,团结!继续支持原神,支持原神文化输出,支持我们的戏曲文化通过游戏的方式向全世界宣传。\n"
|
||||||
|
"相信有人能够处理好现在的局面。\n"
|
||||||
|
"认清敌人,坚定信心!\n"
|
||||||
|
"还有,文化战已经开始了,其残酷程度不亚于真实战争,我们每个人都在这场漩涡里,没法独善其身,同时我们每个人也都是斗士,原神只是开始,往后还会有更多文化产品遭到攻击,能不能打赢这场文化战且看我辈,犯我中华者其远必诛。真的太震撼了,这次心海的传说任务。以前我就认为米哈游的剧情组有世界级的艺术水平,但这次心海的传说任务更是脍炙人口,让人仿佛观看了一场莎士比亚的戏剧,无论是起承转合,还是矛盾冲突,人物塑造,都达到了世界一流大师的水平。尤其是在米哈游极为擅长的人物群像塑造上,心海传说任务更是达到了炉火纯青的地步,无论是堪比诸葛亮的心海,还是作为线索人物的旅行者,乃至天领奉行的九条的塑造都完美的体现并丰满了人物的性格。而他们之间的碰撞冲突也使得这个杰作更具有戏剧性。与此同时,作为心海的传说任务,这次剧情不遗余力的展现了心海强到令人发指的战略能力和统兵能力,体现了她强大的各人魅力,真的很荣幸能看到这么完美的一次传说任务,真的感动。在这个浮躁的社会,一个不玩原神的人是活的很失败的,不分男女。\n"
|
||||||
|
"玩高质量的手游,是人类从二十一世纪以来便存在的行为,而玩原神,体现了一个人的自身价值和身上的附加价值,玩原神,是对自己的一种肯定。\n"
|
||||||
|
"一个不玩原神的人,有两种可能性。一种是没有能力玩原神,买不起高配的手机和抽不起卡等各种自身因素,一个没有能力玩原神的人,无论是因为自身相貌还是经济实力、社会地位种种因素不支持,那么,他的人生就是失败的,是灰暗的,是不被真正的上流社会和高端人士认可的,试问,如果一个人连手机都买不起,氪金抽卡都做不到的话,他的存在还有什么意义?当你的自身条件足够优秀,有的是大把的钱财买高端的手机,抽各种想要的人物,游戏厂商也有做出新内容的动力,不仅促进了玩家和厂商之间双赢的局面,也拉动了GDP,推动了经济发展,这是一个多方收益的局面。\n"
|
||||||
|
"可见,玩原神是一个人证明自己的有力手段,如果连证明自己都做不到,可见人生的失败。\n"
|
||||||
|
"第二种可能:有能力却不玩原神的人,一个人,在有能力而没有玩原神的想法时,那么这个人的思想境界便低到了一个令人发指的程度。一个有能力的人不付出行动来证明自己。原神玩家每天都会发成千上万条评论,而且原神都这么出名了,人也多。你就非要挑出来挂最逆天的这几句话吗?还说什么欧泡之类的东西。也就是原神玩家素质高,懒得管也不想管你这个,但凡放在别的游戏圈子里怎么可能容忍你这种挂人的行为?我来说句公道话,请挂人的和跟风黑的积点口德吧。再怎么说原神玩家三观是要比某些人正很多的,为何非要揪着一点黑不放呢?大家加入这场无意义的狂欢只会造成伤害,理智一点,别被别有用心的人带节奏了。#(汗)",
|
||||||
|
|
||||||
|
"贵贴没有任何规定说不能讨论原神 m,我又何罪之有呢,再说你们@了那么多回吧务部结果也没事,我估计吧务部的人大概也玩原神,你们@了那么多回这就显得很尴尬知道吗【图片】【图片】",
|
||||||
|
|
||||||
|
"适可而止矣!涓埃之事,亦央原神。夫原神者,其一未犯尔,其二固道,尔以何素愚辱之?米哈游者,欲彰华夏之文涵于天下,殚精竭虑。尔等竖子,仗键盘跋扈于网路,构陷良企于冤雪,不舍昼夜。华夏娱戏之前景,皆败于尔属",
|
||||||
|
|
||||||
|
"在屁股肉这款音游红火之前,其实还有一款音游,名为arcaea m,虽然远不及屁股肉的影响力,但也是收货了不少的玩家,我也是其中的一员,他公测的那一年,我也创建了我的嗦哩嗦哩账号,并起名为—生日快乐是个呆子#(欢呼) ;之后的一段时间我不停的上传我的理论值以及单手打歌的arc视频,收货了一大批的粉丝,我也被粉丝们称为—呆神,每次别的up主发音游视频,都会有我的粉丝在下面说——感觉不如呆神#(太开心) 。\n我的嗦哩嗦哩账号也很快的到达了一伯万粉丝,成为了音游届的超级音游王,在我辉煌之际,却不断的有噩耗传来…\narc因为两年不更主线,饱受诟病,终于有一位玩原神 m的神秘C语言大佬看不下去了,黑进了616服务器,还盒盒了游戏制作人guy,之后没几天游戏制作人guy还有优秀的arc谱师吐丝被杀人魔—钢管怪人,用20cm粗的钢管残忍沙嗨,到现场时只看到断掉的20cm粗的钢管以及用雪写下的一句话——感觉不如原神#(汗) 。我也因为经常打个月交先,导致我的左手重伤,被迫退役#(喝酒)\n我坐在屯达集公园的长椅上,用颤抖的手登上了我尘封已久的账号——生日快乐是个呆子…",
|
||||||
|
|
||||||
|
"可你不是....可你不是枫原万叶,会替我挡下无想一刀。可你不是派蒙,会一直陪伴我。可你不是荧,令我朝思暮想。可你不是可莉,会带我去炸鱼。可你不是菲谢尔,会陪我一起中二。可你不是行秋,隐藏身份帮助我。可你不是宵宫,会陪我一起看烟花。可你不是达达利亚,在千岩军手下救我。可你不是托马,在我危难时刻救我一命。可你不是荒泷一斗,愿意把我当兄弟。可你不是钟离,给不了我安全感。可你不是影,会走出一心净土来陪我。可你不是丽莎,会叫我小可爱。可你不是胡桃,会在百忙之中逗我笑。可你不是神里绫华,在河流之中为我跳舞"
|
||||||
|
};
|
||||||
|
// 随机选择一条消息发送
|
||||||
|
auto index = RandomLibrary::getNextRandomNumber<decltype(trashes)::size_type>(
|
||||||
|
RandomLibrary::RandomNumberType::UniformDistribution,
|
||||||
|
0, trashes.size() - 1);
|
||||||
|
group.sendMessage(MiraiCP::PlainText{trashes[index]});
|
||||||
|
}
|
||||||
|
|
||||||
|
void InstructionProcessor::sick(const MessageDispatcher::SingleInstruction &instruction) {
|
||||||
|
auto group = instruction.event.group;
|
||||||
|
if (instruction.arguments.empty()) {
|
||||||
|
group.sendMessage(MiraiCP::At(instruction.event.sender.id()),MiraiCP::PlainText{std::string{"请输入对象"}});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto& object = instruction.arguments[0];
|
||||||
|
char s[1024];
|
||||||
|
sprintf(s, "来个%s吧 求求了 我已经寡疯了 我真的想%s想发疯了 我躺在床上会想%s我洗澡会想%s 我出门会想%s "
|
||||||
|
"我盯着路边的%s看 我盯着地铁的%s看 我盯着好朋友的%s看 "
|
||||||
|
"我好孤独啊 这世界那么多%s为什么就没有一个%s属于我的呜呜呜呜", object.c_str(), object.c_str(), object.c_str(), object.c_str(), object.c_str(),
|
||||||
|
object.c_str(), object.c_str(), object.c_str(), object.c_str(), object.c_str());
|
||||||
|
group.sendMessage(MiraiCP::PlainText{std::string{s}});
|
||||||
|
}
|
||||||
|
|
||||||
|
void InstructionProcessor::kfcCrazyThursday(const MessageDispatcher::SingleInstruction &instruction) {
|
||||||
|
auto group = instruction.event.group;
|
||||||
|
Http::Request req;
|
||||||
|
req.setUrl("http://thursday.gouyin.net/api/kfc.php");
|
||||||
|
req.setVerbose(true);
|
||||||
|
req.send();
|
||||||
|
auto res = req.getResponse();
|
||||||
|
// Parse res as JSON
|
||||||
|
// Response type is:
|
||||||
|
// [
|
||||||
|
// {
|
||||||
|
// "id": 0,
|
||||||
|
// "content": "string"
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
auto json = nlohmann::json::parse(res);
|
||||||
|
group.sendMessage(MiraiCP::PlainText{std::string{json[0]["content"]}});
|
||||||
|
}
|
||||||
|
|
||||||
|
void InstructionProcessor::touhouProject(const MessageDispatcher::SingleInstruction &instruction) {
|
||||||
|
auto group = instruction.event.group;
|
||||||
|
Http::Request req;
|
||||||
|
req.setUrl("https://img.paulzzh.tech/touhou/random");
|
||||||
|
req.setVerbose(true);
|
||||||
|
req.send();
|
||||||
|
auto response = req.getResponse();
|
||||||
|
|
||||||
|
std::string filename = getTemporaryFileName("jpg");
|
||||||
|
Http::FileUtilities::writeFile(filename, response);
|
||||||
|
|
||||||
|
auto uploadedImage = group.uploadImg(filename);
|
||||||
|
group.sendMessage(uploadedImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InstructionProcessor::signOn(const MessageDispatcher::SingleInstruction &instruction) {
|
||||||
|
auto group = instruction.event.group;
|
||||||
|
// 根据用户QQ号,在数据库中查找用户
|
||||||
|
auto& person = PersonCollection::getPerson(instruction.event.from()->id());
|
||||||
|
// 检查用户是否签到
|
||||||
|
if (person.isSignOnToday()) {
|
||||||
|
group.sendMessage(MiraiCP::At(instruction.event.sender.id()),MiraiCP::PlainText("你今天已经签到过了"));
|
||||||
|
} else {
|
||||||
|
// 获得之前的铜钱数
|
||||||
|
auto previousCopperCoins = person.getCopperCoin();
|
||||||
|
// 签到
|
||||||
|
person.signOn();
|
||||||
|
// 获得现在的铜钱数
|
||||||
|
auto currentCopperCoins = person.getCopperCoin();
|
||||||
|
// 计算获得的铜钱数
|
||||||
|
auto copperCoinsDifference = currentCopperCoins - previousCopperCoins;
|
||||||
|
|
||||||
|
char s[1024];
|
||||||
|
sprintf(s, "签到成功!\n"
|
||||||
|
"你获得了 %d 个铜钱\n"
|
||||||
|
"你现在有 %d 个铜钱\n"
|
||||||
|
"你已经连续签到 %d 天", copperCoinsDifference, currentCopperCoins, person.continuousSignOnDays());
|
||||||
|
group.sendMessage(MiraiCP::At(instruction.event.sender.id()),MiraiCP::PlainText(s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InstructionProcessor::otherMessage(const MessageDispatcher::SingleInstruction &instruction) {
|
||||||
|
// 检查这个人是否需要被攻击
|
||||||
|
auto& person = PersonCollection::getPerson(instruction.event.from()->id());
|
||||||
|
if (person.willBeAttackNextTime()) {
|
||||||
|
// 怼
|
||||||
|
auto group = instruction.event.group;
|
||||||
|
group.quoteAndSendMessage( MiraiCP::PlainText("鳖载着理发店"),
|
||||||
|
instruction.event.message.source.value());
|
||||||
|
// 重置计数
|
||||||
|
person.resetAttackCount();
|
||||||
|
} else {
|
||||||
|
// 计数
|
||||||
|
person.increaseSpeakCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,112 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Lucas' Bot.
|
||||||
|
*
|
||||||
|
* Lucas' Bot is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
|
||||||
|
Lucas' Bot is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along
|
||||||
|
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MIRAICPPLUGIN_INSTRUCTIONPROCESSOR_H
|
||||||
|
#define MIRAICPPLUGIN_INSTRUCTIONPROCESSOR_H
|
||||||
|
|
||||||
|
#include <MiraiCP.hpp>
|
||||||
|
#include "MessageDispatcher.h"
|
||||||
|
|
||||||
|
namespace InstructionProcessor {
|
||||||
|
// 重构:
|
||||||
|
// 抽取原MessageDispatcher::dispatch函数中的指令处理部分
|
||||||
|
// 对每个指令的处理将由指令的处理函数负责
|
||||||
|
// 指令的处理函数将由一个map维护
|
||||||
|
// 指令处理函数的原型为:void(const MessageDispatcher::SingleInstruction&)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 复读指令处理函数
|
||||||
|
* @param instruction 指令
|
||||||
|
*/
|
||||||
|
void repeat(const MessageDispatcher::SingleInstruction& instruction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 营销号指令处理函数
|
||||||
|
* @param instruction 指令
|
||||||
|
*/
|
||||||
|
void commercialAccount(const MessageDispatcher::SingleInstruction& instruction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 废话指令处理函数
|
||||||
|
* @param instruction 指令
|
||||||
|
*/
|
||||||
|
void uselessParagraph(const MessageDispatcher::SingleInstruction& instruction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 倒垃圾指令处理函数
|
||||||
|
* @param instruction 指令
|
||||||
|
*/
|
||||||
|
void trash(const MessageDispatcher::SingleInstruction& instruction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 发病指令处理函数
|
||||||
|
* @param instruction 指令
|
||||||
|
*/
|
||||||
|
void sick(const MessageDispatcher::SingleInstruction& instruction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 疯狂星期四V我50指令处理函数
|
||||||
|
* @param instruction 指令
|
||||||
|
*/
|
||||||
|
void kfcCrazyThursday(const MessageDispatcher::SingleInstruction& instruction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 东方Project指令处理函数
|
||||||
|
* @param instruction 指令
|
||||||
|
*/
|
||||||
|
void touhouProject(const MessageDispatcher::SingleInstruction& instruction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 签到指令处理函数
|
||||||
|
* @param instruction 指令
|
||||||
|
*/
|
||||||
|
void signOn(const MessageDispatcher::SingleInstruction& instruction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 钓鱼指令处理函数
|
||||||
|
* @param instruction 指令
|
||||||
|
*/
|
||||||
|
void fishing(const MessageDispatcher::SingleInstruction& instruction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 打工指令处理函数
|
||||||
|
* @param instruction 指令
|
||||||
|
*/
|
||||||
|
void working(const MessageDispatcher::SingleInstruction& instruction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 菜单指令处理函数
|
||||||
|
* @param instruction 指令
|
||||||
|
* @author Lucas
|
||||||
|
*/
|
||||||
|
void menu(const MessageDispatcher::SingleInstruction& instruction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 关于指令处理函数
|
||||||
|
* @param instruction 指令
|
||||||
|
*/
|
||||||
|
void about(const MessageDispatcher::SingleInstruction& instruction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 一般消息处理函数
|
||||||
|
* @param instruction 指令
|
||||||
|
*/
|
||||||
|
void otherMessage(const MessageDispatcher::SingleInstruction& instruction);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //MIRAICPPLUGIN_INSTRUCTIONPROCESSOR_H
|
|
@ -0,0 +1,177 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Lucas' Bot.
|
||||||
|
*
|
||||||
|
* Lucas' Bot is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
|
||||||
|
Lucas' Bot is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along
|
||||||
|
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "MessageDispatcher.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
namespace MessageDispatcher {
|
||||||
|
std::queue<MiraiCP::GroupMessageEvent> messageQueue;
|
||||||
|
|
||||||
|
std::mutex messageQueueMutex;
|
||||||
|
|
||||||
|
std::condition_variable msgQueueCondVariable;
|
||||||
|
|
||||||
|
std::unordered_map<MessageDispatcher::InstructionType,
|
||||||
|
MessageDispatcher::InstructionProcedure> instructionProcedureMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> MessageDispatcher::split(const std::string &str, char delim) {
|
||||||
|
std::vector<std::string> res;
|
||||||
|
std::stringstream ss(str);
|
||||||
|
std::string temp;
|
||||||
|
while (getline(ss, temp, delim)) {
|
||||||
|
res.push_back(temp);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageDispatcher::produceMessage(const MiraiCP::GroupMessageEvent &event) {
|
||||||
|
// 锁定消息队列的互斥锁
|
||||||
|
std::unique_lock<std::mutex> lock(messageQueueMutex);
|
||||||
|
// 往消息队列末尾放入一条消息
|
||||||
|
messageQueue.push(event);
|
||||||
|
// 通知消费者线程取出消息
|
||||||
|
msgQueueCondVariable.notify_one();
|
||||||
|
// std::unique_lock的析构函数会自动释放互斥锁
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageDispatcher::SingleInstruction
|
||||||
|
MessageDispatcher::translateMessage(const MiraiCP::GroupMessageEvent &event) {
|
||||||
|
// 获得消息链
|
||||||
|
auto msgChain = event.message;
|
||||||
|
// 判断消息类型
|
||||||
|
switch(msgChain[0].type()) {
|
||||||
|
// 若为纯文本信息
|
||||||
|
case (int) MessageDispatcher::MessageType::PlainText: {
|
||||||
|
// 获得消息的内容并存储在messageText中
|
||||||
|
auto plain = msgChain[0].get<MiraiCP::PlainText>();
|
||||||
|
std::string messageText = plain.toJson()["content"].get<std::string>();
|
||||||
|
if (messageText[0] == instructionPrefix) {
|
||||||
|
// 以空格为界,分开指令和参数
|
||||||
|
auto command = messageText.substr(1, messageText.find(' ') - 1);
|
||||||
|
auto args = messageText.substr(messageText.find(' ') + 1);
|
||||||
|
// 将指令中的字符全部转换为小写(如果有)
|
||||||
|
for (auto& c: command) {
|
||||||
|
if (std::isalnum(c))
|
||||||
|
c = static_cast<char>(std::tolower(c));
|
||||||
|
}
|
||||||
|
// 切割算法存在的一点问题:如果消息中不存在空格,那么参数字符串将会和指令字符串一样
|
||||||
|
// 此时需要手动置为空
|
||||||
|
if (args == messageText.substr(0, messageText.find(' ') - 1))
|
||||||
|
args.clear();
|
||||||
|
// 翻译指令
|
||||||
|
auto instructionType = queryInstructionTypeFromText(command);
|
||||||
|
// 构建返回值
|
||||||
|
return SingleInstruction{
|
||||||
|
.event = event,
|
||||||
|
.type = instructionType,
|
||||||
|
.arguments = split(args, ' ')
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return SingleInstruction{
|
||||||
|
.event = event,
|
||||||
|
.type = InstructionType::OtherMessage,
|
||||||
|
.arguments = std::vector<std::string>{}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return SingleInstruction{
|
||||||
|
.event = event,
|
||||||
|
.type = InstructionType::OtherMessage,
|
||||||
|
.arguments = std::vector<std::string>{}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageDispatcher::InstructionType MessageDispatcher::queryInstructionTypeFromText(const std::string &text) {
|
||||||
|
if (text == "复读")
|
||||||
|
return InstructionType::Repeat;
|
||||||
|
else if (text == "菜单")
|
||||||
|
return InstructionType::Menu;
|
||||||
|
else if (text == "营销号")
|
||||||
|
return InstructionType::CommercialAccount;
|
||||||
|
else if (text == "发病")
|
||||||
|
return InstructionType::Sick;
|
||||||
|
else if (text == "废话")
|
||||||
|
return InstructionType::UselessParagraph;
|
||||||
|
else if (text == "倒垃圾")
|
||||||
|
return InstructionType::Trash;
|
||||||
|
else if (text == "kfc")
|
||||||
|
return InstructionType::KFCCrazyThursday;
|
||||||
|
else if (text == "东方" || text == "车万")
|
||||||
|
return InstructionType::TouhouProject;
|
||||||
|
else if (text == "签到" || text == "打卡")
|
||||||
|
return InstructionType::SignOn;
|
||||||
|
else if (text == "钓鱼")
|
||||||
|
return InstructionType::Fishing;
|
||||||
|
else if (text == "打工")
|
||||||
|
return InstructionType::Working;
|
||||||
|
else if (text == "五千兆")
|
||||||
|
return InstructionType::FiveThousandMega;
|
||||||
|
else if (text == "关于")
|
||||||
|
return InstructionType::About;
|
||||||
|
else
|
||||||
|
return InstructionType::NotImplemented;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageDispatcher::dispatchInstruction(const MessageDispatcher::SingleInstruction &instruction) {
|
||||||
|
// 找到instructionProcedureMap中对应的入口点
|
||||||
|
// 若未找到,调用defaultInstructionProcedure
|
||||||
|
if (instructionProcedureMap.find(instruction.type) == instructionProcedureMap.end()) {
|
||||||
|
defaultInstructionProcedure(instruction);
|
||||||
|
} else {
|
||||||
|
auto entry = instructionProcedureMap.find(instruction.type)->second;
|
||||||
|
entry(instruction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageDispatcher::registerInstructionProcedure(MessageDispatcher::InstructionType instructionType,
|
||||||
|
MessageDispatcher::InstructionProcedure instructionProcedure) {
|
||||||
|
// 注册消息处理程序,没啥好说的,直接莽就完了
|
||||||
|
// 如果之前注册了,会被替换掉
|
||||||
|
instructionProcedureMap[instructionType] = std::move(instructionProcedure);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageDispatcher::defaultInstructionProcedure(const MessageDispatcher::SingleInstruction &instruction) {
|
||||||
|
// 获得消息来源的组
|
||||||
|
auto group = instruction.event.group;
|
||||||
|
// 发送消息
|
||||||
|
group.sendMessage(MiraiCP::PlainText("未知或未实现的指令"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageDispatcher::consumerThreadFunction() {
|
||||||
|
// 消费者线程函数
|
||||||
|
// 从消息队列中取出消息并处理
|
||||||
|
while (true) {
|
||||||
|
// 构造一个std::unique_lock对象,用于锁定互斥量
|
||||||
|
std::unique_lock<std::mutex> lock(messageQueueMutex);
|
||||||
|
// 如果消息队列为空,那么等待消息队列中有消息
|
||||||
|
msgQueueCondVariable.wait(lock, [] { return !messageQueue.empty(); });
|
||||||
|
// 取出消息队列中的第一条消息
|
||||||
|
auto msg = messageQueue.front();
|
||||||
|
// 从消息队列中删除该消息
|
||||||
|
messageQueue.pop();
|
||||||
|
// 解锁互斥量
|
||||||
|
lock.unlock();
|
||||||
|
// 翻译消息
|
||||||
|
auto instruction = translateMessage(msg);
|
||||||
|
// 处理消息
|
||||||
|
dispatchInstruction(instruction);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,189 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Lucas' Bot.
|
||||||
|
*
|
||||||
|
* Lucas' Bot is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
|
||||||
|
Lucas' Bot is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along
|
||||||
|
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MIRAICPPLUGIN_MESSAGE_DISPATCHER_H
|
||||||
|
#define MIRAICPPLUGIN_MESSAGE_DISPATCHER_H
|
||||||
|
|
||||||
|
#include <MiraiCP.hpp>
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <mutex>
|
||||||
|
#include <thread>
|
||||||
|
#include <queue>
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
namespace MessageDispatcher {
|
||||||
|
// 全局类型定义
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 指令前缀
|
||||||
|
*/
|
||||||
|
constexpr char instructionPrefix = '.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 消息类型
|
||||||
|
* 对应MiraiCP的文档说明
|
||||||
|
*/
|
||||||
|
enum class MessageType {
|
||||||
|
MarketFace = -5,
|
||||||
|
OnlineForwardedMessage = -4,
|
||||||
|
OnlineAudio = -3,
|
||||||
|
QuoteReply = -2,
|
||||||
|
UnSupportMessage = -1,
|
||||||
|
PlainText = 0,
|
||||||
|
At = 1,
|
||||||
|
AtAll = 2,
|
||||||
|
Image = 3,
|
||||||
|
App = 4,
|
||||||
|
Service = 5,
|
||||||
|
File = 6,
|
||||||
|
Face = 7,
|
||||||
|
FlashImage = 8,
|
||||||
|
MusicShare = 9
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 指令类型,根据不同的指令类型注册不同的消息处理程序
|
||||||
|
*/
|
||||||
|
enum class InstructionType{
|
||||||
|
Repeat, // 复读
|
||||||
|
CommercialAccount, // 营销号
|
||||||
|
UselessParagraph, // 废话
|
||||||
|
Trash, // 垃圾
|
||||||
|
Sick, // 发病
|
||||||
|
KFCCrazyThursday, // 疯狂星期四V我50
|
||||||
|
TouhouProject, // 东方Project
|
||||||
|
SignOn, // 签到
|
||||||
|
Fishing, // 钓鱼
|
||||||
|
Working, // 打工
|
||||||
|
FiveThousandMega, // 5000兆表情包生成
|
||||||
|
Menu, // 菜单
|
||||||
|
About, // 关于
|
||||||
|
NotImplemented, // 未实现
|
||||||
|
OtherMessage // 普通聊天消息
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 结构体 SingleInstruction
|
||||||
|
* 代表单条指令的结构
|
||||||
|
*/
|
||||||
|
struct SingleInstruction {
|
||||||
|
const MiraiCP::GroupMessageEvent& event;
|
||||||
|
InstructionType type;
|
||||||
|
std::vector<std::string> arguments;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 消息处理过程的定义,签名为const SingleInstruction& -> void
|
||||||
|
*/
|
||||||
|
using InstructionProcedure = std::function<void(const SingleInstruction&)>;
|
||||||
|
|
||||||
|
// 全局数据结构定义
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 消息队列
|
||||||
|
*/
|
||||||
|
extern std::queue<MiraiCP::GroupMessageEvent> messageQueue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 控制消息队列更改的互斥锁
|
||||||
|
*/
|
||||||
|
extern std::mutex messageQueueMutex;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 控制消息队列更改的条件变量
|
||||||
|
*/
|
||||||
|
extern std::condition_variable msgQueueCondVariable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 消息处理函数映射表
|
||||||
|
*/
|
||||||
|
extern std::unordered_map<InstructionType, InstructionProcedure,
|
||||||
|
std::hash<InstructionType>> instructionProcedureMap;
|
||||||
|
|
||||||
|
// 接口
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief produceMessage 适用于producer的接口,往消息队列末尾放入一条消息
|
||||||
|
* @param event 待处理的消息
|
||||||
|
*/
|
||||||
|
void produceMessage(const MiraiCP::GroupMessageEvent& event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief translateMessage 将文字消息转换为SingleInstruction结构
|
||||||
|
* @param event 待处理的群消息
|
||||||
|
* @return 代表转换后的单条指令
|
||||||
|
*/
|
||||||
|
SingleInstruction translateMessage(const MiraiCP::GroupMessageEvent& event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 查询text字符串对应的指令信息
|
||||||
|
* @param text 待查询的字符串
|
||||||
|
* @return 若text与某一条指令匹配,返回对应的指令;
|
||||||
|
* 若text不与任意一条指令匹配,返回InstructionType::NotImplemented
|
||||||
|
*/
|
||||||
|
InstructionType queryInstructionTypeFromText(const std::string& text);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 将单条指令送往对应的指令处理程序
|
||||||
|
* @param instruction 待处理的消息
|
||||||
|
*/
|
||||||
|
void dispatchInstruction(const SingleInstruction& instruction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 对给定的指令类型,注册对应的指令处理程序
|
||||||
|
* @param instructionType 指令类型
|
||||||
|
* @param instructionProcedure 指令处理程序
|
||||||
|
*/
|
||||||
|
void registerInstructionProcedure(InstructionType instructionType,
|
||||||
|
InstructionProcedure instructionProcedure);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 对未注册指令处理程序的指令类型,默认的处理程序
|
||||||
|
* @param instruction 指令
|
||||||
|
*/
|
||||||
|
void defaultInstructionProcedure(const SingleInstruction& instruction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 消费者线程函数,从消息队列队头取出消息并处理
|
||||||
|
*/
|
||||||
|
[[noreturn]]
|
||||||
|
void consumerThreadFunction();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 根据delim,将str切割并存储在返回值的vector中
|
||||||
|
* @param str 将被分割的字符串
|
||||||
|
* @param delimiter 分隔符
|
||||||
|
* @return 切割完成后的字符串组成的vector
|
||||||
|
*/
|
||||||
|
std::vector<std::string>
|
||||||
|
split(const std::string& str, char delim);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打开命名空间std,并对InstructionType定义std::hash特化
|
||||||
|
namespace std{
|
||||||
|
template<>
|
||||||
|
struct hash<MessageDispatcher::InstructionType>{
|
||||||
|
size_t operator() (const MessageDispatcher::InstructionType& instruction) const {
|
||||||
|
return std::hash<int>()(static_cast<int>(instruction));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //MIRAICPPLUGIN_MESSAGE_DISPATCHER_H
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Lucas' Bot.
|
||||||
|
*
|
||||||
|
* Lucas' Bot is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
|
||||||
|
Lucas' Bot is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License along
|
||||||
|
with Lucas' Bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// MiraiCP依赖文件(只需要引入这一个)
|
||||||
|
#include <MiraiCP.hpp>
|
||||||
|
#include "MessageDispatcher.h"
|
||||||
|
#include "InstructionProcessor.h"
|
||||||
|
#include "PersonCollection.h"
|
||||||
|
|
||||||
|
using namespace MiraiCP;
|
||||||
|
|
||||||
|
const PluginConfig CPPPlugin::config{
|
||||||
|
"0", // 插件id
|
||||||
|
"Lucas' Bot", // 插件名称
|
||||||
|
"alpha-0.1.1", // 插件版本
|
||||||
|
"Lucas" // 插件作者
|
||||||
|
};
|
||||||
|
|
||||||
|
// 插件实例
|
||||||
|
class Main : public CPPPlugin {
|
||||||
|
public:
|
||||||
|
// 配置插件信息
|
||||||
|
Main() : CPPPlugin() {}
|
||||||
|
~Main() override = default;
|
||||||
|
|
||||||
|
// 入口函数
|
||||||
|
void onEnable() override {
|
||||||
|
Logger::logger.info("Hello, world!");
|
||||||
|
// 启动消费者线程
|
||||||
|
std::thread consumerThread{MessageDispatcher::consumerThreadFunction};
|
||||||
|
consumerThread.detach();
|
||||||
|
// 载入本地文件
|
||||||
|
PersonCollection::registerLocalFile("personMap.json");
|
||||||
|
PersonCollection::loadPersonMap();
|
||||||
|
// 注册消息处理函数
|
||||||
|
MessageDispatcher::registerInstructionProcedure(MessageDispatcher::InstructionType::Repeat,
|
||||||
|
InstructionProcessor::repeat);
|
||||||
|
MessageDispatcher::registerInstructionProcedure(MessageDispatcher::InstructionType::CommercialAccount,
|
||||||
|
InstructionProcessor::commercialAccount);
|
||||||
|
MessageDispatcher::registerInstructionProcedure(MessageDispatcher::InstructionType::UselessParagraph,
|
||||||
|
InstructionProcessor::uselessParagraph);
|
||||||
|
MessageDispatcher::registerInstructionProcedure(MessageDispatcher::InstructionType::Trash,
|
||||||
|
InstructionProcessor::trash);
|
||||||
|
MessageDispatcher::registerInstructionProcedure(MessageDispatcher::InstructionType::Sick,
|
||||||
|
InstructionProcessor::sick);
|
||||||
|
MessageDispatcher::registerInstructionProcedure(MessageDispatcher::InstructionType::KFCCrazyThursday,
|
||||||
|
InstructionProcessor::kfcCrazyThursday);
|
||||||
|
MessageDispatcher::registerInstructionProcedure(MessageDispatcher::InstructionType::TouhouProject,
|
||||||
|
InstructionProcessor::touhouProject);
|
||||||
|
MessageDispatcher::registerInstructionProcedure(MessageDispatcher::InstructionType::SignOn,
|
||||||
|
InstructionProcessor::signOn);
|
||||||
|
MessageDispatcher::registerInstructionProcedure(MessageDispatcher::InstructionType::OtherMessage,
|
||||||
|
InstructionProcessor::otherMessage);
|
||||||
|
// 添加消息监听事件
|
||||||
|
Event::registerEvent<GroupMessageEvent>([](GroupMessageEvent event) {
|
||||||
|
MessageDispatcher::produceMessage(event);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 退出函数
|
||||||
|
void onDisable() override {
|
||||||
|
/*插件结束前执行*/
|
||||||
|
// 保存本地文件
|
||||||
|
PersonCollection::savePersonMap();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 绑定当前插件实例
|
||||||
|
void MiraiCP::enrollPlugin() {
|
||||||
|
MiraiCP::enrollPlugin(new Main);
|
||||||
|
}
|
Loading…
Reference in New Issue