Implement SetHTTPRequestRawPostBodyFromFile (#24)
* Implement SetHTTPRequestRawPostBodyFromFile * Made sure that retval of fread() matches filesize * Minor code cleanup * Moved sm_SetHTTPRequestRawPostBodyFromFile to its appropriate place in the file * style
This commit is contained in:
@@ -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;
|
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)
|
static cell_t sm_GetHTTPResponseBodyCallback(IPluginContext *pContext, const cell_t *params)
|
||||||
{
|
{
|
||||||
ISteamHTTP *pHTTP;
|
ISteamHTTP *pHTTP;
|
||||||
@@ -644,6 +692,7 @@ static sp_nativeinfo_t httpnatives[] = {
|
|||||||
{"SteamWorks_GetHTTPDownloadProgressPct", sm_GetHTTPDownloadProgressPct},
|
{"SteamWorks_GetHTTPDownloadProgressPct", sm_GetHTTPDownloadProgressPct},
|
||||||
{"SteamWorks_GetHTTPRequestWasTimedOut", sm_GetHTTPRequestWasTimedOut},
|
{"SteamWorks_GetHTTPRequestWasTimedOut", sm_GetHTTPRequestWasTimedOut},
|
||||||
{"SteamWorks_SetHTTPRequestRawPostBody", sm_SetHTTPRequestRawPostBody},
|
{"SteamWorks_SetHTTPRequestRawPostBody", sm_SetHTTPRequestRawPostBody},
|
||||||
|
{"SteamWorks_SetHTTPRequestRawPostBodyFromFile", sm_SetHTTPRequestRawPostBodyFromFile},
|
||||||
{"SteamWorks_GetHTTPResponseBodyCallback", sm_GetHTTPResponseBodyCallback},
|
{"SteamWorks_GetHTTPResponseBodyCallback", sm_GetHTTPResponseBodyCallback},
|
||||||
{"SteamWorks_WriteHTTPResponseBodyToFile", sm_WriteHTTPResponseBodyToFile},
|
{"SteamWorks_WriteHTTPResponseBodyToFile", sm_WriteHTTPResponseBodyToFile},
|
||||||
{"SteamWorks_SendHTTPRequestAndStreamResponse", sm_SendHTTPRequestAndStreamResponse},
|
{"SteamWorks_SendHTTPRequestAndStreamResponse", sm_SendHTTPRequestAndStreamResponse},
|
||||||
|
|||||||
@@ -281,6 +281,7 @@ native bool:SteamWorks_GetHTTPStreamingResponseBodyData(Handle:hRequest, cOffset
|
|||||||
native bool:SteamWorks_GetHTTPDownloadProgressPct(Handle:hRequest, &Float:percent);
|
native bool:SteamWorks_GetHTTPDownloadProgressPct(Handle:hRequest, &Float:percent);
|
||||||
native bool:SteamWorks_GetHTTPRequestWasTimedOut(Handle:hRequest, &bool:bWasTimedOut);
|
native bool:SteamWorks_GetHTTPRequestWasTimedOut(Handle:hRequest, &bool:bWasTimedOut);
|
||||||
native bool:SteamWorks_SetHTTPRequestRawPostBody(Handle:hRequest, const String:sContentType[], const String:sBody[], bodylen);
|
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
|
funcenum SteamWorksHTTPBodyCallback
|
||||||
{
|
{
|
||||||
@@ -372,6 +373,7 @@ public __ext_SteamWorks_SetNTVOptional()
|
|||||||
MarkNativeAsOptional("SteamWorks_GetHTTPStreamingResponseBodyData");
|
MarkNativeAsOptional("SteamWorks_GetHTTPStreamingResponseBodyData");
|
||||||
MarkNativeAsOptional("SteamWorks_GetHTTPDownloadProgressPct");
|
MarkNativeAsOptional("SteamWorks_GetHTTPDownloadProgressPct");
|
||||||
MarkNativeAsOptional("SteamWorks_SetHTTPRequestRawPostBody");
|
MarkNativeAsOptional("SteamWorks_SetHTTPRequestRawPostBody");
|
||||||
|
MarkNativeAsOptional("SteamWorks_SetHTTPRequestRawPostBodyFromFile");
|
||||||
|
|
||||||
MarkNativeAsOptional("SteamWorks_GetHTTPResponseBodyCallback");
|
MarkNativeAsOptional("SteamWorks_GetHTTPResponseBodyCallback");
|
||||||
MarkNativeAsOptional("SteamWorks_WriteHTTPResponseBodyToFile");
|
MarkNativeAsOptional("SteamWorks_WriteHTTPResponseBodyToFile");
|
||||||
|
|||||||
Reference in New Issue
Block a user