add civetweb for http server.

mcp w.i.p.
This commit is contained in:
Syoyo Fujita
2025-07-02 09:55:17 +09:00
parent 1480510467
commit 0747e87a61
15 changed files with 28172 additions and 7 deletions

View File

@@ -78,6 +78,9 @@ option(TINYUSDZ_WITH_BUILTIN_IMAGE_LOADER
option(TINYUSDZ_WITH_TYDRA
"Build with Tydra module(Handly USD scene converter for the renderer, DCC, etc)."
ON)
option(TINYUSDZ_WITH_MCP_SERVER
"Build with C++ MCP server(http server) support."
OFF)
if(MSVC)
@@ -435,8 +438,8 @@ if (TINYUSDZ_WITH_TYDRA)
${PROJECT_SOURCE_DIR}/src/tydra/render-data.hh
${PROJECT_SOURCE_DIR}/src/tydra/texture-util.cc
${PROJECT_SOURCE_DIR}/src/tydra/texture-util.hh
${PROJECT_SOURCE_DIR}/src/tydra/mcp.cc
${PROJECT_SOURCE_DIR}/src/tydra/mcp.hh
${PROJECT_SOURCE_DIR}/src/tydra/mcp-server.cc
${PROJECT_SOURCE_DIR}/src/tydra/mcp-server.hh
)
endif (TINYUSDZ_WITH_TYDRA)
@@ -552,6 +555,12 @@ if(TINYUSDZ_WITH_ALAC_AUDIO)
)
endif(TINYUSDZ_WITH_ALAC_AUDIO)
if(TINYUSDZ_WITH_MCP_SERVER)
list(APPEND TINYUSDZ_DEP_SOURCES
${PROJECT_SOURCE_DIR}/src/external/civetweb/civetweb.c
)
endif(TINYUSDZ_WITH_MCP_SERVER)
if(TINYUSDZ_WITH_OPENSUBDIV)
# https://stackoverflow.com/questions/41700463/push-pop-a-cmake-variable
@@ -685,6 +694,7 @@ if(TINYUSDZ_WITH_TIFF OR TINYUSDZ_WITH_EXR)
endif()
endif()
# Increase warning level for clang.
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
@@ -1094,6 +1104,15 @@ foreach(TINYUSDZ_LIB_TARGET ${TINYUSDZ_LIBS})
PRIVATE "TINYUSDZ_WITH_ALAC_AUDIO")
endif(TINYUSDZ_WITH_ALAC_AUDIO)
if(TINYUSDZ_WITH_MCP_SERVER)
target_compile_definitions(${TINYUSDZ_LIB_TARGET}
PRIVATE "TINYUSDZ_WITH_MCP_SERVER")
# use dll for SSL + OPENSSL_API_3.0
target_compile_definitions(${TINYUSDZ_LIB_TARGET}
PRIVATE "OPENSSL_API_3_0")
endif(TINYUSDZ_WITH_MCP_SERVER)
if(TINYUSDZ_WITH_OPENSUBDIV)
target_include_directories(${TINYUSDZ_LIB_TARGET} PRIVATE ${osd_DIR})
target_compile_definitions(${TINYUSDZ_LIB_TARGET}

View File

@@ -567,3 +567,4 @@ Some helper code is licensed under MIT license.
* tinymeshutils: MIT license. https://github.com/syoyo/tinymeshutils
* criterion(for benchmark): MIT license. https://github.com/p-ranav/criterion
* yyjson: MIT license. https://github.com/ibireme/yyjson
* civetweb: MIT license. https://github.com/civetweb/civetweb

736
src/external/civetweb/CivetServer.h vendored Normal file
View File

@@ -0,0 +1,736 @@
/* Copyright (c) 2013-2017 the Civetweb developers
* Copyright (c) 2013 No Face Press, LLC
*
* License http://opensource.org/licenses/mit-license.php MIT License
*/
#ifndef CIVETSERVER_HEADER_INCLUDED
#define CIVETSERVER_HEADER_INCLUDED
#ifdef __cplusplus
#include "civetweb.h"
#include <map>
#include <stdexcept>
#include <string>
#include <vector>
#ifndef CIVETWEB_CXX_API
#if defined(_WIN32)
#if defined(CIVETWEB_CXX_DLL_EXPORTS)
#define CIVETWEB_CXX_API __declspec(dllexport)
#elif defined(CIVETWEB_CXX_DLL_IMPORTS)
#define CIVETWEB_CXX_API __declspec(dllimport)
#else
#define CIVETWEB_CXX_API
#endif
#elif __GNUC__ >= 4
#define CIVETWEB_CXX_API __attribute__((visibility("default")))
#else
#define CIVETWEB_CXX_API
#endif
#endif
// forward declaration
class CivetServer;
/**
* Exception class for thrown exceptions within the CivetHandler object.
*/
class CIVETWEB_CXX_API CivetException : public std::runtime_error
{
public:
CivetException(const std::string &msg) : std::runtime_error(msg)
{
}
};
/**
* Basic interface for a URI request handler. Handlers implementations
* must be reentrant.
*/
class CIVETWEB_CXX_API CivetHandler
{
public:
/**
* Destructor
*/
virtual ~CivetHandler()
{
}
/**
* Callback method for GET request.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if implemented, false otherwise
*/
virtual bool handleGet(CivetServer *server, struct mg_connection *conn);
/**
* Callback method for GET request.
*
* @param server - the calling server
* @param conn - the connection information
* @param status_code - pointer to return status code
* @returns true if implemented, false otherwise
*/
virtual bool handleGet(CivetServer *server,
struct mg_connection *conn,
int *status_code);
/**
* Callback method for POST request.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if implemented, false otherwise
*/
virtual bool handlePost(CivetServer *server, struct mg_connection *conn);
/**
* Callback method for POST request.
*
* @param server - the calling server
* @param conn - the connection information
* @param status_code - pointer to return status code
* @returns true if implemented, false otherwise
*/
virtual bool handlePost(CivetServer *server,
struct mg_connection *conn,
int *status_code);
/**
* Callback method for HEAD request.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if implemented, false otherwise
*/
virtual bool handleHead(CivetServer *server, struct mg_connection *conn);
/**
* Callback method for HEAD request.
*
* @param server - the calling server
* @param conn - the connection information
* @param status_code - pointer to return status code
* @returns true if implemented, false otherwise
*/
virtual bool handleHead(CivetServer *server,
struct mg_connection *conn,
int *status_code);
/**
* Callback method for PUT request.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if implemented, false otherwise
*/
virtual bool handlePut(CivetServer *server, struct mg_connection *conn);
/**
* Callback method for PUT request.
*
* @param server - the calling server
* @param conn - the connection information
* @param status_code - pointer to return status code
* @returns true if implemented, false otherwise
*/
virtual bool handlePut(CivetServer *server,
struct mg_connection *conn,
int *status_code);
/**
* Callback method for DELETE request.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if implemented, false otherwise
*/
virtual bool handleDelete(CivetServer *server, struct mg_connection *conn);
/**
* Callback method for DELETE request.
*
* @param server - the calling server
* @param conn - the connection information
* @param status_code - pointer to return status code
* @returns true if implemented, false otherwise
*/
virtual bool handleDelete(CivetServer *server,
struct mg_connection *conn,
int *status_code);
/**
* Callback method for OPTIONS request.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if implemented, false otherwise
*/
virtual bool handleOptions(CivetServer *server, struct mg_connection *conn);
/**
* Callback method for OPTIONS request.
*
* @param server - the calling server
* @param conn - the connection information
* @param status_code - pointer to return status code
* @returns true if implemented, false otherwise
*/
virtual bool handleOptions(CivetServer *server,
struct mg_connection *conn,
int *status_code);
/**
* Callback method for PATCH request.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if implemented, false otherwise
*/
virtual bool handlePatch(CivetServer *server, struct mg_connection *conn);
/**
* Callback method for PATCH request.
*
* @param server - the calling server
* @param conn - the connection information
* @param status_code - pointer to return status code
* @returns true if implemented, false otherwise
*/
virtual bool handlePatch(CivetServer *server,
struct mg_connection *conn,
int *status_code);
};
/**
* Basic interface for a URI authorization handler. Handler implementations
* must be reentrant.
*/
class CIVETWEB_CXX_API CivetAuthHandler
{
public:
/**
* Destructor
*/
virtual ~CivetAuthHandler()
{
}
/**
* Callback method for authorization requests. It is up the this handler
* to generate 401 responses if authorization fails.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if authorization succeeded, false otherwise
*/
virtual bool authorize(CivetServer *server, struct mg_connection *conn) = 0;
};
/**
* Basic interface for a websocket handler. Handlers implementations
* must be reentrant.
*/
class CIVETWEB_CXX_API CivetWebSocketHandler
{
public:
/**
* Destructor
*/
virtual ~CivetWebSocketHandler()
{
}
/**
* Callback method for when the client intends to establish a websocket
*connection, before websocket handshake.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true to keep socket open, false to close it
*/
virtual bool handleConnection(CivetServer *server,
const struct mg_connection *conn);
/**
* Callback method for when websocket handshake is successfully completed,
*and connection is ready for data exchange.
*
* @param server - the calling server
* @param conn - the connection information
*/
virtual void handleReadyState(CivetServer *server,
struct mg_connection *conn);
/**
* Callback method for when a data frame has been received from the client.
*
* @param server - the calling server
* @param conn - the connection information
* @bits: first byte of the websocket frame, see websocket RFC at
*http://tools.ietf.org/html/rfc6455, section 5.2
* @data, data_len: payload, with mask (if any) already applied.
* @returns true to keep socket open, false to close it
*/
virtual bool handleData(CivetServer *server,
struct mg_connection *conn,
int bits,
char *data,
size_t data_len);
/**
* Callback method for when the connection is closed.
*
* @param server - the calling server
* @param conn - the connection information
*/
virtual void handleClose(CivetServer *server,
const struct mg_connection *conn);
};
/**
* CivetCallbacks
*
* wrapper for mg_callbacks
*/
struct CIVETWEB_CXX_API CivetCallbacks : public mg_callbacks {
CivetCallbacks();
};
/**
* CivetServer
*
* Basic class for embedded web server. This has an URL mapping built-in.
*/
class CIVETWEB_CXX_API CivetServer
{
public:
/**
* Constructor
*
* This automatically starts the sever.
* It is good practice to call getContext() after this in case there
* were errors starting the server.
*
* Note: CivetServer should not be used as a static instance in a Windows
* DLL, since the constructor creates threads and the destructor joins
* them again (creating/joining threads should not be done in static
* constructors).
*
* @param options - the web server options.
* @param callbacks - optional web server callback methods.
*
* @throws CivetException
*/
CivetServer(const char **options,
const struct CivetCallbacks *callbacks = 0,
const void *UserContext = 0);
CivetServer(const std::vector<std::string> &options,
const struct CivetCallbacks *callbacks = 0,
const void *UserContext = 0);
/**
* Destructor
*/
virtual ~CivetServer();
/**
* close()
*
* Stops server and frees resources.
*/
void close();
/**
* getContext()
*
* @return the context or 0 if not running.
*/
const struct mg_context *
getContext() const
{
return context;
}
/**
* addHandler(const std::string &, CivetHandler *)
*
* Adds a URI handler. If there is existing URI handler, it will
* be replaced with this one.
*
* URI's are ordered and prefix (REST) URI's are supported.
*
* @param uri - URI to match.
* @param handler - handler instance to use.
*/
void addHandler(const std::string &uri, CivetHandler *handler);
void
addHandler(const std::string &uri, CivetHandler &handler)
{
addHandler(uri, &handler);
}
/**
* addWebSocketHandler
*
* Adds a WebSocket handler for a specific URI. If there is existing URI
*handler, it will
* be replaced with this one.
*
* URI's are ordered and prefix (REST) URI's are supported.
*
* @param uri - URI to match.
* @param handler - handler instance to use.
*/
void addWebSocketHandler(const std::string &uri,
CivetWebSocketHandler *handler);
void
addWebSocketHandler(const std::string &uri, CivetWebSocketHandler &handler)
{
addWebSocketHandler(uri, &handler);
}
/**
* removeHandler(const std::string &)
*
* Removes a handler.
*
* @param uri - the exact URL used in addHandler().
*/
void removeHandler(const std::string &uri);
/**
* removeWebSocketHandler(const std::string &)
*
* Removes a web socket handler.
*
* @param uri - the exact URL used in addWebSocketHandler().
*/
void removeWebSocketHandler(const std::string &uri);
/**
* addAuthHandler(const std::string &, CivetAuthHandler *)
*
* Adds a URI authorization handler. If there is existing URI authorization
* handler, it will be replaced with this one.
*
* URI's are ordered and prefix (REST) URI's are supported.
*
* @param uri - URI to match.
* @param handler - authorization handler instance to use.
*/
void addAuthHandler(const std::string &uri, CivetAuthHandler *handler);
void
addAuthHandler(const std::string &uri, CivetAuthHandler &handler)
{
addAuthHandler(uri, &handler);
}
/**
* removeAuthHandler(const std::string &)
*
* Removes an authorization handler.
*
* @param uri - the exact URL used in addAuthHandler().
*/
void removeAuthHandler(const std::string &uri);
/**
* getListeningPorts()
*
* Returns a list of ports that are listening
*
* @return A vector of ports
*/
std::vector<int> getListeningPorts();
/**
* getListeningPorts()
*
* Variant of getListeningPorts() returning the full port information
* (protocol, SSL, ...)
*
* @return A vector of ports
*/
std::vector<struct mg_server_port> getListeningPortsFull();
/**
* getCookie(struct mg_connection *conn, const std::string &cookieName,
* std::string &cookieValue)
*
* Puts the cookie value string that matches the cookie name in the
* cookieValue destination string.
*
* @param conn - the connection information
* @param cookieName - cookie name to get the value from
* @param cookieValue - cookie value is returned using this reference
* @returns the size of the cookie value string read.
*/
static int getCookie(struct mg_connection *conn,
const std::string &cookieName,
std::string &cookieValue);
/**
* getHeader(struct mg_connection *conn, const std::string &headerName)
* @param conn - the connection information
* @param headerName - header name to get the value from
* @returns a char array which contains the header value as string
*/
static const char *getHeader(struct mg_connection *conn,
const std::string &headerName);
/**
* getMethod(struct mg_connection *conn)
* @param conn - the connection information
* @returns method of HTTP request
*/
static const char *getMethod(struct mg_connection *conn);
/**
* getParam(struct mg_connection *conn, const char *, std::string &, size_t)
*
* Returns a query which contained in the supplied buffer. The
* occurrence value is a zero-based index of a particular key name. This
* should not be confused with the index over all of the keys. Note that
*this
* function assumes that parameters are sent as text in http query string
* format, which is the default for web forms. This function will work for
* html forms with method="GET" and method="POST" attributes. In other
*cases,
* you may use a getParam version that directly takes the data instead of
*the
* connection as a first argument.
*
* @param conn - parameters are read from the data sent through this
*connection
* @param name - the key to search for
* @param dst - the destination string
* @param occurrence - the occurrence of the selected name in the query (0
*based).
* @return true if key was found
*/
static bool getParam(struct mg_connection *conn,
const char *name,
std::string &dst,
size_t occurrence = 0);
/**
* getParam(const std::string &, const char *, std::string &, size_t)
*
* Returns a query parameter contained in the supplied buffer. The
* occurrence value is a zero-based index of a particular key name. This
* should not be confused with the index over all of the keys.
*
* @param data - the query string (text)
* @param name - the key to search for
* @param dst - the destination string
* @param occurrence - the occurrence of the selected name in the query (0
*based).
* @return true if key was found
*/
static bool
getParam(const std::string &data,
const char *name,
std::string &dst,
size_t occurrence = 0)
{
return getParam(data.c_str(), data.length(), name, dst, occurrence);
}
/**
* getParam(const char *, size_t, const char *, std::string &, size_t)
*
* Returns a query parameter contained in the supplied buffer. The
* occurrence value is a zero-based index of a particular key name. This
* should not be confused with the index over all of the keys.
*
* @param data the - query string (text)
* @param data_len - length of the query string
* @param name - the key to search for
* @param dst - the destination string
* @param occurrence - the occurrence of the selected name in the query (0
*based).
* @return true if key was found
*/
static bool getParam(const char *data,
size_t data_len,
const char *name,
std::string &dst,
size_t occurrence = 0);
/**
* getPostData(struct mg_connection *)
*
* Returns response body from a request made as POST. Since the
* connections map is protected, it can't be directly accessed.
* This uses string to store post data to handle big posts.
*
* @param conn - connection from which post data will be read
* @return Post data (empty if not available).
*/
static std::string getPostData(struct mg_connection *conn);
/**
* urlDecode(const std::string &, std::string &, bool)
*
* @param src - string to be decoded
* @param dst - destination string
* @param is_form_url_encoded - true if form url encoded
* form-url-encoded data differs from URI encoding in a way that it
* uses '+' as character for space, see RFC 1866 section 8.2.1
* http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
*/
static void
urlDecode(const std::string &src,
std::string &dst,
bool is_form_url_encoded = true)
{
urlDecode(src.c_str(), src.length(), dst, is_form_url_encoded);
}
/**
* urlDecode(const char *, size_t, std::string &, bool)
*
* @param src - buffer to be decoded
* @param src_len - length of buffer to be decoded
* @param dst - destination string
* @param is_form_url_encoded - true if form url encoded
* form-url-encoded data differs from URI encoding in a way that it
* uses '+' as character for space, see RFC 1866 section 8.2.1
* http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
*/
static void urlDecode(const char *src,
size_t src_len,
std::string &dst,
bool is_form_url_encoded = true);
/**
* urlDecode(const char *, std::string &, bool)
*
* @param src - buffer to be decoded (0 terminated)
* @param dst - destination string
* @param is_form_url_encoded true - if form url encoded
* form-url-encoded data differs from URI encoding in a way that it
* uses '+' as character for space, see RFC 1866 section 8.2.1
* http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
*/
static void urlDecode(const char *src,
std::string &dst,
bool is_form_url_encoded = true);
/**
* urlEncode(const std::string &, std::string &, bool)
*
* @param src - buffer to be encoded
* @param dst - destination string
* @param append - true if string should not be cleared before encoding.
*/
static void
urlEncode(const std::string &src, std::string &dst, bool append = false)
{
urlEncode(src.c_str(), src.length(), dst, append);
}
/**
* urlEncode(const char *, size_t, std::string &, bool)
*
* @param src - buffer to be encoded (0 terminated)
* @param dst - destination string
* @param append - true if string should not be cleared before encoding.
*/
static void
urlEncode(const char *src, std::string &dst, bool append = false);
/**
* urlEncode(const char *, size_t, std::string &, bool)
*
* @param src - buffer to be encoded
* @param src_len - length of buffer to be decoded
* @param dst - destination string
* @param append - true if string should not be cleared before encoding.
*/
static void urlEncode(const char *src,
size_t src_len,
std::string &dst,
bool append = false);
// generic user context which can be set/read,
// the server does nothing with this apart from keep it.
const void *
getUserContext() const
{
return UserContext;
}
protected:
class CivetConnection
{
public:
std::vector<char> postData;
};
struct mg_context *context;
std::map<const struct mg_connection *, CivetConnection> connections;
// generic user context which can be set/read,
// the server does nothing with this apart from keep it.
const void *UserContext;
private:
/**
* requestHandler(struct mg_connection *, void *cbdata)
*
* Handles the incoming request.
*
* @param conn - the connection information
* @param cbdata - pointer to the CivetHandler instance.
* @returns 0 if implemented, false otherwise
*/
static int requestHandler(struct mg_connection *conn, void *cbdata);
static int webSocketConnectionHandler(const struct mg_connection *conn,
void *cbdata);
static void webSocketReadyHandler(struct mg_connection *conn, void *cbdata);
static int webSocketDataHandler(struct mg_connection *conn,
int bits,
char *data,
size_t data_len,
void *cbdata);
static void webSocketCloseHandler(const struct mg_connection *conn,
void *cbdata);
/**
* authHandler(struct mg_connection *, void *cbdata)
*
* Handles the authorization requests.
*
* @param conn - the connection information
* @param cbdata - pointer to the CivetAuthHandler instance.
* @returns 1 if authorized, 0 otherwise
*/
static int authHandler(struct mg_connection *conn, void *cbdata);
/**
* closeHandler(struct mg_connection *)
*
* Handles closing a request (internal handler)
*
* @param conn - the connection information
*/
static void closeHandler(const struct mg_connection *conn);
/**
* Stores the user provided close handler
*/
void (*userCloseHandler)(const struct mg_connection *conn);
};
#endif /* __cplusplus */
#endif /* CIVETSERVER_HEADER_INCLUDED */

252
src/external/civetweb/LICENSE.md vendored Normal file
View File

@@ -0,0 +1,252 @@
ALL LICENSES
=====
This document includes several copyright licenses for different
aspects of the software. Not all licenses may apply depending
on the features chosen.
Civetweb License
-----
### Included with all features.
> Copyright (c) 2013-2021 The CivetWeb developers ([CREDITS.md](https://github.com/civetweb/civetweb/blob/master/CREDITS.md))
>
> Copyright (c) 2004-2013 Sergey Lyubka
>
> Copyright (c) 2013 No Face Press, LLC (Thomas Davis)
>
> Copyright (c) 2013 F-Secure Corporation
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
Lua License
------
### Included only if built with Lua support.
http://www.lua.org/license.html
> Copyright (C) 1994-2020 Lua.org, PUC-Rio.
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
Additional components Copyright (C) Lua.org, PUC-Rio, with MIT license:
http://www.inf.puc-rio.br/~roberto/struct/
SQLite3 License
------
### Included only if built with Lua and SQLite support.
http://www.sqlite.org/copyright.html
> 2001-09-15
>
> The author disclaims copyright to this source code. In place of
> a legal notice, here is a blessing:
>
> May you do good and not evil.
> May you find forgiveness for yourself and forgive others.
> May you share freely, never taking more than you give.
lsqlite3 License
------
### Included only if built with Lua and SQLite support.
> Copyright (C) 2002-2016 Tiago Dionizio, Doug Currie
> All rights reserved.
> Author : Tiago Dionizio <tiago.dionizio@ist.utl.pt>
> Author : Doug Currie <doug.currie@alum.mit.edu>
> Library : lsqlite3 - an SQLite 3 database binding for Lua 5
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
Lua File System License
------
### Included only if built with Lua support.
https://github.com/keplerproject/luafilesystem/blob/master/LICENSE
> Copyright © 2003-2020 Kepler Project.
>
> Permission is hereby granted, free of charge, to any person
> obtaining a copy of this software and associated documentation
> files (the "Software"), to deal in the Software without
> restriction, including without limitation the rights to use, copy,
> modify, merge, publish, distribute, sublicense, and/or sell copies
> of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be
> included in all copies or substantial portions of the Software.
>
> 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 AND
> NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
> BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
> ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
> CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
LuaXML License
------
### Included only if built with Lua and LuaXML support.
Version 1.8.0 (Lua 5.2), 2013-06-10 by Gerald Franz, eludi.net
Modified and extended 2015 by Bernhard Nortmann, https://github.com/n1tehawk/LuaXML version 2.0.x, compatible with Lua 5.1 to 5.3 and LuaJIT.
> LuaXML License
>
> LuaXml is licensed under the terms of the MIT license reproduced below,
> the same as Lua itself. This means that LuaXml is free software and can be
> used for both academic and commercial purposes at absolutely no cost.
>
> Copyright (C) 2007-2013 Gerald Franz, eludi.net
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
Duktape License
------
### Included only if built with Duktape support.
https://github.com/svaarala/duktape/blob/master/LICENSE.txt
> ===============
> Duktape license
> ===============
>
> (http://opensource.org/licenses/MIT)
>
> Copyright (c) 2013-2017 by Duktape authors (see AUTHORS.rst)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
zlib License
------
### Included only if built with zlib support.
https://www.zlib.net/zlib_license.html
> zlib.h -- interface of the 'zlib' general purpose compression library
> version 1.2.11, January 15th, 2017
>
> Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
>
> This software is provided 'as-is', without any express or implied
> warranty. In no event will the authors be held liable for any damages
> arising from the use of this software.
>
> Permission is granted to anyone to use this software for any purpose,
> including commercial applications, and to alter it and redistribute it
> freely, subject to the following restrictions:
>
> 1. The origin of this software must not be misrepresented; you must not
> claim that you wrote the original software. If you use this software
> in a product, an acknowledgment in the product documentation would be
> appreciated but is not required.
> 2. Altered source versions must be plainly marked as such, and must not be
> misrepresented as being the original software.
> 3. This notice may not be removed or altered from any source distribution.
>
> Jean-loup Gailly Mark Adler
> jloup@gzip.org madler@alumni.caltech.edu

193
src/external/civetweb/README.md vendored Normal file
View File

@@ -0,0 +1,193 @@
![CivetWeb](/resources/civetweb_64x64.png "CivetWeb") CivetWeb
=======
**The official home of CivetWeb is on GitHub [https://github.com/civetweb/civetweb](https://github.com/civetweb/civetweb)**
[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)
[![GitHub contributors](https://img.shields.io/github/contributors/civetweb/civetweb.svg)](https://github.com/civetweb/civetweb/blob/master/CREDITS.md)
[![Stargazers](https://img.shields.io/github/stars/civetweb/civetweb.svg)](https://github.com/civetweb/civetweb/stargazers)
[![Forks](https://img.shields.io/github/forks/civetweb/civetweb.svg)](https://github.com/civetweb/civetweb/network/members)
[![Latest Release](https://img.shields.io/github/v/release/civetweb/civetweb.svg)](https://github.com/civetweb/civetweb/releases)
Continuous integration for Linux and macOS ([Travis CI](https://app.travis-ci.com/github/civetweb/civetweb)):
[![Travis Build Status](https://api.travis-ci.com/civetweb/civetweb.svg?branch=master)](https://app.travis-ci.com/github/civetweb/civetweb)
Continuous integration for Windows ([AppVeyor](https://ci.appveyor.com/project/civetweb/civetweb)):
[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/github/civetweb/civetweb?svg=true)](https://ci.appveyor.com/project/civetweb/civetweb/branch/master)
Test coverage check ([coveralls](https://coveralls.io/github/civetweb/civetweb), [codecov](https://codecov.io/gh/civetweb/civetweb/branch/master)) (using different tools/settings):
[![Coveralls](https://img.shields.io/coveralls/civetweb/civetweb.svg?maxAge=3600)]()
[![Coverage Status](https://coveralls.io/repos/github/civetweb/civetweb/badge.svg?branch=master)](https://coveralls.io/github/civetweb/civetweb?branch=master)
[![codecov](https://codecov.io/gh/civetweb/civetweb/branch/master/graph/badge.svg)](https://codecov.io/gh/civetweb/civetweb)
Static source code analysis ([Coverity](https://scan.coverity.com/projects/5784)): [![Coverity Scan Build Status](https://scan.coverity.com/projects/5784/badge.svg)](https://scan.coverity.com/projects/5784)
CodeQL semantic code analysis: [![CodeQL](https://github.com/civetweb/civetweb/workflows/CodeQL/badge.svg)](https://github.com/civetweb/civetweb/actions/workflows/codeql-analysis.yml)
Project Mission
-----------------
Project mission is to provide easy to use, powerful, C (C/C++) embeddable web server with optional CGI, SSL and Lua support.
CivetWeb has a MIT license so you can innovate without restrictions.
CivetWeb can be used by developers as a library, to add web server functionality to an existing application.
It can also be used by end users as a stand-alone web server running on a Windows or Linux PC. It is available as single executable, no installation is required.
Where to find the official version?
-----------------------------------
End users can download CivetWeb binaries / releases from here on GitHub [https://github.com/civetweb/civetweb/releases](https://github.com/civetweb/civetweb/releases) or SourceForge
[https://sourceforge.net/projects/civetweb/](https://sourceforge.net/projects/civetweb/)
Developers can contribute to CivetWeb via GitHub
[https://github.com/civetweb/civetweb](https://github.com/civetweb/civetweb)
Due to a [bug in Git for Windows V2.24](https://github.com/git-for-windows/git/issues/2435)
CivetWeb must be used with an earlier or later version (see also [here](https://github.com/civetweb/civetweb/issues/812)).
Bugs and requests should be filed on GitHub
[https://github.com/civetweb/civetweb/issues](https://github.com/civetweb/civetweb/issues)
New releases are announced on Google Groups
[https://groups.google.com/d/forum/civetweb](https://groups.google.com/d/forum/civetweb)
Formerly some support question and discussion threads have been at [Google groups](https://groups.google.com/d/forum/civetweb).
Recent questions and discussions use [GitHub issues](https://github.com/civetweb/civetweb/issues).
Source releases can be found on GitHub
[https://github.com/civetweb/civetweb/releases](https://github.com/civetweb/civetweb/releases)
A very brief overview can be found on GitHub Pages
[https://civetweb.github.io/civetweb/](https://civetweb.github.io/civetweb/)
Quick start documentation
--------------------------
- [docs/Installing.md](https://github.com/civetweb/civetweb/blob/master/docs/Installing.md) - Install Guide (for end users using pre-built binaries)
- [docs/UserManual.md](https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md) - End User Guide
- [docs/Building.md](https://github.com/civetweb/civetweb/blob/master/docs/Building.md) - Building the Server (quick start guide)
- [docs/Embedding.md](https://github.com/civetweb/civetweb/blob/master/docs/Embedding.md) - Embedding (how to add HTTP support to an existing application)
- [docs/OpenSSL.md](https://github.com/civetweb/civetweb/blob/master/docs/OpenSSL.md) - Adding HTTPS (SSL/TLS) support using OpenSSL.
- [docs/Docker.md](https://github.com/civetweb/civetweb/blob/master/docs/Docker.md) - Use CivetWeb in a Docker container.
- [API documentation](https://github.com/civetweb/civetweb/tree/master/docs/api) - Additional documentation on the civetweb application programming interface ([civetweb.h](https://github.com/civetweb/civetweb/blob/master/include/civetweb.h)).
- [RELEASE_NOTES.md](https://github.com/civetweb/civetweb/blob/master/RELEASE_NOTES.md) - Release Notes
- [SECURITY.md](https://github.com/civetweb/civetweb/blob/master/SECURITY.md) - Security Policy
- [LICENSE.md](https://github.com/civetweb/civetweb/blob/master/LICENSE.md) - Copyright License
Overview
--------
CivetWeb keeps the balance between functionality and
simplicity by a carefully selected list of features:
- Forked from [Mongoose](https://code.google.com/p/mongoose/) in 2013, before
it changed the licence from MIT to commercial + GPL. A lot of enhancements
have been added since then, see
[RELEASE_NOTES.md](https://github.com/civetweb/civetweb/blob/master/RELEASE_NOTES.md).
- Maintains the liberal, permissive, commercial-friendly,
[MIT license](https://en.wikipedia.org/wiki/MIT_License)
- Project is free from copy-left licenses, like GPL, because you should innovate without
restrictions.
- Works on Windows, Mac, Linux, UNIX, IOS, Android, Buildroot, and many
other platforms.
- Scripting and database support (CGI, Lua Server Pages, Server side Lua scripts, Lua SQLite database,
Server side JavaScript).
This provides a ready to go, powerful web development platform in a one
single-click executable with **no dependencies**. 0
- Support for CGI, SSI, HTTP digest (MD5) authorization, WebSocket, WebDAV.
- Experimental HTTP/2 support.
- HTTPS (SSL/TLS) support using [OpenSSL](https://www.openssl.org/).
- Optional support for authentication using client side X.509 certificates.
- Resumed download, URL rewrite, file blacklist, IP-based ACL.
- Can run as a Windows service or systemd service.
- Download speed limit based on client subnet or URI pattern.
- Simple and clean embedding API.
- The source is in single file for drop in compilation.
- Embedding examples included.
- HTTP client capable of sending arbitrary HTTP/HTTPS requests.
- Websocket client functionality available (WS/WSS).
### Optionally included software
[![Lua](/resources/lua-logo.jpg "Lua Logo")](https://lua.org)
[![LuaFileSystem](/resources/luafilesystem-logo.jpg "LuaFileSystem Logo")](https://keplerproject.github.io/luafilesystem/)
[![LuaSQLite3](/resources/luasqlite-logo.jpg "LuaSQLite3 Logo")](https://lua.sqlite.org/index.cgi/index)
[![Sqlite3](/resources/sqlite3-logo.jpg "Sqlite3 Logo")](https://sqlite.org)
[![LuaXML](/resources/luaxml-logo.jpg "LuaXML Logo")](https://github.com/n1tehawk/LuaXML)
[![Duktape](/resources/duktape-logo.png "Duktape Logo")](https://duktape.org)
### Optional dependencies
[zlib](https://zlib.net)
[OpenSSL](https://www.openssl.org/)
[Mbed TLS](https://github.com/ARMmbed/mbedtls)
[GNU TLS](https://gnutls.org)
Support
-------
This project is very easy to install and use.
Please read the [documentation](https://github.com/civetweb/civetweb/blob/master/docs/)
and have a look at the [examples](https://github.com/civetweb/civetweb/blob/master/examples/).
Recent questions and discussions usually use [GitHub issues](https://github.com/civetweb/civetweb/issues).
Some old information may be found on the [mailing list](https://groups.google.com/d/forum/civetweb),
but this information may be outdated.
Feel free to create a GitHub issue for bugs, feature requests, questions, suggestions or if you want to share tips and tricks.
When creating an issues for a bug, add enough description to reproduce the issue - at least add CivetWeb version and operating system.
Please see also the guidelines for [Contributions](https://github.com/civetweb/civetweb/blob/master/docs/Contribution.md) and the [Security Policy](https://github.com/civetweb/civetweb/blob/master/SECURITY.md)
Note: We do not take any liability or warranty for any linked contents. Visit these pages and try the community support suggestions at your own risk.
Any link provided in this project (including source and documentation) is provided in the hope that this information will be helpful.
However, we cannot accept any responsibility for any content on an external page.
Contributions
-------------
Contributions are welcome provided all contributions carry the MIT license.
DO NOT APPLY fixes copied from Mongoose to this project to prevent GPL tainting.
Since 2013, CivetWeb and Mongoose have been developed independently.
By now the code base differs, so patches cannot be safely transferred in either direction.
Some guidelines can be found in [docs/Contribution.md](https://github.com/civetweb/civetweb/blob/master/docs/Contribution.md).
Authors
-------
CivetWeb was forked from the last MIT version of Mongoose in August 2013.
Since then, CivetWeb has seen many improvements from various authors
(Copyright (c) 2013-2021 the CivetWeb developers, MIT license).
A list of authors can be found in [CREDITS.md](https://github.com/civetweb/civetweb/blob/master/CREDITS.md).
CivetWeb is based on the [Mongoose project](https://github.com/cesanta/mongoose). The original author of Mongoose was
Sergey Lyubka(2004-2013) who released it under the MIT license.
However, on August 16, 2013,
[Mongoose was relicensed to a dual GPL V2 + commercial license](https://groups.google.com/forum/#!topic/mongoose-users/aafbOnHonkI)
and CiwetWeb was created by Thomas Davis (sunsetbrew) as "the MIT fork of mongoose".
The license change and CivetWeb fork was mentioned on the Mongoose
[Wikipedia](https://en.wikipedia.org/wiki/Mongoose_(web_server))
page as well, but it's getting deleted (and added again) there every
now and then.
Using the CivetWeb project ensures the MIT licenses terms are applied and
GPL cannot be imposed on any of this code, as long as it is sourced from
here. This code will remain free with the MIT license protection.

23201
src/external/civetweb/civetweb.c vendored Normal file

File diff suppressed because it is too large Load Diff

1833
src/external/civetweb/civetweb.h vendored Normal file

File diff suppressed because it is too large Load Diff

472
src/external/civetweb/md5.inl vendored Normal file
View File

@@ -0,0 +1,472 @@
/*
* This an amalgamation of md5.c and md5.h into a single file
* with all static declaration to reduce linker conflicts
* in Civetweb.
*
* The MD5_STATIC declaration was added to facilitate static
* inclusion.
* No Face Press, LLC
*/
/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
/*
Independent implementation of MD5 (RFC 1321).
This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
copyrighted.
The original and principal author of md5.h is L. Peter Deutsch
<ghost@aladdin.com>. Other authors are noted in the change history
that follows (in reverse chronological order):
2002-04-13 lpd Removed support for non-ANSI compilers; removed
references to Ghostscript; clarified derivation from RFC 1321;
now handles byte order either statically or dynamically.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
added conditionalization for C++ compilation from Martin
Purschke <purschke@bnl.gov>.
1999-05-03 lpd Original version.
*/
#if !defined(md5_INCLUDED)
#define md5_INCLUDED
/*
* This package supports both compile-time and run-time determination of CPU
* byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
* compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
* defined as non-zero, the code will be compiled to run only on big-endian
* CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
* run on either big- or little-endian CPUs, but will run slightly less
* efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
*/
typedef unsigned char md5_byte_t; /* 8-bit byte */
typedef unsigned int md5_word_t; /* 32-bit word */
/* Define the state of the MD5 Algorithm. */
typedef struct md5_state_s {
md5_word_t count[2]; /* message length in bits, lsw first */
md5_word_t abcd[4]; /* digest buffer */
md5_byte_t buf[64]; /* accumulate block */
} md5_state_t;
#if defined(__cplusplus)
extern "C" {
#endif
/* Initialize the algorithm. */
MD5_STATIC void md5_init(md5_state_t *pms);
/* Append a string to the message. */
MD5_STATIC void
md5_append(md5_state_t *pms, const md5_byte_t *data, size_t nbytes);
/* Finish the message and return the digest. */
MD5_STATIC void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
#if defined(__cplusplus)
} /* end extern "C" */
#endif
#endif /* md5_INCLUDED */
/*
Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
L. Peter Deutsch
ghost@aladdin.com
*/
/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */
/*
Independent implementation of MD5 (RFC 1321).
This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
copyrighted.
The original and principal author of md5.c is L. Peter Deutsch
<ghost@aladdin.com>. Other authors are noted in the change history
that follows (in reverse chronological order):
2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order
either statically or dynamically; added missing #include <string.h>
in library.
2002-03-11 lpd Corrected argument list for main(), and added int return
type, in test program and T value program.
2002-02-21 lpd Added missing #include <stdio.h> in test program.
2000-07-03 lpd Patched to eliminate warnings about "constant is
unsigned in ANSI C, signed in traditional"; made test program
self-checking.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
1999-05-03 lpd Original version.
*/
#if !defined(MD5_STATIC)
#include <stdint.h>
#include <string.h>
#endif
#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
#if defined(ARCH_IS_BIG_ENDIAN)
#define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
#else
#define BYTE_ORDER (0)
#endif
#define T_MASK ((md5_word_t)~0)
#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87)
#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9)
#define T3 (0x242070db)
#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111)
#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050)
#define T6 (0x4787c62a)
#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec)
#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe)
#define T9 (0x698098d8)
#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850)
#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e)
#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841)
#define T13 (0x6b901122)
#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c)
#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71)
#define T16 (0x49b40821)
#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d)
#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf)
#define T19 (0x265e5a51)
#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855)
#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2)
#define T22 (0x02441453)
#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e)
#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437)
#define T25 (0x21e1cde6)
#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829)
#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278)
#define T28 (0x455a14ed)
#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa)
#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07)
#define T31 (0x676f02d9)
#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375)
#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd)
#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e)
#define T35 (0x6d9d6122)
#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3)
#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb)
#define T38 (0x4bdecfa9)
#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f)
#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f)
#define T41 (0x289b7ec6)
#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805)
#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a)
#define T44 (0x04881d05)
#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6)
#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a)
#define T47 (0x1fa27cf8)
#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a)
#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb)
#define T50 (0x432aff97)
#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58)
#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6)
#define T53 (0x655b59c3)
#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d)
#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82)
#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e)
#define T57 (0x6fa87e4f)
#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f)
#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb)
#define T60 (0x4e0811a1)
#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d)
#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca)
#define T63 (0x2ad7d2bb)
#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e)
static void
md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
{
md5_word_t a = pms->abcd[0], b = pms->abcd[1], c = pms->abcd[2],
d = pms->abcd[3];
md5_word_t t;
#if BYTE_ORDER > 0
/* Define storage only for big-endian CPUs. */
md5_word_t X[16];
#else
/* Define storage for little-endian or both types of CPUs. */
md5_word_t xbuf[16];
const md5_word_t *X;
#endif
{
#if BYTE_ORDER == 0
/*
* Determine dynamically whether this is a big-endian or
* little-endian machine, since we can use a more efficient
* algorithm on the latter.
*/
static const int w = 1;
if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
#endif
#if BYTE_ORDER <= 0 /* little-endian */
{
/*
* On little-endian machines, we can process properly aligned
* data without copying it.
*/
if (!(((uintptr_t)data) & 3)) {
/* data are properly aligned, a direct assignment is possible */
/* cast through a (void *) should avoid a compiler warning,
see
https://github.com/bel2125/civetweb/issues/94#issuecomment-98112861
*/
X = (const md5_word_t *)(const void *)data;
} else {
/* not aligned */
memcpy(xbuf, data, 64);
X = xbuf;
}
}
#endif
#if BYTE_ORDER == 0
else /* dynamic big-endian */
#endif
#if BYTE_ORDER >= 0 /* big-endian */
{
/*
* On big-endian machines, we must arrange the bytes in the
* right order.
*/
const md5_byte_t *xp = data;
int i;
#if BYTE_ORDER == 0
X = xbuf; /* (dynamic only) */
#else
#define xbuf X /* (static only) */
#endif
for (i = 0; i < 16; ++i, xp += 4)
xbuf[i] = (md5_word_t)(xp[0]) + (md5_word_t)(xp[1] << 8)
+ (md5_word_t)(xp[2] << 16)
+ (md5_word_t)(xp[3] << 24);
}
#endif
}
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
/* Round 1. */
/* Let [abcd k s i] denote the operation
a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
#define F(x, y, z) (((x) & (y)) | (~(x) & (z)))
#define SET(a, b, c, d, k, s, Ti) \
t = (a) + F(b, c, d) + X[k] + (Ti); \
(a) = ROTATE_LEFT(t, s) + (b)
/* Do the following 16 operations. */
SET(a, b, c, d, 0, 7, T1);
SET(d, a, b, c, 1, 12, T2);
SET(c, d, a, b, 2, 17, T3);
SET(b, c, d, a, 3, 22, T4);
SET(a, b, c, d, 4, 7, T5);
SET(d, a, b, c, 5, 12, T6);
SET(c, d, a, b, 6, 17, T7);
SET(b, c, d, a, 7, 22, T8);
SET(a, b, c, d, 8, 7, T9);
SET(d, a, b, c, 9, 12, T10);
SET(c, d, a, b, 10, 17, T11);
SET(b, c, d, a, 11, 22, T12);
SET(a, b, c, d, 12, 7, T13);
SET(d, a, b, c, 13, 12, T14);
SET(c, d, a, b, 14, 17, T15);
SET(b, c, d, a, 15, 22, T16);
#undef SET
/* Round 2. */
/* Let [abcd k s i] denote the operation
a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
#define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
#define SET(a, b, c, d, k, s, Ti) \
t = (a) + G(b, c, d) + X[k] + (Ti); \
(a) = ROTATE_LEFT(t, s) + (b)
/* Do the following 16 operations. */
SET(a, b, c, d, 1, 5, T17);
SET(d, a, b, c, 6, 9, T18);
SET(c, d, a, b, 11, 14, T19);
SET(b, c, d, a, 0, 20, T20);
SET(a, b, c, d, 5, 5, T21);
SET(d, a, b, c, 10, 9, T22);
SET(c, d, a, b, 15, 14, T23);
SET(b, c, d, a, 4, 20, T24);
SET(a, b, c, d, 9, 5, T25);
SET(d, a, b, c, 14, 9, T26);
SET(c, d, a, b, 3, 14, T27);
SET(b, c, d, a, 8, 20, T28);
SET(a, b, c, d, 13, 5, T29);
SET(d, a, b, c, 2, 9, T30);
SET(c, d, a, b, 7, 14, T31);
SET(b, c, d, a, 12, 20, T32);
#undef SET
/* Round 3. */
/* Let [abcd k s t] denote the operation
a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define SET(a, b, c, d, k, s, Ti) \
t = (a) + H(b, c, d) + X[k] + (Ti); \
(a) = ROTATE_LEFT(t, s) + b
/* Do the following 16 operations. */
SET(a, b, c, d, 5, 4, T33);
SET(d, a, b, c, 8, 11, T34);
SET(c, d, a, b, 11, 16, T35);
SET(b, c, d, a, 14, 23, T36);
SET(a, b, c, d, 1, 4, T37);
SET(d, a, b, c, 4, 11, T38);
SET(c, d, a, b, 7, 16, T39);
SET(b, c, d, a, 10, 23, T40);
SET(a, b, c, d, 13, 4, T41);
SET(d, a, b, c, 0, 11, T42);
SET(c, d, a, b, 3, 16, T43);
SET(b, c, d, a, 6, 23, T44);
SET(a, b, c, d, 9, 4, T45);
SET(d, a, b, c, 12, 11, T46);
SET(c, d, a, b, 15, 16, T47);
SET(b, c, d, a, 2, 23, T48);
#undef SET
/* Round 4. */
/* Let [abcd k s t] denote the operation
a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
#define SET(a, b, c, d, k, s, Ti) \
t = (a) + I(b, c, d) + X[k] + (Ti); \
(a) = ROTATE_LEFT(t, s) + (b)
/* Do the following 16 operations. */
SET(a, b, c, d, 0, 6, T49);
SET(d, a, b, c, 7, 10, T50);
SET(c, d, a, b, 14, 15, T51);
SET(b, c, d, a, 5, 21, T52);
SET(a, b, c, d, 12, 6, T53);
SET(d, a, b, c, 3, 10, T54);
SET(c, d, a, b, 10, 15, T55);
SET(b, c, d, a, 1, 21, T56);
SET(a, b, c, d, 8, 6, T57);
SET(d, a, b, c, 15, 10, T58);
SET(c, d, a, b, 6, 15, T59);
SET(b, c, d, a, 13, 21, T60);
SET(a, b, c, d, 4, 6, T61);
SET(d, a, b, c, 11, 10, T62);
SET(c, d, a, b, 2, 15, T63);
SET(b, c, d, a, 9, 21, T64);
#undef SET
/* Then perform the following additions. (That is increment each
of the four registers by the value it had before this block
was started.) */
pms->abcd[0] += a;
pms->abcd[1] += b;
pms->abcd[2] += c;
pms->abcd[3] += d;
}
MD5_STATIC void
md5_init(md5_state_t *pms)
{
pms->count[0] = pms->count[1] = 0;
pms->abcd[0] = 0x67452301;
pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476;
pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301;
pms->abcd[3] = 0x10325476;
}
MD5_STATIC void
md5_append(md5_state_t *pms, const md5_byte_t *data, size_t nbytes)
{
const md5_byte_t *p = data;
size_t left = nbytes;
size_t offset = (pms->count[0] >> 3) & 63;
md5_word_t nbits = (md5_word_t)(nbytes << 3);
if (nbytes <= 0)
return;
/* Update the message length. */
pms->count[1] += (md5_word_t)(nbytes >> 29);
pms->count[0] += nbits;
if (pms->count[0] < nbits)
pms->count[1]++;
/* Process an initial partial block. */
if (offset) {
size_t copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
memcpy(pms->buf + offset, p, copy);
if (offset + copy < 64)
return;
p += copy;
left -= copy;
md5_process(pms, pms->buf);
}
/* Process full blocks. */
for (; left >= 64; p += 64, left -= 64)
md5_process(pms, p);
/* Process a final partial block. */
if (left)
memcpy(pms->buf, p, left);
}
MD5_STATIC void
md5_finish(md5_state_t *pms, md5_byte_t digest[16])
{
static const md5_byte_t pad[64] = {0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
md5_byte_t data[8];
int i;
/* Save the length before padding. */
for (i = 0; i < 8; ++i)
data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
/* Pad to 56 bytes mod 64. */
md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
/* Append the length. */
md5_append(pms, data, 8);
for (i = 0; i < 16; ++i)
digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
}
/* End of md5.inl */

545
src/external/civetweb/openssl_dl.inl vendored Normal file
View File

@@ -0,0 +1,545 @@
/* Copyright (c) 2013-2021 the Civetweb developers
* Copyright (c) 2004-2013 Sergey Lyubka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
typedef struct ssl_st SSL;
typedef struct ssl_method_st SSL_METHOD;
typedef struct ssl_ctx_st SSL_CTX;
typedef struct x509_store_ctx_st X509_STORE_CTX;
typedef struct x509_name X509_NAME;
typedef struct asn1_integer ASN1_INTEGER;
typedef struct bignum BIGNUM;
typedef struct ossl_init_settings_st OPENSSL_INIT_SETTINGS;
typedef struct evp_md EVP_MD;
typedef struct x509 X509;
#define SSL_CTRL_OPTIONS (32)
#define SSL_CTRL_CLEAR_OPTIONS (77)
#define SSL_CTRL_SET_ECDH_AUTO (94)
#define OPENSSL_INIT_NO_LOAD_SSL_STRINGS 0x00100000L
#define OPENSSL_INIT_LOAD_SSL_STRINGS 0x00200000L
#define OPENSSL_INIT_LOAD_CRYPTO_STRINGS 0x00000002L
#define SSL_VERIFY_NONE (0)
#define SSL_VERIFY_PEER (1)
#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT (2)
#define SSL_VERIFY_CLIENT_ONCE (4)
#define SSL_OP_ALL (0x80000BFFul)
#define SSL_OP_NO_SSLv2 (0x01000000ul)
#define SSL_OP_NO_SSLv3 (0x02000000ul)
#define SSL_OP_NO_TLSv1 (0x04000000ul)
#define SSL_OP_NO_TLSv1_2 (0x08000000ul)
#define SSL_OP_NO_TLSv1_1 (0x10000000ul)
#define SSL_OP_NO_TLSv1_3 (0x20000000ul)
#define SSL_OP_SINGLE_DH_USE (0x00100000ul)
#define SSL_OP_CIPHER_SERVER_PREFERENCE (0x00400000ul)
#define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION (0x00010000ul)
#define SSL_OP_NO_COMPRESSION (0x00020000ul)
#define SSL_OP_NO_RENEGOTIATION (0x40000000ul)
#define SSL_CB_HANDSHAKE_START (0x10)
#define SSL_CB_HANDSHAKE_DONE (0x20)
#define SSL_ERROR_NONE (0)
#define SSL_ERROR_SSL (1)
#define SSL_ERROR_WANT_READ (2)
#define SSL_ERROR_WANT_WRITE (3)
#define SSL_ERROR_WANT_X509_LOOKUP (4)
#define SSL_ERROR_SYSCALL (5) /* see errno */
#define SSL_ERROR_ZERO_RETURN (6)
#define SSL_ERROR_WANT_CONNECT (7)
#define SSL_ERROR_WANT_ACCEPT (8)
#define TLSEXT_TYPE_server_name (0)
#define TLSEXT_NAMETYPE_host_name (0)
#define SSL_TLSEXT_ERR_OK (0)
#define SSL_TLSEXT_ERR_ALERT_WARNING (1)
#define SSL_TLSEXT_ERR_ALERT_FATAL (2)
#define SSL_TLSEXT_ERR_NOACK (3)
#define SSL_SESS_CACHE_BOTH (3)
enum ssl_func_category {
TLS_Mandatory, /* required for HTTPS */
TLS_ALPN, /* required for Application Layer Protocol Negotiation */
TLS_END_OF_LIST
};
/* Check if all TLS functions/features are available */
static int tls_feature_missing[TLS_END_OF_LIST] = {0};
struct ssl_func {
const char *name; /* SSL function name */
enum ssl_func_category required; /* Mandatory or optional */
void (*ptr)(void); /* Function pointer */
};
#if (defined(OPENSSL_API_1_1) || defined(OPENSSL_API_3_0)) \
&& !defined(NO_SSL_DL)
#define SSL_free (*(void (*)(SSL *))ssl_sw[0].ptr)
#define SSL_accept (*(int (*)(SSL *))ssl_sw[1].ptr)
#define SSL_connect (*(int (*)(SSL *))ssl_sw[2].ptr)
#define SSL_read (*(int (*)(SSL *, void *, int))ssl_sw[3].ptr)
#define SSL_write (*(int (*)(SSL *, const void *, int))ssl_sw[4].ptr)
#define SSL_get_error (*(int (*)(SSL *, int))ssl_sw[5].ptr)
#define SSL_set_fd (*(int (*)(SSL *, SOCKET))ssl_sw[6].ptr)
#define SSL_new (*(SSL * (*)(SSL_CTX *)) ssl_sw[7].ptr)
#define SSL_CTX_new (*(SSL_CTX * (*)(SSL_METHOD *)) ssl_sw[8].ptr)
#define TLS_server_method (*(SSL_METHOD * (*)(void)) ssl_sw[9].ptr)
#define OPENSSL_init_ssl \
(*(int (*)(uint64_t opts, \
const OPENSSL_INIT_SETTINGS *settings))ssl_sw[10] \
.ptr)
#define SSL_CTX_use_PrivateKey_file \
(*(int (*)(SSL_CTX *, const char *, int))ssl_sw[11].ptr)
#define SSL_CTX_use_certificate_file \
(*(int (*)(SSL_CTX *, const char *, int))ssl_sw[12].ptr)
#define SSL_CTX_set_default_passwd_cb \
(*(void (*)(SSL_CTX *, mg_callback_t))ssl_sw[13].ptr)
#define SSL_CTX_free (*(void (*)(SSL_CTX *))ssl_sw[14].ptr)
#define SSL_CTX_use_certificate_chain_file \
(*(int (*)(SSL_CTX *, const char *))ssl_sw[15].ptr)
#define TLS_client_method (*(SSL_METHOD * (*)(void)) ssl_sw[16].ptr)
#define SSL_pending (*(int (*)(SSL *))ssl_sw[17].ptr)
#define SSL_CTX_set_verify \
(*(void (*)(SSL_CTX *, \
int, \
int (*verify_callback)(int, X509_STORE_CTX *)))ssl_sw[18] \
.ptr)
#define SSL_shutdown (*(int (*)(SSL *))ssl_sw[19].ptr)
#define SSL_CTX_load_verify_locations \
(*(int (*)(SSL_CTX *, const char *, const char *))ssl_sw[20].ptr)
#define SSL_CTX_set_default_verify_paths (*(int (*)(SSL_CTX *))ssl_sw[21].ptr)
#define SSL_CTX_set_verify_depth (*(void (*)(SSL_CTX *, int))ssl_sw[22].ptr)
#define SSL_get_peer_certificate (*(X509 * (*)(SSL *)) ssl_sw[23].ptr)
#define SSL_get_version (*(const char *(*)(SSL *))ssl_sw[24].ptr)
#define SSL_get_current_cipher (*(SSL_CIPHER * (*)(SSL *)) ssl_sw[25].ptr)
#define SSL_CIPHER_get_name \
(*(const char *(*)(const SSL_CIPHER *))ssl_sw[26].ptr)
#define SSL_CTX_check_private_key (*(int (*)(SSL_CTX *))ssl_sw[27].ptr)
#define SSL_CTX_set_session_id_context \
(*(int (*)(SSL_CTX *, const unsigned char *, unsigned int))ssl_sw[28].ptr)
#define SSL_CTX_ctrl (*(long (*)(SSL_CTX *, int, long, void *))ssl_sw[29].ptr)
#define SSL_CTX_set_cipher_list \
(*(int (*)(SSL_CTX *, const char *))ssl_sw[30].ptr)
#define SSL_CTX_set_options \
(*(unsigned long (*)(SSL_CTX *, unsigned long))ssl_sw[31].ptr)
#define SSL_CTX_set_info_callback \
(*(void (*)(SSL_CTX * ctx, void (*callback)(const SSL *, int, int))) \
ssl_sw[32] \
.ptr)
#define SSL_get_ex_data (*(char *(*)(const SSL *, int))ssl_sw[33].ptr)
#define SSL_set_ex_data (*(void (*)(SSL *, int, char *))ssl_sw[34].ptr)
#define SSL_CTX_callback_ctrl \
(*(long (*)(SSL_CTX *, int, void (*)(void)))ssl_sw[35].ptr)
#define SSL_get_servername \
(*(const char *(*)(const SSL *, int type))ssl_sw[36].ptr)
#define SSL_set_SSL_CTX (*(SSL_CTX * (*)(SSL *, SSL_CTX *)) ssl_sw[37].ptr)
#define SSL_ctrl (*(long (*)(SSL *, int, long, void *))ssl_sw[38].ptr)
#define SSL_CTX_set_alpn_protos \
(*(int (*)(SSL_CTX *, const unsigned char *, unsigned))ssl_sw[39].ptr)
typedef int (*tSSL_alpn_select_cb)(SSL *ssl,
const unsigned char **out,
unsigned char *outlen,
const unsigned char *in,
unsigned int inlen,
void *arg);
#define SSL_CTX_set_alpn_select_cb \
(*(void (*)(SSL_CTX *, tSSL_alpn_select_cb, void *))ssl_sw[40].ptr)
typedef int (*tSSL_next_protos_advertised_cb)(SSL *ssl,
const unsigned char **out,
unsigned int *outlen,
void *arg);
#define SSL_CTX_set_next_protos_advertised_cb \
(*(void (*)(SSL_CTX *, tSSL_next_protos_advertised_cb, void *))ssl_sw[41] \
.ptr)
#define SSL_CTX_set_timeout (*(long (*)(SSL_CTX *, long))ssl_sw[42].ptr)
#define SSL_CTX_clear_options(ctx, op) \
SSL_CTX_ctrl((ctx), SSL_CTRL_CLEAR_OPTIONS, (op), NULL)
#define SSL_CTX_set_ecdh_auto(ctx, onoff) \
SSL_CTX_ctrl(ctx, SSL_CTRL_SET_ECDH_AUTO, onoff, NULL)
#define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB 53
#define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG 54
#define SSL_CTRL_SET_TLSEXT_HOSTNAME 55
#define SSL_CTX_set_tlsext_servername_callback(ctx, cb) \
SSL_CTX_callback_ctrl(ctx, \
SSL_CTRL_SET_TLSEXT_SERVERNAME_CB, \
(void (*)(void))cb)
#define SSL_set_tlsext_host_name(ctx, arg) \
SSL_ctrl(ctx, SSL_CTRL_SET_TLSEXT_HOSTNAME, 0, (void *)arg)
#define X509_get_notBefore(x) ((x)->cert_info->validity->notBefore)
#define X509_get_notAfter(x) ((x)->cert_info->validity->notAfter)
#define SSL_set_app_data(s, arg) (SSL_set_ex_data(s, 0, (char *)arg))
#define SSL_get_app_data(s) (SSL_get_ex_data(s, 0))
#define SSL_CTX_sess_set_cache_size(ctx, size) SSL_CTX_ctrl(ctx, 42, size, NULL)
#define SSL_CTX_set_session_cache_mode(ctx, mode) \
SSL_CTX_ctrl(ctx, 44, mode, NULL)
#define ERR_get_error (*(unsigned long (*)(void))crypto_sw[0].ptr)
#define ERR_error_string (*(char *(*)(unsigned long, char *))crypto_sw[1].ptr)
#define CONF_modules_unload (*(void (*)(int))crypto_sw[2].ptr)
#define X509_free (*(void (*)(X509 *))crypto_sw[3].ptr)
#define X509_get_subject_name (*(X509_NAME * (*)(X509 *)) crypto_sw[4].ptr)
#define X509_get_issuer_name (*(X509_NAME * (*)(X509 *)) crypto_sw[5].ptr)
#define X509_NAME_oneline \
(*(char *(*)(X509_NAME *, char *, int))crypto_sw[6].ptr)
#define X509_get_serialNumber (*(ASN1_INTEGER * (*)(X509 *)) crypto_sw[7].ptr)
#define EVP_get_digestbyname \
(*(const EVP_MD *(*)(const char *))crypto_sw[8].ptr)
#define EVP_Digest \
(*(int (*)( \
const void *, size_t, void *, unsigned int *, const EVP_MD *, void *)) \
crypto_sw[9] \
.ptr)
#define i2d_X509 (*(int (*)(X509 *, unsigned char **))crypto_sw[10].ptr)
#define BN_bn2hex (*(char *(*)(const BIGNUM *a))crypto_sw[11].ptr)
#define ASN1_INTEGER_to_BN \
(*(BIGNUM * (*)(const ASN1_INTEGER *ai, BIGNUM *bn)) crypto_sw[12].ptr)
#define BN_free (*(void (*)(const BIGNUM *a))crypto_sw[13].ptr)
#define CRYPTO_free (*(void (*)(void *addr))crypto_sw[14].ptr)
#define ERR_clear_error (*(void (*)(void))crypto_sw[15].ptr)
#define OPENSSL_free(a) CRYPTO_free(a)
#define OPENSSL_REMOVE_THREAD_STATE()
/* init_ssl_ctx() function updates this array.
* It loads SSL library dynamically and changes NULLs to the actual addresses
* of respective functions. The macros above (like SSL_connect()) are really
* just calling these functions indirectly via the pointer. */
static struct ssl_func ssl_sw[] = {
{"SSL_free", TLS_Mandatory, NULL},
{"SSL_accept", TLS_Mandatory, NULL},
{"SSL_connect", TLS_Mandatory, NULL},
{"SSL_read", TLS_Mandatory, NULL},
{"SSL_write", TLS_Mandatory, NULL},
{"SSL_get_error", TLS_Mandatory, NULL},
{"SSL_set_fd", TLS_Mandatory, NULL},
{"SSL_new", TLS_Mandatory, NULL},
{"SSL_CTX_new", TLS_Mandatory, NULL},
{"TLS_server_method", TLS_Mandatory, NULL},
{"OPENSSL_init_ssl", TLS_Mandatory, NULL},
{"SSL_CTX_use_PrivateKey_file", TLS_Mandatory, NULL},
{"SSL_CTX_use_certificate_file", TLS_Mandatory, NULL},
{"SSL_CTX_set_default_passwd_cb", TLS_Mandatory, NULL},
{"SSL_CTX_free", TLS_Mandatory, NULL},
{"SSL_CTX_use_certificate_chain_file", TLS_Mandatory, NULL},
{"TLS_client_method", TLS_Mandatory, NULL},
{"SSL_pending", TLS_Mandatory, NULL},
{"SSL_CTX_set_verify", TLS_Mandatory, NULL},
{"SSL_shutdown", TLS_Mandatory, NULL},
{"SSL_CTX_load_verify_locations", TLS_Mandatory, NULL},
{"SSL_CTX_set_default_verify_paths", TLS_Mandatory, NULL},
{"SSL_CTX_set_verify_depth", TLS_Mandatory, NULL},
#if defined(OPENSSL_API_3_0)
{"SSL_get1_peer_certificate", TLS_Mandatory, NULL},
#else
{"SSL_get_peer_certificate", TLS_Mandatory, NULL},
#endif
{"SSL_get_version", TLS_Mandatory, NULL},
{"SSL_get_current_cipher", TLS_Mandatory, NULL},
{"SSL_CIPHER_get_name", TLS_Mandatory, NULL},
{"SSL_CTX_check_private_key", TLS_Mandatory, NULL},
{"SSL_CTX_set_session_id_context", TLS_Mandatory, NULL},
{"SSL_CTX_ctrl", TLS_Mandatory, NULL},
{"SSL_CTX_set_cipher_list", TLS_Mandatory, NULL},
{"SSL_CTX_set_options", TLS_Mandatory, NULL},
{"SSL_CTX_set_info_callback", TLS_Mandatory, NULL},
{"SSL_get_ex_data", TLS_Mandatory, NULL},
{"SSL_set_ex_data", TLS_Mandatory, NULL},
{"SSL_CTX_callback_ctrl", TLS_Mandatory, NULL},
{"SSL_get_servername", TLS_Mandatory, NULL},
{"SSL_set_SSL_CTX", TLS_Mandatory, NULL},
{"SSL_ctrl", TLS_Mandatory, NULL},
{"SSL_CTX_set_alpn_protos", TLS_ALPN, NULL},
{"SSL_CTX_set_alpn_select_cb", TLS_ALPN, NULL},
{"SSL_CTX_set_next_protos_advertised_cb", TLS_ALPN, NULL},
{"SSL_CTX_set_timeout", TLS_Mandatory, NULL},
{NULL, TLS_END_OF_LIST, NULL}};
/* Similar array as ssl_sw. These functions could be located in different
* lib. */
static struct ssl_func crypto_sw[] = {
{"ERR_get_error", TLS_Mandatory, NULL},
{"ERR_error_string", TLS_Mandatory, NULL},
{"CONF_modules_unload", TLS_Mandatory, NULL},
{"X509_free", TLS_Mandatory, NULL},
{"X509_get_subject_name", TLS_Mandatory, NULL},
{"X509_get_issuer_name", TLS_Mandatory, NULL},
{"X509_NAME_oneline", TLS_Mandatory, NULL},
{"X509_get_serialNumber", TLS_Mandatory, NULL},
{"EVP_get_digestbyname", TLS_Mandatory, NULL},
{"EVP_Digest", TLS_Mandatory, NULL},
{"i2d_X509", TLS_Mandatory, NULL},
{"BN_bn2hex", TLS_Mandatory, NULL},
{"ASN1_INTEGER_to_BN", TLS_Mandatory, NULL},
{"BN_free", TLS_Mandatory, NULL},
{"CRYPTO_free", TLS_Mandatory, NULL},
{"ERR_clear_error", TLS_Mandatory, NULL},
{NULL, TLS_END_OF_LIST, NULL}};
#endif
#if defined(OPENSSL_API_1_0)
#define SSL_free (*(void (*)(SSL *))ssl_sw[0].ptr)
#define SSL_accept (*(int (*)(SSL *))ssl_sw[1].ptr)
#define SSL_connect (*(int (*)(SSL *))ssl_sw[2].ptr)
#define SSL_read (*(int (*)(SSL *, void *, int))ssl_sw[3].ptr)
#define SSL_write (*(int (*)(SSL *, const void *, int))ssl_sw[4].ptr)
#define SSL_get_error (*(int (*)(SSL *, int))ssl_sw[5].ptr)
#define SSL_set_fd (*(int (*)(SSL *, SOCKET))ssl_sw[6].ptr)
#define SSL_new (*(SSL * (*)(SSL_CTX *)) ssl_sw[7].ptr)
#define SSL_CTX_new (*(SSL_CTX * (*)(SSL_METHOD *)) ssl_sw[8].ptr)
#define SSLv23_server_method (*(SSL_METHOD * (*)(void)) ssl_sw[9].ptr)
#define SSL_library_init (*(int (*)(void))ssl_sw[10].ptr)
#define SSL_CTX_use_PrivateKey_file \
(*(int (*)(SSL_CTX *, const char *, int))ssl_sw[11].ptr)
#define SSL_CTX_use_certificate_file \
(*(int (*)(SSL_CTX *, const char *, int))ssl_sw[12].ptr)
#define SSL_CTX_set_default_passwd_cb \
(*(void (*)(SSL_CTX *, mg_callback_t))ssl_sw[13].ptr)
#define SSL_CTX_free (*(void (*)(SSL_CTX *))ssl_sw[14].ptr)
#define SSL_load_error_strings (*(void (*)(void))ssl_sw[15].ptr)
#define SSL_CTX_use_certificate_chain_file \
(*(int (*)(SSL_CTX *, const char *))ssl_sw[16].ptr)
#define SSLv23_client_method (*(SSL_METHOD * (*)(void)) ssl_sw[17].ptr)
#define SSL_pending (*(int (*)(SSL *))ssl_sw[18].ptr)
#define SSL_CTX_set_verify \
(*(void (*)(SSL_CTX *, \
int, \
int (*verify_callback)(int, X509_STORE_CTX *)))ssl_sw[19] \
.ptr)
#define SSL_shutdown (*(int (*)(SSL *))ssl_sw[20].ptr)
#define SSL_CTX_load_verify_locations \
(*(int (*)(SSL_CTX *, const char *, const char *))ssl_sw[21].ptr)
#define SSL_CTX_set_default_verify_paths (*(int (*)(SSL_CTX *))ssl_sw[22].ptr)
#define SSL_CTX_set_verify_depth (*(void (*)(SSL_CTX *, int))ssl_sw[23].ptr)
#define SSL_get_peer_certificate (*(X509 * (*)(SSL *)) ssl_sw[24].ptr)
#define SSL_get_version (*(const char *(*)(SSL *))ssl_sw[25].ptr)
#define SSL_get_current_cipher (*(SSL_CIPHER * (*)(SSL *)) ssl_sw[26].ptr)
#define SSL_CIPHER_get_name \
(*(const char *(*)(const SSL_CIPHER *))ssl_sw[27].ptr)
#define SSL_CTX_check_private_key (*(int (*)(SSL_CTX *))ssl_sw[28].ptr)
#define SSL_CTX_set_session_id_context \
(*(int (*)(SSL_CTX *, const unsigned char *, unsigned int))ssl_sw[29].ptr)
#define SSL_CTX_ctrl (*(long (*)(SSL_CTX *, int, long, void *))ssl_sw[30].ptr)
#define SSL_CTX_set_cipher_list \
(*(int (*)(SSL_CTX *, const char *))ssl_sw[31].ptr)
#define SSL_CTX_set_info_callback \
(*(void (*)(SSL_CTX *, void (*callback)(const SSL *, int, int)))ssl_sw[32] \
.ptr)
#define SSL_get_ex_data (*(char *(*)(const SSL *, int))ssl_sw[33].ptr)
#define SSL_set_ex_data (*(void (*)(SSL *, int, char *))ssl_sw[34].ptr)
#define SSL_CTX_callback_ctrl \
(*(long (*)(SSL_CTX *, int, void (*)(void)))ssl_sw[35].ptr)
#define SSL_get_servername \
(*(const char *(*)(const SSL *, int type))ssl_sw[36].ptr)
#define SSL_set_SSL_CTX (*(SSL_CTX * (*)(SSL *, SSL_CTX *)) ssl_sw[37].ptr)
#define SSL_ctrl (*(long (*)(SSL *, int, long, void *))ssl_sw[38].ptr)
#define SSL_CTX_set_alpn_protos \
(*(int (*)(SSL_CTX *, const unsigned char *, unsigned))ssl_sw[39].ptr)
typedef int (*tSSL_alpn_select_cb)(SSL *ssl,
const unsigned char **out,
unsigned char *outlen,
const unsigned char *in,
unsigned int inlen,
void *arg);
#define SSL_CTX_set_alpn_select_cb \
(*(void (*)(SSL_CTX *, tSSL_alpn_select_cb, void *))ssl_sw[40].ptr)
typedef int (*tSSL_next_protos_advertised_cb)(SSL *ssl,
const unsigned char **out,
unsigned int *outlen,
void *arg);
#define SSL_CTX_set_next_protos_advertised_cb \
(*(void (*)(SSL_CTX *, tSSL_next_protos_advertised_cb, void *))ssl_sw[41] \
.ptr)
#define SSL_CTX_set_timeout (*(long (*)(SSL_CTX *, long))ssl_sw[42].ptr)
#define SSL_CTX_set_options(ctx, op) \
SSL_CTX_ctrl((ctx), SSL_CTRL_OPTIONS, (op), NULL)
#define SSL_CTX_clear_options(ctx, op) \
SSL_CTX_ctrl((ctx), SSL_CTRL_CLEAR_OPTIONS, (op), NULL)
#define SSL_CTX_set_ecdh_auto(ctx, onoff) \
SSL_CTX_ctrl(ctx, SSL_CTRL_SET_ECDH_AUTO, onoff, NULL)
#define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB 53
#define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG 54
#define SSL_CTRL_SET_TLSEXT_HOSTNAME 55
#define SSL_CTX_set_tlsext_servername_callback(ctx, cb) \
SSL_CTX_callback_ctrl(ctx, \
SSL_CTRL_SET_TLSEXT_SERVERNAME_CB, \
(void (*)(void))cb)
#define SSL_set_tlsext_host_name(ctx, arg) \
SSL_ctrl(ctx, SSL_CTRL_SET_TLSEXT_HOSTNAME, 0, (void *)arg)
#define X509_get_notBefore(x) ((x)->cert_info->validity->notBefore)
#define X509_get_notAfter(x) ((x)->cert_info->validity->notAfter)
#define SSL_set_app_data(s, arg) (SSL_set_ex_data(s, 0, (char *)arg))
#define SSL_get_app_data(s) (SSL_get_ex_data(s, 0))
#define SSL_CTX_sess_set_cache_size(ctx, size) SSL_CTX_ctrl(ctx, 42, size, NULL)
#define SSL_CTX_set_session_cache_mode(ctx, mode) \
SSL_CTX_ctrl(ctx, 44, mode, NULL)
#define CRYPTO_num_locks (*(int (*)(void))crypto_sw[0].ptr)
#define CRYPTO_set_locking_callback \
(*(void (*)(void (*)(int, int, const char *, int)))crypto_sw[1].ptr)
#define CRYPTO_set_id_callback \
(*(void (*)(unsigned long (*)(void)))crypto_sw[2].ptr)
#define ERR_get_error (*(unsigned long (*)(void))crypto_sw[3].ptr)
#define ERR_error_string (*(char *(*)(unsigned long, char *))crypto_sw[4].ptr)
#define ERR_remove_state (*(void (*)(unsigned long))crypto_sw[5].ptr)
#define ERR_free_strings (*(void (*)(void))crypto_sw[6].ptr)
#define ENGINE_cleanup (*(void (*)(void))crypto_sw[7].ptr)
#define CONF_modules_unload (*(void (*)(int))crypto_sw[8].ptr)
#define CRYPTO_cleanup_all_ex_data (*(void (*)(void))crypto_sw[9].ptr)
#define EVP_cleanup (*(void (*)(void))crypto_sw[10].ptr)
#define X509_free (*(void (*)(X509 *))crypto_sw[11].ptr)
#define X509_get_subject_name (*(X509_NAME * (*)(X509 *)) crypto_sw[12].ptr)
#define X509_get_issuer_name (*(X509_NAME * (*)(X509 *)) crypto_sw[13].ptr)
#define X509_NAME_oneline \
(*(char *(*)(X509_NAME *, char *, int))crypto_sw[14].ptr)
#define X509_get_serialNumber (*(ASN1_INTEGER * (*)(X509 *)) crypto_sw[15].ptr)
#define i2c_ASN1_INTEGER \
(*(int (*)(ASN1_INTEGER *, unsigned char **))crypto_sw[16].ptr)
#define EVP_get_digestbyname \
(*(const EVP_MD *(*)(const char *))crypto_sw[17].ptr)
#define EVP_Digest \
(*(int (*)( \
const void *, size_t, void *, unsigned int *, const EVP_MD *, void *)) \
crypto_sw[18] \
.ptr)
#define i2d_X509 (*(int (*)(X509 *, unsigned char **))crypto_sw[19].ptr)
#define BN_bn2hex (*(char *(*)(const BIGNUM *a))crypto_sw[20].ptr)
#define ASN1_INTEGER_to_BN \
(*(BIGNUM * (*)(const ASN1_INTEGER *ai, BIGNUM *bn)) crypto_sw[21].ptr)
#define BN_free (*(void (*)(const BIGNUM *a))crypto_sw[22].ptr)
#define CRYPTO_free (*(void (*)(void *addr))crypto_sw[23].ptr)
#define ERR_clear_error (*(void (*)(void))crypto_sw[24].ptr)
#define OPENSSL_free(a) CRYPTO_free(a)
/* use here ERR_remove_state,
* while on some platforms function is not included into library due to
* deprication */
#define OPENSSL_REMOVE_THREAD_STATE() ERR_remove_state(0)
/* init_ssl_ctx() function updates this array.
* It loads SSL library dynamically and changes NULLs to the actual addresses
* of respective functions. The macros above (like SSL_connect()) are really
* just calling these functions indirectly via the pointer. */
static struct ssl_func ssl_sw[] = {
{"SSL_free", TLS_Mandatory, NULL},
{"SSL_accept", TLS_Mandatory, NULL},
{"SSL_connect", TLS_Mandatory, NULL},
{"SSL_read", TLS_Mandatory, NULL},
{"SSL_write", TLS_Mandatory, NULL},
{"SSL_get_error", TLS_Mandatory, NULL},
{"SSL_set_fd", TLS_Mandatory, NULL},
{"SSL_new", TLS_Mandatory, NULL},
{"SSL_CTX_new", TLS_Mandatory, NULL},
{"SSLv23_server_method", TLS_Mandatory, NULL},
{"SSL_library_init", TLS_Mandatory, NULL},
{"SSL_CTX_use_PrivateKey_file", TLS_Mandatory, NULL},
{"SSL_CTX_use_certificate_file", TLS_Mandatory, NULL},
{"SSL_CTX_set_default_passwd_cb", TLS_Mandatory, NULL},
{"SSL_CTX_free", TLS_Mandatory, NULL},
{"SSL_load_error_strings", TLS_Mandatory, NULL},
{"SSL_CTX_use_certificate_chain_file", TLS_Mandatory, NULL},
{"SSLv23_client_method", TLS_Mandatory, NULL},
{"SSL_pending", TLS_Mandatory, NULL},
{"SSL_CTX_set_verify", TLS_Mandatory, NULL},
{"SSL_shutdown", TLS_Mandatory, NULL},
{"SSL_CTX_load_verify_locations", TLS_Mandatory, NULL},
{"SSL_CTX_set_default_verify_paths", TLS_Mandatory, NULL},
{"SSL_CTX_set_verify_depth", TLS_Mandatory, NULL},
{"SSL_get_peer_certificate", TLS_Mandatory, NULL},
{"SSL_get_version", TLS_Mandatory, NULL},
{"SSL_get_current_cipher", TLS_Mandatory, NULL},
{"SSL_CIPHER_get_name", TLS_Mandatory, NULL},
{"SSL_CTX_check_private_key", TLS_Mandatory, NULL},
{"SSL_CTX_set_session_id_context", TLS_Mandatory, NULL},
{"SSL_CTX_ctrl", TLS_Mandatory, NULL},
{"SSL_CTX_set_cipher_list", TLS_Mandatory, NULL},
{"SSL_CTX_set_info_callback", TLS_Mandatory, NULL},
{"SSL_get_ex_data", TLS_Mandatory, NULL},
{"SSL_set_ex_data", TLS_Mandatory, NULL},
{"SSL_CTX_callback_ctrl", TLS_Mandatory, NULL},
{"SSL_get_servername", TLS_Mandatory, NULL},
{"SSL_set_SSL_CTX", TLS_Mandatory, NULL},
{"SSL_ctrl", TLS_Mandatory, NULL},
{"SSL_CTX_set_alpn_protos", TLS_ALPN, NULL},
{"SSL_CTX_set_alpn_select_cb", TLS_ALPN, NULL},
{"SSL_CTX_set_next_protos_advertised_cb", TLS_ALPN, NULL},
{"SSL_CTX_set_timeout", TLS_Mandatory, NULL},
{NULL, TLS_END_OF_LIST, NULL}};
/* Similar array as ssl_sw. These functions could be located in different
* lib. */
static struct ssl_func crypto_sw[] = {
{"CRYPTO_num_locks", TLS_Mandatory, NULL},
{"CRYPTO_set_locking_callback", TLS_Mandatory, NULL},
{"CRYPTO_set_id_callback", TLS_Mandatory, NULL},
{"ERR_get_error", TLS_Mandatory, NULL},
{"ERR_error_string", TLS_Mandatory, NULL},
{"ERR_remove_state", TLS_Mandatory, NULL},
{"ERR_free_strings", TLS_Mandatory, NULL},
{"ENGINE_cleanup", TLS_Mandatory, NULL},
{"CONF_modules_unload", TLS_Mandatory, NULL},
{"CRYPTO_cleanup_all_ex_data", TLS_Mandatory, NULL},
{"EVP_cleanup", TLS_Mandatory, NULL},
{"X509_free", TLS_Mandatory, NULL},
{"X509_get_subject_name", TLS_Mandatory, NULL},
{"X509_get_issuer_name", TLS_Mandatory, NULL},
{"X509_NAME_oneline", TLS_Mandatory, NULL},
{"X509_get_serialNumber", TLS_Mandatory, NULL},
{"i2c_ASN1_INTEGER", TLS_Mandatory, NULL},
{"EVP_get_digestbyname", TLS_Mandatory, NULL},
{"EVP_Digest", TLS_Mandatory, NULL},
{"i2d_X509", TLS_Mandatory, NULL},
{"BN_bn2hex", TLS_Mandatory, NULL},
{"ASN1_INTEGER_to_BN", TLS_Mandatory, NULL},
{"BN_free", TLS_Mandatory, NULL},
{"CRYPTO_free", TLS_Mandatory, NULL},
{"ERR_clear_error", TLS_Mandatory, NULL},
{NULL, TLS_END_OF_LIST, NULL}};
#endif /* OPENSSL_API_1_0 */

323
src/external/civetweb/sha1.inl vendored Normal file
View File

@@ -0,0 +1,323 @@
/*
SHA-1 in C
By Steve Reid <sreid@sea-to-sky.net>
100% Public Domain
-----------------
Modified 7/98
By James H. Brown <jbrown@burgoyne.com>
Still 100% Public Domain
Corrected a problem which generated improper hash values on 16 bit machines
Routine SHA1Update changed from
void SHA1Update(SHA_CTX* context, unsigned char* data, unsigned int
len)
to
void SHA1Update(SHA_CTX* context, unsigned char* data, unsigned
long len)
The 'len' parameter was declared an int which works fine on 32 bit machines.
However, on 16 bit machines an int is too small for the shifts being done
against
it. This caused the hash function to generate incorrect values if len was
greater than 8191 (8K - 1) due to the 'len << 3' on line 3 of SHA1Update().
Since the file IO in main() reads 16K at a time, any file 8K or larger would
be guaranteed to generate the wrong hash (e.g. Test Vector #3, a million
"a"s).
I also changed the declaration of variables i & j in SHA1Update to
unsigned long from unsigned int for the same reason.
These changes should make no difference to any 32 bit implementations since
an
int and a long are the same size in those environments.
--
I also corrected a few compiler warnings generated by Borland C.
1. Added #include <process.h> for exit() prototype
2. Removed unused variable 'j' in SHA1Final
3. Changed exit(0) to return(0) at end of main.
ALL changes I made can be located by searching for comments containing 'JHB'
-----------------
Modified 8/98
By Steve Reid <sreid@sea-to-sky.net>
Still 100% public domain
1- Removed #include <process.h> and used return() instead of exit()
2- Fixed overwriting of finalcount in SHA1Final() (discovered by Chris Hall)
3- Changed email address from steve@edmweb.com to sreid@sea-to-sky.net
-----------------
Modified 4/01
By Saul Kravitz <Saul.Kravitz@celera.com>
Still 100% PD
Modified to run on Compaq Alpha hardware.
-----------------
Modified 07/2002
By Ralph Giles <giles@ghostscript.com>
Still 100% public domain
modified for use with stdint types, autoconf
code cleanup, removed attribution comments
switched SHA1Final() argument order for consistency
use SHA1_ prefix for public api
move public api to sha1.h
*/
/*
11/2016 adapted for CivetWeb:
include sha1.h in sha1.c,
rename to sha1.inl
remove unused #ifdef sections
make endian independent
align buffer to 4 bytes
remove unused variable assignments
*/
/*
Test Vectors (from FIPS PUB 180-1)
"abc"
A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
A million repetitions of "a"
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
*/
#include <stdint.h>
#include <string.h>
typedef struct {
uint32_t state[5];
uint32_t count[2];
uint8_t buffer[64];
} SHA_CTX;
#define SHA1_DIGEST_SIZE 20
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
/* blk0() and blk() perform the initial expand. */
/* I got the idea of expanding during the round function from SSLeay */
typedef union {
uint8_t c[64];
uint32_t l[16];
} CHAR64LONG16;
static uint32_t
blk0(CHAR64LONG16 *block, int i)
{
static const uint32_t n = 1u;
if ((*((uint8_t *)(&n))) == 1) {
/* little endian / intel byte order */
block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00)
| (rol(block->l[i], 8) & 0x00FF00FF);
}
return block->l[i];
}
#define blk(block, i) \
((block)->l[(i)&15] = \
rol((block)->l[((i) + 13) & 15] ^ (block)->l[((i) + 8) & 15] \
^ (block)->l[((i) + 2) & 15] ^ (block)->l[(i)&15], \
1))
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
#define R0(v, w, x, y, z, i) \
z += ((w & (x ^ y)) ^ y) + blk0(block, i) + 0x5A827999 + rol(v, 5); \
w = rol(w, 30);
#define R1(v, w, x, y, z, i) \
z += ((w & (x ^ y)) ^ y) + blk(block, i) + 0x5A827999 + rol(v, 5); \
w = rol(w, 30);
#define R2(v, w, x, y, z, i) \
z += (w ^ x ^ y) + blk(block, i) + 0x6ED9EBA1 + rol(v, 5); \
w = rol(w, 30);
#define R3(v, w, x, y, z, i) \
z += (((w | x) & y) | (w & x)) + blk(block, i) + 0x8F1BBCDC + rol(v, 5); \
w = rol(w, 30);
#define R4(v, w, x, y, z, i) \
z += (w ^ x ^ y) + blk(block, i) + 0xCA62C1D6 + rol(v, 5); \
w = rol(w, 30);
/* Hash a single 512-bit block. This is the core of the algorithm. */
static void
SHA1_Transform(uint32_t state[5], const uint8_t buffer[64])
{
uint32_t a, b, c, d, e;
/* Must use an aligned, read/write buffer */
CHAR64LONG16 block[1];
memcpy(block, buffer, sizeof(block));
/* Copy context->state[] to working vars */
a = state[0];
b = state[1];
c = state[2];
d = state[3];
e = state[4];
/* 4 rounds of 20 operations each. Loop unrolled. */
R0(a, b, c, d, e, 0);
R0(e, a, b, c, d, 1);
R0(d, e, a, b, c, 2);
R0(c, d, e, a, b, 3);
R0(b, c, d, e, a, 4);
R0(a, b, c, d, e, 5);
R0(e, a, b, c, d, 6);
R0(d, e, a, b, c, 7);
R0(c, d, e, a, b, 8);
R0(b, c, d, e, a, 9);
R0(a, b, c, d, e, 10);
R0(e, a, b, c, d, 11);
R0(d, e, a, b, c, 12);
R0(c, d, e, a, b, 13);
R0(b, c, d, e, a, 14);
R0(a, b, c, d, e, 15);
R1(e, a, b, c, d, 16);
R1(d, e, a, b, c, 17);
R1(c, d, e, a, b, 18);
R1(b, c, d, e, a, 19);
R2(a, b, c, d, e, 20);
R2(e, a, b, c, d, 21);
R2(d, e, a, b, c, 22);
R2(c, d, e, a, b, 23);
R2(b, c, d, e, a, 24);
R2(a, b, c, d, e, 25);
R2(e, a, b, c, d, 26);
R2(d, e, a, b, c, 27);
R2(c, d, e, a, b, 28);
R2(b, c, d, e, a, 29);
R2(a, b, c, d, e, 30);
R2(e, a, b, c, d, 31);
R2(d, e, a, b, c, 32);
R2(c, d, e, a, b, 33);
R2(b, c, d, e, a, 34);
R2(a, b, c, d, e, 35);
R2(e, a, b, c, d, 36);
R2(d, e, a, b, c, 37);
R2(c, d, e, a, b, 38);
R2(b, c, d, e, a, 39);
R3(a, b, c, d, e, 40);
R3(e, a, b, c, d, 41);
R3(d, e, a, b, c, 42);
R3(c, d, e, a, b, 43);
R3(b, c, d, e, a, 44);
R3(a, b, c, d, e, 45);
R3(e, a, b, c, d, 46);
R3(d, e, a, b, c, 47);
R3(c, d, e, a, b, 48);
R3(b, c, d, e, a, 49);
R3(a, b, c, d, e, 50);
R3(e, a, b, c, d, 51);
R3(d, e, a, b, c, 52);
R3(c, d, e, a, b, 53);
R3(b, c, d, e, a, 54);
R3(a, b, c, d, e, 55);
R3(e, a, b, c, d, 56);
R3(d, e, a, b, c, 57);
R3(c, d, e, a, b, 58);
R3(b, c, d, e, a, 59);
R4(a, b, c, d, e, 60);
R4(e, a, b, c, d, 61);
R4(d, e, a, b, c, 62);
R4(c, d, e, a, b, 63);
R4(b, c, d, e, a, 64);
R4(a, b, c, d, e, 65);
R4(e, a, b, c, d, 66);
R4(d, e, a, b, c, 67);
R4(c, d, e, a, b, 68);
R4(b, c, d, e, a, 69);
R4(a, b, c, d, e, 70);
R4(e, a, b, c, d, 71);
R4(d, e, a, b, c, 72);
R4(c, d, e, a, b, 73);
R4(b, c, d, e, a, 74);
R4(a, b, c, d, e, 75);
R4(e, a, b, c, d, 76);
R4(d, e, a, b, c, 77);
R4(c, d, e, a, b, 78);
R4(b, c, d, e, a, 79);
/* Add the working vars back into context.state[] */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
state[4] += e;
}
/* SHA1Init - Initialize new context */
SHA_API void
SHA1_Init(SHA_CTX *context)
{
/* SHA1 initialization constants */
context->state[0] = 0x67452301;
context->state[1] = 0xEFCDAB89;
context->state[2] = 0x98BADCFE;
context->state[3] = 0x10325476;
context->state[4] = 0xC3D2E1F0;
context->count[0] = context->count[1] = 0;
}
SHA_API void
SHA1_Update(SHA_CTX *context, const uint8_t *data, const uint32_t len)
{
uint32_t i, j;
j = context->count[0];
if ((context->count[0] += (len << 3)) < j) {
context->count[1]++;
}
context->count[1] += (len >> 29);
j = (j >> 3) & 63;
if ((j + len) > 63) {
i = 64 - j;
memcpy(&context->buffer[j], data, i);
SHA1_Transform(context->state, context->buffer);
for (; i + 63 < len; i += 64) {
SHA1_Transform(context->state, &data[i]);
}
j = 0;
} else {
i = 0;
}
memcpy(&context->buffer[j], &data[i], len - i);
}
/* Add padding and return the message digest. */
SHA_API void
SHA1_Final(unsigned char *digest, SHA_CTX *context)
{
uint32_t i;
uint8_t finalcount[8];
for (i = 0; i < 8; i++) {
finalcount[i] =
(uint8_t)((context->count[(i >= 4 ? 0 : 1)] >> ((3 - (i & 3)) * 8))
& 255); /* Endian independent */
}
SHA1_Update(context, (uint8_t *)"\x80", 1);
while ((context->count[0] & 504) != 448) {
SHA1_Update(context, (uint8_t *)"\x00", 1);
}
SHA1_Update(context, finalcount, 8); /* Should cause a SHA1_Transform() */
for (i = 0; i < SHA1_DIGEST_SIZE; i++) {
digest[i] =
(uint8_t)((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
}
/* Wipe variables */
memset(context, '\0', sizeof(*context));
}
/* End of sha1.inl */

48
src/external/civetweb/sort.inl vendored Normal file
View File

@@ -0,0 +1,48 @@
/* Sort function. */
/* from https://github.com/bel2125/sort_r */
static void
mg_sort(void *data,
size_t elemcount,
size_t elemsize,
int (*compfunc)(const void *data1, const void *data2, void *userarg),
void *userarg)
{
/* We cannot use qsort_r here. For a detailed reason, see
* https://github.com/civetweb/civetweb/issues/1048#issuecomment-1047093014
* https://stackoverflow.com/questions/39560773/different-declarations-of-qsort-r-on-mac-and-linux
*/
/* We use ShellSort here with this gap sequence: https://oeis.org/A102549 */
size_t A102549[9] = {1, 4, 10, 23, 57, 132, 301, 701, 1750};
size_t gap, i, j, k;
int Aidx;
void *tmp = alloca(elemsize);
for (Aidx = 8; Aidx >= 0; Aidx--) {
gap = A102549[Aidx];
if (gap > (elemcount / 2)) {
continue;
}
for (i = 0; i < gap; i++) {
for (j = i; j < elemcount; j += gap) {
memcpy(tmp, (void *)((size_t)data + elemsize * j), elemsize);
for (k = j; k >= gap; k -= gap) {
void *cmp = (void *)((size_t)data + elemsize * (k - gap));
int cmpres = compfunc(cmp, tmp, userarg);
if (cmpres > 0) {
memcpy((void *)((size_t)data + elemsize * k),
cmp,
elemsize);
} else {
break;
}
}
memcpy((void *)((size_t)data + elemsize * k), tmp, elemsize);
}
}
}
}
/* end if sort.inl */

273
src/tydra/mcp-server.cc Normal file
View File

@@ -0,0 +1,273 @@
#include "mcp-server.hh"
#if defined(TINYUSDZ_WITH_MCP_SERVER)
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#endif
#include "external/jsonhpp/nlohmann/json.hpp"
#include "external/civetweb/civetweb.h"
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#include <functional>
#include <map>
#include <string>
namespace tinyusdz {
namespace tydra {
// JSON-RPC request structure
struct JsonRpcRequest {
std::string jsonrpc = "2.0";
std::string method;
nlohmann::json params;
nlohmann::json id;
bool is_notification() const { return id.is_null(); }
};
// JSON-RPC response structure
struct JsonRpcResponse {
std::string jsonrpc = "2.0";
nlohmann::json result;
nlohmann::json error;
nlohmann::json id;
nlohmann::json to_json() const {
nlohmann::json response;
response["jsonrpc"] = jsonrpc;
response["id"] = id;
if (!error.is_null()) {
response["error"] = error;
} else {
response["result"] = result;
}
return response;
}
};
// JSON-RPC error codes
enum JsonRpcErrorCode {
PARSE_ERROR = -32700,
INVALID_REQUEST = -32600,
METHOD_NOT_FOUND = -32601,
INVALID_PARAMS = -32602,
INTERNAL_ERROR = -32603
};
// Method handler function type
using MethodHandler = std::function<nlohmann::json(const nlohmann::json&)>;
class MCPServer::Impl {
public:
// Constructor and destructor
Impl() = default;
~Impl() {
if (ctx_) {
mg_stop(ctx_);
}
}
// Initialize the server with the specified port and host
bool init(int port, const std::string &host = "localhost");
// Run the server
bool run();
// Register a JSON-RPC method handler
void register_method(const std::string& method, MethodHandler handler);
private:
struct mg_context *ctx_ = nullptr; // Pointer to the CivetWeb context
std::map<std::string, MethodHandler> method_handlers_;
// Static callback for HTTP requests
static int http_handler(struct mg_connection *conn, void *user_data);
// Process JSON-RPC request
JsonRpcResponse process_request(const JsonRpcRequest& request);
// Parse JSON-RPC request from string
JsonRpcRequest parse_request(const std::string& json_str);
// Create JSON-RPC error response
JsonRpcResponse create_error_response(int code, const std::string& message, const nlohmann::json& id = nullptr);
};
// Static HTTP handler implementation
int MCPServer::Impl::http_handler(struct mg_connection *conn, void *user_data) {
MCPServer::Impl* server = static_cast<MCPServer::Impl*>(user_data);
const struct mg_request_info *request_info = mg_get_request_info(conn);
// Handle POST requests for JSON-RPC
if (strcmp(request_info->request_method, "POST") == 0) {
// Read request body
std::string body;
char buffer[1024];
int bytes_read;
while ((bytes_read = mg_read(conn, buffer, sizeof(buffer))) > 0) {
body.append(buffer, size_t(bytes_read));
}
// Parse and process JSON-RPC request
JsonRpcRequest rpc_request = server->parse_request(body);
JsonRpcResponse rpc_response = server->process_request(rpc_request);
// Send JSON-RPC response
std::string response_json = rpc_response.to_json().dump();
mg_printf(conn,
"HTTP/1.1 200 OK\r\n"
"Content-Type: application/json\r\n"
"Content-Length: %d\r\n"
"\r\n"
"%s",
static_cast<int>(response_json.length()),
response_json.c_str());
return 200; // Request handled
}
// Handle OPTIONS for CORS
if (strcmp(request_info->request_method, "OPTIONS") == 0) {
mg_printf(conn,
"HTTP/1.1 200 OK\r\n"
"Access-Control-Allow-Origin: *\r\n"
"Access-Control-Allow-Methods: POST, OPTIONS\r\n"
"Access-Control-Allow-Headers: Content-Type\r\n"
"\r\n");
return 200;
}
return 404; // Not found
}
JsonRpcRequest MCPServer::Impl::parse_request(const std::string& json_str) {
JsonRpcRequest request;
nlohmann::json json_obj = nlohmann::json::parse(json_str);
if (json_obj.contains("jsonrpc")) {
request.jsonrpc = json_obj["jsonrpc"];
}
if (json_obj.contains("method")) {
request.method = json_obj["method"];
}
if (json_obj.contains("params")) {
request.params = json_obj["params"];
}
if (json_obj.contains("id")) {
request.id = json_obj["id"];
}
return request;
}
JsonRpcResponse MCPServer::Impl::process_request(const JsonRpcRequest& request) {
// Validate JSON-RPC version
if (request.jsonrpc != "2.0") {
return create_error_response(INVALID_REQUEST, "Invalid JSON-RPC version", request.id);
}
// Check if method exists
auto handler_it = method_handlers_.find(request.method);
if (handler_it == method_handlers_.end()) {
return create_error_response(METHOD_NOT_FOUND, "Method not found", request.id);
}
// Execute method handler
nlohmann::json result = handler_it->second(request.params);
JsonRpcResponse response;
response.id = request.id;
response.result = result;
return response;
}
JsonRpcResponse MCPServer::Impl::create_error_response(int code, const std::string& message, const nlohmann::json& id) {
JsonRpcResponse response;
response.id = id;
response.error = nlohmann::json{
{"code", code},
{"message", message}
};
return response;
}
void MCPServer::Impl::register_method(const std::string& method, MethodHandler handler) {
method_handlers_[method] = handler;
}
bool MCPServer::Impl::init(int port, const std::string &host) {
// TODO
(void)host;
// CivetWeb options
std::string port_str = std::to_string(port);
std::vector<const char *> options;
options.push_back("listening_ports");
options.push_back(port_str.c_str());
options.push_back("num_threads");
options.push_back("4");
// Initialize the server
ctx_ = mg_start(NULL, this, options.data());
if (!ctx_) {
return false; // Failed to start server
}
// Register HTTP handler for JSON-RPC endpoint
mg_set_request_handler(ctx_, "/jsonrpc", http_handler, this);
return true; // Server initialized successfully
}
bool MCPServer::Impl::run() {
if (!ctx_) {
return false;
}
// Server is already running after mg_start
// This method can be used for additional setup or monitoring
return true;
}
MCPServer::MCPServer() : impl_(new tydra::MCPServer::Impl()) {}
bool MCPServer::init(int port, const std::string &host) {
return impl_->init(port, host);
}
} // namespace tydra
} // namespace tinyusdz
#else
namespace tinyusdz {
namespace tydra {
MCPServer::MCPServer() {}
bool MCPServer::init(int port, const std::string &host) {
(void)port;
(void)host;
return false;
}
} // namespace tydra
} // namespace tinyusdz
#endif

26
src/tydra/mcp-server.hh Normal file
View File

@@ -0,0 +1,26 @@
// Interface for MCP(ModelContextProtocol)
#pragma once
#include <string>
namespace tinyusdz {
namespace tydra {
class MCPServer
{
public:
MCPServer();
bool init(int port, const std::string &host = "localhost");
bool run();
private:
class Impl;
Impl *impl_ = nullptr; // Pointer to implementation details
};
} // namespace tydra
} // namespace tinyusdz

View File

@@ -1,8 +1,255 @@
#include "mcp.hh"
#include "mcp-server.hh"
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#endif
#include "external/jsonhpp/nlohmann/json.hpp"
#include "external/civetweb/civetweb.h"
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#include <functional>
#include <map>
#include <string>
namespace tinyusdz {
namespace tydra {
// JSON-RPC request structure
struct JsonRpcRequest {
std::string jsonrpc = "2.0";
std::string method;
nlohmann::json params;
nlohmann::json id;
bool is_notification() const { return id.is_null(); }
};
// JSON-RPC response structure
struct JsonRpcResponse {
std::string jsonrpc = "2.0";
nlohmann::json result;
nlohmann::json error;
nlohmann::json id;
nlohmann::json to_json() const {
nlohmann::json response;
response["jsonrpc"] = jsonrpc;
response["id"] = id;
if (!error.is_null()) {
response["error"] = error;
} else {
response["result"] = result;
}
return response;
}
};
// JSON-RPC error codes
enum JsonRpcErrorCode {
PARSE_ERROR = -32700,
INVALID_REQUEST = -32600,
METHOD_NOT_FOUND = -32601,
INVALID_PARAMS = -32602,
INTERNAL_ERROR = -32603
};
// Method handler function type
using MethodHandler = std::function<nlohmann::json(const nlohmann::json&)>;
class MCPServerImpl {
public:
// Constructor and destructor
MCPServerImpl() = default;
~MCPServerImpl() {
if (ctx_) {
mg_stop(ctx_);
}
}
// Initialize the server with the specified port and host
bool init(int port, const std::string &host = "localhost");
// Run the server
bool run();
// Register a JSON-RPC method handler
void register_method(const std::string& method, MethodHandler handler);
private:
struct mg_context *ctx_ = nullptr; // Pointer to the CivetWeb context
std::map<std::string, MethodHandler> method_handlers_;
// Static callback for HTTP requests
static int http_handler(struct mg_connection *conn, void *user_data);
// Process JSON-RPC request
JsonRpcResponse process_request(const JsonRpcRequest& request);
// Parse JSON-RPC request from string
JsonRpcRequest parse_request(const std::string& json_str);
// Create JSON-RPC error response
JsonRpcResponse create_error_response(int code, const std::string& message, const nlohmann::json& id = nullptr);
};
// Static HTTP handler implementation
int MCPServerImpl::http_handler(struct mg_connection *conn, void *user_data) {
MCPServerImpl* server = static_cast<MCPServerImpl*>(user_data);
const struct mg_request_info *request_info = mg_get_request_info(conn);
// Handle POST requests for JSON-RPC
if (strcmp(request_info->request_method, "POST") == 0) {
// Read request body
std::string body;
char buffer[1024];
int bytes_read;
while ((bytes_read = mg_read(conn, buffer, sizeof(buffer))) > 0) {
body.append(buffer, bytes_read);
}
// Parse and process JSON-RPC request
JsonRpcRequest rpc_request = server->parse_request(body);
JsonRpcResponse rpc_response = server->process_request(rpc_request);
// Send JSON-RPC response
std::string response_json = rpc_response.to_json().dump();
mg_printf(conn,
"HTTP/1.1 200 OK\r\n"
"Content-Type: application/json\r\n"
"Content-Length: %d\r\n"
"\r\n"
"%s",
static_cast<int>(response_json.length()),
response_json.c_str());
return 200; // Request handled
}
// Handle OPTIONS for CORS
if (strcmp(request_info->request_method, "OPTIONS") == 0) {
mg_printf(conn,
"HTTP/1.1 200 OK\r\n"
"Access-Control-Allow-Origin: *\r\n"
"Access-Control-Allow-Methods: POST, OPTIONS\r\n"
"Access-Control-Allow-Headers: Content-Type\r\n"
"\r\n");
return 200;
}
return 404; // Not found
}
JsonRpcRequest MCPServerImpl::parse_request(const std::string& json_str) {
JsonRpcRequest request;
try {
nlohmann::json json_obj = nlohmann::json::parse(json_str);
if (json_obj.contains("jsonrpc")) {
request.jsonrpc = json_obj["jsonrpc"];
}
if (json_obj.contains("method")) {
request.method = json_obj["method"];
}
if (json_obj.contains("params")) {
request.params = json_obj["params"];
}
if (json_obj.contains("id")) {
request.id = json_obj["id"];
}
} catch (const std::exception&) {
// Parse error will be handled by process_request
}
return request;
}
JsonRpcResponse MCPServerImpl::process_request(const JsonRpcRequest& request) {
// Validate JSON-RPC version
if (request.jsonrpc != "2.0") {
return create_error_response(INVALID_REQUEST, "Invalid JSON-RPC version", request.id);
}
// Check if method exists
auto handler_it = method_handlers_.find(request.method);
if (handler_it == method_handlers_.end()) {
return create_error_response(METHOD_NOT_FOUND, "Method not found", request.id);
}
// Execute method handler
try {
nlohmann::json result = handler_it->second(request.params);
JsonRpcResponse response;
response.id = request.id;
response.result = result;
return response;
} catch (const std::exception& e) {
return create_error_response(INTERNAL_ERROR, e.what(), request.id);
}
}
JsonRpcResponse MCPServerImpl::create_error_response(int code, const std::string& message, const nlohmann::json& id) {
JsonRpcResponse response;
response.id = id;
response.error = nlohmann::json{
{"code", code},
{"message", message}
};
return response;
}
void MCPServerImpl::register_method(const std::string& method, MethodHandler handler) {
method_handlers_[method] = handler;
}
bool MCPServerImpl::init(int port, const std::string &host) {
// CivetWeb options
const char *options[] = {
"listening_ports", std::to_string(port).c_str(),
"num_threads", "4",
NULL
};
// Initialize the server
ctx_ = mg_start(NULL, this, options);
if (!ctx_) {
return false; // Failed to start server
}
// Register HTTP handler for JSON-RPC endpoint
mg_set_request_handler(ctx_, "/jsonrpc", http_handler, this);
return true; // Server initialized successfully
}
bool MCPServerImpl::run() {
if (!ctx_) {
return false;
}
// Server is already running after mg_start
// This method can be used for additional setup or monitoring
return true;
}
MCPServer::MCPServer() : impl_(new tydra::MCPServerImpl()) {}
bool MCPServer::init(int port, const std::string &host) {
return impl_->init(port, host);
}
} // namespace tydra
} // namespace tinyusdz

View File

@@ -1,11 +1,7 @@
// Interface for MCP(ModelContextProtocol)
#pragma once
namespace tinyusdz {
namespace tydra {
} // namespace tydra
} // namespace tinyusdz