Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const char* lookup(const char* path)
- {
- // char pointer to find dot
- char* dot_ptr;
- // array to store file type extension
- char ext[6];
- int i = 0;
- dot_ptr = strrchr(path,'.');
- do
- {
- ext[i] = *dot_ptr;
- i++;
- dot_ptr++;
- }while(*dot_ptr != '\0');
- ext[i] = '\0';
- if(strcasecmp(".css", ext) == 0)
- return "text/css";
- else if(strcasecmp(".html", ext) == 0)
- return "text/html";
- else if(strcasecmp(".gif", ext) == 0)
- return "image/gif";
- else if(strcasecmp(".ico", ext) == 0)
- return "image/x-icon";
- else if(strcasecmp(".jpg", ext) == 0)
- return "image/jpeg";
- else if(strcasecmp(".js", ext) == 0)
- return "text/javascript";
- else if(strcasecmp(".php", ext) == 0)
- return "text/x-php";
- else if(strcasecmp(".png", ext) == 0)
- return "image/png";
- else
- return NULL;
- }
- bool load(FILE* file, BYTE** content, size_t* length)
- {
- int counter = 0;
- BYTE* ptr;
- ptr = (BYTE *)malloc(sizeof(BYTE));
- while(fread(ptr, sizeof(BYTE), 1, file) == 1)
- {
- counter++;
- ptr = (BYTE *)realloc(ptr,sizeof(BYTE)*(counter + 1));
- }
- *content = ptr;
- *length = counter;
- return true;
- }
- char* indexes(const char* path)
- {
- int res_p; // store access return integer
- int res_h;
- char* php = NULL;
- char* html= NULL;
- strcpy(php, path);
- strcat(php, "index.php");
- const char* php_c =(const char*)php;
- strcpy(html, path);
- strcat(html, "index.html");
- const char* html_c =(const char*)html;
- char* path_p = malloc(strlen(path) + 1 + 9);
- strcpy(path_p, path);
- strcat(path_p, "index.php");
- char* path_h = malloc(strlen(path) + 1 + 10);
- strcpy(path_h, path);
- strcat(path_h, "index.html");
- res_p = access(php_c, F_OK);
- res_h = access(html_c, F_OK);
- if (res_p == 0)
- return path_p;
- else
- {
- if (res_h == 0)
- return path_h;
- else
- return NULL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement