ErikMinekus / sm-ripext

SourceMod REST in Pawn Extension
https://forums.alliedmods.net/showthread.php?t=298024
GNU General Public License v3.0
136 stars 38 forks source link

Crash when folder doesn't exist #34

Closed Bara closed 3 years ago

Bara commented 3 years ago

Server crash when a folder doesn't exist, where the file should be stored.

Working example (from AM thread):

#include <sourcemod>
#include <ripext>

HTTPClient httpClient;

public void OnPluginStart()
{
    httpClient = new HTTPClient("https://nghttp2.org/httpbin");

    char sImagePath[PLATFORM_MAX_PATH];
    BuildPath(Path_SM, sImagePath, sizeof(sImagePath), "data/image.jpg");

    httpClient.DownloadFile("image/jpeg", sImagePath, OnImageDownloaded);
}

void OnImageDownloaded(HTTPStatus status, any value)
{
    if (status != HTTPStatus_OK) {
        // Download failed
        return;
    }

    PrintToServer("Download complete");
}

Not working example (I changed data/image.jpg to data2/image.jpg for reproduzing the crash):

#include <sourcemod>
#include <ripext>

HTTPClient httpClient;

public void OnPluginStart()
{
    httpClient = new HTTPClient("https://nghttp2.org/httpbin");

    char sImagePath[PLATFORM_MAX_PATH];
    BuildPath(Path_SM, sImagePath, sizeof(sImagePath), "data2/image.jpg");

    httpClient.DownloadFile("image/jpeg", sImagePath, OnImageDownloaded);
}

void OnImageDownloaded(HTTPStatus status, any value)
{
    if (status != HTTPStatus_OK) {
        // Download failed
        return;
    }

    PrintToServer("Download complete");
}
Bara commented 3 years ago

Before I forget it...

The last console output is: L 01/30/2021 - 10:41:41: [RIPEXT] Could not open file addons/sourcemod/data2/image.jpg.

Crash dump: https://crash.limetech.org/ddjcdmzhurlk

ErikMinekus commented 3 years ago

Thanks. It basically fails to initialize the request, but tries to perform the request anyway. This should be an easy fix.