Home | History | Annotate | Download | only in server
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef _DNSPROXYLISTENER_H__
     18 #define _DNSPROXYLISTENER_H__
     19 
     20 #include <sysutils/FrameworkListener.h>
     21 
     22 #include "NetdCommand.h"
     23 
     24 class NetworkController;
     25 
     26 class DnsProxyListener : public FrameworkListener {
     27 public:
     28     explicit DnsProxyListener(const NetworkController* netCtrl);
     29     virtual ~DnsProxyListener() {}
     30 
     31 private:
     32     const NetworkController *mNetCtrl;
     33     class GetAddrInfoCmd : public NetdCommand {
     34     public:
     35         GetAddrInfoCmd(const DnsProxyListener* dnsProxyListener);
     36         virtual ~GetAddrInfoCmd() {}
     37         int runCommand(SocketClient *c, int argc, char** argv);
     38     private:
     39         const DnsProxyListener* mDnsProxyListener;
     40     };
     41 
     42     class GetAddrInfoHandler {
     43     public:
     44         // Note: All of host, service, and hints may be NULL
     45         GetAddrInfoHandler(SocketClient *c,
     46                            char* host,
     47                            char* service,
     48                            struct addrinfo* hints,
     49                            unsigned netId,
     50                            uint32_t mark);
     51         ~GetAddrInfoHandler();
     52 
     53         static void* threadStart(void* handler);
     54         void start();
     55 
     56     private:
     57         void run();
     58         SocketClient* mClient;  // ref counted
     59         char* mHost;    // owned
     60         char* mService; // owned
     61         struct addrinfo* mHints;  // owned
     62         unsigned mNetId;
     63         uint32_t mMark;
     64     };
     65 
     66     /* ------ gethostbyname ------*/
     67     class GetHostByNameCmd : public NetdCommand {
     68     public:
     69         GetHostByNameCmd(const DnsProxyListener* dnsProxyListener);
     70         virtual ~GetHostByNameCmd() {}
     71         int runCommand(SocketClient *c, int argc, char** argv);
     72     private:
     73         const DnsProxyListener* mDnsProxyListener;
     74     };
     75 
     76     class GetHostByNameHandler {
     77     public:
     78         GetHostByNameHandler(SocketClient *c,
     79                             char *name,
     80                             int af,
     81                             unsigned netId,
     82                             uint32_t mark);
     83         ~GetHostByNameHandler();
     84         static void* threadStart(void* handler);
     85         void start();
     86     private:
     87         void run();
     88         SocketClient* mClient; //ref counted
     89         char* mName; // owned
     90         int mAf;
     91         unsigned mNetId;
     92         uint32_t mMark;
     93     };
     94 
     95     /* ------ gethostbyaddr ------*/
     96     class GetHostByAddrCmd : public NetdCommand {
     97     public:
     98         GetHostByAddrCmd(const DnsProxyListener* dnsProxyListener);
     99         virtual ~GetHostByAddrCmd() {}
    100         int runCommand(SocketClient *c, int argc, char** argv);
    101     private:
    102         const DnsProxyListener* mDnsProxyListener;
    103     };
    104 
    105     class GetHostByAddrHandler {
    106     public:
    107         GetHostByAddrHandler(SocketClient *c,
    108                             void* address,
    109                             int addressLen,
    110                             int addressFamily,
    111                             unsigned netId,
    112                             uint32_t mark);
    113         ~GetHostByAddrHandler();
    114 
    115         static void* threadStart(void* handler);
    116         void start();
    117 
    118     private:
    119         void run();
    120         SocketClient* mClient;  // ref counted
    121         void* mAddress;    // address to lookup; owned
    122         int mAddressLen; // length of address to look up
    123         int mAddressFamily;  // address family
    124         unsigned mNetId;
    125         uint32_t mMark;
    126     };
    127 };
    128 
    129 #endif
    130