+++ /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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#ifndef __STG_STGLIBS_SRVCONF_PARSER_H__
-#define __STG_STGLIBS_SRVCONF_PARSER_H__
-
-namespace STG
-{
-
-class PARSER
-{
-public:
- virtual ~PARSER() {}
- virtual int ParseStart(const char *el, const char **attr) = 0;
- virtual void ParseEnd(const char *el) = 0;
-};
-
-} // namespace STG
-
-#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>
-inline
-bool GetValue(const char ** attr, T & value)
-{
-if (CheckValue(attr))
- if (str2x(attr[1], value) < 0)
- return false;
-return true;
-}
-
-template <>
-inline
-bool GetValue<std::string>(const char ** attr, std::string & value)
-{
-if (!CheckValue(attr))
- return false;
-value = attr[1];
-return true;
-}
-
-template <>
-inline
-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>
-inline
-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
--- /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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_H__
+
+namespace STG
+{
+
+class PARSER
+{
+public:
+ virtual ~PARSER() {}
+ virtual int ParseStart(const char *el, const char **attr) = 0;
+ virtual void ParseEnd(const char *el) = 0;
+};
+
+} // namespace STG
+
+#endif
#ifndef __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__
#define __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__
-#include "stg/parser.h"
+#include "parser.h"
#include "stg/servconf_types.h"
-#include <vector>
#include <string>
namespace STG
{
public:
PARSER();
- 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;
#ifndef __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__
#define __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__
-#include "stg/parser.h"
-#include "stg/servconf_types.h"
+#include "parser.h"
-#include <string>
+#include "stg/servconf_types.h"
namespace STG
{
class PARSER: public STG::PARSER
{
public:
-
PARSER();
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
void SetCallback(CALLBACK f, void * data);
+
private:
CALLBACK callback;
void * data;
#ifndef __STG_STGLIBS_SRVCONF_PARSER_CHG_USER_H__
#define __STG_STGLIBS_SRVCONF_PARSER_CHG_USER_H__
-#include "stg/parser.h"
+#include "parser.h"
+
#include "stg/servconf_types.h"
namespace STG
class PARSER: public STG::PARSER
{
public:
-
PARSER();
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
void SetCallback(CALLBACK f, void * data);
+
private:
CALLBACK callback;
void * data;
using namespace STG;
+namespace STG
+{
+
template <>
bool GetValue<GET_USER::STAT>(const char ** attr, GET_USER::STAT & value)
{
return true;
}
+}
+
GET_USER::PARSER::PARSER()
: callback(NULL),
data(NULL),
#ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__
#define __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__
-#include "stg/parser.h"
+#include "parser.h"
+#include "property_parsers.h"
-#include "stg/property_parsers.h"
#include "stg/servconf_types.h"
#include <string>
-#include <ctime>
-
namespace STG
{
namespace GET_USER
class PARSER: public STG::PARSER
{
public:
-
PARSER();
virtual ~PARSER();
- 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:
PROPERTY_PARSERS propertyParsers;
CALLBACK callback;
bool parsingAnswer;
std::string error;
- void ParseUser(const char *el, const char **attr);
- void ParseUserParams(const char *el, const char **attr);
+ void ParseUser(const char * el, const char ** attr);
+ void ParseUserParams(const char * el, const char ** attr);
};
} // namespace GET_USER
#ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__
#define __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__
-#include "stg/parser.h"
-#include "stg/servconf_types.h"
-
+#include "parser.h"
#include "parser_get_user.h"
-#include <vector>
+#include "stg/servconf_types.h"
+
+#include <string>
namespace STG
{
class PARSER: public STG::PARSER
{
public:
-
PARSER();
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
void SetCallback(CALLBACK f, void * data);
+
private:
CALLBACK callback;
void * data;
#ifndef __STG_STGLIBS_SRVCONF_PARSER_SEND_MESSAGE_H__
#define __STG_STGLIBS_SRVCONF_PARSER_SEND_MESSAGE_H__
-#include "stg/parser.h"
-#include "stg/servconf_types.h"
+#include "parser.h"
-#include <string>
+#include "stg/servconf_types.h"
namespace STG
{
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
void SetCallback(CALLBACK f, void * data);
+
private:
CALLBACK callback;
void * data;
#ifndef __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__
#define __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__
-#include "stg/parser.h"
+#include "parser.h"
+#include "property_parsers.h"
-#include "stg/property_parsers.h"
#include "stg/servconf_types.h"
#include <string>
class PARSER: public STG::PARSER
{
public:
-
PARSER();
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
void SetCallback(CALLBACK f, void * data);
+
private:
PROPERTY_PARSERS propertyParsers;
CALLBACK callback;
* Author : Maxim Mamontov <faust@stargazer.dp.ua>
*/
-#include "stg/property_parsers.h"
+#include "property_parsers.h"
#include <strings.h>
-bool CheckValue(const char ** attr)
+bool STG::CheckValue(const char ** attr)
{
return attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0;
}
-bool GetEncodedValue(const char ** attr, std::string & value)
+bool STG::GetEncodedValue(const char ** attr, std::string & value)
{
if (!CheckValue(attr))
return false;
return true;
}
-bool GetIPValue(const char ** attr, uint32_t & value)
+bool STG::GetIPValue(const char ** attr, uint32_t & value)
{
if (!CheckValue(attr))
return false;
return true;
}
-bool TryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr)
+bool STG::TryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr)
{
PROPERTY_PARSERS::iterator it(parsers.find(name));
if (it != parsers.end())
--- /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 "stg/common.h"
+
+#include <map>
+#include <string>
+
+namespace STG
+{
+
+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>
+inline
+bool GetValue(const char ** attr, T & value)
+{
+if (CheckValue(attr))
+ if (str2x(attr[1], value) < 0)
+ return false;
+return true;
+}
+
+template <>
+inline
+bool GetValue<std::string>(const char ** attr, std::string & value)
+{
+if (!CheckValue(attr))
+ return false;
+value = attr[1];
+return true;
+}
+
+template <>
+inline
+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>
+inline
+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);
+
+} // namespace STG
+
+#endif