diff --git a/bin/httpsrv b/bin/httpsrv index 606e68f..0261de7 100755 Binary files a/bin/httpsrv and b/bin/httpsrv differ diff --git a/lib/file.h b/lib/file.h index e8beffd..690aae7 100644 --- a/lib/file.h +++ b/lib/file.h @@ -57,7 +57,6 @@ void* readFileBin(int* len, char* path) { stat(path, &st); int length = st.st_size; *len = length; - printf("%d\n", length); buf = (void*)malloc(sizeof(int) * (length + 1)); fread(buf, sizeof(int), length, fp); diff --git a/lib/reqHeader.h b/lib/reqHeader.h index 0ffecfb..c9d0ead 100644 --- a/lib/reqHeader.h +++ b/lib/reqHeader.h @@ -21,10 +21,11 @@ ReqHeader readReqHeader(int client) { ReqHeader header; header.method = malloc(1024); header.path = malloc(1024); + char* tBuf = malloc(1024); /*strcpy(header.method, strtok(buf, " ")); strcpy(header.path, strtok(NULL, " "));*/ - sprintf(header.method, "%s", strtok(buf, " ")); - sprintf(header.path, "%s", strtok(NULL, " ")); + sprintf(header.method, "%s", strtok_r(buf, " ", &tBuf)); + sprintf(header.path, "%s", strtok_r(NULL, " ", &tBuf)); if (header.path[1] == '\0') { //strcpy(header.path, "/index.html"); sprintf(header.path, "/index.html"); diff --git a/src/srv.c b/src/srv.c index 0a57a1b..a4f2fbe 100644 --- a/src/srv.c +++ b/src/srv.c @@ -37,8 +37,8 @@ void *handle(void* arg) { rawHeader.protocol = request.protocol; rawHeader.status = 200; rawHeader.notice = "OK"; - int useBinary = getMime(&rawHeader.mime, request.path); + int useBinary = getMime(&rawHeader.mime, request.path); if (errno == -1) { rawHeader.status = 404; rawHeader.notice = "Not Found"; @@ -62,9 +62,6 @@ void *handle(void* arg) { file = readFileBin(&len, request.path); 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); return 0; }