parser_get_user.cpp \
parser_get_users.cpp \
parser_chg_user.cpp \
+ parser_send_message.cpp \
servconf.cpp
INCS = servconf.h \
--- /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_SEND_MESSAGE_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_SEND_MESSAGE_H__
+
+#include "parser.h"
+
+class PARSER_SEND_MESSAGE: public PARSER
+{
+public:
+ typedef int (* CALLBACK)(const char * answer, void * data);
+
+ PARSER_SEND_MESSAGE();
+ 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);
+};
+
+#endif
#include "stg/parser_get_user.h"
#include "stg/parser_get_users.h"
#include "stg/parser_chg_user.h"
+#include "stg/parser_send_message.h"
#include "stg/os_int.h"
#include "stg/const.h"
#define MAX_ERR_STR_LEN (64)
#define IP_STRING_LEN (255)
-//-----------------------------------------------------------------------------
-typedef int (* RecvSendMessageCb_t)(const char * answer, void * data);
-//-----------------------------------------------------------------------------
+
struct ADMINDATA
{
char login[ADM_LOGIN_LEN];
};
//-----------------------------------------------------------------------------
-class PARSER_SEND_MESSAGE: public PARSER
-{
-public:
- PARSER_SEND_MESSAGE();
- int ParseStart(const char * el, const char ** attr);
- void ParseEnd(const char * el);
- void ParseAnswer(const char * el, const char ** attr);
- void SetSendMessageRecvCb(RecvSendMessageCb_t, void * data);
-private:
- RecvSendMessageCb_t RecvSendMessageCb;
- void * sendMessageCbData;
- int depth;
-};
-//-----------------------------------------------------------------------------
class SERVCONF
{
public:
void SetChgUserCallback(PARSER_CHG_USER::CALLBACK f, void * data);
void SetCheckUserCallback(PARSER_CHECK_USER::CALLBACK f, void * data);
void SetGetUserCallback(PARSER_GET_USER::CALLBACK f, void * data);
- void SetSendMessageCb(RecvSendMessageCb_t, void * data);
+ void SetSendMessageCallback(PARSER_SEND_MESSAGE::CALLBACK f, void * data);
int GetUsers();
int GetUser(const char * login);
int ChgUser(const char * request);
int AuthBy(const char * login);
- // TODO: Remove this shit!
- int MsgUser(const char * request);
- int SendMessage(const char * login, const char * message, int prio);
+ int SendMessage(const char * request);
int ServerInfo();
int CheckUser(const char * login, const char * password);
std::string errorMsg;
XML_Parser parser;
- RecvSendMessageCb_t RecvSendMessageCb;
-
- void * sendMessageDataCb;
-
int Exec(const char * request);
friend int AnsRecv(void * data, std::list<std::string> * list);
using namespace std;
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE()
- : RecvSendMessageCb(NULL),
- sendMessageCbData(NULL),
- depth(0)
-{
-}
-//-----------------------------------------------------------------------------
-int PARSER_SEND_MESSAGE::ParseStart(const char *el, const char **attr)
-{
-depth++;
-if (depth == 1)
- {
- if (strcasecmp(el, "SendMessageResult") == 0)
- {
- ParseAnswer(el, attr);
- }
- }
-return 0;
-}
-//-----------------------------------------------------------------------------
-void PARSER_SEND_MESSAGE::ParseEnd(const char *)
-{
-depth--;
-}
-//-----------------------------------------------------------------------------
-void PARSER_SEND_MESSAGE::ParseAnswer(const char *, const char **attr)
-{
-if (RecvSendMessageCb)
- RecvSendMessageCb(attr[1], sendMessageCbData);
-}
-//-----------------------------------------------------------------------------
-void PARSER_SEND_MESSAGE::SetSendMessageRecvCb(RecvSendMessageCb_t f, void * data)
-{
-RecvSendMessageCb = f;
-sendMessageCbData = data;
-}
-//-----------------------------------------------------------------------------
--- /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>
+ */
+
+#include "stg/parser_send_message.h"
+
+#include <cstddef>
+
+#include <strings.h>
+
+PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE()
+ : callback(NULL),
+ data(NULL),
+ depth(0)
+{
+}
+//-----------------------------------------------------------------------------
+int PARSER_SEND_MESSAGE::ParseStart(const char * el, const char ** attr)
+{
+depth++;
+if (depth == 1)
+ if (strcasecmp(el, "SendMessageResult") == 0)
+ ParseAnswer(el, attr);
+return 0;
+}
+//-----------------------------------------------------------------------------
+void PARSER_SEND_MESSAGE::ParseEnd(const char * /*el*/)
+{
+depth--;
+}
+//-----------------------------------------------------------------------------
+void PARSER_SEND_MESSAGE::ParseAnswer(const char * /*el*/, const char **attr)
+{
+if (attr && attr[0] && attr[1])
+ if (callback)
+ callback(attr[1], data);
+}
+//-----------------------------------------------------------------------------
+void PARSER_SEND_MESSAGE::SetCallback(CALLBACK f, void * d)
+{
+callback = f;
+data = d;
+}
currParser = &parserGetUsers;
-return Exec(request);
-}
-//-----------------------------------------------------------------------------
-int SERVCONF::SendMessage(const char * login, const char * message, int prio)
-{
-char request[1000];
-char msg[500];
-Encode12(msg, message, strlen(message));
-snprintf(request, 1000, "<Message login=\"%s\" priority=\"%d\" text=\"%s\"/>", login, prio, msg);
-
-currParser = &parserSendMessage;
-parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb);
-
return Exec(request);
}
//-----------------------------------------------------------------------------
return Exec(request);
}
//-----------------------------------------------------------------------------
-// TODO: remove this shit!
-//-----------------------------------------------------------------------------
-int SERVCONF::MsgUser(const char * request)
+int SERVCONF::SendMessage(const char * request)
{
currParser = &parserSendMessage;
-parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb);
return Exec(request);
}
return Exec(request);
}
//-----------------------------------------------------------------------------
-int SERVCONF::Start(const char *el, const char **attr)
+int SERVCONF::Start(const char * el, const char ** attr)
{
currParser->ParseStart(el, attr);
return 0;
}
//-----------------------------------------------------------------------------
-void SERVCONF::End(const char *el)
+void SERVCONF::End(const char * el)
{
currParser->ParseEnd(el);
}
parserCheckUser.SetCallback(f, data);
}
//-----------------------------------------------------------------------------
-void SERVCONF::SetSendMessageCb(RecvSendMessageCb_t f, void * data)
+void SERVCONF::SetSendMessageCallback(PARSER_SEND_MESSAGE::CALLBACK f, void * data)
{
-RecvSendMessageCb = f;
-sendMessageDataCb = data;
+parserSendMessage.SetCallback(f, data);
}
//-----------------------------------------------------------------------------
const std::string & SERVCONF::GetStrError() const