fixed checkLine mem issue
This commit is contained in:
23
cmd/server.c
23
cmd/server.c
@@ -8,15 +8,15 @@
|
|||||||
// Local Includes
|
// Local Includes
|
||||||
#include "httpStruct.h"
|
#include "httpStruct.h"
|
||||||
#include "socketHelp.h"
|
#include "socketHelp.h"
|
||||||
|
#include "returnRequest.h"
|
||||||
|
|
||||||
#define PORT 8080
|
#define PORT 8080
|
||||||
|
|
||||||
int parseHTTPRequest(char buffer[], struct HTTPRequest *r) {
|
int parseHTTPRequest(char buffer[], struct HTTPRequest *r) {
|
||||||
char temp[1];
|
char temp[1];
|
||||||
char *token;
|
char *token = calloc(8, sizeof(char));
|
||||||
int line = 0;
|
int line = 0;
|
||||||
char * checkLine;
|
char *checkLine = calloc(1000, sizeof(char));;
|
||||||
checkLine = malloc(1000);
|
|
||||||
|
|
||||||
for (int i = 0; i < strlen(buffer); i++) {
|
for (int i = 0; i < strlen(buffer); i++) {
|
||||||
temp[0] = buffer[i];
|
temp[0] = buffer[i];
|
||||||
@@ -63,28 +63,13 @@ int parseHTTPRequest(char buffer[], struct HTTPRequest *r) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int returnRequest(int socket, char *message) {
|
|
||||||
send(socket, message, strlen(message), 0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int return200Request(int socket) {
|
|
||||||
char *message = "HTTP/1.1 200 OK\nContent-Length: 6\nConnection: close\n\nhello\n";
|
|
||||||
return returnRequest(socket, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
int return404Request(int socket) {
|
|
||||||
char *message = "HTTP/1.1 404 Not Found\nContent-Length: 12\nConnection: close\n\n404 Request\n";
|
|
||||||
return returnRequest(socket, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
int handleRequest(char buffer[], int socket) {
|
int handleRequest(char buffer[], int socket) {
|
||||||
struct HTTPRequest r; // Holds relevant HTTP request information
|
struct HTTPRequest r; // Holds relevant HTTP request information
|
||||||
int checkerr = 0;
|
int checkerr = 0;
|
||||||
// Grabbing relevant information out of request
|
// Grabbing relevant information out of request
|
||||||
checkerr = parseHTTPRequest(buffer, &r);
|
checkerr = parseHTTPRequest(buffer, &r);
|
||||||
if (checkerr != 0) { // Checking for HTTP parsing error
|
if (checkerr != 0) { // Checking for HTTP parsing error
|
||||||
perror("Badness!!!");
|
perror("Error parsing");
|
||||||
return return404Request(socket);
|
return return404Request(socket);
|
||||||
}
|
}
|
||||||
// Return response to socket
|
// Return response to socket
|
||||||
|
|||||||
3
include/returnRequest.h
Normal file
3
include/returnRequest.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
int returnRequest(int socket, char *message, int status);
|
||||||
|
int return200Request(int socket);
|
||||||
|
int return404Request(int socket);
|
||||||
18
src/returnRequest.c
Normal file
18
src/returnRequest.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
int returnRequest(int socket, char *message, int status) {
|
||||||
|
send(socket, message, strlen(message), 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int return200Request(int socket) {
|
||||||
|
char *message = "HTTP/1.1 200 OK\nContent-Length: 6\nConnection: close\n\nhello\n";
|
||||||
|
return returnRequest(socket, message, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
int return404Request(int socket) {
|
||||||
|
char *message = "HTTP/1.1 404 Not Found\nContent-Length: 12\nConnection: close\n\n404 Request\n";
|
||||||
|
return returnRequest(socket, message, 400);
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user