]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/sgconfig-ng/config_thread.h
Merge branch 'naffanya-dev'
[stg.git] / projects / stargazer / plugins / configuration / sgconfig-ng / config_thread.h
1 #ifndef __CONFIG_THREAD_H__
2 #define __CONFIG_THREAD_H__
3
4 #include <arpa/inet.h>
5 #include <openssl/blowfish.h>
6
7 class ADMINS;
8 class ADMIN;
9 class TARIFFS;
10 class USERS;
11 class SETTINGS;
12
13 namespace boost {
14     class mutex;
15 };
16
17 class CONFIG_THREAD {
18 public:
19     CONFIG_THREAD(ADMINS * , TARIFFS * t, USERS * u, const SETTINGS * s);
20     CONFIG_THREAD(const CONFIG_THREAD & rvalue);
21     ~CONFIG_THREAD();
22
23
24     void operator() ();
25
26     void SetConnection(int sock, struct sockaddr_in sin);
27     bool IsDone() const;
28
29     enum {ST_NOOP, ST_OK, ST_ERROR};
30
31 private:
32     int sd;
33     struct sockaddr_in remoteAddr;
34     bool done;
35     int state;
36     uint16_t versionMinor;
37     uint16_t versionMajor;
38     std::string message;
39     std::string login;
40     std::string password;
41     std::string xml;
42     uint32_t respCode;
43
44     BF_KEY key;
45     unsigned char * iv;
46
47     ADMINS * admins;
48     TARIFFS * tariffs;
49     USERS * users;
50     const SETTINGS * settings;
51     const ADMIN * currAdmin;
52
53     mutable boost::mutex mutex;
54
55     bool ReadBlock(void * dest, size_t & size, int timeout) const;
56     bool WriteBlock(const void * source, size_t & size, int timeout) const;
57
58     bool ReadReq();
59     void Process();
60     void WriteResp() const;
61     //void MakeErrorXML();
62
63     bool CheckLogin(const std::string & login, std::string & password);
64     bool ReceiveData();
65     void SendData() const;
66
67     static void TagBegin(void * userData, const char * name, const char ** attr);
68     static void TagEnd(void * userData, const char * name);
69
70
71     CONFIG_THREAD & operator=(const CONFIG_THREAD & rvalue);
72 };
73
74 #endif