Skip to content
This repository was archived by the owner on Mar 20, 2021. It is now read-only.

Commit 5040359

Browse files
committed
Project upload
1 parent 29213b8 commit 5040359

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+20106
-1
lines changed

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
18+
# Fortran module files
19+
*.mod
20+
*.smod
21+
22+
# Compiled Static libraries
23+
*.lai
24+
*.la
25+
*.a
26+
*.lib
27+
28+
# Executables
29+
*.out
30+
*.app
31+
32+
**/.vs
33+
**/Debug
34+
**/Release

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "plutonium-http/submodules/cpp-httplib"]
2+
path = plutonium-http/submodules/cpp-httplib
3+
url = https://github.com/yhirose/cpp-httplib.git

LICENSE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2020
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,121 @@
1-
plutonium-http
1+
# <div align="center">plutonium-http</div>
2+
3+
<div align="center">
4+
<img src="https://img.shields.io/badge/License-MIT-important?style=flat-square" />
5+
<img src="https://img.shields.io/badge/%E2%80%8E-C++-00599C?style=flat-square&logoWidth=20&logo=image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48dGl0bGU+QysrIGljb248L3RpdGxlPjxwYXRoIGZpbGw9IndoaXRlIiBkPSJNMjIuMzkzIDZjLS4xNjctLjI5LS4zOTgtLjU0My0uNjUyLS42OUwxMi45MjUuMjJjLS41MDgtLjI5My0xLjMzOS0uMjkzLTEuODQ3IDBMMi4yNiA1LjMxYy0uNTA4LjI5My0uOTIzIDEuMDEzLS45MjMgMS42djEwLjE4YzAgLjI5NC4xMDQuNjIuMjcxLjkxLjE2Ny4yOS4zOTguNTQzLjY1Mi42ODlsOC44MTYgNS4wOTFjLjUwOC4yOTMgMS4zMzkuMjkzIDEuODQ3IDBsOC44MTYtNS4wOTFjLjI1NC0uMTQ2LjQ4NS0uMzk5LjY1Mi0uNjg5cy4yNzEtLjYxNi4yNzEtLjkxVjYuOTFjLjAwMi0uMjk0LS4xMDItLjYyLS4yNjktLjkxek0xMiAxOS4xMDljLTMuOTIgMC03LjEwOS0zLjE4OS03LjEwOS03LjEwOVM4LjA4IDQuODkxIDEyIDQuODkxYTcuMTMzIDcuMTMzIDAgMCAxIDYuMTU2IDMuNTUybC0zLjA3NiAxLjc4MUEzLjU2NyAzLjU2NyAwIDAgMCAxMiA4LjQ0NWMtMS45NiAwLTMuNTU0IDEuNTk1LTMuNTU0IDMuNTU1UzEwLjA0IDE1LjU1NSAxMiAxNS41NTVhMy41NyAzLjU3IDAgMCAwIDMuMDgtMS43NzhsMy4wNzcgMS43OEE3LjEzNSA3LjEzNSAwIDAgMSAxMiAxOS4xMDl6bTcuMTA5LTYuNzE0aC0uNzl2Ljc5aC0uNzl2LS43OWgtLjc5di0uNzloLjc5di0uNzloLjc5di43OWguNzl2Ljc5em0yLjk2MiAwaC0uNzl2Ljc5aC0uNzl2LS43OWgtLjc4OXYtLjc5aC43ODl2LS43OWguNzl2Ljc5aC43OXYuNzl6Ii8+PC9zdmc+" />
6+
<br/><br/>
7+
Making it possible to do basic http GET, POST, PUT & DELETE requests within ChaiScript.<br/>
8+
This plugin was mainly built for <a href="https://plutonium.pw/">Plutonium MW3</a>.
9+
</div>
10+
11+
___
12+
13+
## Download
14+
15+
Download the [latest release](https://github.com/ryanocf/plutonium-http/releases) and put the <kbd>**plutonium-http.dll**</kbd> in your servers plugin folder.
16+
17+
___
18+
19+
## Usage
20+
21+
:exclamation: **OpenSSL is currently not supported.**<br/>
22+
Every function returns the same Vector scheme:
23+
24+
```c++
25+
0: version
26+
1: error
27+
2: status
28+
3: reason
29+
4: body
30+
5: headers
31+
```
32+
33+
```c++
34+
/*
35+
* Params
36+
* url: String
37+
* route: String
38+
* headers: Map
39+
*
40+
* return: Vector
41+
*/
42+
http_get("http://example.com", "/route", ["header": "value"]);
43+
```
44+
45+
```c++
46+
/*
47+
* Params
48+
* url: String
49+
* route: String
50+
* body: String
51+
* headers: Map
52+
* content_type: String
53+
*
54+
* return: Vector
55+
*/
56+
http_post("http://example.com", "/route", "body" ["header": "value"], "text/plain");
57+
http_post("http://example.com", "/route", "param=body&format=string" ["header": "value"], "application/x-www-form-urlencoded");
58+
```
59+
60+
```c++
61+
/*
62+
* Params
63+
* url: String
64+
* route: String
65+
* body: String
66+
* headers: Map
67+
* content_type: String
68+
*
69+
* return: Vector
70+
*/
71+
http_put("http://example.com", "/route", "body" ["header": "value"], "text/plain");
72+
http_put("http://example.com", "/route", "param=body&format=string" ["header": "value"], "application/x-www-form-urlencoded");
73+
```
74+
75+
```c++
76+
/*
77+
* Params
78+
* url: String
79+
* route: String
80+
* body: String
81+
* headers: Map
82+
* content_type: String
83+
*
84+
* return: Vector
85+
*/
86+
http_delete("http://example.com", "/route", "body" ["header": "value"], "text/plain");
87+
http_delete("http://example.com", "/route", "param=body&format=string" ["header": "value"], "application/x-www-form-urlencoded");
88+
```
89+
90+
___
91+
92+
## Errors
93+
94+
```c++
95+
std::array<std::string, 13> error_list = {
96+
"Success",
97+
"Unknown",
98+
"Connection",
99+
"BindIPAddress",
100+
"Read",
101+
"Write",
102+
"ExceedRedirectCount",
103+
"Canceled",
104+
"SSLConnection",
105+
"SSLLoadingCerts",
106+
"SSLServerVerification",
107+
"UnsupportedMultipartBoundaryChars",
108+
"Compression"
109+
};
110+
```
111+
112+
___
113+
114+
Any questions or problems?<br/>
115+
Feel free to open an [issue](https://github.com/ryanocf/plutonium-http/issues/new) or visit this project on [Plutonium](https://forum.plutonium.pw/).
116+
117+
## Credits
118+
119+
https://github.com/yhirose/cpp-httplib<br/>
120+
https://github.com/ChaiScript/ChaiScript<br/>
121+
https://github.com/xensik/plutoscript

plutonium-http.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30413.136
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "plutonium-http", "plutonium-http\plutonium-http.vcxproj", "{74D8D476-2FE3-4DA5-93DF-69065B84A611}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{74D8D476-2FE3-4DA5-93DF-69065B84A611}.Debug|x64.ActiveCfg = Debug|x64
17+
{74D8D476-2FE3-4DA5-93DF-69065B84A611}.Debug|x64.Build.0 = Debug|x64
18+
{74D8D476-2FE3-4DA5-93DF-69065B84A611}.Debug|x86.ActiveCfg = Debug|Win32
19+
{74D8D476-2FE3-4DA5-93DF-69065B84A611}.Debug|x86.Build.0 = Debug|Win32
20+
{74D8D476-2FE3-4DA5-93DF-69065B84A611}.Release|x64.ActiveCfg = Release|x64
21+
{74D8D476-2FE3-4DA5-93DF-69065B84A611}.Release|x64.Build.0 = Release|x64
22+
{74D8D476-2FE3-4DA5-93DF-69065B84A611}.Release|x86.ActiveCfg = Release|Win32
23+
{74D8D476-2FE3-4DA5-93DF-69065B84A611}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {CE266889-B641-4518-B700-82EDCA59CBA9}
30+
EndGlobalSection
31+
EndGlobal

plutonium-http/core/client.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "client.hpp"
2+
3+
auto Client::Get(const char* url, const char* route, const httplib::Headers headers) -> httplib::Result
4+
{
5+
httplib::Client cli(url);
6+
return cli.Get(route, headers);
7+
}
8+
9+
auto Client::Post(const char* url, const char* route, const std::string body, const httplib::Headers headers, const char* content_type) -> httplib::Result
10+
{
11+
httplib::Client cli(url);
12+
return cli.Post(route, headers, body, content_type);
13+
}
14+
15+
auto Client::Put(const char* url, const char* route, const std::string body, const httplib::Headers headers, const char* content_type) -> httplib::Result
16+
{
17+
httplib::Client cli(url);
18+
return cli.Put(route, headers, body, content_type);
19+
}
20+
21+
auto Client::Delete(const char* url, const char* route, const std::string body, const httplib::Headers headers, const char* content_type) -> httplib::Result
22+
{
23+
httplib::Client cli(url);
24+
return cli.Delete(route, headers, body, content_type);
25+
}

plutonium-http/core/client.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
#include "../include.hpp"
3+
4+
class Client
5+
{
6+
public:
7+
auto Get(const char* url, const char* route, httplib::Headers headers) -> httplib::Result;
8+
9+
auto Post(const char* url, const char* route, std::string body, httplib::Headers headers, const char* content_type) -> httplib::Result;
10+
11+
auto Put(const char* url, const char* route, std::string body, httplib::Headers headers, const char* content_type) -> httplib::Result;
12+
13+
auto Delete(const char* url, const char* route, std::string body, httplib::Headers headers, const char* content_type) -> httplib::Result;
14+
};
15+
16+
inline std::unique_ptr<Client> client = std::make_unique<Client>();

plutonium-http/core/conversion.hpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#pragma once
2+
#include "../include.hpp"
3+
4+
namespace Conversion
5+
{
6+
inline std::array<std::string, 13> error_list = {
7+
"Success",
8+
"Unknown",
9+
"Connection",
10+
"BindIPAddress",
11+
"Read",
12+
"Write",
13+
"ExceedRedirectCount",
14+
"Canceled",
15+
"SSLConnection",
16+
"SSLLoadingCerts",
17+
"SSLServerVerification",
18+
"UnsupportedMultipartBoundaryChars",
19+
"Compression"
20+
};
21+
22+
inline auto map_to_headers(std::map<std::string, chaiscript::Boxed_Value> map) -> httplib::Headers
23+
{
24+
httplib::Headers headers;
25+
26+
for (auto const& [key, val] : map) {
27+
if (key.empty() || chaiscript::boxed_cast<std::string>(val).empty()) continue;
28+
29+
headers.emplace(key, chaiscript::boxed_cast<std::string>(val));
30+
}
31+
32+
return headers;
33+
}
34+
35+
inline auto headers_to_map(httplib::Headers headers) -> std::map<std::string, chaiscript::Boxed_Value>
36+
{
37+
std::map<std::string, chaiscript::Boxed_Value> map;
38+
39+
for (auto const& [key, val] : headers) {
40+
map.emplace(key, chaiscript::var(val));
41+
}
42+
43+
return map;
44+
}
45+
46+
inline auto map_to_params(std::map<std::string, chaiscript::Boxed_Value> map) -> httplib::Params
47+
{
48+
httplib::Params params;
49+
50+
for (auto const& [key, val] : map) {
51+
if (key.empty() || chaiscript::boxed_cast<std::string>(val).empty()) continue;
52+
53+
params.emplace(key, chaiscript::boxed_cast<std::string>(val));
54+
}
55+
56+
return params;
57+
}
58+
59+
inline auto result_to_chai(httplib::Result result) -> chaiscript::Boxed_Value
60+
{
61+
std::vector<chaiscript::Boxed_Value> values;
62+
63+
values.push_back(chaiscript::var(result->version));
64+
values.push_back(chaiscript::var(error_list[result.error()]));
65+
values.push_back(chaiscript::var(result->status));
66+
values.push_back(chaiscript::var(result->reason));
67+
values.push_back(chaiscript::var(result->body));
68+
values.push_back(chaiscript::var(headers_to_map(result->headers)));
69+
70+
return chaiscript::Boxed_Value(values);
71+
}
72+
}

plutonium-http/dllmain.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "include.hpp"
2+
3+
DLL_EXPORT void on_initialize_context(const char* script, chaiscript::ChaiScript* chai)
4+
{
5+
chai->add(chaiscript::fun([](const std::string& url, const std::string& route, const std::map<std::string, chaiscript::Boxed_Value>& headers)
6+
{ return Conversion::result_to_chai(client->Get(url.c_str(), route.c_str(), Conversion::map_to_headers(headers))); }), "http_get");
7+
8+
chai->add(chaiscript::fun([](const std::string& url, const std::string& route, const std::string& body, const std::map<std::string, chaiscript::Boxed_Value>& headers, const std::string& content_type)
9+
{ return Conversion::result_to_chai(client->Post(url.c_str(), route.c_str(), body, Conversion::map_to_headers(headers), content_type.c_str())); }), "http_post");
10+
11+
chai->add(chaiscript::fun([](const std::string& url, const std::string& route, const std::string& body, const std::map<std::string, chaiscript::Boxed_Value>& headers, const std::string& content_type)
12+
{ return Conversion::result_to_chai(client->Put(url.c_str(), route.c_str(), body, Conversion::map_to_headers(headers), content_type.c_str())); }), "http_put");
13+
14+
chai->add(chaiscript::fun([](const std::string& url, const std::string& route, const std::string& body, const std::map<std::string, chaiscript::Boxed_Value>& headers, const std::string& content_type)
15+
{ return Conversion::result_to_chai(client->Delete(url.c_str(), route.c_str(), body, Conversion::map_to_headers(headers), content_type.c_str())); }), "http_delete");
16+
}
17+
18+
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
19+
{
20+
switch (dwReason)
21+
{
22+
case DLL_PROCESS_ATTACH:
23+
case DLL_THREAD_ATTACH:
24+
case DLL_THREAD_DETACH:
25+
case DLL_PROCESS_DETACH:
26+
break;
27+
}
28+
29+
return TRUE;
30+
}

plutonium-http/include.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma warning(disable: 4244)
2+
#pragma warning(disable: 6031)
3+
#pragma warning(disable: 26451)
4+
#pragma warning(disable: 26495)
5+
#pragma warning(disable: 26812)
6+
#pragma warning(disable: 28020)
7+
8+
#define DLL_EXPORT extern "C" __declspec(dllexport)
9+
#define WIN32_LEAN_AND_MEAN
10+
#include <windows.h>
11+
#include <vector>
12+
13+
#include "submodules/cpp-httplib/httplib.h"
14+
#include "submodules/ChaiScript/include/chaiscript/chaiscript.hpp"
15+
16+
#include "core/conversion.hpp"
17+
#include "core/client.hpp"

0 commit comments

Comments
 (0)