OSDN Git Service

am 6aac1ccd: Merge "system: netd: prevent infinite loop"
[android-x86/system-netd.git] / DnsProxyListener.h
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 #include "NetworkController.h"
24
25 class DnsProxyListener : public FrameworkListener {
26 public:
27     DnsProxyListener(const NetworkController* controller);
28     virtual ~DnsProxyListener() {}
29
30 private:
31     const NetworkController *mNetCtrl;
32     class GetAddrInfoCmd : public NetdCommand {
33     public:
34         GetAddrInfoCmd(const NetworkController* controller);
35         virtual ~GetAddrInfoCmd() {}
36         int runCommand(SocketClient *c, int argc, char** argv);
37     private:
38         const NetworkController* mNetCtrl;
39     };
40
41     class GetAddrInfoHandler {
42     public:
43         // Note: All of host, service, and hints may be NULL
44         GetAddrInfoHandler(SocketClient *c,
45                            char* host,
46                            char* service,
47                            struct addrinfo* hints,
48                            unsigned netId);
49         ~GetAddrInfoHandler();
50
51         static void* threadStart(void* handler);
52         void start();
53
54     private:
55         void run();
56         SocketClient* mClient;  // ref counted
57         char* mHost;    // owned
58         char* mService; // owned
59         struct addrinfo* mHints;  // owned
60         unsigned mNetId;
61     };
62
63     /* ------ gethostbyname ------*/
64     class GetHostByNameCmd : public NetdCommand {
65     public:
66         GetHostByNameCmd(const NetworkController* controller);
67         virtual ~GetHostByNameCmd() {}
68         int runCommand(SocketClient *c, int argc, char** argv);
69     private:
70         const NetworkController* mNetCtrl;
71     };
72
73     class GetHostByNameHandler {
74     public:
75         GetHostByNameHandler(SocketClient *c,
76                             char *name,
77                             int af,
78                             unsigned netId);
79         ~GetHostByNameHandler();
80         static void* threadStart(void* handler);
81         void start();
82     private:
83         void run();
84         SocketClient* mClient; //ref counted
85         char* mName; // owned
86         int mAf;
87         unsigned mNetId;
88     };
89
90     /* ------ gethostbyaddr ------*/
91     class GetHostByAddrCmd : public NetdCommand {
92     public:
93         GetHostByAddrCmd(const NetworkController* controller);
94         virtual ~GetHostByAddrCmd() {}
95         int runCommand(SocketClient *c, int argc, char** argv);
96     private:
97         const NetworkController* mNetCtrl;
98     };
99
100     class GetHostByAddrHandler {
101     public:
102         GetHostByAddrHandler(SocketClient *c,
103                             void* address,
104                             int addressLen,
105                             int addressFamily,
106                             unsigned netId);
107         ~GetHostByAddrHandler();
108
109         static void* threadStart(void* handler);
110         void start();
111
112     private:
113         void run();
114         SocketClient* mClient;  // ref counted
115         void* mAddress;    // address to lookup; owned
116         int mAddressLen; // length of address to look up
117         int mAddressFamily;  // address family
118         unsigned mNetId;
119     };
120 };
121
122 #endif