Created
June 2, 2015 12:38
-
-
Save ajpen/101d51543f2ad14edf08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// extract query from request-target | |
const char* temp = qextract(line); | |
int len = strlen(temp); | |
char query[len+1]; | |
// make a usable copy of query | |
strncpy(query, temp,len+1); | |
// concatenate root and absolute-path | |
const char* abpath = textract(line, 1); | |
int len2 = strlen(abpath); | |
char acopy[len2+1]; | |
strncpy(acopy,abpath,len2+1); | |
len = strlen(root); | |
char path[len+len2+1]; | |
strncpy(path, root,len+1); | |
strncat(path, acopy, len2); | |
// ensure path exists | |
if (access(path, F_OK) != 0) | |
error(404); | |
// TODO: ensure path is readable | |
if (access(path, X_OK) != 0) | |
error(404); | |
// TODO: extract path's extension | |
char* ext = strtok(acopy, "."); | |
ext = strtok(NULL,"."); | |
if (ext == NULL) | |
printf("Error with extracting extension at strtok"); | |
len = strlen(ext); | |
char extension[len+1]; | |
strncpy(extension,ext,len+1); | |
extension[len] = '\0'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment