Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions Extension/swhttprequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,54 @@ static cell_t sm_SetHTTPRequestRawPostBody(IPluginContext *pContext, const cell_
return pHTTP->SetHTTPRequestRawPostBody(pRequest->request, pName, reinterpret_cast<uint8_t *>(pBuffer), params[4]) ? 1 : 0;
}

static cell_t sm_SetHTTPRequestRawPostBodyFromFile(IPluginContext *pContext, const cell_t *params)
{
ISteamHTTP *pHTTP;
SteamWorksHTTPRequest *pRequest = GetRequestPointer(pHTTP, pContext, params[1]);
if (pRequest == NULL)
{
return 0;
}

char *pContentType, *pFilePath;
pContext->LocalToString(params[2], &pContentType);
pContext->LocalToString(params[3], &pFilePath);

char szFinalPath[PLATFORM_MAX_PATH];
smutils->BuildPath(Path_Game, szFinalPath, sizeof(szFinalPath), "%s", pFilePath);

FILE *pInputFile = fopen(szFinalPath, "rb");
if (!pInputFile)
{
return pContext->ThrowNativeError("Unable to open %s for reading. errno: %d", szFinalPath, errno);
}

fseek(pInputFile, 0, SEEK_END);
uint32_t size = ftell(pInputFile);
fseek(pInputFile, 0, SEEK_SET);

if (size <= 0)
{
fclose(pInputFile);
return 0;
}

char *pBuffer = new char[size + 1];
uint32_t itemsRead = fread(pBuffer, sizeof(char), size, pInputFile);
fclose(pInputFile);

if (itemsRead != size)
{
delete [] pBuffer;
return 0;
}

cell_t result = pHTTP->SetHTTPRequestRawPostBody(pRequest->request, pContentType, reinterpret_cast<uint8_t *>(pBuffer), size) ? 1 : 0;

delete [] pBuffer;
return result;
}

static cell_t sm_GetHTTPResponseBodyCallback(IPluginContext *pContext, const cell_t *params)
{
ISteamHTTP *pHTTP;
Expand Down Expand Up @@ -644,6 +692,7 @@ static sp_nativeinfo_t httpnatives[] = {
{"SteamWorks_GetHTTPDownloadProgressPct", sm_GetHTTPDownloadProgressPct},
{"SteamWorks_GetHTTPRequestWasTimedOut", sm_GetHTTPRequestWasTimedOut},
{"SteamWorks_SetHTTPRequestRawPostBody", sm_SetHTTPRequestRawPostBody},
{"SteamWorks_SetHTTPRequestRawPostBodyFromFile", sm_SetHTTPRequestRawPostBodyFromFile},
{"SteamWorks_GetHTTPResponseBodyCallback", sm_GetHTTPResponseBodyCallback},
{"SteamWorks_WriteHTTPResponseBodyToFile", sm_WriteHTTPResponseBodyToFile},
{"SteamWorks_SendHTTPRequestAndStreamResponse", sm_SendHTTPRequestAndStreamResponse},
Expand Down
2 changes: 2 additions & 0 deletions Pawn/includes/SteamWorks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ native bool:SteamWorks_GetHTTPStreamingResponseBodyData(Handle:hRequest, cOffset
native bool:SteamWorks_GetHTTPDownloadProgressPct(Handle:hRequest, &Float:percent);
native bool:SteamWorks_GetHTTPRequestWasTimedOut(Handle:hRequest, &bool:bWasTimedOut);
native bool:SteamWorks_SetHTTPRequestRawPostBody(Handle:hRequest, const String:sContentType[], const String:sBody[], bodylen);
native bool:SteamWorks_SetHTTPRequestRawPostBodyFromFile(Handle:hRequest, const String:sContentType[], const String:sFileName[]);

funcenum SteamWorksHTTPBodyCallback
{
Expand Down Expand Up @@ -372,6 +373,7 @@ public __ext_SteamWorks_SetNTVOptional()
MarkNativeAsOptional("SteamWorks_GetHTTPStreamingResponseBodyData");
MarkNativeAsOptional("SteamWorks_GetHTTPDownloadProgressPct");
MarkNativeAsOptional("SteamWorks_SetHTTPRequestRawPostBody");
MarkNativeAsOptional("SteamWorks_SetHTTPRequestRawPostBodyFromFile");

MarkNativeAsOptional("SteamWorks_GetHTTPResponseBodyCallback");
MarkNativeAsOptional("SteamWorks_WriteHTTPResponseBodyToFile");
Expand Down