• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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 _COMMANDLISTENER_H__
18 #define _COMMANDLISTENER_H__
19 
20 #include <sysutils/FrameworkListener.h>
21 
22 #include "NetdCommand.h"
23 #include "NetworkController.h"
24 #include "TetherController.h"
25 #include "NatController.h"
26 #include "PppController.h"
27 #include "SoftapController.h"
28 #include "BandwidthController.h"
29 #include "IdletimerController.h"
30 #include "InterfaceController.h"
31 #include "ResolverController.h"
32 #include "FirewallController.h"
33 #include "ClatdController.h"
34 #include "StrictController.h"
35 
36 class CommandListener : public FrameworkListener {
37     static TetherController *sTetherCtrl;
38     static NatController *sNatCtrl;
39     static PppController *sPppCtrl;
40     static SoftapController *sSoftapCtrl;
41     static BandwidthController *sBandwidthCtrl;
42     static IdletimerController *sIdletimerCtrl;
43     static InterfaceController *sInterfaceCtrl;
44     static ResolverController *sResolverCtrl;
45     static FirewallController *sFirewallCtrl;
46     static ClatdController *sClatdCtrl;
47     static StrictController *sStrictCtrl;
48 
49 public:
50     static NetworkController *sNetCtrl;
51 
52     CommandListener();
~CommandListener()53     virtual ~CommandListener() {}
54 
55 private:
56 
57     class SoftapCmd : public NetdCommand {
58     public:
59         SoftapCmd();
~SoftapCmd()60         virtual ~SoftapCmd() {}
61         int runCommand(SocketClient *c, int argc, char ** argv);
62     };
63 
64     class InterfaceCmd : public NetdCommand {
65     public:
66         InterfaceCmd();
~InterfaceCmd()67         virtual ~InterfaceCmd() {}
68         int runCommand(SocketClient *c, int argc, char ** argv);
69     };
70 
71     class IpFwdCmd : public NetdCommand {
72     public:
73         IpFwdCmd();
~IpFwdCmd()74         virtual ~IpFwdCmd() {}
75         int runCommand(SocketClient *c, int argc, char ** argv);
76     };
77 
78     class TetherCmd : public NetdCommand {
79     public:
80         TetherCmd();
~TetherCmd()81         virtual ~TetherCmd() {}
82         int runCommand(SocketClient *c, int argc, char ** argv);
83     };
84 
85     class NatCmd : public NetdCommand {
86     public:
87         NatCmd();
~NatCmd()88         virtual ~NatCmd() {}
89         int runCommand(SocketClient *c, int argc, char ** argv);
90     };
91 
92     class ListTtysCmd : public NetdCommand {
93     public:
94         ListTtysCmd();
~ListTtysCmd()95         virtual ~ListTtysCmd() {}
96         int runCommand(SocketClient *c, int argc, char ** argv);
97     };
98 
99     class PppdCmd : public NetdCommand {
100     public:
101         PppdCmd();
~PppdCmd()102         virtual ~PppdCmd() {}
103         int runCommand(SocketClient *c, int argc, char ** argv);
104     };
105 
106     class BandwidthControlCmd : public NetdCommand {
107     public:
108         BandwidthControlCmd();
~BandwidthControlCmd()109         virtual ~BandwidthControlCmd() {}
110         int runCommand(SocketClient *c, int argc, char ** argv);
111     protected:
112         void sendGenericOkFail(SocketClient *cli, int cond);
113         void sendGenericOpFailed(SocketClient *cli, const char *errMsg);
114         void sendGenericSyntaxError(SocketClient *cli, const char *usageMsg);
115     };
116 
117     class IdletimerControlCmd : public NetdCommand {
118     public:
119         IdletimerControlCmd();
~IdletimerControlCmd()120         virtual ~IdletimerControlCmd() {}
121         int runCommand(SocketClient *c, int argc, char ** argv);
122     };
123 
124     class ResolverCmd : public NetdCommand {
125     public:
126         ResolverCmd();
~ResolverCmd()127         virtual ~ResolverCmd() {}
128         int runCommand(SocketClient *c, int argc, char ** argv);
129     };
130 
131     class FirewallCmd: public NetdCommand {
132     public:
133         FirewallCmd();
~FirewallCmd()134         virtual ~FirewallCmd() {}
135         int runCommand(SocketClient *c, int argc, char ** argv);
136     protected:
137         int sendGenericOkFail(SocketClient *cli, int cond);
138         static FirewallRule parseRule(const char* arg);
139         static FirewallType parseFirewallType(const char* arg);
140         static ChildChain parseChildChain(const char* arg);
141     };
142 
143     class ClatdCmd : public NetdCommand {
144     public:
145         ClatdCmd();
~ClatdCmd()146         virtual ~ClatdCmd() {}
147         int runCommand(SocketClient *c, int argc, char ** argv);
148     };
149 
150     class StrictCmd : public NetdCommand {
151     public:
152         StrictCmd();
~StrictCmd()153         virtual ~StrictCmd() {}
154         int runCommand(SocketClient *c, int argc, char ** argv);
155     protected:
156         int sendGenericOkFail(SocketClient *cli, int cond);
157         static StrictPenalty parsePenalty(const char* arg);
158     };
159 
160     class NetworkCommand : public NetdCommand {
161     public:
162         NetworkCommand();
~NetworkCommand()163         virtual ~NetworkCommand() {}
164         int runCommand(SocketClient* client, int argc, char** argv);
165     private:
166         int syntaxError(SocketClient* cli, const char* message);
167         int operationError(SocketClient* cli, const char* message, int ret);
168         int success(SocketClient* cli);
169     };
170 };
171 
172 #endif
173