When i run my code i get a error proxy could not be processed request. During check50 2 everything is red with no reason as to why, I am thinking its a seg fault but valgrind didn't give one. Honestly, no idea where the issue is so any help would be greatly appreciated.
Lookup:
const char* lookup(const char* path)
{
char* ext = strchr(path, '.');
if (strcasecmp(ext, ".css") == 0)
{
return "text/css";
}
else if (strcasecmp(ext, ".html") == 0)
{
return "text/html";
}
else if (strcasecmp(ext, ".gif") == 0)
{
return "image/gif";
}
else if (strcasecmp(ext, ".ico") == 0)
{
return "image/x-icon";
}
else if (strcasecmp(ext, ".jpg") == 0)
{
return "image/jpeg";
}
else if (strcasecmp(ext, ".js") == 0)
{
return "text/javascript";
}
else if (strcasecmp(ext, ".php") == 0)
{
return "text/x-php";
}
else if (strcasecmp(ext, ".png") == 0)
{
return "image/png";
}
else
{
return NULL;
}
}
Parse:
bool parse(const char* line, char* abs_path, char* query)
{
if (strncmp(line, "GET ", 4) != 0)
{
error(405);
return false;
}
if (strncmp(line, "GET /", 5) !=0)
{
error(501);
return false;
}
char* request = strchr(line, '/');
char* httptype = strchr(request, ' ');
char buffer[strlen(request)+1];
strcpy(buffer, request);
char* abscopy = strtok(buffer, " ");
if (abscopy[0] != '/')
{
error(501);
return false;
}
if (strchr(abscopy, '"') != NULL)
{
error(400);
return false;
}
if (strchr(abscopy, ' ') != NULL)
{
error(400);
return false;
}
if (strchr(abscopy, '?') != NULL)
{
char* absbuffer = malloc(sizeof(abscopy+1));
strcpy(absbuffer, abscopy);
char* absnew = strtok(absbuffer, "?");
strcpy(abs_path, absnew);
}
if (strchr(abscopy, '?') == NULL)
{
strcpy(abs_path, abscopy);
}
if ((strstr(httptype, " ")) != NULL)
{
error(400);
return false;
}
if ((strstr(httptype, "HTTP/1.1")) == NULL)
{
error(505);
return false;
}
char q[] = "q=";
if (strstr(abscopy, q) == NULL)
{
query = "";
}
else
{
query = strstr(abscopy,q);
}
return false;
}
Load:
bool load(FILE* file, BYTE** content, size_t* length)
{
if (file == NULL)
{
return false;
}
*content = NULL;
*length = 0;
char* buffer = malloc(sizeof(char));
int counter = 0;
BYTE x = 1;
for (int i = fgetc(file); i != EOF; i = fgetc(file))
{
buffer[counter] = (char) i;
counter++;
if (sizeof(buffer) <= (sizeof(x) * counter))
{
buffer = realloc(buffer, sizeof(buffer) * 2);
}
}
*content = buffer;
*length = counter;
return true;
}
Indexes:
char* indexes(const char* path)
{
int x = strlen(path);
char php_index[] = "/index.php";
char html_index[] = "/index.html";
char* php_path = malloc(x + strlen(php_index)+ 1);
char* html_path = malloc(x + strlen(html_index) + 1);
strcpy(php_path, path);
strcpy(html_path, path);
strcat(php_path, php_index);
strcat(html_path, html_index);
if (access(php_path, F_OK) == 0)
{
return php_path;
}
if (access(html_path, F_OK) == 0)
{
return html_path;
}
else
{
return NULL;
}
free(php_path);
free(html_path);
}