]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/configuration/sgconfig/parser_services.cpp
Fix divert_cap in FreeBSD.
[stg.git] / projects / stargazer / plugins / configuration / sgconfig / parser_services.cpp
index 59e7f03cea4e7c24a63791023cedd46df212d7bc..2ccddd386ef6f2dc28c5fbb6473d9e04804fc451 100644 (file)
@@ -34,7 +34,7 @@ const char * GET_SERVICES::tag = "GetServices";
 const char * GET_SERVICE::tag  = "AddService";
 const char * ADD_SERVICE::tag  = "AddService";
 const char * DEL_SERVICE::tag  = "DelService";
-const char * CHG_SERVICE::tag  = "ChgService";
+const char * CHG_SERVICE::tag  = "SetService";
 
 void GET_SERVICES::CreateAnswer()
 {
@@ -47,14 +47,14 @@ void GET_SERVICES::CreateAnswer()
     }*/
 
     m_answer = "<Services>";
-    SERVICE_CONF conf;
+    ServiceConf conf;
     int h = m_services.OpenSearch();
     while (m_services.SearchNext(h, &conf) == 0)
     {
         m_answer += "<Service name=\"" + conf.name +
                     "\" comment=\"" + Encode12str(conf.comment) +
-                    "\" cost=\"" + x2str(conf.cost) +
-                    "\" payDay=\"" + x2str(conf.payDay) + "\"/>";
+                    "\" cost=\"" + std::to_string(conf.cost) +
+                    "\" payDay=\"" + std::to_string(conf.payDay) + "\"/>";
     }
     m_services.CloseSearch(h);
     m_answer += "</Services>";
@@ -80,14 +80,14 @@ void GET_SERVICE::CreateAnswer()
         return;
     }*/
 
-    SERVICE_CONF conf;
+    ServiceConf conf;
     if (!m_services.Find(m_name, &conf))
         m_answer = "<Error result=\"Service '" + m_name + "' does not exist.\"/>";
     else
         m_answer += "<" + m_tag + " name=\"" + conf.name +
                     "\" comment=\"" + Encode12str(conf.comment) +
-                    "\" cost=\"" + x2str(conf.cost) +
-                    "\" payDay=\"" + x2str(conf.payDay) + "\"/>";
+                    "\" cost=\"" + std::to_string(conf.cost) +
+                    "\" payDay=\"" + std::to_string(conf.payDay) + "\"/>";
 }
 
 int ADD_SERVICE::Start(void *, const char * el, const char ** attr)
@@ -102,11 +102,11 @@ int ADD_SERVICE::Start(void *, const char * el, const char ** attr)
 
 void ADD_SERVICE::CreateAnswer()
 {
-    SERVICE_CONF conf(m_name);
+    ServiceConf conf(m_name);
     if (m_services.Add(conf, &m_currAdmin) == 0)
         m_answer = "<" + m_tag + " result=\"Ok\"/>";
     else
-        m_answer = "<" + m_tag + " result=\"Error. " + m_services.GetStrError() + "\"/>";
+        m_answer = "<" + m_tag + " result=\"" + m_services.GetStrError() + "\"/>";
 }
 
 int DEL_SERVICE::Start(void *, const char * el, const char ** attr)
@@ -124,7 +124,7 @@ void DEL_SERVICE::CreateAnswer()
     if (m_services.Del(m_name, &m_currAdmin) == 0)
         m_answer = "<" + m_tag + " result=\"Ok\"/>";
     else
-        m_answer = "<" + m_tag + " result=\"Error. " + m_services.GetStrError() + "\"/>";
+        m_answer = "<" + m_tag + " result=\"" + m_services.GetStrError() + "\"/>";
 }
 
 int CHG_SERVICE::Start(void *, const char * el, const char ** attr)
@@ -133,7 +133,6 @@ int CHG_SERVICE::Start(void *, const char * el, const char ** attr)
     {
         for (size_t i = 0; i < 8; i += 2)
         {
-            printfd(__FILE__, "PARSER_CHG_SERVICE::attr[%d] = %s\n", i, attr[i]);
             if (attr[i] == NULL)
                 break;
 
@@ -154,6 +153,8 @@ int CHG_SERVICE::Start(void *, const char * el, const char ** attr)
                 double cost = 0;
                 if (str2x(attr[i + 1], cost) == 0)
                     m_service.cost = cost;
+                else
+                    printfd(__FILE__, "Bad cast from '%s' to double\n", attr[i + 1]);
                 // TODO: log it
                 continue;
             }
@@ -163,6 +164,8 @@ int CHG_SERVICE::Start(void *, const char * el, const char ** attr)
                 unsigned payDay;
                 if (str2x(attr[i + 1], payDay) == 0)
                     m_service.payDay = payDay;
+                else
+                    printfd(__FILE__, "Bad cast from '%s' to unsigned\n", attr[i + 1]);
                 // TODO: log it
                 continue;
             }
@@ -175,24 +178,25 @@ int CHG_SERVICE::Start(void *, const char * el, const char ** attr)
 
 void CHG_SERVICE::CreateAnswer()
 {
-    if (m_service.name.empty())
+    if (!m_service.name)
     {
         m_answer = "<" + m_tag + " result=\"Empty service name.\"/>";
         return;
     }
 
-    if (!m_services.Exists(m_service.name.const_data()))
+    if (!m_services.Exists(m_service.name.value()))
     {
-        m_answer = "<" + m_tag + " result = \"Service '" + m_service.name.const_data() + "' does not exist.\"/>";
+        m_answer = "<" + m_tag + " result = \"Service '" + m_service.name.value() + "' does not exist.\"/>";
         return;
     }
 
-    SERVICE_CONF orig;
-    m_services.Find(m_service.name.const_data(), &orig);
+    ServiceConf orig;
+    m_services.Find(m_service.name.value(), &orig);
 
-    m_service.Splice(orig);
+    ServiceConfOpt conf(orig);
+    conf.splice(m_service);
 
-    if (m_services.Change(m_service.GetData(), &m_currAdmin) != 0)
+    if (m_services.Change(conf.get({}), &m_currAdmin) != 0)
         m_answer = "<" + m_tag + " result = \"" + m_services.GetStrError() + "\"/>";
     else
         m_answer = "<" + m_tag + " result = \"Ok\"/>";