hewei.it 5 years ago
parent
commit
490f47f63b
5 changed files with 88 additions and 89 deletions
  1. 1 2
      http/server/FileCache.h
  2. 0 1
      http/server/HttpService.h
  3. 1 1
      protocol/icmp.h
  4. 81 4
      utils/iniparser.cpp
  5. 5 81
      utils/iniparser.h

+ 1 - 2
http/server/FileCache.h

@@ -3,11 +3,10 @@
 
 #include <map>
 #include <string>
+#include <mutex>
 
 #include "hbuf.h"
-#include "hfile.h"
 #include "hstring.h"
-#include "hmutex.h"
 
 #define HTTP_HEADER_MAX_LENGTH      1024 // 1k
 

+ 0 - 1
http/server/HttpService.h

@@ -1,7 +1,6 @@
 #ifndef HTTP_SERVICE_H_
 #define HTTP_SERVICE_H_
 
-#include <string.h>
 #include <string>
 #include <map>
 #include <list>

+ 1 - 1
protocol/icmp.h

@@ -8,7 +8,7 @@ BEGIN_EXTERN_C
 // @param cnt: ping count
 // @return: ok count
 // @note: printd $CC -DPRINT_DEBUG
-int ping(const char* host, int cnt DEFAULT(4));
+HV_EXPORT int ping(const char* host, int cnt DEFAULT(4));
 
 END_EXTERN_C
 

+ 81 - 4
utils/iniparser.cpp

@@ -1,16 +1,93 @@
 #include "iniparser.h"
 
+#include <list>
+#include <sstream>
+
 #include "hdef.h"
 #include "herr.h"
 #include "hstring.h"
 #include "hfile.h"
 #include "hbase.h"
 
-#include <sstream>
+/**********************************
+# div
+
+[section]
+
+key = value # span
+
+# div
+***********************************/
+
+class IniNode {
+public:
+    enum Type {
+        INI_NODE_TYPE_UNKNOWN,
+        INI_NODE_TYPE_ROOT,
+        INI_NODE_TYPE_SECTION,
+        INI_NODE_TYPE_KEY_VALUE,
+        INI_NODE_TYPE_DIV,
+        INI_NODE_TYPE_SPAN,
+    } type;
+    string  label; // section|key|comment
+    string  value;
+    std::list<IniNode*>    children;
+
+    virtual ~IniNode() {
+        for (auto pNode : children) {
+            if (pNode) {
+                delete pNode;
+            }
+        }
+        children.clear();
+    }
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+    void Add(IniNode* pNode) {
+        children.push_back(pNode);
+    }
+
+    void Del(IniNode* pNode) {
+        for (auto iter = children.begin(); iter != children.end(); ++iter) {
+            if ((*iter) == pNode) {
+                delete (*iter);
+                children.erase(iter);
+                return;
+            }
+        }
+    }
+
+    IniNode* Get(const string& label, Type type = INI_NODE_TYPE_KEY_VALUE) {
+        for (auto pNode : children) {
+            if (pNode->type == type && pNode->label == label) {
+                return pNode;
+            }
+        }
+        return NULL;
+    }
+};
+
+class IniSection : public IniNode {
+public:
+    IniSection() : IniNode(), section(label) {
+        type = INI_NODE_TYPE_SECTION;
+    }
+    string &section;
+};
+
+class IniKeyValue : public IniNode {
+public:
+    IniKeyValue() : IniNode(), key(label) {
+        type = INI_NODE_TYPE_KEY_VALUE;
+    }
+    string &key;
+};
+
+class IniComment : public IniNode {
+public:
+    IniComment() : IniNode(), comment(label) {
+    }
+    string &comment;
+};
 
 IniParser::IniParser() {
     _comment = DEFAULT_INI_COMMENT;

+ 5 - 81
utils/iniparser.h

@@ -1,7 +1,6 @@
 #ifndef HV_INI_PARSER_H_
 #define HV_INI_PARSER_H_
 
-#include <list>
 #include <string>
 using std::string;
 
@@ -10,85 +9,8 @@ using std::string;
 #define DEFAULT_INI_COMMENT "#"
 #define DEFAULT_INI_DELIM   "="
 
-/**********************************
-# div
-
-[section]
-
-key = value # span
-
-# div
-***********************************/
-
-class HV_EXPORT IniNode {
-public:
-    enum Type {
-        INI_NODE_TYPE_UNKNOWN,
-        INI_NODE_TYPE_ROOT,
-        INI_NODE_TYPE_SECTION,
-        INI_NODE_TYPE_KEY_VALUE,
-        INI_NODE_TYPE_DIV,
-        INI_NODE_TYPE_SPAN,
-    } type;
-    string  label; // section|key|comment
-    string  value;
-    std::list<IniNode*>    children;
-
-    virtual ~IniNode() {
-        for (auto pNode : children) {
-            if (pNode) {
-                delete pNode;
-            }
-        }
-        children.clear();
-    }
-
-    void Add(IniNode* pNode) {
-        children.push_back(pNode);
-    }
-
-    void Del(IniNode* pNode) {
-        for (auto iter = children.begin(); iter != children.end(); ++iter) {
-            if ((*iter) == pNode) {
-                delete (*iter);
-                children.erase(iter);
-                return;
-            }
-        }
-    }
-
-    IniNode* Get(const string& label, Type type = INI_NODE_TYPE_KEY_VALUE) {
-        for (auto pNode : children) {
-            if (pNode->type == type && pNode->label == label) {
-                return pNode;
-            }
-        }
-        return NULL;
-    }
-};
-
-class HV_EXPORT IniSection : public IniNode {
-public:
-    IniSection() : IniNode(), section(label) {
-        type = INI_NODE_TYPE_SECTION;
-    }
-    string &section;
-};
-
-class HV_EXPORT IniKeyValue : public IniNode {
-public:
-    IniKeyValue() : IniNode(), key(label) {
-        type = INI_NODE_TYPE_KEY_VALUE;
-    }
-    string &key;
-};
-
-class HV_EXPORT IniComment : public IniNode {
-public:
-    IniComment() : IniNode(), comment(label) {
-    }
-    string &comment;
-};
+// fwd
+class IniNode;
 
 class HV_EXPORT IniParser {
 public:
@@ -100,7 +22,6 @@ public:
     int Unload();
     int Reload();
 
-    void DumpString(IniNode* pNode, string& str);
     string DumpString();
     int Save();
     int SaveAs(const char* filepath);
@@ -116,6 +37,9 @@ public:
     template<typename T>
     void Set(const string& key, const T& value, const string& section = "");
 
+protected:
+    void DumpString(IniNode* pNode, string& str);
+
 public:
     string  _comment;
     string  _delim;