OSDN Git Service

Merge "dns cache per interface iteration 2"
[android-x86/system-netd.git] / DnsProxyListener.h
index 2d796d9..4c125ff 100644 (file)
@@ -17,7 +17,6 @@
 #ifndef _DNSPROXYLISTENER_H__
 #define _DNSPROXYLISTENER_H__
 
-#include <pthread.h>
 #include <sysutils/FrameworkListener.h>
 
 #include "NetdCommand.h"
@@ -41,11 +40,15 @@ private:
         GetAddrInfoHandler(SocketClient *c,
                            char* host,
                            char* service,
-                           struct addrinfo* hints)
+                           struct addrinfo* hints,
+                           char* iface,
+                           int pid)
             : mClient(c),
               mHost(host),
               mService(service),
-              mHints(hints) {}
+              mHints(hints),
+              mIface(iface),
+              mPid(pid) {}
         ~GetAddrInfoHandler();
 
         static void* threadStart(void* handler);
@@ -53,11 +56,81 @@ private:
 
     private:
         void run();
-        pthread_t mThread;
-        SocketClient* mClient;  // not owned
+        SocketClient* mClient;  // ref counted
         char* mHost;    // owned
         char* mService; // owned
         struct addrinfo* mHints;  // owned
+        char* mIface; // owned
+        int mPid;
+    };
+
+    /* ------ gethostbyname ------*/
+    class GetHostByNameCmd : public NetdCommand {
+    public:
+        GetHostByNameCmd();
+        virtual ~GetHostByNameCmd() {}
+        int runCommand(SocketClient *c, int argc, char** argv);
+    };
+
+    class GetHostByNameHandler {
+    public:
+        GetHostByNameHandler(SocketClient *c,
+                            int pid,
+                            char *iface,
+                            char *name,
+                            int af)
+            : mClient(c),
+              mPid(pid),
+              mIface(iface),
+              mName(name),
+              mAf(af) {}
+        ~GetHostByNameHandler();
+        static void* threadStart(void* handler);
+        void start();
+    private:
+        void run();
+        SocketClient* mClient; //ref counted
+        int mPid;
+        char* mIface; // owned
+        char* mName; // owned
+        int mAf;
+    };
+
+    /* ------ gethostbyaddr ------*/
+    class GetHostByAddrCmd : public NetdCommand {
+    public:
+        GetHostByAddrCmd();
+        virtual ~GetHostByAddrCmd() {}
+        int runCommand(SocketClient *c, int argc, char** argv);
+    };
+
+    class GetHostByAddrHandler {
+    public:
+        GetHostByAddrHandler(SocketClient *c,
+                            void* address,
+                            int   addressLen,
+                            int   addressFamily,
+                            char* iface,
+                            int   pid)
+            : mClient(c),
+              mAddress(address),
+              mAddressLen(addressLen),
+              mAddressFamily(addressFamily),
+              mIface(iface),
+              mPid(pid) {}
+        ~GetHostByAddrHandler();
+
+        static void* threadStart(void* handler);
+        void start();
+
+    private:
+        void run();
+        SocketClient* mClient;  // ref counted
+        void* mAddress;    // address to lookup; owned
+        int   mAddressLen; // length of address to look up
+        int   mAddressFamily;  // address family
+        char* mIface; // owned
+        int   mPid;
     };
 };