mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-04-02 22:06:10 +00:00
Use strtok_r()/strtok_s() instead of regular strtok()
This commit is contained in:
@@ -52,6 +52,12 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef LC_WINDOWS
|
||||
// Windows doesn't have strtok_r() but it has the same
|
||||
// function named strtok_s().
|
||||
#define strtok_r strtok_s
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "Limelight.h"
|
||||
|
||||
|
||||
@@ -972,6 +972,7 @@ int performRtspHandshake(PSERVER_INFORMATION serverInfo) {
|
||||
char* sessionId;
|
||||
char* pingPayload;
|
||||
int error = -1;
|
||||
char* strtokCtx;
|
||||
|
||||
if (!setupStream(&response,
|
||||
AppVersionQuad[0] >= 5 ? "streamid=audio/0/0" : "streamid=audio",
|
||||
@@ -1025,7 +1026,7 @@ int performRtspHandshake(PSERVER_INFORMATION serverInfo) {
|
||||
// resolves any 454 session not found errors on
|
||||
// standard RTSP server implementations.
|
||||
// (i.e - sessionId = "DEADBEEFCAFE;timeout = 90")
|
||||
sessionIdString = strdup(strtok(sessionId, ";"));
|
||||
sessionIdString = strdup(strtok_r(sessionId, ";", &strtokCtx));
|
||||
if (sessionIdString == NULL) {
|
||||
Limelog("Failed to duplicate session ID string\n");
|
||||
ret = -1;
|
||||
|
||||
@@ -63,6 +63,7 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
|
||||
char flag;
|
||||
bool messageEnded = false;
|
||||
|
||||
char* strtokCtx = NULL;
|
||||
char* payload = NULL;
|
||||
char* opt = NULL;
|
||||
int statusCode = 0;
|
||||
@@ -89,7 +90,7 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
|
||||
messageBuffer[length] = 0;
|
||||
|
||||
// Get the first token of the message
|
||||
token = strtok(messageBuffer, delim);
|
||||
token = strtok_r(messageBuffer, delim, &strtokCtx);
|
||||
if (token == NULL) {
|
||||
exitCode = RTSP_ERROR_MALFORMED;
|
||||
goto ExitFailure;
|
||||
@@ -102,7 +103,7 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
|
||||
protocol = token;
|
||||
|
||||
// Get the status code
|
||||
token = strtok(NULL, delim);
|
||||
token = strtok_r(NULL, delim, &strtokCtx);
|
||||
statusCode = atoi(token);
|
||||
if (token == NULL) {
|
||||
exitCode = RTSP_ERROR_MALFORMED;
|
||||
@@ -110,7 +111,7 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
|
||||
}
|
||||
|
||||
// Get the status string
|
||||
statusStr = strtok(NULL, end);
|
||||
statusStr = strtok_r(NULL, end, &strtokCtx);
|
||||
if (statusStr == NULL) {
|
||||
exitCode = RTSP_ERROR_MALFORMED;
|
||||
goto ExitFailure;
|
||||
@@ -125,12 +126,12 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
|
||||
else {
|
||||
flag = TYPE_REQUEST;
|
||||
command = token;
|
||||
target = strtok(NULL, delim);
|
||||
target = strtok_r(NULL, delim, &strtokCtx);
|
||||
if (target == NULL) {
|
||||
exitCode = RTSP_ERROR_MALFORMED;
|
||||
goto ExitFailure;
|
||||
}
|
||||
protocol = strtok(NULL, delim);
|
||||
protocol = strtok_r(NULL, delim, &strtokCtx);
|
||||
if (protocol == NULL) {
|
||||
exitCode = RTSP_ERROR_MALFORMED;
|
||||
goto ExitFailure;
|
||||
@@ -145,7 +146,7 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
|
||||
// Parse remaining options
|
||||
while (token != NULL)
|
||||
{
|
||||
token = strtok(NULL, typeFlag == TOKEN_OPTION ? optDelim : end);
|
||||
token = strtok_r(NULL, typeFlag == TOKEN_OPTION ? optDelim : end, &strtokCtx);
|
||||
if (token != NULL) {
|
||||
if (typeFlag == TOKEN_OPTION) {
|
||||
opt = token;
|
||||
|
||||
Reference in New Issue
Block a user