added forking
This commit is contained in:
26
Dockerfile
26
Dockerfile
@@ -1,11 +1,27 @@
|
|||||||
FROM ubuntu:latest
|
FROM ubuntu:latest
|
||||||
|
|
||||||
RUN apt-get update && \
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
apt-get install -y openssl
|
|
||||||
|
|
||||||
COPY ./bin/seaweb /bin/
|
RUN apt-get update && \
|
||||||
COPY ./certs/cert.pem /etc/ssl/certs/
|
apt-get install \
|
||||||
COPY ./certs/key.pem /etc/ssl/private/
|
-y openssl libssl-dev make gcc pkg-config
|
||||||
|
|
||||||
|
COPY Makefile /src/
|
||||||
|
COPY src/ /src/src/
|
||||||
|
COPY cmd/ /src/cmd/
|
||||||
|
COPY include/ /src/include/
|
||||||
|
COPY ca/ /src/ca/
|
||||||
|
|
||||||
|
COPY content/ /var/www/html
|
||||||
|
|
||||||
|
RUN mkdir -p /var/log/seaweb
|
||||||
|
|
||||||
|
WORKDIR /src/
|
||||||
|
|
||||||
|
RUN make && make install
|
||||||
|
|
||||||
|
# Create Certificates
|
||||||
|
RUN printf "y\ny\n" | make genCerts
|
||||||
|
|
||||||
EXPOSE 8080/tcp
|
EXPOSE 8080/tcp
|
||||||
|
|
||||||
|
|||||||
14
Makefile
14
Makefile
@@ -5,13 +5,13 @@ OUTPUT = -o ${OUTPUT_DIR}/PROG
|
|||||||
INSTALL_OUTPUT = ${OUTPUT_DIR}/PROG
|
INSTALL_OUTPUT = ${OUTPUT_DIR}/PROG
|
||||||
|
|
||||||
build: output_dir
|
build: output_dir
|
||||||
gcc -Wall ${LIBRARIES} ${SOURCES} ${OUTPUT:PROG=seaweb}
|
gcc -Wall ${SOURCES} ${OUTPUT:PROG=seaweb} ${LIBRARIES}
|
||||||
|
|
||||||
debug: output_dir
|
debug: output_dir
|
||||||
gcc -Wall -g ${LIBRARIES} ${SOURCES} ${OUTPUT:PROG=seaweb}
|
gcc -Wall -g ${SOURCES} ${OUTPUT:PROG=seaweb} ${LIBRARIES}
|
||||||
|
|
||||||
install:
|
install:
|
||||||
mv ${INSTALL_OUTPUT:PROG=server} /usr/bin/
|
mv ${INSTALL_OUTPUT:PROG=seaweb} /usr/bin/
|
||||||
|
|
||||||
output_dir:
|
output_dir:
|
||||||
mkdir -p ${OUTPUT_DIR}
|
mkdir -p ${OUTPUT_DIR}
|
||||||
@@ -36,3 +36,11 @@ genCerts:
|
|||||||
-rand_serial -config ./ca/ca.cnf \
|
-rand_serial -config ./ca/ca.cnf \
|
||||||
-out ./certs/cert.pem -infiles ./certs/cert.csr
|
-out ./certs/cert.pem -infiles ./certs/cert.csr
|
||||||
|
|
||||||
|
dockerBuild: output_dir
|
||||||
|
docker build . -t seaweb:latest
|
||||||
|
|
||||||
|
dockerTestDeploy: dockerBuild
|
||||||
|
docker run -p8080:8080 --rm seaweb:latest seaweb &
|
||||||
|
|
||||||
|
killTestDocker:
|
||||||
|
docker stop -t 0 `docker ps | grep "seaweb:latest" | tail -n 1 | tr -s " " | cut -d " " -f 1`
|
||||||
|
|||||||
120
cmd/server.c
120
cmd/server.c
@@ -6,6 +6,8 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <wait.h>
|
||||||
|
|
||||||
// Local Includes
|
// Local Includes
|
||||||
#include "httpStruct.h"
|
#include "httpStruct.h"
|
||||||
@@ -14,12 +16,15 @@
|
|||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
//#define WEB_ROOT "/var/www/html/"
|
||||||
#define WEB_ROOT "content/"
|
#define WEB_ROOT "content/"
|
||||||
#define BUFF_READ 1024
|
#define BUFF_READ 1024
|
||||||
|
|
||||||
static int verbose_flag = 0;
|
static int verbose_flag = 0;
|
||||||
bool enableHTTPS = 0;
|
bool enableHTTPS = 0;
|
||||||
|
|
||||||
|
static int timeout = 0;
|
||||||
|
|
||||||
int printDebug(char message[]) {
|
int printDebug(char message[]) {
|
||||||
if (verbose_flag == 1) {
|
if (verbose_flag == 1) {
|
||||||
printf("[Debug] %s\n", message);
|
printf("[Debug] %s\n", message);
|
||||||
@@ -43,13 +48,14 @@ int parseHTTPRequest(unsigned char *buffer, struct HTTPRequest *r) {
|
|||||||
// Checking for newline character OR end of string
|
// Checking for newline character OR end of string
|
||||||
if (((!strcmp(temp, "\n")) && (i != 0)) || (i == strlen((char *)buffer))) {
|
if (((!strcmp(temp, "\n")) && (i != 0)) || (i == strlen((char *)buffer))) {
|
||||||
// Config Check
|
// Config Check
|
||||||
if (line == 0) {
|
if (line == 0) { // Grabbing first line for type parsing
|
||||||
logLine = calloc(strlen((char *)checkLine), sizeof(char));
|
logLine = calloc(strlen((char *)checkLine), sizeof(char));
|
||||||
strcpy((char *)logLine, (char *)checkLine);
|
strcpy((char *)logLine, (char *)checkLine);
|
||||||
token = strtok((char *)checkLine, " ");
|
token = strtok((char *)checkLine, " ");
|
||||||
// HTTP Request Type
|
// HTTP Request Type
|
||||||
if ((!strcmp(token, "GET")) || (!strcmp(token, "POST")) ||
|
if ((!strcmp(token, "GET")) || (!strcmp(token, "POST")) ||
|
||||||
(!strcmp(token, "PUT")) || (!strcmp(token, "DELETE"))) {
|
(!strcmp(token, "PUT")) || (!strcmp(token, "DELETE")) ||
|
||||||
|
(!strcmp(token, "CONNECT"))) {
|
||||||
// Grabbing HTTP Request Type
|
// Grabbing HTTP Request Type
|
||||||
r->requestType = malloc(strlen(token));
|
r->requestType = malloc(strlen(token));
|
||||||
strcpy(r->requestType, token);
|
strcpy(r->requestType, token);
|
||||||
@@ -59,27 +65,24 @@ int parseHTTPRequest(unsigned char *buffer, struct HTTPRequest *r) {
|
|||||||
strcpy(r->requestDir, token);
|
strcpy(r->requestDir, token);
|
||||||
// Grabbing HTTP Request Version
|
// Grabbing HTTP Request Version
|
||||||
token = strtok(NULL, "");
|
token = strtok(NULL, "");
|
||||||
|
token[strlen(token) - 1] = '\0'; // Fixing version end char
|
||||||
r->requestVersion = malloc(strlen(token));
|
r->requestVersion = malloc(strlen(token));
|
||||||
strcpy(r->requestVersion, token);
|
strcpy(r->requestVersion, token);
|
||||||
} else {
|
} else { // First line contains unsupported request
|
||||||
char *errMessage = "Unsupported request type: ";
|
|
||||||
logLine = calloc(strlen(errMessage) + strlen(token), sizeof(unsigned char));
|
|
||||||
sprintf((char *)logLine, "%s%s", errMessage, token);
|
|
||||||
PrintLog(logLine);
|
|
||||||
free(logLine);
|
free(logLine);
|
||||||
free(checkLine);
|
free(checkLine);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
// Log Request
|
// Log Request
|
||||||
PrintLog(logLine);
|
PrintLog(logLine);
|
||||||
} else {
|
} else { // Gather information on >first line
|
||||||
if (contentCheck) { // Once content check is set to one everything after is part of the body
|
if (contentCheck) { // Once content check is set to one everything after is part of the body
|
||||||
r->requestBody = realloc(r->requestBody,
|
r->requestBody = realloc(r->requestBody,
|
||||||
(strlen((char *)checkLine) + strlen((char *)r->requestBody) + 1));
|
(strlen((char *)checkLine) + strlen((char *)r->requestBody) + 1));
|
||||||
strcat((char *)r->requestBody, (char *)checkLine);
|
strcat((char *)r->requestBody, (char *)checkLine);
|
||||||
// Adding newline to requestBody
|
// Adding newline to requestBody
|
||||||
sprintf((char *)r->requestBody, "%s\n", r->requestBody);
|
sprintf((char *)r->requestBody, "%s\n", r->requestBody);
|
||||||
} else {
|
} else { // Information parsing !content
|
||||||
if (strlen((char *)checkLine) == 1) { // Looking for blank empty line to end header info
|
if (strlen((char *)checkLine) == 1) { // Looking for blank empty line to end header info
|
||||||
contentCheck = 1;
|
contentCheck = 1;
|
||||||
}
|
}
|
||||||
@@ -127,7 +130,7 @@ int handleGetRequest(int socket, struct HTTPRequest *r, SSL *ssl) {
|
|||||||
} else {
|
} else {
|
||||||
workingReqDir = r->requestDir;
|
workingReqDir = r->requestDir;
|
||||||
}
|
}
|
||||||
char *reqDir = calloc(strlen(WEB_ROOT) + strlen(workingReqDir), sizeof(char));
|
char *reqDir = calloc((strlen(WEB_ROOT) + strlen(workingReqDir) + 1), sizeof(char));
|
||||||
|
|
||||||
sprintf(reqDir, "%s%s", WEB_ROOT, workingReqDir);
|
sprintf(reqDir, "%s%s", WEB_ROOT, workingReqDir);
|
||||||
|
|
||||||
@@ -176,15 +179,48 @@ int handlePUTRequest(int socket, struct HTTPRequest *r, SSL *ssl) {
|
|||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
sprintf(errResponse, "Error opening file: %s", workingReqDir);
|
sprintf(errResponse, "Error opening file: %s", workingReqDir);
|
||||||
printDebug(errResponse);
|
printDebug(errResponse);
|
||||||
return404Request(socket, ssl);
|
return return404Request(socket, ssl);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(fp, "%s", r->requestBody);
|
fprintf(fp, "%s", r->requestBody);
|
||||||
|
|
||||||
free(reqDir);
|
free(reqDir);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return201Request(socket, r->requestBody, ssl);
|
return return201Request(socket, r->requestBody, ssl);
|
||||||
|
}
|
||||||
|
|
||||||
|
int handleDELETERequest(int socket, struct HTTPRequest *r, SSL *ssl) {
|
||||||
|
char *reqDir;
|
||||||
|
char * workingReqDir;
|
||||||
|
char logLine[256];
|
||||||
|
|
||||||
|
if (!strcmp(r->requestDir, "/")) {
|
||||||
|
workingReqDir = "index.html";
|
||||||
|
} else {
|
||||||
|
workingReqDir = r->requestDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
reqDir = calloc(strlen(WEB_ROOT) + strlen(workingReqDir), sizeof(char));
|
||||||
|
sprintf(reqDir, "%s%s", WEB_ROOT, workingReqDir);
|
||||||
|
|
||||||
|
if (remove(reqDir) == 0) {
|
||||||
|
sprintf(logLine, "Deleted file");
|
||||||
|
free(reqDir);
|
||||||
|
return return200Request(socket, NULL, ssl);
|
||||||
|
} else {
|
||||||
|
printDebug("Failed to delete file");
|
||||||
|
free(reqDir);
|
||||||
|
if (errno == 1) { // Permission denided
|
||||||
|
return return403Request(socket, ssl);
|
||||||
|
} else { // Catch all (likely file != exist)
|
||||||
|
return return404Request(socket, ssl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int handlePOSTRequest(int socket, struct HTTPRequest *r, SSL *ssl) {
|
||||||
|
return501Request(socket, ssl);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,25 +232,33 @@ int handleRequest(unsigned char buffer[], int socket, SSL *ssl) {
|
|||||||
checkerr = parseHTTPRequest(buffer, &r);
|
checkerr = parseHTTPRequest(buffer, &r);
|
||||||
if (checkerr != 0) { // Checking for HTTP parsing error
|
if (checkerr != 0) { // Checking for HTTP parsing error
|
||||||
if (checkerr == -1) {
|
if (checkerr == -1) {
|
||||||
printDebug("Error reading request, returning empty 404");
|
printDebug("Error reading request, returning empty 500");
|
||||||
|
return500Request(socket, ssl);
|
||||||
} else {
|
} else {
|
||||||
printDebug("Error parsing, returning 500");
|
printDebug("Error parsing, returning 501");
|
||||||
return return501Request(socket, ssl);
|
return return501Request(socket, ssl);
|
||||||
}
|
}
|
||||||
return return400Request(socket, ssl);
|
} else {
|
||||||
|
checkerr = checkHTTPVersion(r.requestVersion);
|
||||||
|
if (checkerr != 0) {
|
||||||
|
return return505Request(socket, ssl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(r.requestType, "GET")) {
|
if (!strcmp(r.requestType, "GET")) {
|
||||||
handleGetRequest(socket, &r, ssl);
|
handleGetRequest(socket, &r, ssl);
|
||||||
return 0;
|
return 0;
|
||||||
} else if (!strcmp(r.requestType, "POST")) {
|
} else if (!strcmp(r.requestType, "POST")) {
|
||||||
return501Request(socket, ssl);
|
handlePOSTRequest(socket, &r, ssl);
|
||||||
return 0;
|
return 0;
|
||||||
} else if (!strcmp(r.requestType, "PUT")) {
|
} else if (!strcmp(r.requestType, "PUT")) {
|
||||||
handlePUTRequest(socket, &r, ssl);
|
handlePUTRequest(socket, &r, ssl);
|
||||||
return 0;
|
return 0;
|
||||||
} else if (!strcmp(r.requestType, "DELETE")) {
|
} else if (!strcmp(r.requestType, "DELETE")) {
|
||||||
return501Request(socket, ssl);
|
handleDELETERequest(socket, &r, ssl);
|
||||||
|
return 0;
|
||||||
|
} else if (!strcmp(r.requestType, "CONNECT")) {
|
||||||
|
return200Request(socket, NULL, ssl);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return500Request(socket, ssl);
|
return500Request(socket, ssl);
|
||||||
@@ -222,6 +266,10 @@ int handleRequest(unsigned char buffer[], int socket, SSL *ssl) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void timeoutChild(int sig) {
|
||||||
|
timeout = 1;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
struct sockaddr_in address;
|
struct sockaddr_in address;
|
||||||
int server_fd, new_socket;
|
int server_fd, new_socket;
|
||||||
@@ -342,6 +390,16 @@ int main(int argc, char **argv) {
|
|||||||
perror("Accept connection error");
|
perror("Accept connection error");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Forking process
|
||||||
|
pid_t pid;
|
||||||
|
pid = fork();
|
||||||
|
|
||||||
|
if (pid == 0) {
|
||||||
|
pid_t pid2;
|
||||||
|
pid2 = fork();
|
||||||
|
|
||||||
|
if (pid2 == 0) {
|
||||||
bufSize = BUFF_READ;
|
bufSize = BUFF_READ;
|
||||||
if ( enableHTTPS ) {
|
if ( enableHTTPS ) {
|
||||||
size_t buffCont = 1;
|
size_t buffCont = 1;
|
||||||
@@ -375,8 +433,32 @@ int main(int argc, char **argv) {
|
|||||||
handleRequest(buffer, new_socket, NULL);
|
handleRequest(buffer, new_socket, NULL);
|
||||||
buffer = calloc(bufSize, sizeof(unsigned char));
|
buffer = calloc(bufSize, sizeof(unsigned char));
|
||||||
}
|
}
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
} else if (pid2 < 0) {
|
||||||
|
printDebug("Error forking supervisor...");
|
||||||
|
} else {
|
||||||
|
int status;
|
||||||
|
signal(SIGALRM, timeoutChild);
|
||||||
|
alarm(2);
|
||||||
|
pause();
|
||||||
|
if (timeout) {
|
||||||
|
status = waitpid(pid, NULL, WNOHANG);
|
||||||
|
if (status == 0) {
|
||||||
|
printDebug("Killing child");
|
||||||
|
kill(pid2, 9);
|
||||||
|
wait(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
close(new_socket);
|
close(new_socket);
|
||||||
|
} else if (pid < 0) {
|
||||||
|
printDebug("Error forking...");
|
||||||
|
} else {
|
||||||
|
signal(SIGCHLD, SIG_IGN);
|
||||||
|
close(new_socket);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(privKeyFile);
|
free(privKeyFile);
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
int PrintLog(unsigned char *message);
|
int PrintLog(unsigned char *message);
|
||||||
|
int checkHTTPVersion(char *version);
|
||||||
|
|
||||||
|
|||||||
@@ -14,18 +14,24 @@ int returnRequest(int socket, char *message, int status, SSL *ssl) {
|
|||||||
} else {
|
} else {
|
||||||
send(socket, message, strlen(message), 0);
|
send(socket, message, strlen(message), 0);
|
||||||
}
|
}
|
||||||
|
free(message);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int return200Request(int socket, unsigned char *content, SSL *ssl) {
|
int return200Request(int socket, unsigned char *content, SSL *ssl) {
|
||||||
char *message = "";
|
char *message = "";
|
||||||
message = calloc(strlen((char *)content) + 128, sizeof(unsigned char));
|
if (content != NULL) {
|
||||||
|
message = calloc(strlen((char *)content) + 128, sizeof(char));
|
||||||
sprintf(message, "HTTP/1.1 200 OK\nContent-Length: %zu\nConnection: close\n\n%s\n",
|
sprintf(message, "HTTP/1.1 200 OK\nContent-Length: %zu\nConnection: close\n\n%s\n",
|
||||||
strlen((char *)content), content);
|
strlen((char *)content), content);
|
||||||
|
} else { // Sending empty response
|
||||||
|
message = calloc(128, sizeof(char));
|
||||||
|
sprintf(message, "HTTP/1.1 200 OK\nContent-Length: 0\nConnection: close\n\n");
|
||||||
|
}
|
||||||
return returnRequest(socket, message, 200, ssl);
|
return returnRequest(socket, message, 200, ssl);
|
||||||
}
|
}
|
||||||
|
|
||||||
int return201Request(int socket, unsigned char *content, SSL *ssl) {
|
int return201Request(int socket, char *content, SSL *ssl) {
|
||||||
char *message = "";
|
char *message = "";
|
||||||
message = calloc(strlen((char *)content) + 128, sizeof(unsigned char));
|
message = calloc(strlen((char *)content) + 128, sizeof(unsigned char));
|
||||||
sprintf(message, "HTTP/1.1 201 Created\nContent-Length: %zu\nConnection: close\n\n%s\n",
|
sprintf(message, "HTTP/1.1 201 Created\nContent-Length: %zu\nConnection: close\n\n%s\n",
|
||||||
@@ -33,22 +39,38 @@ int return201Request(int socket, unsigned char *content, SSL *ssl) {
|
|||||||
return returnRequest(socket, message, 201, ssl);
|
return returnRequest(socket, message, 201, ssl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int return403Request(int socket, SSL *ssl) {
|
||||||
|
char *message = calloc(128, sizeof(char));
|
||||||
|
sprintf(message, "HTTP/1.1 403 Forbidden\nContent-Length: 0\nConnection: close\n\n");
|
||||||
|
return returnRequest(socket, message, 403, ssl);
|
||||||
|
}
|
||||||
|
|
||||||
int return404Request(int socket, SSL *ssl) {
|
int return404Request(int socket, SSL *ssl) {
|
||||||
char *message = "HTTP/1.1 404 Not Found\nContent-Length: 12\nConnection: close\n\n404 Request\n";
|
char *message = calloc(128, sizeof(char));
|
||||||
|
sprintf(message, "HTTP/1.1 404 Not Found\nContent-Length: 12\nConnection: close\n\n404 Request\n\n");
|
||||||
return returnRequest(socket, message, 404, ssl);
|
return returnRequest(socket, message, 404, ssl);
|
||||||
}
|
}
|
||||||
|
|
||||||
int return400Request(int socket, SSL *ssl) {
|
int return400Request(int socket, SSL *ssl) {
|
||||||
char *message = "HTTP/1.1 400 HTTP Request Not Valid\nContent-Length: 0\nConnection: close\n\n";
|
char *message = calloc(128, sizeof(char));
|
||||||
|
sprintf(message, "HTTP/1.1 400 HTTP Request Not Valid\nContent-Length: 0\nConnection: close\n\n");
|
||||||
return returnRequest(socket, message, 400, ssl);
|
return returnRequest(socket, message, 400, ssl);
|
||||||
}
|
}
|
||||||
|
|
||||||
int return500Request(int socket, SSL *ssl) {
|
int return500Request(int socket, SSL *ssl) {
|
||||||
char *message = "HTTP/1.1 500 Internal Server Error\nContent-Length: 0\nConnection: close\n\n";
|
char *message = calloc(128, sizeof(char));
|
||||||
|
sprintf(message, "HTTP/1.1 500 Internal Server Error\nContent-Length: 0\nConnection: close\n\n");
|
||||||
return returnRequest(socket, message, 500, ssl);
|
return returnRequest(socket, message, 500, ssl);
|
||||||
}
|
}
|
||||||
|
|
||||||
int return501Request(int socket, SSL *ssl) {
|
int return501Request(int socket, SSL *ssl) {
|
||||||
char *message = "HTTP/1.1 501 Not Implemented\nContent-Length: 0\nConnection: close\n\n";
|
char *message = calloc(128, sizeof(char));
|
||||||
|
sprintf(message, "HTTP/1.1 501 Not Implemented\nContent-Length: 0\nConnection: close\n\n");
|
||||||
return returnRequest(socket, message, 501, ssl);
|
return returnRequest(socket, message, 501, ssl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int return505Request(int socket, SSL *ssl) {
|
||||||
|
char *message = calloc(128, sizeof(char));
|
||||||
|
sprintf(message, "HTTP/1.1 505 HTTP Version Not Supported\nContent-Length: 0\nConnection: close\n\n");
|
||||||
|
return returnRequest(socket, message, 505, ssl);
|
||||||
|
}
|
||||||
|
|||||||
20
src/utils.c
20
src/utils.c
@@ -1,5 +1,12 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define NUM_SUPPORTED_VERSIONS 2
|
||||||
|
static char supportedHTTPVersions[NUM_SUPPORTED_VERSIONS][16] = {
|
||||||
|
"HTTP/1.1",
|
||||||
|
"HTTP/1.0"
|
||||||
|
};
|
||||||
|
|
||||||
int PrintLog(unsigned char *message) {
|
int PrintLog(unsigned char *message) {
|
||||||
time_t UTCTime;
|
time_t UTCTime;
|
||||||
@@ -11,3 +18,16 @@ int PrintLog(unsigned char *message) {
|
|||||||
(now->tm_year + 1900), now->tm_hour, now->tm_min, now->tm_sec, message);
|
(now->tm_year + 1900), now->tm_hour, now->tm_min, now->tm_sec, message);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return supported;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user