next21team / amxxcurl Goto Github PK
View Code? Open in Web Editor NEWCurl module for amxmodx
License: MIT License
Curl module for amxmodx
License: MIT License
Sometimes server freezes forever during file download, it doesn't matter whether I download 10KB or 10MB file, the problem occurs in any case.
I'm using Windows and this happens on both HLDS and reHLDS as well as in 1.8.2 and 1.8.3 AMXModX. Changing CURLOPT_BUFFERSIZE helps a bit but doesn't really solve the issue.
Sometimes it freezes on the first download and sometimes it may take 50 or more attempts, for this reason I'm running download in a cycle for test plugin.
Test plugin: https://gist.github.com/F4M3Z0R/9d6181c2227d6f93dd1c463d543c2a66
L 10/10/2018 - 09:03:00: [AMXX] Module "cstrike/addons/amxmodx/modules/curl_amxx_i386.so" failed to load (cstrike/addons/amxmodx/modules/curl_amxx_i386.so: undefined symbol: MD5_Init)
L 10/10/2018 - 09:03:00: Error:
L 10/10/2018 - 09:03:00: [AMXX] Module is not a valid library (file "cstrike/addons/amxmodx/modules/curl_amxx_i386.so")
Doesn't work with ReHLDS
This module seems to crash the server whenever multiple cURL requests are made on the same frame. The server crashes at Curl_resolv_timeout after CURLOPT_CONNECTTIMEOUT time has passed from initializing the requests, although they are successful.
After a ton of debugging and research, I believe having USE_ALARM_TIMEOUT enabled is the reason:
curl/curl#1700 (comment)
Using CURLOPT_NOSIGNAL 1 seems to be an effective workaround for this issue for the time being.
Hello,
CURLOPT_WRITEFUNCTION is returning a malformed string:
``buff: {
"status": "ok",
"104.245.146.53": {
p/l
buff:"proxy": "yes",
"type": "Compromised Server"
}``
The response buffer is splited by two.
Real response buffer:
{ "status": "ok", "104.245.146.53": { "proxy": "yes", "type": "Compromised Server" } }
CURLOPT_BUFFERSIZE is setted to 1024.
Hello, is it possible to reuse a curl handler? I will be sending multiple requests to the same host but with different parameters.
Example
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/a")
curl_easy_perform(curl, "completed_callback")
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/b")
curl_easy_perform(curl, "completed_callback")
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/c")
curl_easy_perform(curl, "completed_callback")
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/d")
curl_easy_perform(curl, "completed_callback")
Example plugin:
#include <amxmodx>
#include <amxmisc>
#include <curl>
#define CURL_BUFFER_SIZE 1024
enum dataStruct { curl_slist: linkedList };
public plugin_init()
{
register_plugin("curl http get", "1.0", "Polarhigh")
register_srvcmd("curl", "curlSend", ADMIN_RCON, "^"url^"");
}
public curlSend(id, level, cid)
{
if (!cmd_access(id, level, cid, 2)) {
return PLUGIN_HANDLED
}
new CURL:curl = curl_easy_init(), curl_slist: pHeaders, data[dataStruct], url[64]
pHeaders = curl_slist_append(pHeaders, "User-Agent: curl")
data[linkedList] = pHeaders
read_args(url, charsmax(url))
remove_quotes(url)
trim(url)
if (!url[0]) {
server_print("Не заполнен URL")
return PLUGIN_HANDLED
}
server_print("Go url: %s", url)
curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, CURL_BUFFER_SIZE)
curl_easy_setopt(curl, CURLOPT_URL, url)
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pHeaders)
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, "write")
curl_easy_perform(curl, "complite", data, dataStruct)
return PLUGIN_HANDLED
}
public write(data[], size, nmemb)
{
new actual_size = size * nmemb;
server_print(data)
return actual_size
}
public complite(CURL:curl, CURLcode:code, data[dataStruct])
{
if(code == CURLE_WRITE_ERROR)
server_print("transfer aborted")
else
server_print("curl complete")
curl_easy_cleanup(curl)
curl_slist_free_all(data[linkedList]);
}
Send one request in server console
curl http://asd.ru
Output:
Go url: http://asd.ru
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://www.asd.ru/">here</a>.</p>
<hr>
<address>Apache/2.4.25 (Debian) Serve
curl complete
Send two request
curl http://2ip.ru
Output:
Go url: http://2ip.ru
46.174.48.15
L PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://www.asd.ru/">here</a>.</p>
<hr>
<address>Apache/2.4.25 (Debian) Serve
curl complete
Real response from server
46.174.48.15
Restart server and send request
Go url: http://2ip.ru
46.174.48.15
curl complete
PS: sorry my bad english
This module seems to make the server freeze randomly. There are no errors or anything, server suddenly just stops responding and uses 0% CPU. I've created a test plugin to make sure it's cause by this module. With only this plugin running, the server freezes eventually every single time, usually within 10 minutes.
Test plugin: https://pastebin.com/T4JnRAKD
I also tried it without the JSON part, with cURL being the only module running, and it had the same results.
Can it be set with given address and port to communicate via http proxies?
Like:
curl https://raw.githubusercontent.com/AlucardNosferatu/GS_Dumpster/SvenCoop_AngelScripts/UREnhanced.as -o fuck.as --proxy http://127.0.0.1:1080
Thx!
Hi,
I'm trying to use this library in my project, but unfortunately I stucked.
I would like to have access to response body in requestComplete
callback without using global variables.
My code looks like this:
new CURL: handle = curl_easy_init();
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, "@responseWrite");
curl_easy_perform(handle, "@requestComplete");
@responseWrite(const data[], const size, const nmemb)
{
return size * nmemb;
}
@requestComplete(CURL: curl, CURLcode: code)
{
// TODO: Have access to data from responseWrite
}
Can you help me with implementation?
Hello,
I am doing some test on players and when a command is sent through server, it is added to CURLOPT_WRITEFUNCTION callback. Like this:
public ResponseReceived(szBuffer[] , iSize , iNumMemb , id)
{
server_print("buff[0]: %s end", szBuffer[0]);
log_to_file("custom.log", "buff: %s end", szBuffer);
return iNumMemb * iSize;
}
log:
buff[0]: Nlient sent 'drop' end
L 07/24/2021 - 17:26:53: buff: Nlient sent 'drop' end
That "N" from logs is the real value got from Request.
Performed some more debugs:
new iID[1];
iID[0] = id;
curl_easy_perform(curl, "CurlCallback", iID, sizeof(iID) );
public CurlCallback(CURL:cURLHandle , CURLcode:code, id[])
{
if(code != CURLE_OK)
{
log_amx("cURL error: %d", code);
}
// id[0] is player's Index and "id" is the actual string retrieved
server_print("preid: %s: %d", id, id[0]);
id[0] = EOS;
server_print("postid: %s: %d", id, id[0]);
curl_easy_cleanup(cURLHandle);
}
Results:
preid: ilient sent 'drop': 9
postid: : 0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.