* Author : Maxim Mamontov <faust@stargazer.dp.ua>
*/
-#include "stg/parser_get_user.h"
+#include "parser_get_user.h"
#include "stg/common.h"
#include <strings.h>
+using namespace STG;
+
+namespace STG
+{
+
template <>
-bool GetValue<PARSER_GET_USER::STAT>(const char ** attr, PARSER_GET_USER::STAT & value)
+bool GetValue<GET_USER::STAT>(const char ** attr, GET_USER::STAT & value)
{
if (!attr)
return false;
return true;
}
-PARSER_GET_USER::PARSER_GET_USER()
+}
+
+GET_USER::PARSER::PARSER()
: callback(NULL),
data(NULL),
- depth(0)
+ depth(0),
+ parsingAnswer(false)
{
AddParser(propertyParsers, "login", info.login);
AddParser(propertyParsers, "password", info.password);
AddParser(propertyParsers, "passive", info.passive);
AddParser(propertyParsers, "disableDetailStat", info.disableDetailStat);
AddParser(propertyParsers, "connected", info.connected);
- AddParser(propertyParsers, "alwaysOnline", info.alwaysOnline);
+ AddParser(propertyParsers, "aonline", info.alwaysOnline);
AddParser(propertyParsers, "currIP", info.ip, GetIPValue);
AddParser(propertyParsers, "ip", info.ips);
AddParser(propertyParsers, "tariff", info.tariff);
AddParser(propertyParsers, "userData" + x2str(i), info.userData[i], GetEncodedValue);
}
//-----------------------------------------------------------------------------
-PARSER_GET_USER::~PARSER_GET_USER()
+GET_USER::PARSER::~PARSER()
{
PROPERTY_PARSERS::iterator it(propertyParsers.begin());
while (it != propertyParsers.end())
delete (it++)->second;
}
//-----------------------------------------------------------------------------
-int PARSER_GET_USER::ParseStart(const char * el, const char ** attr)
+int GET_USER::PARSER::ParseStart(const char * el, const char ** attr)
{
depth++;
if (depth == 1)
ParseUser(el, attr);
-if (depth == 2)
+if (depth == 2 && parsingAnswer)
ParseUserParams(el, attr);
return 0;
}
//-----------------------------------------------------------------------------
-void PARSER_GET_USER::ParseEnd(const char * /*el*/)
+void GET_USER::PARSER::ParseEnd(const char * /*el*/)
{
depth--;
-if (depth == 0)
+if (depth == 0 && parsingAnswer)
{
if (callback)
callback(error.empty(), error, info, data);
error.clear();
+ parsingAnswer = false;
}
}
//-----------------------------------------------------------------------------
-void PARSER_GET_USER::ParseUser(const char * el, const char ** attr)
+void GET_USER::PARSER::ParseUser(const char * el, const char ** attr)
{
if (strcasecmp(el, "user") == 0)
- if (strcasecmp(attr[1], "error") == 0)
- error = "User not found.";
+ if (attr && attr[0] && attr[1])
+ {
+ if (strcasecmp(attr[1], "error") == 0)
+ {
+ if (attr[2] && attr[3])
+ error = attr[3];
+ else
+ error = "User not found.";
+ }
+ else
+ parsingAnswer = true;
+ }
+ else
+ parsingAnswer = true;
}
//-----------------------------------------------------------------------------
-void PARSER_GET_USER::ParseUserParams(const char * el, const char ** attr)
+void GET_USER::PARSER::ParseUserParams(const char * el, const char ** attr)
{
if (!TryParse(propertyParsers, ToLower(el), attr))
error = "Invalid parameter.";
}
//-----------------------------------------------------------------------------
-void PARSER_GET_USER::SetCallback(CALLBACK f, void * d)
+void GET_USER::PARSER::SetCallback(CALLBACK f, void * d)
{
callback = f;
data = d;