When I load a page from my webserver all I get is a blank page if it's HTTP or a tiny white box with a black outline instead of the contents of the pages. What functions should I look at to solve this? I also get error 500 when requesting PHP files and error 501 when requesting favicon.ico.
Lookup:
const char* lookup(const char* path)
{
bool tFound = false;
char* fType = malloc(sizeof(char));
int fIncriment = 0;
if(path == NULL)
{
return NULL;
}
for(int i = 0; i<strlen(path);i++)
{
if (path[i] == '.')
{
tFound = true;
}
if(tFound == true)
{
fType[fIncriment] = path[i];
fIncriment++;
}
}
if(strcasecmp(fType,".css") == 0)
{
free(fType);
return "text/css";
}
else if(strcasecmp(fType,".html") == 0)
{
free(fType);
return "text/html";
}
else if(strcasecmp(fType,".gif") == 0)
{
free(fType);
return "text/css";
}
else if(strcasecmp(fType,".css") == 0)
{
free(fType);
return "x-icon/ico";
}
else if(strcasecmp(fType,".jpg") == 0)
{
free(fType);
return "image/jpeg";
}
else if(strcasecmp(fType,".js") == 0)
{
free(fType);
return "text/javascript";
}
else if(strcasecmp(fType,".php") == 0)
{
free(fType);
return "text/x-php";
}
else if(strcasecmp(fType,".png") == 0)
{
free(fType);
return "image/png";
}
free(fType);
return NULL;
}
Parse:
bool parse(const char* line, char* abs_path, char* query)
{
char* lnCopy = strdup(line); // creates a copy of a non constant version of the line
char* method = strtok(lnCopy," "); // gets the first part of the line
char* request_target = strtok(NULL, " "); // second part
char* version = strtok(NULL,"\r"); // third part
if(strcasecmp(version,"HTTP/1.1") != 0) // checks to make sure its the right HTTP version
{
error(505);
return false;
}
if(strcmp(method,"GET") != 0)
{
error(405);
return false;
}
for(int i = 0; i< strlen(request_target); i++)
{
if(request_target[i] == 34)
{
error(400);
return false;
}
}
if(request_target[0] != '/')
{
error(501);
return false;
}
bool qCheck = false;
for(int i =0; i< strlen(request_target);i++)
{
if(qCheck == false)
{
abs_path[i]=request_target[i];
if(strcmp(&request_target[i],"?") == 0)
{
abs_path[i] = '\0';
qCheck = true;
}
}
else if(qCheck == true)
{
if(strcmp(&request_target[i],"?") != 0)
{
query[i] = request_target[i];
}
}
}
if(qCheck == false)
{
abs_path[strlen(request_target)] = '\0';
query[0] = '\0';
}
else if(qCheck == true)
{
abs_path[strlen(request_target)-strlen(query)] = '\0';
query[strlen(query)] = '\0';
}
return true;
}
Load:
bool load(FILE* file, BYTE** content, size_t* length)
{
if(file == NULL)
{
error(404);
return false;
}
BYTE *storage = malloc(sizeof(BYTES));
fread(storage,sizeof(storage),1,file);
*length = BYTES;
*content = &storage[0];
return true;
}
Indexes:
char* indexes(const char* path)
{
FILE *filetest;
FILE *filetestTheSequal;
char* index = malloc(sizeof(char*));
if (path == NULL)
{
return NULL;
}
filetest = fopen("index.php","r");
filetestTheSequal = fopen("index.html","r");
if(filetest == NULL && filetestTheSequal ==NULL)
{
return NULL;
}
else if(filetest != NULL && filetestTheSequal == NULL)
{
fclose(filetest);
fclose(filetestTheSequal);
return index = "/path/to/a/directory/index.php";
}
else if(filetestTheSequal != NULL && filetest == NULL)
{
fclose(filetest);
fclose(filetestTheSequal);
return index = "/path/to/a/directory/index.html";
}
free(index);
fclose(filetest);
fclose(filetestTheSequal);
return NULL;
}
Full Code: http://pastebin.com/3e319PEB