]> git.stg.codes - stg.git/blob - stglibs/srvconf.lib/include/stg/netunit.h
Fixed compilation of srvconf lib.
[stg.git] / stglibs / srvconf.lib / include / stg / 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 "stg/blowfish.h"
38
39 #define  STG_HEADER     "SG04"
40 #define  OK_HEADER      "OKHD"
41 #define  ERR_HEADER     "ERHD"
42 #define  OK_LOGIN       "OKLG"
43 #define  ERR_LOGIN      "ERLG"
44 #define  OK_LOGINS      "OKLS"
45 #define  ERR_LOGINS     "ERLS"
46
47 // äÌÉÎÎÁ ÛÉÆÒÕÅÍÏÇÏ É ÐÅÒÅÄÁ×ÁÅÍÏÇ ÚÁ ÏÄÉΠÒÁÚ ÂÌÏËÁ ÉÎÆÏÒÍÁÃÉÉ
48 #define  ENC_MSG_LEN    (8)
49
50 #define MAX_ERR_STR_LEN (64)
51
52 typedef int(*RxCallback_t)(void *, std::list<std::string> *);
53
54 enum status
55 {
56 st_ok = 0,
57 st_conn_fail,
58 st_send_fail,
59 st_recv_fail,
60 st_header_err,
61 st_login_err,
62 st_logins_err,
63 st_data_err,
64 st_unknown_err,
65 st_dns_err,
66 st_xml_parse_error,
67 st_data_error
68 };
69
70 enum CONF_STATE
71 {
72 confHdr = 0,
73 confLogin,
74 confLoginCipher,
75 confData
76 };
77 //---------------------------------------------------------------------------
78 class NETTRANSACT
79 {
80 public:
81     NETTRANSACT();
82     int     Transact(const char * data);
83     const std::string & GetError() const;
84
85     void    SetRxCallback(void * data, RxCallback_t);
86
87     void    SetServer(const char * serverName);
88     void    SetServerPort(short unsigned p);
89
90     void    SetLogin(const char * l);
91     void    SetPassword(const char * p);
92     ////////////////////////////////////////////
93     int     Connect();
94     int     Disconnect();
95     void    Reset();
96 private:
97     int     TxHeader();
98     int     RxHeaderAnswer();
99
100     int     TxLogin();
101     int     RxLoginAnswer();
102
103     int     TxLoginS();
104     int     RxLoginSAnswer();
105
106     int     TxData(const char * text);
107     int     RxDataAnswer();
108
109     std::string server;
110     short unsigned  port;
111     std::string login;
112     std::string password;
113     int     outerSocket;
114     std::list<std::string>   answerList;
115     RxCallback_t RxCallBack;
116     void *  dataRxCallBack;
117     std::string errorMsg;
118 };
119 //---------------------------------------------------------------------------
120 #endif