#include <langinfo.h>
#include <iconv.h>
+using namespace STG;
+
const int usageConf = 0;
const int usageInfo = 1;
}
//-----------------------------------------------------------------------------
void RecvAuthByData(bool result, const std::string & reason,
- const PARSER_AUTH_BY::INFO & list, void * d)
+ const AUTH_BY::INFO & list, void * d)
{
ResultData * data = static_cast<ResultData *>(d);
data->result = result;
#ifndef __STG_STGLIBS_SRVCONF_PARSER_H__
#define __STG_STGLIBS_SRVCONF_PARSER_H__
+namespace STG
+{
+
class PARSER
{
public:
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_PARSER_AUTH_BY_H__
-#define __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__
-
-#include "parser.h"
-
-#include <vector>
-#include <string>
-
-class PARSER_AUTH_BY: public PARSER
-{
-public:
- typedef std::vector<std::string> INFO;
- typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
-
- PARSER_AUTH_BY();
- 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;
- bool parsingAnswer;
- INFO info;
- std::string error;
-};
-
-#endif
#include <string>
+namespace STG
+{
+
class PARSER_CHECK_USER: public PARSER
{
public:
void ParseAnswer(const char * el, const char ** attr);
};
+} // namespace STG
+
#endif
#include <string>
+namespace STG
+{
+
class PARSER_CHG_USER: public PARSER
{
public:
void ParseAnswer(const char * el, const char ** attr);
};
+} // namespace STG
+
#endif
#include <ctime>
+namespace STG
+{
+
class PARSER_GET_USER: public PARSER
{
public:
void ParseUserParams(const char *el, const char **attr);
};
+} // namespace STG
+
#endif
#include <vector>
+namespace STG
+{
+
class PARSER_GET_USERS: public PARSER
{
public:
static void UserCallback(bool result, const std::string& reason, const PARSER_GET_USER::INFO & info, void * data);
};
+} // namespace STG
+
#endif
#include <string>
+namespace STG
+{
+
class PARSER_SEND_MESSAGE: public PARSER
{
public:
void ParseAnswer(const char * el, const char ** attr);
};
+} // namespace STG
+
#endif
#include <string>
+namespace STG
+{
+
class PARSER_SERVER_INFO: public PARSER
{
public:
std::string error;
};
+}
+
#endif
$Author: faust $
*/
-#ifndef SERVCONF_H
-#define SERVCONF_H
+#ifndef __STG_STGLIBS_SERVCONF_H__
+#define __STG_STGLIBS_SERVCONF_H__
-#include "stg/parser_auth_by.h"
#include "stg/parser_server_info.h"
#include "stg/parser_check_user.h"
#include "stg/parser_get_user.h"
#include "stg/parser_chg_user.h"
#include "stg/parser_send_message.h"
+#include "stg/servconf_types.h"
+
#include "stg/os_int.h"
#include <string>
+namespace STG
+{
+
class SERVCONF
{
public:
int GetUsers(PARSER_GET_USERS::CALLBACK f, void * data);
int GetUser(const std::string & login, PARSER_GET_USER::CALLBACK f, void * data);
int ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f, void * data);
- int AuthBy(const std::string & login, PARSER_AUTH_BY::CALLBACK f, void * data);
+ int AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data);
int SendMessage(const std::string & request, PARSER_SEND_MESSAGE::CALLBACK f, void * data);
int ServerInfo(PARSER_SERVER_INFO::CALLBACK f, void * data);
int CheckUser(const std::string & login, const std::string & password, PARSER_CHECK_USER::CALLBACK f, void * data);
class IMPL;
IMPL * pImpl;
};
-//-----------------------------------------------------------------------------
-#endif /* _SERVCONF_H_ */
+} // namespace STG
+
+#endif
#ifndef __STG_STGLIBS_SRVCONF_TYPES_H__
#define __STG_STGLIBS_SRVCONF_TYPES_H__
+#include <string>
+#include <vector>
+
#define STG_HEADER "SG04"
#define OK_HEADER "OKHD"
#define ERR_HEADER "ERHD"
#define ENC_MSG_LEN (8)
+namespace STG
+{
+
enum status
{
st_ok = 0,
confData
};
+namespace AUTH_BY
+{
+
+typedef std::vector<std::string> INFO;
+typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
+
+} // namespace AUTH_BY
+} // namespace STG
+
#endif
#include <sys/socket.h>
#include <netinet/in.h>
+using namespace STG;
+
namespace
{
* Author : Maxim Mamontov <faust@stargazer.dp.ua>
*/
-#include "stg/parser_auth_by.h"
+#include "parser_auth_by.h"
#include <cstddef>
#include <strings.h> // strcasecmp
-PARSER_AUTH_BY::PARSER_AUTH_BY()
+using namespace STG;
+
+AUTH_BY::PARSER::PARSER()
: callback(NULL),
data(NULL),
depth(0),
{
}
//-----------------------------------------------------------------------------
-int PARSER_AUTH_BY::ParseStart(const char *el, const char **attr)
+int AUTH_BY::PARSER::ParseStart(const char *el, const char **attr)
{
depth++;
if (depth == 1)
return 0;
}
//-----------------------------------------------------------------------------
-void PARSER_AUTH_BY::ParseEnd(const char * /*el*/)
+void AUTH_BY::PARSER::ParseEnd(const char * /*el*/)
{
depth--;
if (depth == 0)
}
}
//-----------------------------------------------------------------------------
-void PARSER_AUTH_BY::SetCallback(CALLBACK f, void * d)
+void AUTH_BY::PARSER::SetCallback(AUTH_BY::CALLBACK f, void * d)
{
callback = f;
data = d;
--- /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_PARSER_AUTH_BY_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__
+
+#include "stg/parser.h"
+
+#include "stg/servconf_types.h"
+
+#include <vector>
+#include <string>
+
+namespace STG
+{
+namespace AUTH_BY
+{
+
+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;
+ int depth;
+ bool parsingAnswer;
+ INFO info;
+ std::string error;
+};
+
+} // namespace AUTH_BY
+} // namespace STG
+
+#endif
#include <strings.h>
+using namespace STG;
+
PARSER_CHECK_USER::PARSER_CHECK_USER()
: callback(NULL),
data(NULL),
#include <strings.h>
+using namespace STG;
+
PARSER_CHG_USER::PARSER_CHG_USER()
: callback(NULL),
data(NULL),
#include <strings.h>
+using namespace STG;
+
template <>
bool GetValue<PARSER_GET_USER::STAT>(const char ** attr, PARSER_GET_USER::STAT & value)
{
#include <strings.h>
+using namespace STG;
+
PARSER_GET_USERS::PARSER_GET_USERS()
: callback(NULL),
data(NULL),
#include <strings.h>
+using namespace STG;
+
PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE()
: callback(NULL),
data(NULL),
#include <strings.h>
+using namespace STG;
+
namespace
{
#include "stg/servconf.h"
#include "netunit.h"
-#include "stg/servconf_types.h"
+#include "parser_auth_by.h"
#include "stg/common.h"
#include <expat.h>
+using namespace STG;
+
class SERVCONF::IMPL
{
public:
int GetUsers(PARSER_GET_USERS::CALLBACK f, void * data);
int GetUser(const std::string & login, PARSER_GET_USER::CALLBACK f, void * data);
int ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f, void * data);
- int AuthBy(const std::string & login, PARSER_AUTH_BY::CALLBACK f, void * data);
+ int AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data);
int SendMessage(const std::string & request, PARSER_SEND_MESSAGE::CALLBACK f, void * data);
int ServerInfo(PARSER_SERVER_INFO::CALLBACK f, void * data);
int CheckUser(const std::string & login, const std::string & password, PARSER_CHECK_USER::CALLBACK f, void * data);
private:
PARSER_GET_USERS parserGetUsers;
PARSER_GET_USER parserGetUser;
- PARSER_AUTH_BY parserAuthBy;
+ AUTH_BY::PARSER parserAuthBy;
PARSER_SERVER_INFO parserServerInfo;
PARSER_CHG_USER parserChgUser;
PARSER_CHECK_USER parserCheckUser;
static bool AnsRecv(void * data, const std::string & chunk, bool final);
};
-/*namespace
-{
-
-void ElementStart(void * data, const char * el, const char ** attr)
-{
-static_cast<SERVCONF::IMPL *>(data)->Start(el, attr);
-}
-
-void ElementEnd(void * data, const char * el)
-{
-static_cast<SERVCONF::IMPL *>(data)->End(el);
-}
-
-} // namespace anonymous
-*/
-
bool SERVCONF::IMPL::AnsRecv(void * data, const std::string & chunk, bool final)
{
SERVCONF::IMPL * sc = static_cast<SERVCONF::IMPL *>(data);
return pImpl->ChgUser(request, f, data);
}
-int SERVCONF::AuthBy(const std::string & login, PARSER_AUTH_BY::CALLBACK f, void * data)
+int SERVCONF::AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data)
{
return pImpl->AuthBy(login, f, data);
}
return Exec("<GetUser login=\"" + login + "\"/>", parserGetUser);
}
//-----------------------------------------------------------------------------
-int SERVCONF::IMPL::AuthBy(const std::string & login, PARSER_AUTH_BY::CALLBACK f, void * data)
+int SERVCONF::IMPL::AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data)
{
parserAuthBy.SetCallback(f, data);
return Exec("<GetUserAuthBy login=\"" + login + "\"/>", parserAuthBy);