further php support
This commit is contained in:
@@ -22,7 +22,7 @@ int return200Request(int socket, unsigned char *content, SSL *ssl) {
|
||||
char *message = "";
|
||||
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",
|
||||
strlen((char *)content), content);
|
||||
} else { // Sending empty response
|
||||
message = calloc(128, sizeof(char));
|
||||
@@ -65,7 +65,7 @@ int return411Request(int socket, SSL *ssl) {
|
||||
|
||||
int return418Request(int socket, SSL *ssl) {
|
||||
char *message=calloc(128, sizeof(char));
|
||||
sprintf(message, "HTTP/1.1 418 I'm a teapotnContent-Length: 0\nConnection: close\n\n");
|
||||
sprintf(message, "HTTP/1.1 418 I'm a teapot\nContent-Length: 0\nConnection: close\n\n");
|
||||
return returnRequest(socket, message, 418, ssl);
|
||||
}
|
||||
|
||||
@@ -86,3 +86,34 @@ int return505Request(int socket, SSL *ssl) {
|
||||
sprintf(message, "HTTP/1.1 505 HTTP Version Not Supported\nContent-Length: 0\nConnection: close\n\n");
|
||||
return returnRequest(socket, message, 505, ssl);
|
||||
}
|
||||
|
||||
int returnPHPRequest(int socket, char *content, SSL *ssl) {
|
||||
char *message = malloc(1024);
|
||||
memset(message, 0, 1024);
|
||||
char *line = malloc(1024);
|
||||
memset(line, 0, 1024);
|
||||
char temp[1];
|
||||
size_t lineNum = 0;
|
||||
for (int i = 0; i <= strlen(content); i++) {
|
||||
temp[0] = content[i];
|
||||
if (((!strcmp(temp, "\n")) && (i != 0)) || (i == strlen(content))) {
|
||||
if (lineNum != 0) {
|
||||
strcat(message, line);
|
||||
strcat(message, "\n");
|
||||
}
|
||||
if (strlen(line) > 0) {
|
||||
memset(line, 0, strlen(line));
|
||||
}
|
||||
lineNum++;
|
||||
} else {
|
||||
strcat(line, temp);
|
||||
}
|
||||
}
|
||||
|
||||
free(line);
|
||||
if (strlen(message) == 0) { // Return 500 on error parsing
|
||||
free(message);
|
||||
return return500Request(socket, ssl);
|
||||
}
|
||||
return return200Request(socket, (unsigned char *)message, ssl);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user