]> git.stg.codes - stg.git/blob - stglibs/srvconf.lib/netunit.h
В библиотеке поддержки протокола консольного конфигуратора еще пару
[stg.git] / stglibs / srvconf.lib / netunit.h
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  */
20
21  /*
22  $Revision: 1.6 $
23  $Date: 2010/02/11 12:32:53 $
24  $Author: faust $
25  */
26
27 #ifndef NetUnitH
28 #define NetUnitH
29
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33
34 #include <list>
35 #include <string>
36
37 #include "common.h"
38 #include "blowfish.h"
39
40 #define  STG_HEADER     "SG04"
41 #define  OK_HEADER      "OKHD"
42 #define  ERR_HEADER     "ERHD"
43 #define  OK_LOGIN       "OKLG"
44 #define  ERR_LOGIN      "ERLG"
45 #define  OK_LOGINS      "OKLS"
46 #define  ERR_LOGINS     "ERLS"
47
48 // äÌÉÎÎÁ ÛÉÆÒÕÅÍÏÇÏ É ÐÅÒÅÄÁ×ÁÅÍÏÇ ÚÁ ÏÄÉΠÒÁÚ ÂÌÏËÁ ÉÎÆÏÒÍÁÃÉÉ
49 #define  ENC_MSG_LEN    (8)
50
51 #define MAX_ERR_STR_LEN (64)
52
53 typedef int(*RxCallback_t)(void *, std::list<std::string> *);
54
55 enum status
56 {
57 st_ok = 0,
58 st_conn_fail,
59 st_send_fail,
60 st_recv_fail,
61 st_header_err,
62 st_login_err,
63 st_logins_err,
64 st_data_err,
65 st_unknown_err,
66 st_dns_err,
67 st_xml_parse_error,
68 st_data_error
69 };
70
71 enum CONF_STATE
72 {
73 confHdr = 0,
74 confLogin,
75 confLoginCipher,
76 confData
77 };
78 //---------------------------------------------------------------------------
79 class NETTRANSACT
80 {
81 public:
82     NETTRANSACT();
83     int     Transact(const char * data);
84     const std::string & GetError() const;
85
86     void    SetRxCallback(void * data, RxCallback_t);
87
88     void    SetServer(const char * serverName);
89     void    SetServerPort(short unsigned p);
90
91     void    SetLogin(const char * l);
92     void    SetPassword(const char * p);
93     ////////////////////////////////////////////
94     int     Connect();
95     int     Disconnect();
96     void    Reset();
97 private:
98     int     TxHeader();
99     int     RxHeaderAnswer();
100
101     int     TxLogin();
102     int     RxLoginAnswer();
103
104     int     TxLoginS();
105     int     RxLoginSAnswer();
106
107     int     TxData(const char * text);
108     int     TxData(char * data);
109     int     RxDataAnswer();
110
111     void Encrypt(char * d, const char * s, BLOWFISH_CTX *ctx);
112     void EnDecryptInit(const char * passwd, int passwdLen, BLOWFISH_CTX *ctx);
113     void Decrypt(char * d, const char * s, BLOWFISH_CTX *ctx);
114
115     std::string server;
116     short unsigned  port;
117     std::string login;
118     std::string password;
119     int     outerSocket;
120     std::list<std::string>   answerList;
121     RxCallback_t RxCallBack;
122     void *  dataRxCallBack;
123     std::string errorMsg;
124 };
125 //---------------------------------------------------------------------------
126 #endif