break;
case res_params_error:
printfd(__FILE__, "res_params_error\n");
- answerList->push_back("<SendMessageResult value=\"Parameters error\"/>");
+ answerList->push_back("<SendMessageResult value=\"Parameters error.\"/>");
break;
case res_unknown:
printfd(__FILE__, "res_unknown\n");
- answerList->push_back("<SendMessageResult value=\"Unknown user\"/>");
+ answerList->push_back("<SendMessageResult value=\"Unknown user.\"/>");
break;
default:
printfd(__FILE__, "res_default\n");
answerList->push_back("<DelUser value=\"ok\"/>");
}
//-----------------------------------------------------------------------------
-/*void PARSERDELUSER::CreateAnswer(char * mes)
-{
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-
-char str[255];
-sprintf(str, "<DelUser value=\"%s\"/>", mes);
-answerList->push_back(str);
-}*/
-//-----------------------------------------------------------------------------
// CHECK USER
// <checkuser login="vasya" password=\"123456\"/>
//-----------------------------------------------------------------------------
int PARSER_CHECK_USER::ParseStart(void *, const char *el, const char **attr)
{
-result = false;
-
if (strcasecmp(el, "CheckUser") == 0)
{
if (attr[0] == NULL || attr[1] == NULL
|| attr[2] == NULL || attr[3] == NULL)
{
- result = false;
- CreateAnswer();
+ CreateAnswer("Invalid parameters.");
printfd(__FILE__, "PARSER_CHECK_USER - attr err\n");
return 0;
}
USER_PTR user;
if (users->FindByName(attr[1], &user))
{
- result = false;
- CreateAnswer();
+ CreateAnswer("User not found.");
printfd(__FILE__, "PARSER_CHECK_USER - login err\n");
return 0;
}
if (strcmp(user->GetProperty().password.Get().c_str(), attr[3]))
{
- result = false;
- CreateAnswer();
+ CreateAnswer("Wrong password.");
printfd(__FILE__, "PARSER_CHECK_USER - passwd err\n");
return 0;
}
- result = true;
- CreateAnswer();
+ CreateAnswer(NULL);
return 0;
}
return -1;
return -1;
}
//-----------------------------------------------------------------------------
-void PARSER_CHECK_USER::CreateAnswer()
+void PARSER_CHECK_USER::CreateAnswer(const char * error)
{
-if (result)
- answerList->push_back("<CheckUser value=\"Ok\"/>");
+if (error)
+ answerList->push_back(std::string("<CheckUser value=\"Err\" reason=\"") + error + "\"/>");
else
- answerList->push_back("<CheckUser value=\"Err\"/>");
+ answerList->push_back("<CheckUser value=\"Ok\"/>");
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#ifndef PARSER_H
#define PARSER_H
-#include <list>
-#include <string>
-#include <vector>
-
#include "stg/resetable.h"
#include "stg/const.h"
#include "stg/store.h"
#include "stg/users.h"
#include "stg/message.h"
+#include <list>
+#include <string>
+#include <vector>
+
class TARIFFS;
class SETTINGS;
PARSER_CHECK_USER() : BASE_PARSER(), result(false) {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-private:
- bool result;
+ void CreateAnswer(const char * error);
};
//-----------------------------------------------------------------------------
class PARSER_SEND_MESSAGE: public BASE_PARSER {
LIBS = -lexpat
SRCS = netunit.cpp \
+ property_parsers.cpp \
parser_auth_by.cpp \
parser_server_info.cpp \
parser_check_user.cpp \
#include "parser.h"
+#include <string>
+
class PARSER_CHECK_USER: public PARSER
{
public:
- typedef int (* CALLBACK)(const char * answer, void * data);
+ typedef int (* CALLBACK)(bool result, const std::string & reason, void * data);
PARSER_CHECK_USER();
- int ParseStart(const char *el, const char **attr);
- void ParseEnd(const char *el);
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
void SetCallback(CALLBACK f, void * data);
private:
CALLBACK callback;
void * data;
int depth;
- void ParseAnswer(const char *el, const char **attr);
+ void ParseAnswer(const char * el, const char ** attr);
};
#endif
#include "parser.h"
+#include <string>
+
class PARSER_CHG_USER: public PARSER
{
public:
- typedef int (* CALLBACK)(const char * asnwer, void * data);
+ typedef int (* CALLBACK)(bool result, const std::string& reason, void * data);
PARSER_CHG_USER();
int ParseStart(const char * el, const char ** attr);
#include "parser.h"
+#include "property_parsers.h"
+
#include "stg/os_int.h"
#include "stg/const.h"
#include <string>
-#include <map>
#include <ctime>
-class BASE_PROPERTY_PARSER
-{
- public:
- virtual ~BASE_PROPERTY_PARSER() {}
- virtual void Parse(const char ** attr) = 0;
-};
-
-template <typename T>
-class PROPERTY_PARSER : public BASE_PROPERTY_PARSER
-{
- public:
- typedef T (* FUNC)(const char **);
- PROPERTY_PARSER(T & v, FUNC f) : value(v), func(f) {}
- virtual void Parse(const char ** attr) { value = func(attr); }
- private:
- T & value;
- FUNC func;
-};
-
-typedef std::map<std::string, BASE_PROPERTY_PARSER *> PROPERTY_PARSERS;
-
class PARSER_GET_USER: public PARSER
{
public:
std::string userData[USERDATA_NUM];
};
- typedef void (* CALLBACK)(const INFO & info, void * data);
+ typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
PARSER_GET_USER();
virtual ~PARSER_GET_USER();
void * data;
INFO info;
int depth;
+ std::string error;
void ParseUser(const char *el, const char **attr);
void ParseUserParams(const char *el, const char **attr);
{
public:
typedef std::vector<PARSER_GET_USER::INFO> INFO;
- typedef void (* CALLBACK)(const INFO & info, void * data);
+ typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
PARSER_GET_USERS();
int ParseStart(const char * el, const char ** attr);
PARSER_GET_USER userParser;
INFO info;
int depth;
+ std::string error;
void AddUser(const PARSER_GET_USER::INFO & userInfo);
+ void SetError(const std::string & e) { error = e; }
void ParseUsers(const char * el, const char ** attr);
static void UserCallback(const PARSER_GET_USER::INFO & info, void * data);
#include "parser.h"
+#include <string>
+
class PARSER_SEND_MESSAGE: public PARSER
{
public:
- typedef int (* CALLBACK)(const char * answer, void * data);
+ typedef int (* CALLBACK)(bool result, const std::string& reason, void * data);
PARSER_SEND_MESSAGE();
int ParseStart(const char * el, const char ** attr);
#include "parser.h"
+#include "property_parsers.h"
#include "stg/const.h"
#include <string>
int dirNum;
std::string dirName[DIR_NUM];
};
- typedef void (* CALLBACK)(const INFO & info, void * data);
+ typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
PARSER_SERVER_INFO();
- int ParseStart(const char *el, const char **attr);
- void ParseEnd(const char *el);
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
void SetCallback(CALLBACK f, void * data);
private:
- void ParseDirName(const char **attr, int d);
-
+ PROPERTY_PARSERS propertyParsers;
CALLBACK callback;
void * data;
int depth;
INFO info;
+ std::string error;
};
#endif
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PROPERTY_PARSERS_H__
+#define __STG_STGLIBS_SRVCONF_PROPERTY_PARSERS_H__
+
+#include <map>
+#include <string>
+
+#include "stg/common.h"
+
+class BASE_PROPERTY_PARSER
+{
+ public:
+ virtual ~BASE_PROPERTY_PARSER() {}
+ virtual bool Parse(const char ** attr) = 0;
+};
+
+template <typename T>
+class PROPERTY_PARSER : public BASE_PROPERTY_PARSER
+{
+ public:
+ typedef bool (* FUNC)(const char **, T &);
+ PROPERTY_PARSER(T & v, FUNC f) : value(v), func(f) {}
+ virtual bool Parse(const char ** attr) { return func(attr, value); }
+ private:
+ T & value;
+ FUNC func;
+};
+
+typedef std::map<std::string, BASE_PROPERTY_PARSER *> PROPERTY_PARSERS;
+
+bool CheckValue(const char ** attr);
+
+template <typename T>
+bool GetValue(const char ** attr, T & value)
+{
+if (CheckValue(attr))
+ if (str2x(attr[1], value) < 0)
+ return false;
+return true;
+}
+
+template <>
+bool GetValue<std::string>(const char ** attr, std::string & value)
+{
+if (!CheckValue(attr))
+ return false;
+value = attr[1];
+return true;
+}
+
+template <>
+bool GetValue<double>(const char ** attr, double & value)
+{
+if (CheckValue(attr))
+ if (strtodouble2(attr[1], value))
+ return false;
+return true;
+}
+
+bool GetEncodedValue(const char ** attr, std::string & value);
+
+bool GetIPValue(const char ** attr, uint32_t& value);
+
+template <typename T>
+void AddParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER<T>::FUNC & func = GetValue<T>);
+
+template <typename T>
+void AddParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER<T>::FUNC & func)
+{
+ parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER<T>(value, func)));
+}
+
+bool TryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr);
+
+#endif
//-----------------------------------------------------------------------------
void PARSER_CHECK_USER::ParseAnswer(const char *, const char **attr)
{
+if (!callback)
+ return;
if (attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0)
- if (callback)
- callback(attr[1], data);
+ callback(strcasecmp(attr[1], "ok") == 0, attr[2] && attr[3] ? attr[3] : "", data);
+else
+ callback(false, "Invalid response.", data);
}
//-----------------------------------------------------------------------------
void PARSER_CHECK_USER::SetCallback(CALLBACK f, void * d)
//-----------------------------------------------------------------------------
void PARSER_CHG_USER::ParseAnswer(const char * /*el*/, const char ** attr)
{
+if (!callback)
+ return;
if (attr && attr[0] && attr[1])
- if (callback)
- callback(attr[1], data);
+ callback(strcasecmp(attr[1], "ok") == 0, attr[2] && attr[3] ? attr[3] : "", data);
+else
+ callback(false, "Invalid response.", data);
}
//-----------------------------------------------------------------------------
void PARSER_CHG_USER::SetCallback(CALLBACK f, void * d)
#include "stg/common.h"
+#include <map>
#include <utility>
#include <cstddef>
#include <strings.h>
-namespace
-{
-
-bool checkValue(const char ** attr)
-{
-return attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0;
-}
-
-template <typename T>
-T getValue(const char ** attr)
-{
-T value = 0;
-if (checkValue(attr))
- if (str2x(attr[1], value) < 0)
- return 0;
-return value;
-}
-
template <>
-std::string getValue<std::string>(const char ** attr)
+bool GetValue<PARSER_GET_USER::STAT>(const char ** attr, PARSER_GET_USER::STAT & value)
{
-if (checkValue(attr))
- return attr[1];
-return "";
-}
-
-template <>
-double getValue<double>(const char ** attr)
-{
-double value = 0;
-if (checkValue(attr))
- if (strtodouble2(attr[1], value))
- return 0;
-return value;
-}
-
-template <>
-PARSER_GET_USER::STAT getValue<PARSER_GET_USER::STAT>(const char ** attr)
-{
-PARSER_GET_USER::STAT value;
if (!attr)
- return value;
+ return false;
std::map<std::string, long long *> props;
for (size_t i = 0; i < DIR_NUM; ++i)
{
std::string name(ToLower(attr[pos++]));
std::map<std::string, long long *>::iterator it(props.find(name));
if (it != props.end())
- str2x(attr[pos++], *it->second);
+ if (str2x(attr[pos++], *it->second) < 0)
+ return false;
}
-return value;
+return true;
}
-std::string getEncodedValue(const char ** attr)
-{
-std::string value;
-if (checkValue(attr))
- Decode21str(value, attr[1]);
-return value;
-}
-
-uint32_t getIPValue(const char ** attr)
-{
-if (checkValue(attr))
- return inet_strington(attr[1]);
-return 0;
-}
-
-template <typename T>
-void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER<T>::FUNC & func = getValue<T>);
-
-template <typename T>
-void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER<T>::FUNC & func)
-{
- parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER<T>(value, func)));
-}
-
-void tryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr)
-{
- PROPERTY_PARSERS::iterator it(parsers.find(name));
- if (it != parsers.end())
- it->second->Parse(attr);
-}
-
-} // namespace anonymous
-
PARSER_GET_USER::PARSER_GET_USER()
: callback(NULL),
data(NULL),
depth(0)
{
- addParser(propertyParsers, "login", info.login);
- addParser(propertyParsers, "password", info.password);
- addParser(propertyParsers, "cash", info.cash);
- addParser(propertyParsers, "credit", info.credit);
- addParser(propertyParsers, "creditExpire", info.creditExpire);
- addParser(propertyParsers, "lastCash", info.lastCash);
- addParser(propertyParsers, "prepaidTraff", info.prepaidTraff);
- addParser(propertyParsers, "down", info.down);
- addParser(propertyParsers, "passive", info.passive);
- addParser(propertyParsers, "disableDetailStat", info.disableDetailStat);
- addParser(propertyParsers, "connected", info.connected);
- addParser(propertyParsers, "alwaysOnline", info.alwaysOnline);
- 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, "traff", info.stat);
+ AddParser(propertyParsers, "login", info.login);
+ AddParser(propertyParsers, "password", info.password);
+ AddParser(propertyParsers, "cash", info.cash);
+ AddParser(propertyParsers, "credit", info.credit);
+ AddParser(propertyParsers, "creditExpire", info.creditExpire);
+ AddParser(propertyParsers, "lastCash", info.lastCash);
+ AddParser(propertyParsers, "prepaidTraff", info.prepaidTraff);
+ AddParser(propertyParsers, "down", info.down);
+ AddParser(propertyParsers, "passive", info.passive);
+ AddParser(propertyParsers, "disableDetailStat", info.disableDetailStat);
+ AddParser(propertyParsers, "connected", info.connected);
+ AddParser(propertyParsers, "alwaysOnline", info.alwaysOnline);
+ 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, "traff", info.stat);
for (size_t i = 0; i < USERDATA_NUM; ++i)
- addParser(propertyParsers, "userData" + x2str(i), info.userData[i], getEncodedValue);
+ AddParser(propertyParsers, "userData" + x2str(i), info.userData[i], GetEncodedValue);
}
//-----------------------------------------------------------------------------
PARSER_GET_USER::~PARSER_GET_USER()
delete (it++)->second;
}
//-----------------------------------------------------------------------------
-int PARSER_GET_USER::ParseStart(const char *el, const char **attr)
+int PARSER_GET_USER::ParseStart(const char * el, const char ** attr)
{
depth++;
if (depth == 1)
return 0;
}
//-----------------------------------------------------------------------------
-void PARSER_GET_USER::ParseEnd(const char *)
+void PARSER_GET_USER::ParseEnd(const char * /*el*/)
{
depth--;
if (depth == 0)
+ {
if (callback)
- callback(info, data);
+ callback(error.empty(), error, info, data);
+ error.clear();
+ }
}
//-----------------------------------------------------------------------------
void PARSER_GET_USER::ParseUser(const char * el, const char ** attr)
{
if (strcasecmp(el, "user") == 0)
if (strcasecmp(attr[1], "error") == 0)
- info.login = "";
+ error = "User not found.";
}
//-----------------------------------------------------------------------------
void PARSER_GET_USER::ParseUserParams(const char * el, const char ** attr)
{
-tryParse(propertyParsers, ToLower(el), attr);
+if (!TryParse(propertyParsers, ToLower(el), attr))
+ error = "Invalid parameter.";
}
//-----------------------------------------------------------------------------
void PARSER_GET_USER::SetCallback(CALLBACK f, void * d)
userParser.ParseEnd(el);
if (depth == 0)
+ {
if (callback)
- callback(info, data);
+ callback(error.empty(), error, info, data);
+ error.clear();
+ }
}
//-----------------------------------------------------------------------------
void PARSER_GET_USERS::ParseUsers(const char * el, const char ** /*attr*/)
data = d;
}
//-----------------------------------------------------------------------------
-void PARSER_GET_USERS::UserCallback(const PARSER_GET_USER::INFO & info, void * data)
+void PARSER_GET_USERS::UserCallback(bool result, const std::string & error, const PARSER_GET_USER::INFO & info, void * data)
{
PARSER_GET_USERS * parser = static_cast<PARSER_GET_USERS *>(data);
- parser->AddUser(info);
+ if (!result)
+ parser->SetError(error);
+ else
+ parser->AddUser(info);
}
//-----------------------------------------------------------------------------
void PARSER_SEND_MESSAGE::ParseAnswer(const char * /*el*/, const char **attr)
{
+if (!callback)
+ return;
if (attr && attr[0] && attr[1])
- if (callback)
- callback(attr[1], data);
+ callback(strcasecmp(attr[1], "ok") == 0, attr[1], data);
+else
+ callback(false, "Invalid response.", data);
}
//-----------------------------------------------------------------------------
void PARSER_SEND_MESSAGE::SetCallback(CALLBACK f, void * d)
const size_t SERV_VER_LEN = 64;
const size_t DIRNAME_LEN = 16;
-bool checkValue(const char ** attr)
-{
-return attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0;
-}
-
-int getIntValue(const char ** attr)
-{
-int value = -1;
-if (checkValue(attr))
- if (str2x(attr[1], value) < 0)
- return -1;
-return value;
-}
-
-std::string getStringValue(const char ** attr)
-{
-if (checkValue(attr))
- return attr[1];
-return "";
-}
-
}
PARSER_SERVER_INFO::PARSER_SERVER_INFO()
data(NULL),
depth(0)
{
+ AddParser(propertyParsers, "uname", info.uname);
+ AddParser(propertyParsers, "version", info.version);
+ AddParser(propertyParsers, "tariff", info.tariffType);
+ AddParser(propertyParsers, "dir_num", info.dirNum);
+ AddParser(propertyParsers, "users_num", info.usersNum);
+ AddParser(propertyParsers, "tariff_num", info.tariffNum);
+
+ for (size_t i = 0; i < DIR_NUM; i++)
+ AddParser(propertyParsers, "dir_name_" + x2str(i), info.dirName[i], GetEncodedValue);
}
//-----------------------------------------------------------------------------
int PARSER_SERVER_INFO::ParseStart(const char *el, const char **attr)
{
depth++;
if (depth == 1)
- {
if (strcasecmp(el, "ServerInfo") != 0)
- {
- //printf("%s\n", el);
- }
- }
+ error = "Invalid response.";
else
- {
if (depth == 2)
- {
- if (strcasecmp(el, "uname") == 0)
- {
- info.uname = getStringValue(attr);
- return 0;
- }
- if (strcasecmp(el, "version") == 0)
- {
- info.version = getStringValue(attr);
- return 0;
- }
- if (strcasecmp(el, "tariff") == 0)
- {
- info.tariffType = getIntValue(attr);
- return 0;
- }
- if (strcasecmp(el, "dir_num") == 0)
- {
- info.dirNum = getIntValue(attr);
- return 0;
- }
- if (strcasecmp(el, "users_num") == 0)
- {
- info.usersNum = getIntValue(attr);
- return 0;
- }
- if (strcasecmp(el, "tariff_num") == 0)
- {
- info.tariffNum = getIntValue(attr);
- return 0;
- }
-
- for (int j = 0; j < DIR_NUM; j++)
- {
- char str[16];
- sprintf(str, "dir_name_%d", j);
- if (strcasecmp(el, str) == 0)
- ParseDirName(attr, j);
- }
-
- }
- }
+ if (!TryParse(propertyParsers, ToLower(el), attr))
+ error = "Invalid parameter.";
return 0;
}
//-----------------------------------------------------------------------------
void PARSER_SERVER_INFO::ParseEnd(const char * /*el*/)
{
depth--;
-if (depth == 0 && callback)
- callback(info, data);
+if (depth == 0)
+ {
+ if (callback)
+ callback(error.empty(), error, info, data);
+ error.clear();
+ }
}
//-----------------------------------------------------------------------------
void PARSER_SERVER_INFO::SetCallback(CALLBACK f, void * d)
callback = f;
data = d;
}
-//-----------------------------------------------------------------------------
-void PARSER_SERVER_INFO::ParseDirName(const char **attr, int d)
-{
-if (checkValue(attr))
- {
- char str[2 * DIRNAME_LEN + 1];
- Decode21(str, attr[1]);
- info.dirName[d] = str;
- }
-}
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "stg/property_parsers.h"
+
+#include <strings.h>
+
+bool CheckValue(const char ** attr)
+{
+return attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0;
+}
+
+bool GetEncodedValue(const char ** attr, std::string & value)
+{
+if (!CheckValue(attr))
+ return false;
+Decode21str(value, attr[1]);
+return true;
+}
+
+bool GetIPValue(const char ** attr, uint32_t value)
+{
+if (!CheckValue(attr))
+ return false;
+std::string ip(attr[1]);
+value = inet_strington(attr[1]);
+if (value == 0 && ip != "0.0.0.0")
+ return false;
+return true;
+}
+
+bool TryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr)
+{
+ PROPERTY_PARSERS::iterator it(parsers.find(name));
+ if (it != parsers.end())
+ return it->second->Parse(attr);
+ return true; // Assume that non-existing params are ok.
+}