ithewei 6 년 전
부모
커밋
47abbb8e1f
5개의 변경된 파일38개의 추가작업 그리고 19개의 파일을 삭제
  1. 7 8
      Makefile
  2. 0 5
      base/hplatform.h
  3. 11 2
      base/hstring.h
  4. 9 0
      base/htime.c
  5. 11 4
      http/http_content.cpp

+ 7 - 8
Makefile

@@ -6,7 +6,7 @@ default: all
 all: test client server httpd webbench
 
 clean:
-	$(MAKEF) clean SRCDIRS=". base utils event http $(TMPDIR)"
+	$(MAKEF) clean SRCDIRS=". base utils event http http/client http/server examples $(TMPDIR)"
 
 prepare:
 	-mkdir -p $(TMPDIR)
@@ -34,13 +34,12 @@ httpd: prepare
 	$(MAKEF) TARGET=$@ SRCDIRS=". base utils event http http/server $(TMPDIR)"
 
 webbench: prepare
-	-rm $(TMPDIR)/*.o $(TMPDIR)/*.c $(TMPDIR)/*.cpp
-	cp examples/webbench.c $(TMPDIR)/webbench.c
-	$(MAKEF) TARGET=$@ SRCS="$(TMPDIR)/webbench.c"
+	$(MAKEF) TARGET=$@ SRCS="examples/webbench.c"
 
-curl: prepare
-	-rm $(TMPDIR)/*.o $(TMPDIR)/*.c $(TMPDIR)/*.cpp
-	cp examples/curl.cpp $(TMPDIR)/curl.cpp
-	$(MAKEF) TARGET=$@ SRCDIRS=". base utils event http http/client $(TMPDIR)" LIBS="curl"
+# curl
+INCDIRS:=". base utils http http/client"
+SRCS:="examples/curl.cpp http/client/http_client.cpp http/http_parser.c http/multipart_parser.c http/http_content.cpp base/hstring.cpp"
+curl:
+	$(MAKEF) TARGET=$@ INCDIRS=$(INCDIRS) SRCS=$(SRCS) DEFINES="CURL_STATICLIB" LIBS="curl"
 
 .PHONY: clean prepare test client server curl httpd webbench

+ 0 - 5
base/hplatform.h

@@ -99,8 +99,6 @@
     #include <direct.h>     // for mkdir,rmdir,chdir,getcwd
     #include <io.h>         // for open,close,read,write,lseek,tell
 
-    #define strcasecmp stricmp
-    #define strncasecmp strnicmp
     #define MKDIR(dir) mkdir(dir)
 #else
     #include <unistd.h>
@@ -117,9 +115,6 @@
     #include <fcntl.h>
     #include <netdb.h>  // for gethostbyname
 
-    #include <strings.h>
-    #define stricmp     strcasecmp
-    #define strnicmp    strncasecmp
     #define MKDIR(dir) mkdir(dir, 0777)
 #endif
 

+ 11 - 2
base/hstring.h

@@ -1,15 +1,24 @@
 #ifndef HW_STRING_H_
 #define HW_STRING_H_
 
+#include <string.h>
+#ifdef _MSC_VER
+    #define strcasecmp stricmp
+    #define strncasecmp strnicmp
+#else
+    #include <strings.h>
+    #define stricmp     strcasecmp
+    #define strnicmp    strncasecmp
+#endif
+
 #include <string>
 #include <vector>
 using std::string;
+typedef std::vector<string> StringList;
 
 #define SPACE_CHARS     " \t\r\n"
 #define PAIR_CHARS      "{}[]()<>\"\"\'\'``"
 
-typedef std::vector<string> StringList;
-
 char* strupper(char* str);
 char* strlower(char* str);
 

+ 9 - 0
base/htime.c

@@ -56,6 +56,15 @@ datetime_t get_datetime() {
 static const char* s_month[] = {"January", "February", "March", "April", "May", "June",
     "July", "August", "September", "October", "November", "December"};
 
+#include <string.h>
+#ifdef _MSC_VER
+    #define strcasecmp stricmp
+    #define strncasecmp strnicmp
+#else
+    #include <strings.h>
+    #define stricmp     strcasecmp
+    #define strnicmp    strncasecmp
+#endif
 int month_atoi(const char* month) {
     for (size_t i = 0; i < 12; ++i) {
         if (strnicmp(month, s_month[i], strlen(month)) == 0)

+ 11 - 4
http/http_content.cpp

@@ -1,6 +1,8 @@
 #include "http_content.h"
 
-#include "hfile.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+
 #include "hstring.h"
 
 #ifndef LOWER
@@ -168,9 +170,14 @@ std::string dump_multipart(MultiPart& mp, const char* boundary) {
         auto& form = pair.second;
         if (form.filename.size() != 0) {
             if (form.content.size() == 0) {
-                HFile file;
-                if (file.open(form.filename.c_str(), "r") == 0) {
-                    file.readall(form.content);
+                FILE* fp = fopen(form.filename.c_str(), "r");
+                if (fp) {
+                    struct stat st;
+                    if (stat(form.filename.c_str(), &st) == 0 && st.st_size != 0) {
+                        form.content.resize(st.st_size);
+                        fread((void*)form.content.data(), 1, st.st_size, fp);
+                    }
+                    fclose(fp);
                 }
             }
             snprintf(c_str, sizeof(c_str), "; filename=\"%s\"", basename(form.filename).c_str());