Next21Team / AmxxCurl

Curl module for amxmodx
MIT License
33 stars 12 forks source link

CURLOPT_WRITEFUNCTION performing wrong task? #10

Closed ShadowsAdi closed 3 years ago

ShadowsAdi commented 3 years ago

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
Polarhigh commented 3 years ago

Hi! I'm not quite understand what's the question. In CurlCallback, why would you read id as a string? Then in ResponseReceived you print non-zero-terminated array, so some garbage is printed, too

ShadowsAdi commented 3 years ago

Found the answer here: https://github.com/Polarhigh/AmxxCurl/issues/8 . Thank you !