bug fixes
This commit is contained in:
15
cmd/server.c
15
cmd/server.c
@@ -40,12 +40,16 @@ int parseHTTPRequest(unsigned char *buffer, struct HTTPRequest *r) {
|
||||
int line = 0;
|
||||
int contentCheck = 0;
|
||||
unsigned char *checkLine = calloc(1000, sizeof(unsigned char));
|
||||
size_t checkLineLen = 0;
|
||||
unsigned char *logLine = malloc(sizeof(unsigned char));
|
||||
char * varCheck;
|
||||
|
||||
// Creating empty requestBody
|
||||
r->requestBody = calloc(8, sizeof(char));
|
||||
r->requestBody = malloc(sizeof(char));
|
||||
r->requestBodyLen = 0;
|
||||
r->requestVars = malloc(sizeof(char));
|
||||
memset(r->requestBody, 0, sizeof(char));
|
||||
memset(r->requestVars, 0, sizeof(char));
|
||||
|
||||
for (int i = 0; i <= strlen((char *)buffer); i++) {
|
||||
temp[0] = buffer[i];
|
||||
@@ -84,12 +88,15 @@ int parseHTTPRequest(unsigned char *buffer, struct HTTPRequest *r) {
|
||||
PrintLog(logLine);
|
||||
} else { // Gather information on >first line
|
||||
if (contentCheck) { // Once content check is set to one everything after is part of the body
|
||||
printf("Check Line: %s\n", checkLine);
|
||||
r->requestBody = realloc(r->requestBody,
|
||||
(strlen((char *)checkLine) + strlen((char *)r->requestBody) + 1));
|
||||
(checkLineLen + r->requestBodyLen + 2));
|
||||
strcat((char *)r->requestBody, (char *)checkLine);
|
||||
// Adding newline to requestBody
|
||||
strcat((char *)r->requestBody, "\n");
|
||||
r->requestBodyLen += strlen((char *)checkLine);
|
||||
r->requestBodyLen += checkLineLen + 2;
|
||||
printf("Size: %zu\nCheck Size: %zu\n", r->requestBodyLen, checkLineLen);
|
||||
printf("Req:\n%s\n", r->requestBody);
|
||||
} else { // Information parsing !content
|
||||
if (strlen((char *)checkLine) == 1) { // Looking for blank empty line to end header info
|
||||
contentCheck = 1;
|
||||
@@ -118,10 +125,12 @@ int parseHTTPRequest(unsigned char *buffer, struct HTTPRequest *r) {
|
||||
if (strlen((char *)checkLine) > 0) {
|
||||
// Clear checkLine
|
||||
memset(checkLine,0,strlen((char *)checkLine));
|
||||
checkLineLen = 0;
|
||||
}
|
||||
line++;
|
||||
} else {
|
||||
strcat((char *)checkLine, temp);
|
||||
checkLineLen++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user