char* indexes(const char* path)
{
char* html = "index.html";
char* php = "index.php";
char* index = malloc(strlen(path) + strlen(html) + 1);
strcpy(index,path);
strcat(index,php);
if(access(index,R_OK) != -1){
return index;
}
strcpy(index,path);
strcat(index,html);
if(access(index,R_OK) != -1){
return index;
}
else{
return NULL;
}
}
Here's my snippet of parse funcion
//storing the query
if(strchr(line,63) != 0){ //63 is the ascii value of ?
temp = (strchr(line,'?') + 1);
strcpy(query,temp);
query[strlen(query)-strlen(http_ver) - 3] = '\0';
}
else{
strcpy(query,"");
}
//request method
// char request[80];
// char absolute[80];
temp = strchr(line,47);
char* request = malloc(sizeof(temp));
char* absolute = malloc(sizeof(temp));
strcpy(request,temp);
request[strlen(request)-strlen(http_ver) - 3] = '\0';
if(strcmp(query,"") == 0){
strcpy(absolute,temp);
absolute[strlen(absolute)-strlen(http_ver) - 3] = '\0';
}
else{
strcpy(absolute,request);
absolute[strlen(absolute)-strlen(query)-1] = '\0';
}
strcpy(abs_path,absolute);
// char* query_ex = malloc(sizeof(query));
if(query == 0 || (strcmp(query,"?") == 0)){
strcpy(query,"");
}
return true;