]> git.stg.codes - stg.git/blobdiff - projects/rlm_stg/stg_client.h
Implemented async parser in rlm_stg.
[stg.git] / projects / rlm_stg / stg_client.h
index 60ed6af899ac4bd780edb29f1f236dfe3e30b73c..ee15774f1a8b720b7243aab7c8908cd73bac4da8 100644 (file)
  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
  */
 
-/*
- *  Header file for client part of data access via Stargazer for RADIUS
- *
- *  $Revision: 1.4 $
- *  $Date: 2010/04/16 12:30:02 $
- *
- */
-
 #ifndef STG_CLIENT_H
 #define STG_CLIENT_H
 
-#include <string>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/socket.h> // socklen_t
-
-#include "blowfish.h"
-#include "rad_packets.h"
-
-class STG_CLIENT
-{
-public:
-    STG_CLIENT();
-    ~STG_CLIENT();
-
-    void SetServer(const std::string & host);
-    void SetPort(uint16_t port);
-    void SetLocalPort(uint16_t port);
-    void SetPassword(const std::string & password);
+#include "stg/os_int.h"
 
-    int Start();
-    int Stop();
+#include <boost/scoped_ptr.hpp>
 
-    std::string GetUserPassword() const;
+#include <string>
+#include <vector>
+#include <stdexcept>
 
-    int Authorize(const std::string & login, const std::string & svc);
-    int Authenticate(const std::string & login, const std::string & svc);
-    int PostAuthenticate(const std::string & login, const std::string & svc);
-    int Account(const std::string & type, const std::string & login, const std::string & svc, const std::string & sessid);
+typedef std::vector<std::pair<std::string, std::string> > PAIRS;
 
-    uint32_t GetFramedIP() const;
+struct RESULT
+{
+    PAIRS modify;
+    PAIRS reply;
+};
 
+struct ChannelConfig {
+    struct Error : std::runtime_error {
+        Error(const std::string& message) : runtime_error(message) {}
+    };
 
-    const std::string & GetError() const { return errorStr; };
+    ChannelConfig(std::string address);
 
-private:
-    std::string host;
+    std::string transport;
+    std::string key;
+    std::string address;
+    std::string portStr;
     uint16_t port;
-    uint16_t localPort;
-    std::string password;
-    int sock;
-    std::string errorStr;
-
-    struct sockaddr_in outerAddr;
-    socklen_t outerAddrLen;
-
-    std::string userPassword;
-
-    uint32_t framedIP;
-
-    BLOWFISH_CTX ctx;
+};
 
-    int PrepareNet();
-    void FinalizeNet();
+class STG_CLIENT
+{
+public:
+    enum TYPE {
+        AUTHORIZE,
+        AUTHENTICATE,
+        POST_AUTH,
+        PRE_ACCT,
+        ACCOUNT
+    };
+    struct Error : std::runtime_error {
+        Error(const std::string& message) : runtime_error(message) {}
+    };
+
+    typedef bool (*Callback)(void* /*data*/, const RESULT& /*result*/, bool /*status*/);
+
+    STG_CLIENT(const std::string& address, Callback callback, void* data);
+    ~STG_CLIENT();
 
-    void InitEncrypt();
-    void Encrypt(char * dst, const char * src, int len8);
-    void Decrypt(char * dst, const char * src, int len8);
+    bool stop();
 
-    int Request(RAD_PACKET * packet, const std::string & login, const std::string & svc, uint8_t packetType);
+    static STG_CLIENT* get();
+    static bool configure(const std::string& address, Callback callback, void* data);
 
-    int RecvData(RAD_PACKET * packet);
-    int Send(const RAD_PACKET & packet);
+    bool request(TYPE type, const std::string& userName, const std::string& password, const PAIRS& pairs);
 
+private:
+    class Impl;
+    boost::scoped_ptr<Impl> m_impl;
 };
 
 #endif