summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
3b56895)
протокола конфигуратора, строковые данные представлены строками C++ а не
обычными строками C как ранее
*/
//---------------------------------------------------------------------------
*/
//---------------------------------------------------------------------------
-#include <stdio.h>
-#include <string.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <unistd.h>
+#include <cstdio>
+#include <cstring>
+
#include "netunit.h"
#include "common.h"
#include "netunit.h"
#include "common.h"
RxCallBack(NULL),
dataRxCallBack(NULL)
{
RxCallBack(NULL),
dataRxCallBack(NULL)
{
- memset(server, 0, SERVER_NAME_LEN);
memset(login, 0, ADM_LOGIN_LEN);
memset(password, 0, ADM_PASSWD_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)
{
}
//-----------------------------------------------------------------------------
void NETTRANSACT::EnDecryptInit(const char * passwd, int, BLOWFISH_CTX *ctx)
{
-unsigned char * keyL = NULL; // ��� ������
+unsigned char * keyL = NULL;
keyL = new unsigned char[PASSWD_LEN];
keyL = new unsigned char[PASSWD_LEN];
outerSocket = socket(PF_INET, SOCK_STREAM, 0);
if (outerSocket < 0)
{
outerSocket = socket(PF_INET, SOCK_STREAM, 0);
if (outerSocket < 0)
{
- strcpy(errorMsg, CREATE_SOCKET_ERROR);
+ errorMsg = CREATE_SOCKET_ERROR;
struct hostent * phe;
unsigned long ip;
struct hostent * phe;
unsigned long ip;
+ip = inet_addr(server.c_str());
- phe = gethostbyname(server);
+ phe = gethostbyname(server.c_str());
- sprintf(errorMsg, "DNS error.\nCan not reslove %s", server);
+ errorMsg = "DNS error.\nCan not reslove " + server;
- strcpy(errorMsg, CONNECT_FAILED);
+ errorMsg = CONNECT_FAILED;
close(outerSocket);
return st_conn_fail;
}
close(outerSocket);
return st_conn_fail;
}
ret = send(outerSocket, STG_HEADER, strlen(STG_HEADER), 0);
if (ret <= 0)
{
ret = send(outerSocket, STG_HEADER, strlen(STG_HEADER), 0);
if (ret <= 0)
{
- strcpy(errorMsg, SEND_HEADER_ERROR);
+ errorMsg = SEND_HEADER_ERROR;
ret = recv(outerSocket, buffer, strlen(OK_HEADER), 0);
if (ret <= 0)
{
ret = recv(outerSocket, buffer, strlen(OK_HEADER), 0);
if (ret <= 0)
{
- strcpy(errorMsg, RECV_HEADER_ANSWER_ERROR);
+ errorMsg = RECV_HEADER_ANSWER_ERROR;
{
if (strncmp(ERR_HEADER, buffer, strlen(ERR_HEADER)) == 0)
{
{
if (strncmp(ERR_HEADER, buffer, strlen(ERR_HEADER)) == 0)
{
- strcpy(errorMsg, INCORRECT_HEADER);
+ errorMsg = INCORRECT_HEADER;
return st_header_err;
}
else
{
return st_header_err;
}
else
{
- strcpy(errorMsg, UNKNOWN_ERROR);
+ errorMsg = UNKNOWN_ERROR;
return st_unknown_err;
}
}
return st_unknown_err;
}
}
- strcpy(errorMsg, SEND_LOGIN_ERROR);
+ errorMsg = SEND_LOGIN_ERROR;
int NETTRANSACT::RxLoginAnswer()
{
char buffer[sizeof(OK_LOGIN)+1];
int NETTRANSACT::RxLoginAnswer()
{
char buffer[sizeof(OK_LOGIN)+1];
ret = recv(outerSocket, buffer, strlen(OK_LOGIN), 0);
if (ret <= 0)
{
ret = recv(outerSocket, buffer, strlen(OK_LOGIN), 0);
if (ret <= 0)
{
- strcpy(errorMsg, RECV_LOGIN_ANSWER_ERROR);
+ errorMsg = RECV_LOGIN_ANSWER_ERROR;
{
if (strncmp(ERR_LOGIN, buffer, strlen(ERR_LOGIN)) == 0)
{
{
if (strncmp(ERR_LOGIN, buffer, strlen(ERR_LOGIN)) == 0)
{
- strcpy(errorMsg, INCORRECT_LOGIN);
+ errorMsg = INCORRECT_LOGIN;
return st_login_err;
}
else
{
return st_login_err;
}
else
{
- strcpy(errorMsg, UNKNOWN_ERROR);
+ errorMsg = UNKNOWN_ERROR;
return st_unknown_err;
}
}
return st_unknown_err;
}
}
ret = send(outerSocket, ct, ENC_MSG_LEN, 0);
if (ret <= 0)
{
ret = send(outerSocket, ct, ENC_MSG_LEN, 0);
if (ret <= 0)
{
- strcpy(errorMsg, SEND_LOGIN_ERROR);
+ errorMsg = SEND_LOGIN_ERROR;
ret = recv(outerSocket, buffer, strlen(OK_LOGINS), 0);
if (ret <= 0)
{
ret = recv(outerSocket, buffer, strlen(OK_LOGINS), 0);
if (ret <= 0)
{
- strcpy(errorMsg, RECV_LOGIN_ANSWER_ERROR);
+ errorMsg = RECV_LOGIN_ANSWER_ERROR;
{
if (strncmp(ERR_LOGINS, buffer, strlen(ERR_LOGINS)) == 0)
{
{
if (strncmp(ERR_LOGINS, buffer, strlen(ERR_LOGINS)) == 0)
{
- strcpy(errorMsg, INCORRECT_LOGIN);
+ errorMsg = INCORRECT_LOGIN;
return st_logins_err;
}
else
{
return st_logins_err;
}
else
{
- strcpy(errorMsg, UNKNOWN_ERROR);
+ errorMsg = UNKNOWN_ERROR;
return st_unknown_err;
}
}
return st_unknown_err;
}
}
ret = send(outerSocket, ct, ENC_MSG_LEN, 0);
if (ret <= 0)
{
ret = send(outerSocket, ct, ENC_MSG_LEN, 0);
if (ret <= 0)
{
- strcpy(errorMsg, SEND_DATA_ERROR);
+ errorMsg = SEND_DATA_ERROR;
ret = send(outerSocket, ct, ENC_MSG_LEN, 0);
if (ret <= 0)
{
ret = send(outerSocket, ct, ENC_MSG_LEN, 0);
if (ret <= 0)
{
- strcpy(errorMsg, SEND_DATA_ERROR);
+ errorMsg = SEND_DATA_ERROR;
if (ret <= 0)
{
close(outerSocket);
if (ret <= 0)
{
close(outerSocket);
- strcpy(errorMsg, RECV_DATA_ANSWER_ERROR);
+ errorMsg = RECV_DATA_ANSWER_ERROR;
//---------------------------------------------------------------------------
void NETTRANSACT::SetServer(const char * serverName)
{
//---------------------------------------------------------------------------
void NETTRANSACT::SetServer(const char * serverName)
{
-strncpy(server, serverName, SERVER_NAME_LEN);
}
//---------------------------------------------------------------------------
void NETTRANSACT::SetServerPort(short unsigned p)
}
//---------------------------------------------------------------------------
void NETTRANSACT::SetServerPort(short unsigned p)
dataRxCallBack = data;
}
//---------------------------------------------------------------------------
dataRxCallBack = data;
}
//---------------------------------------------------------------------------
-char * NETTRANSACT::GetError()
+const std::string & NETTRANSACT::GetError() const
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <list>
#include <string>
#include <list>
#include <string>
public:
NETTRANSACT();
int Transact(const char * data);
public:
NETTRANSACT();
int Transact(const char * data);
+ const std::string & GetError() const;
void SetRxCallback(void * data, RxCallback_t);
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);
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];
short unsigned port;
char login[ADM_LOGIN_LEN];
char password[ADM_PASSWD_LEN];
short unsigned port;
char login[ADM_LOGIN_LEN];
char password[ADM_PASSWD_LEN];
std::list<std::string> answerList;
RxCallback_t RxCallBack;
void * dataRxCallBack;
std::list<std::string> answerList;
RxCallback_t RxCallBack;
void * dataRxCallBack;
- char errorMsg[MAX_ERR_STR_LEN];
};
//---------------------------------------------------------------------------
#endif
};
//---------------------------------------------------------------------------
#endif
-#include <stdio.h>
-#include <string.h>
+#include <cstdio>
+#include <cstring>
if (XML_Parse(sc->parser, ans, len, done) == XML_STATUS_ERROR)
{
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;
return st_xml_parse_error;
}
++node;
if ((ret = nt.Connect()) != st_ok)
{
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)
{
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)
{
return ret;
}
if ((ret = nt.Disconnect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
if ((ret = nt.Connect()) != st_ok)
{
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)
{
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)
{
return ret;
}
if ((ret = nt.Disconnect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
if ((ret = nt.Connect()) != st_ok)
{
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)
{
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)
{
return ret;
}
if ((ret = nt.Disconnect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
if ((ret = nt.Connect()) != st_ok)
{
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)
{
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)
{
return ret;
}
if ((ret = nt.Disconnect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
if ((ret = nt.Connect()) != st_ok)
{
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)
{
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)
{
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();
if ((ret = nt.Connect()) != st_ok)
{
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)
{
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)
{
return ret;
}
if ((ret = nt.Disconnect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
if ((ret = nt.Connect()) != st_ok)
{
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)
{
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)
{
return ret;
}
if ((ret = nt.Disconnect()) != st_ok)
{
- strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN);
+ errorMsg = nt.GetError();
sendMessageDataCb = data;
}
//-----------------------------------------------------------------------------
sendMessageDataCb = data;
}
//-----------------------------------------------------------------------------
-char * SERVCONF::GetStrError()
+const std::string & SERVCONF::GetStrError() const
int GetServerInfo();
int CheckUser(const char * login, const char * password);
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 Start(const char *el, const char **attr);
void End(const char *el);
int parseDepth;
USERDATA ud;
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;
RecvUserDataCb_t RecvUserDataCb;
RecvUserDataCb_t RecvGetUserDataCb;