*/
//---------------------------------------------------------------------------
-#include <stdio.h>
-#include <string.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <unistd.h>
+#include <cstdio>
+#include <cstring>
+
#include "netunit.h"
#include "common.h"
RxCallBack(NULL),
dataRxCallBack(NULL)
{
- memset(server, 0, SERVER_NAME_LEN);
memset(login, 0, ADM_LOGIN_LEN);
memset(password, 0, ADM_PASSWD_LEN);
- memset(errorMsg, 0, MAX_ERR_STR_LEN);
}
//-----------------------------------------------------------------------------
void NETTRANSACT::EnDecryptInit(const char * passwd, int, BLOWFISH_CTX *ctx)
{
-unsigned char * keyL = NULL; // ��� ������
+unsigned char * keyL = NULL;
keyL = new unsigned char[PASSWD_LEN];
outerSocket = socket(PF_INET, SOCK_STREAM, 0);
if (outerSocket < 0)
{
- strcpy(errorMsg, CREATE_SOCKET_ERROR);
+ errorMsg = CREATE_SOCKET_ERROR;
return st_conn_fail;
}
struct hostent * phe;
unsigned long ip;
-ip = inet_addr(server);
+ip = inet_addr(server.c_str());
if (ip == INADDR_NONE)
{
- phe = gethostbyname(server);
+ phe = gethostbyname(server.c_str());
if (phe == NULL)
{
- sprintf(errorMsg, "DNS error.\nCan not reslove %s", server);
+ errorMsg = "DNS error.\nCan not reslove " + server;
return st_dns_err;
}
if (ret < 0)
{
- strcpy(errorMsg, CONNECT_FAILED);
+ errorMsg = CONNECT_FAILED;
close(outerSocket);
return st_conn_fail;
}
ret = send(outerSocket, STG_HEADER, strlen(STG_HEADER), 0);
if (ret <= 0)
{
- strcpy(errorMsg, SEND_HEADER_ERROR);
+ errorMsg = SEND_HEADER_ERROR;
return st_send_fail;
}
ret = recv(outerSocket, buffer, strlen(OK_HEADER), 0);
if (ret <= 0)
{
- strcpy(errorMsg, RECV_HEADER_ANSWER_ERROR);
+ errorMsg = RECV_HEADER_ANSWER_ERROR;
return st_recv_fail;
}
{
if (strncmp(ERR_HEADER, buffer, strlen(ERR_HEADER)) == 0)
{
- strcpy(errorMsg, INCORRECT_HEADER);
+ errorMsg = INCORRECT_HEADER;
return st_header_err;
}
else
{
- strcpy(errorMsg, UNKNOWN_ERROR);
+ errorMsg = UNKNOWN_ERROR;
return st_unknown_err;
}
}
if (ret <= 0)
{
- strcpy(errorMsg, SEND_LOGIN_ERROR);
+ errorMsg = SEND_LOGIN_ERROR;
return st_send_fail;
}
int NETTRANSACT::RxLoginAnswer()
{
char buffer[sizeof(OK_LOGIN)+1];
-int ret;//, we;
+int ret;
ret = recv(outerSocket, buffer, strlen(OK_LOGIN), 0);
if (ret <= 0)
{
- strcpy(errorMsg, RECV_LOGIN_ANSWER_ERROR);
+ errorMsg = RECV_LOGIN_ANSWER_ERROR;
return st_recv_fail;
}
{
if (strncmp(ERR_LOGIN, buffer, strlen(ERR_LOGIN)) == 0)
{
- strcpy(errorMsg, INCORRECT_LOGIN);
+ errorMsg = INCORRECT_LOGIN;
return st_login_err;
}
else
{
- strcpy(errorMsg, UNKNOWN_ERROR);
+ errorMsg = UNKNOWN_ERROR;
return st_unknown_err;
}
}
ret = send(outerSocket, ct, ENC_MSG_LEN, 0);
if (ret <= 0)
{
- strcpy(errorMsg, SEND_LOGIN_ERROR);
+ errorMsg = SEND_LOGIN_ERROR;
return st_send_fail;
}
}
ret = recv(outerSocket, buffer, strlen(OK_LOGINS), 0);
if (ret <= 0)
{
- strcpy(errorMsg, RECV_LOGIN_ANSWER_ERROR);
+ errorMsg = RECV_LOGIN_ANSWER_ERROR;
return st_recv_fail;
}
{
if (strncmp(ERR_LOGINS, buffer, strlen(ERR_LOGINS)) == 0)
{
- strcpy(errorMsg, INCORRECT_LOGIN);
+ errorMsg = INCORRECT_LOGIN;
return st_logins_err;
}
else
{
- strcpy(errorMsg, UNKNOWN_ERROR);
+ errorMsg = UNKNOWN_ERROR;
return st_unknown_err;
}
}
ret = send(outerSocket, ct, ENC_MSG_LEN, 0);
if (ret <= 0)
{
- strcpy(errorMsg, SEND_DATA_ERROR);
+ errorMsg = SEND_DATA_ERROR;
return st_send_fail;
}
}
ret = send(outerSocket, ct, ENC_MSG_LEN, 0);
if (ret <= 0)
{
- strcpy(errorMsg, SEND_DATA_ERROR);
+ errorMsg = SEND_DATA_ERROR;
return st_send_fail;
}
if (ret <= 0)
{
close(outerSocket);
- strcpy(errorMsg, RECV_DATA_ANSWER_ERROR);
+ errorMsg = RECV_DATA_ANSWER_ERROR;
return st_recv_fail;
}
//---------------------------------------------------------------------------
void NETTRANSACT::SetServer(const char * serverName)
{
-strncpy(server, serverName, SERVER_NAME_LEN);
+server = serverName;
}
//---------------------------------------------------------------------------
void NETTRANSACT::SetServerPort(short unsigned p)
dataRxCallBack = data;
}
//---------------------------------------------------------------------------
-char * NETTRANSACT::GetError()
+const std::string & NETTRANSACT::GetError() const
{
return errorMsg;
}
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
+
#include <list>
#include <string>
public:
NETTRANSACT();
int Transact(const char * data);
- char *GetError();
+ const std::string & GetError() const;
void SetRxCallback(void * data, RxCallback_t);
void EnDecryptInit(const char * passwd, int passwdLen, BLOWFISH_CTX *ctx);
void Decrypt(char * d, const char * s, BLOWFISH_CTX *ctx);
- char server[SERVER_NAME_LEN];
+ std::string server;
short unsigned port;
char login[ADM_LOGIN_LEN];
char password[ADM_PASSWD_LEN];
std::list<std::string> answerList;
RxCallback_t RxCallBack;
void * dataRxCallBack;
- char errorMsg[MAX_ERR_STR_LEN];
+ std::string errorMsg;
};
//---------------------------------------------------------------------------
#endif
$Author: faust $
*/
-#include <stdio.h>
-#include <string.h>
+#include <cstdio>
+#include <cstring>
#include "servconf.h"
if (XML_Parse(sc->parser, ans, len, done) == XML_STATUS_ERROR)
{
- snprintf(sc->errorMsg, MAX_ERR_STR_LEN, "XML parse error at line %d: %s",
- static_cast<int>(XML_GetCurrentLineNumber(sc->parser)),
- XML_ErrorString(XML_GetErrorCode(sc->parser)));
- printf(sc->errorMsg, "XML parse error at line %d: %s",
- XML_GetCurrentLineNumber(sc->parser),
- XML_ErrorString(XML_GetErrorCode(sc->parser)));
+ strprintf(&sc->errorMsg, "XML parse error at line %d: %s",
+ static_cast<int>(XML_GetCurrentLineNumber(sc->parser)),
+ XML_ErrorString(XML_GetErrorCode(sc->parser)));
return st_xml_parse_error;
}
++node;
if ((ret = nt.Connect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Transact(request)) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Disconnect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Connect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Transact(request)) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Disconnect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Connect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Transact(request)) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Disconnect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Connect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Transact(request)) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Disconnect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Connect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
- printfd(__FILE__, "Error on connect: '%s'\n", errorMsg);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Transact(request)) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
- printfd(__FILE__, "Error on transact: '%s'\n", errorMsg);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Disconnect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
- printfd(__FILE__, "Error on disconnect: '%s'\n", errorMsg);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Connect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Transact(request)) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Disconnect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Connect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Transact(request)) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
if ((ret = nt.Disconnect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
return ret;
}
sendMessageDataCb = data;
}
//-----------------------------------------------------------------------------
-char * SERVCONF::GetStrError()
+const std::string & SERVCONF::GetStrError() const
{
return errorMsg;
}
int GetServerInfo();
int CheckUser(const char * login, const char * password);
- char * GetStrError();
- int GetError();
+ const std::string & GetStrError() const;
+ int GetError();
int Start(const char *el, const char **attr);
void End(const char *el);
int parseDepth;
USERDATA ud;
- char errorMsg[MAX_ERR_STR_LEN];
- int error;
- XML_Parser parser;
+ std::string errorMsg;
+ int error;
+ XML_Parser parser;
RecvUserDataCb_t RecvUserDataCb;
RecvUserDataCb_t RecvGetUserDataCb;