summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/dir/dir.c72
-rwxr-xr-xsrc/dir/dir.h36
-rwxr-xr-xsrc/net/net.c11
-rwxr-xr-xsrc/net/net.h4
4 files changed, 7 insertions, 116 deletions
diff --git a/src/dir/dir.c b/src/dir/dir.c
deleted file mode 100755
index 18ef4f4..0000000
--- a/src/dir/dir.c
+++ /dev/null
@@ -1,72 +0,0 @@
-#include "dir.h"
-
-
-uint64_t get_fd_size(int fd){
- struct stat st;
- if(fstat(fd, &st) == 0){
- return st.st_size;
- }
- return 0;
-}
-
-uint64_t get_fp_size(FILE *fp){
- if(fp != NULL){
- return get_fd_size(fileno(fp));
- }
- return 0;
-}
-
-uint64_t get_file_size(char *filename){
- struct stat st;
- if(stat(filename, &st) == 0){
- return st.st_size;
- }
- return 0;
-}
-
-str get_file_format(str filename){
- int i = 0;
- while(filename.len-i > 0){
- if(filename.ptr[filename.len-i-1] == '.') break;
- i++;
- }
- if(i == 0 || i == filename.len){
- return ((str){0});
- }
- str fmt;
- fmt.len = i;
- fmt.ptr = calloc(fmt.len+1, sizeof(char));
- if(fmt.ptr == NULL) return ((str){0});
- memcpy(fmt.ptr, filename.ptr+filename.len-i, fmt.len);
- return fmt;
-}
-
-uint64_t getNEntries(const char *dir){
- uint64_t r = 0;
- DIR *d = opendir(dir);
- if(d){
- seekdir(d, (unsigned)-1);
- r = telldir(d) - 2; // . and ..
- closedir(d);
- }
- return r;
-}
-
-char **getFiles(const char *dir){
- /*int i = 0, n = getNEntries(dir);
- if(n > 0){
- char **r = calloc(n, sizeof(char*));
- DIR *d = opendir(dir);
- readdir(d); readdir(d); // . and ..
- struct dirent *t;
- while((t = readdir(d)) != NULL){
- int l = len(t->d_name);
- r[i] = calloc(l+1, sizeof(char));
- memmove(r[i++], t->d_name, l);
- }
- closedir(d);
- return r;
- }*/
- return NULL;
-}
-
diff --git a/src/dir/dir.h b/src/dir/dir.h
deleted file mode 100755
index 8dd0b0e..0000000
--- a/src/dir/dir.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef DIR_H
-#define DIR_H
-
-#ifndef _LARGEFILE_SOURCE
-#define _LARGEFILE_SOURCE
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <string.h>
-#include <inttypes.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include "str/str.h"
-
-
-struct file {
- str name;
- bool temp;
-};
-
-
-uint64_t get_fd_size(int fd);
-
-uint64_t get_fp_size(FILE *fp);
-
-uint64_t get_file_size(char *filename);
-
-str get_file_format(str filename);
-
-uint64_t getNEntries(const char *dir);
-
-char **getFiles(const char *dir);
-
-#endif
diff --git a/src/net/net.c b/src/net/net.c
index 91014e7..e7c5981 100755
--- a/src/net/net.c
+++ b/src/net/net.c
@@ -282,8 +282,8 @@ int receive_request(http_worker *hw, str *request){
return 0;
}
-struct file generate_resource(struct uri resource, str url){
- struct file file = {0};
+str generate_resource(struct uri resource, str url){
+ str file = {0};
/*
generate if all of these are true
1) no file specified (aka we need index.html)
@@ -309,7 +309,7 @@ struct file generate_resource(struct uri resource, str url){
free_str(&command);
}
free_str(&phpfile);
- file.name = dup_str(resource.path);
+ file = dup_str(resource.path);
/*
if(uri.query.len > 0){
if(access(uri.path.ptr, F_OK) != 0){
@@ -598,7 +598,7 @@ void send_file(http_worker *hw, str filename){
log_info("sending '%.*s'", filename.len, filename.ptr);
enum mime_type type = TXT;
- str fmt = get_file_format(filename);
+ str fmt = dstr(get_extension(filename.ptr));
for(int i = 0; i < sizeof(mime_types)/sizeof(mime_types[0]); i++){
if(strncmp(fmt.ptr, mime_types[i].fmt.ptr, fmt.len) == 0){
type = i;
@@ -641,8 +641,7 @@ void send_file(http_worker *hw, str filename){
// sendfile(socket, fd, NULL, fsize);
// we're ignoring MAX_BODY_SIZE
- str fuckcygwinineedsendfile;
- fd_to_str(&fuckcygwinineedsendfile, fd, fsize);
+ str fuckcygwinineedsendfile = fd_to_nstr(fd, fsize);
sent = worker_write(hw, fuckcygwinineedsendfile);
free_str(&fuckcygwinineedsendfile);
diff --git a/src/net/net.h b/src/net/net.h
index 55ffe44..79886df 100755
--- a/src/net/net.h
+++ b/src/net/net.h
@@ -17,7 +17,7 @@
#include <time.h>
#include "str/str.h"
#include "list/list.h"
-#include "dir/dir.h"
+#include "files/files.h"
#include "log/log.h"
#include <openssl/ssl.h>
#include <openssl/err.h>
@@ -115,7 +115,7 @@ int accept_connection(http_worker *hw, char ip[INET_ADDRSTRLEN]);
int receive_request(http_worker *hw, str *request);
-struct file generate_resource(struct uri resource, str url);
+str generate_resource(struct uri resource, str url);
char *handlePOST(char *request);