]> git.stg.codes - stg.git/blobdiff - stglibs/srvconf.lib/netunit.h
Merge branch 'stg-2.409-radius'
[stg.git] / stglibs / srvconf.lib / netunit.h
index 6b6cef53d12a9a7ac0dc63aab94f439bb21553c7..ca13bbc867b83bc611607f7e6e57a934d4f23811 100644 (file)
  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
  */
 
- /*
- $Revision: 1.6 $
- $Date: 2010/02/11 12:32:53 $
- $Author: faust $
- */
-
 #ifndef NetUnitH
 #define NetUnitH
 
 
 #include <string>
 
-typedef bool (* RxCallback_t)(void *, const std::string &, bool);
+namespace STG
+{
 
-//---------------------------------------------------------------------------
 class NETTRANSACT
 {
 public:
+    typedef bool (* CALLBACK)(const std::string &, bool, void *);
+
+    NETTRANSACT(const std::string & server, uint16_t port,
+                const std::string & login, const std::string & password);
     NETTRANSACT(const std::string & server, uint16_t port,
+                const std::string & localAddress, uint16_t localPort,
                 const std::string & login, const std::string & password);
-    int     Transact(const char * data);
+    ~NETTRANSACT();
+    int Transact(const std::string & request, CALLBACK f, void * data);
     const std::string & GetError() const { return errorMsg; }
 
-    void    SetRxCallback(void * data, RxCallback_t cb);
-    RxCallback_t GetRxCallback() const { return dataRxCallBack; }
-
-    int     Connect();
-    int     Disconnect();
+    int  Connect();
+    void Disconnect();
 private:
-    int     TxHeader();
-    int     RxHeaderAnswer();
+    int  TxHeader();
+    int  RxHeaderAnswer();
 
-    int     TxLogin();
-    int     RxLoginAnswer();
+    int  TxLogin();
+    int  RxLoginAnswer();
 
-    int     TxLoginS();
-    int     RxLoginSAnswer();
+    int  TxLoginS();
+    int  RxLoginSAnswer();
 
-    int     TxData(const char * text);
-    int     TxData(char * data);
-    int     RxDataAnswer();
+    int  TxData(const std::string & text);
+    int  RxDataAnswer(CALLBACK f, void * data);
 
     std::string server;
     uint16_t  port;
+    std::string localAddress;
+    uint16_t localPort;
     std::string login;
     std::string password;
-    int outerSocket;
-    RxCallback_t RxCallBack;
-    void * dataRxCallBack;
+    int sock;
     std::string errorMsg;
+
+    static bool TxCrypto(const void * block, size_t size, void * data);
+    static bool RxCrypto(const void * block, size_t size, void * data);
 };
-//---------------------------------------------------------------------------
+
+} // namespace STG
+
 #endif