]> git.stg.codes - stg.git/blobdiff - stglibs/srvconf.lib/parsers/get_user.cpp
Merge branch 'stg-2.409-radius'
[stg.git] / stglibs / srvconf.lib / parsers / get_user.cpp
index e796d45094cd249ca5a8933b7f78209ac0f1c7c6..03327c4dc588a6f9c4d2c86fbcb2d373957ea4d2 100644 (file)
@@ -60,9 +60,10 @@ return true;
 
 }
 
-GET_USER::PARSER::PARSER(CALLBACK f, void * d)
+GET_USER::PARSER::PARSER(CALLBACK f, void * d, const std::string & e)
     : callback(f),
       data(d),
+      encoding(e),
       depth(0),
       parsingAnswer(false)
 {
@@ -82,18 +83,19 @@ GET_USER::PARSER::PARSER(CALLBACK f, void * d)
     AddParser(propertyParsers, "currIP", info.ip, GetIPValue);
     AddParser(propertyParsers, "ip", info.ips);
     AddParser(propertyParsers, "tariff", info.tariff);
-    AddParser(propertyParsers, "group", info.group, GetEncodedValue);
-    AddParser(propertyParsers, "note", info.note, GetEncodedValue);
-    AddParser(propertyParsers, "email", info.email, GetEncodedValue);
-    AddParser(propertyParsers, "name", info.name, GetEncodedValue);
-    AddParser(propertyParsers, "address", info.address, GetEncodedValue);
-    AddParser(propertyParsers, "phone", info.phone, GetEncodedValue);
+    AddParser(propertyParsers, "group", info.group, "koi8-ru", GetEncodedValue);
+    AddParser(propertyParsers, "note", info.note, "koi8-ru", GetEncodedValue);
+    AddParser(propertyParsers, "email", info.email, "koi8-ru", GetEncodedValue);
+    AddParser(propertyParsers, "name", info.name, "koi8-ru", GetEncodedValue);
+    AddParser(propertyParsers, "address", info.address, "koi8-ru", GetEncodedValue);
+    AddParser(propertyParsers, "phone", info.phone, "cp1251", GetEncodedValue);
+    AddParser(propertyParsers, "corp", info.corp);
     AddParser(propertyParsers, "traff", info.stat);
     AddParser(propertyParsers, "pingTime", info.pingTime);
     AddParser(propertyParsers, "lastActivityTime", info.lastActivityTime);
 
     for (size_t i = 0; i < USERDATA_NUM; ++i)
-        AddParser(propertyParsers, "userData" + unsigned2str(i), info.userData[i], GetEncodedValue);
+        AddParser(propertyParsers, "userData" + unsigned2str(i), info.userData[i], "koi8-ru", GetEncodedValue);
 }
 //-----------------------------------------------------------------------------
 GET_USER::PARSER::~PARSER()
@@ -112,6 +114,12 @@ if (depth == 1)
 if (depth == 2 && parsingAnswer)
     ParseUserParams(el, attr);
 
+if (depth == 3 && parsingAnswer)
+    {
+    ParseAuthBy(el, attr);
+    ParseServices(el, attr);
+    }
+
 return 0;
 }
 //-----------------------------------------------------------------------------
@@ -149,6 +157,26 @@ if (strcasecmp(el, "user") == 0)
 //-----------------------------------------------------------------------------
 void GET_USER::PARSER::ParseUserParams(const char * el, const char ** attr)
 {
-if (!TryParse(propertyParsers, ToLower(el), attr))
+if (strcasecmp(el, "AuthorizedBy") != 0 &&
+    !TryParse(propertyParsers, ToLower(el), attr, encoding))
     error = "Invalid parameter.";
+else if (strcasecmp(el, "Services") != 0 &&
+    !TryParse(propertyParsers, ToLower(el), attr, encoding))
+    error = "Invalid parameter.";
+}
+//-----------------------------------------------------------------------------
+void GET_USER::PARSER::ParseAuthBy(const char * el, const char ** attr)
+{
+if (strcasecmp(el, "Auth") == 0 &&
+    attr && attr[0] && attr[1] &&
+    strcasecmp(attr[0], "name") == 0)
+    info.authBy.push_back(attr[1]);
+}
+//-----------------------------------------------------------------------------
+void GET_USER::PARSER::ParseServices(const char * el, const char ** attr)
+{
+if (strcasecmp(el, "Service") == 0 &&
+    attr && attr[0] && attr[1] &&
+    strcasecmp(attr[0], "name") == 0)
+    info.services.push_back(attr[1]);
 }