small fixes

This commit is contained in:
Pin
2022-02-24 20:55:27 -05:00
parent 16801086ff
commit 7520553672
3 changed files with 8 additions and 4 deletions

View File

@@ -39,6 +39,7 @@ int parseHTTPRequest(unsigned char *buffer, struct HTTPRequest *r) {
int contentCheck = 0;
unsigned char *checkLine = calloc(1000, sizeof(unsigned char));
unsigned char *logLine = malloc(sizeof(unsigned char));
char * varCheck;
// Creating empty requestBody
r->requestBody = calloc(8, sizeof(char));
@@ -61,8 +62,11 @@ int parseHTTPRequest(unsigned char *buffer, struct HTTPRequest *r) {
strcpy(r->requestType, token);
// Grabbing HTTP Request Dir
token = strtok(NULL, " ");
r->requestDir = malloc(strlen(token));
strcpy(r->requestDir, token);
varCheck = strchr(token, '?');
if (varCheck != NULL) {
*varCheck = ' ';
}
sscanf(token, "%ms %ms", &r->requestDir, &r->requestVars);
// Grabbing HTTP Request Version
token = strtok(NULL, "");
token[strlen(token) - 1] = '\0'; // Fixing version end char
@@ -233,7 +237,7 @@ int handleRequest(unsigned char buffer[], int socket, SSL *ssl) {
if (checkerr != 0) { // Checking for HTTP parsing error
if (checkerr == -1) {
printDebug("Error reading request, returning empty 500");
return500Request(socket, ssl);
return return500Request(socket, ssl);
} else {
printDebug("Error parsing, returning 501");
return return501Request(socket, ssl);

View File

@@ -7,5 +7,6 @@ struct HTTPRequest {
char *requestVersion;
char *requestHost;
char *requestDir;
char *requestVars;
unsigned char *requestBody;
};

View File

@@ -23,7 +23,6 @@ int checkHTTPVersion(char *version) {
int supported = -1; // Default fail state
char testVer[16];
strcpy(testVer, version);
//testVer[strlen(version) - 1] = '\0'; // Removing
for (int i = 0; i < NUM_SUPPORTED_VERSIONS; i++) {
if (!strcmp(testVer, supportedHTTPVersions[i])) {
supported = 0;