X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/641204dfbdb9fc870cdd2e7f9e3169a44693e7bf..c94bf8a43922c544b485e50ea1f37f41a45821f5:/projects/stargazer/plugins/other/userstat/datathread.h?ds=inline

diff --git a/projects/stargazer/plugins/other/userstat/datathread.h b/projects/stargazer/plugins/other/userstat/datathread.h
index cd9a87b6..4371516e 100644
--- a/projects/stargazer/plugins/other/userstat/datathread.h
+++ b/projects/stargazer/plugins/other/userstat/datathread.h
@@ -1,58 +1,87 @@
 #ifndef __DATATHREAD_H__
 #define __DATATHREAD_H__
 
-#include "../../../users.h"
-#include "base_store.h"
-#include <pthread.h>
+#include <map>
+#include <string>
+
 #include <expat.h>
+#include <pthread.h>
+
+#include "common.h"
+#include "../../../users.h"
+
+uint32_t n2l(unsigned char * c)
+{
+    uint32_t t = *c++ << 24;
+    t += *c++ << 16;
+    t += *c++ << 8;
+    t += *c;
+    return t;
+}
+
+void l2n(uint32_t t, unsigned char * c)
+{
+    *c++ = t >> 24 & 0x000000FF;
+    *c++ = t >> 16 & 0x000000FF;
+    *c++ = t >> 8 & 0x000000FF;
+    *c++ = t & 0x000000FF;
+}
+
+typedef std::map<std::string, std::string> PV_LIST;
 
 class DataThread {
 public:
-    DataThread() : done(false), sock(-1) { Init(); };
-    DataThread(USERS * u, BASE_STORE * s, int sd)
-        : users(u),
-          store(s),
-          sock(sd),
-          done(false)
-    {
-        Init();
-    };
+    DataThread();
     ~DataThread();
 
     void SetUsers(USERS * u) { users = u; };
     void SetStore(BASE_STORE * s) { store = s; };
-    void SetSocket(int s) { sock = s; };
 
     bool isDone() const { return done; };
-    bool Init();
-
-    bool Start();
-    bool Stop();
-
-    static void * Run(void *);
 
+    bool Handle(int s);
 
+    friend void DTXMLStart(void * data, const char * name, const char ** attr);
+    friend void DTXMLEnd(void * data, const char * name);
 private:
-    pthread_t thread;
+    pthread_t tid;
     USERS * users;
     BASE_STORE * store;
-    XML_Parser parser;
     int sock;
     bool done;
-    bool running;
-    bool stopped;
-    BLOWFISH_CTX ctx;
-    std::string password;
-    std::string reply;
-
-    void Handle();
-    bool PrepareContect();
-    void Encode(const std::string &, char *);
-    void Decode(char *, const std::string &);
-
-    friend void StartHandler(void *data, const char *el, const char **attr);
-    friend void EndHandler(void *data, const char *el);
-    friend void DataHandler(void *data, const char *el);
+    struct Request {
+        PV_LIST conf;
+        PV_LIST stat;
+        std::string login;
+        bool isOk;
+        bool isBad;
+    } request;
+    PV_LIST * pvList;
+    char * data;
+    int32_t dataSize;
+
+    std::string login;
+    user_iter uit;
+
+    XML_Parser xmlParser;
+
+    static void * Run(void * self);
+
+    bool ReadRequest();
+    bool DecodeRequest();
+    bool ParseRequest();
+    bool MakeAnswer();
+
+    bool MakeConf();
+    bool MakeStat();
+    bool SendAnswer();
+
+    void Cleanup();
+
+    void ParseTag(const std::string & name, const char ** attr);
 };
 
+void DTXMLStart(void * data, const char * name, const char ** attr);
+void DTXMLEnd(void * data, const char * name);
+
 #endif