assorted attempted fixes of things

master
Drake 2 years ago
parent 4d323d55cd
commit 64c38adca5

Binary file not shown.

@ -57,7 +57,6 @@ void* readFileBin(int* len, char* path) {
stat(path, &st); stat(path, &st);
int length = st.st_size; int length = st.st_size;
*len = length; *len = length;
printf("%d\n", length);
buf = (void*)malloc(sizeof(int) * (length + 1)); buf = (void*)malloc(sizeof(int) * (length + 1));
fread(buf, sizeof(int), length, fp); fread(buf, sizeof(int), length, fp);

@ -21,10 +21,11 @@ ReqHeader readReqHeader(int client) {
ReqHeader header; ReqHeader header;
header.method = malloc(1024); header.method = malloc(1024);
header.path = malloc(1024); header.path = malloc(1024);
char* tBuf = malloc(1024);
/*strcpy(header.method, strtok(buf, " ")); /*strcpy(header.method, strtok(buf, " "));
strcpy(header.path, strtok(NULL, " "));*/ strcpy(header.path, strtok(NULL, " "));*/
sprintf(header.method, "%s", strtok(buf, " ")); sprintf(header.method, "%s", strtok_r(buf, " ", &tBuf));
sprintf(header.path, "%s", strtok(NULL, " ")); sprintf(header.path, "%s", strtok_r(NULL, " ", &tBuf));
if (header.path[1] == '\0') { if (header.path[1] == '\0') {
//strcpy(header.path, "/index.html"); //strcpy(header.path, "/index.html");
sprintf(header.path, "/index.html"); sprintf(header.path, "/index.html");

@ -37,8 +37,8 @@ void *handle(void* arg) {
rawHeader.protocol = request.protocol; rawHeader.protocol = request.protocol;
rawHeader.status = 200; rawHeader.status = 200;
rawHeader.notice = "OK"; rawHeader.notice = "OK";
int useBinary = getMime(&rawHeader.mime, request.path);
int useBinary = getMime(&rawHeader.mime, request.path);
if (errno == -1) { if (errno == -1) {
rawHeader.status = 404; rawHeader.status = 404;
rawHeader.notice = "Not Found"; rawHeader.notice = "Not Found";
@ -62,9 +62,6 @@ void *handle(void* arg) {
file = readFileBin(&len, request.path); file = readFileBin(&len, request.path);
send(client, file, len, 0); send(client, file, len, 0);
} }
//char* resHeader = malloc(strlen(tmpHeader) + strlen(file) + 1); //= "HTTP/1.1 200 OK\r\n\nHello, world!";
//sprintf(resHeader, "%s%s", (char*)tmpHeader, file);
//send(client, resHeader, strlen(resHeader), 0);
close(client); close(client);
return 0; return 0;
} }

Loading…
Cancel
Save