|
1 #!perl |
|
2 # wsp |
|
3 # |
|
4 # Copyright (c) 2002 - 2010 Accenture. All rights reserved. |
|
5 # This component and the accompanying materials are made available |
|
6 # under the terms of the "Eclipse Public License v1.0" |
|
7 # which accompanies this distribution, and is available |
|
8 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 # |
|
10 # Initial Contributors: |
|
11 # Accenture - Initial contribution |
|
12 # |
|
13 |
|
14 # Description: |
|
15 # wsp - A tool for enabling / disabling the Symbian OS WinSock protocol module |
|
16 |
|
17 use strict; |
|
18 use Getopt::Long; |
|
19 use File::Copy; |
|
20 use File::Basename; |
|
21 |
|
22 # |
|
23 # Globals. |
|
24 # |
|
25 |
|
26 my $verbose = 0; |
|
27 my $commands = { |
|
28 'enable' => \&HandleEnable, |
|
29 'e' => \&HandleEnable, |
|
30 'disable' => \&HandleDisable, |
|
31 'd' => \&HandleDisable, |
|
32 'status' => \&HandleStatus, |
|
33 's' => \&HandleStatus |
|
34 }; |
|
35 |
|
36 my $kRoot = $ENV{EPOCROOT} . 'epoc32\winscw\c\Private\101f7989\esock\\'; |
|
37 |
|
38 my @files = ( |
|
39 { |
|
40 enabled => $kRoot . 'ip.winsockprt.esk', |
|
41 disabled => $kRoot . 'ip.winsockprt.esk.disabled', |
|
42 }, |
|
43 { |
|
44 enabled => $kRoot . 'ip.dwinsockprt.esk.disabled', |
|
45 disabled => $kRoot . 'ip.dwinsockprt.esk', |
|
46 }, |
|
47 { |
|
48 enabled => $kRoot . 'ip.tcpip.esk.disabled', |
|
49 disabled => $kRoot . 'ip.tcpip.esk', |
|
50 }, |
|
51 ); |
|
52 |
|
53 my @undoStack; |
|
54 |
|
55 |
|
56 # |
|
57 # Main. |
|
58 # |
|
59 |
|
60 ProcessCommandLine(); |
|
61 |
|
62 |
|
63 # |
|
64 # Subs. |
|
65 # |
|
66 |
|
67 sub ProcessCommandLine { |
|
68 Getopt::Long::Configure ("bundling"); |
|
69 my $help; |
|
70 GetOptions('h' => \$help, 'v+' => \$verbose); |
|
71 if ($help) { |
|
72 Usage(); |
|
73 } |
|
74 |
|
75 my $command = shift @ARGV; |
|
76 unless ($command and scalar(@ARGV) == 0) { |
|
77 print "Error: Invalid arguments\n"; |
|
78 Usage(); |
|
79 } |
|
80 unless (exists $commands->{$command}) { |
|
81 print "Error: Unrecognised command\n"; |
|
82 Usage(); |
|
83 } |
|
84 my $commandSub = $commands->{$command}; |
|
85 &$commandSub(); |
|
86 } |
|
87 |
|
88 sub Usage { |
|
89 die ("\nUsage: wsp [options] (enable | e | disable | d | status | s) |
|
90 |
|
91 options: |
|
92 |
|
93 -h help |
|
94 -v verbose output\n"); |
|
95 } |
|
96 |
|
97 sub HandleEnable { |
|
98 my $currentStatus = Status(); |
|
99 unless ($currentStatus eq 'disabled') { |
|
100 die "Error: Current status is $currentStatus\n"; |
|
101 } |
|
102 |
|
103 RenameFilesEnabled(); |
|
104 print "WinSock protocol module enabled\n"; |
|
105 } |
|
106 |
|
107 sub HandleDisable { |
|
108 my $currentStatus = Status(); |
|
109 unless ($currentStatus eq 'enabled') { |
|
110 die "Error: Current status is $currentStatus\n"; |
|
111 } |
|
112 |
|
113 RenameFilesDisabled(); |
|
114 print "WinSock protocol module disabled\n"; |
|
115 } |
|
116 |
|
117 sub HandleStatus { |
|
118 print "Current status: ", Status(), "\n"; |
|
119 } |
|
120 |
|
121 sub Status { |
|
122 my $numEnabled = 0; |
|
123 my $numDisabled = 0; |
|
124 foreach my $file (@files) { |
|
125 if (-e $file->{enabled}) { |
|
126 ++$numEnabled; |
|
127 } |
|
128 if (-e $file->{disabled}) { |
|
129 ++$numDisabled; |
|
130 } |
|
131 } |
|
132 |
|
133 if (($numEnabled == scalar(@files)) and ($numDisabled == 0)) { |
|
134 return 'enabled'; |
|
135 } |
|
136 elsif (($numDisabled == scalar(@files)) and ($numEnabled == 0)) { |
|
137 return 'disabled'; |
|
138 } |
|
139 return 'indeterminate'; |
|
140 } |
|
141 |
|
142 sub RenameFilesDisabled { |
|
143 my $sub = sub { |
|
144 my $file = shift; |
|
145 RenameFile($file->{enabled}, $file->{disabled}); |
|
146 }; |
|
147 ProcessFilesWithUndo($sub); |
|
148 } |
|
149 |
|
150 sub RenameFilesEnabled { |
|
151 my $sub = sub { |
|
152 my $file = shift; |
|
153 RenameFile($file->{disabled}, $file->{enabled}); |
|
154 }; |
|
155 ProcessFilesWithUndo($sub); |
|
156 } |
|
157 |
|
158 sub ProcessFilesWithUndo { |
|
159 my $sub = shift; |
|
160 eval { |
|
161 foreach my $thisFile (@files) { |
|
162 &$sub($thisFile); |
|
163 } |
|
164 }; |
|
165 if ($@) { |
|
166 while (my $thisUndo = pop (@undoStack)) { |
|
167 &$thisUndo(); |
|
168 } |
|
169 die $@; |
|
170 } |
|
171 } |
|
172 |
|
173 sub RenameFile { |
|
174 my $from = shift; |
|
175 my $to = shift; |
|
176 if (-e $to) { |
|
177 die "Error: Attempting to rename \"$from\" to \"$to\" which already exists\n"; |
|
178 } |
|
179 print "Renaming \"$from\" -> \"$to\"...\n" if ($verbose); |
|
180 rename($from, $to) or die "Error: Couldn't rename \"$from\" to \"$to\": $!\n"; |
|
181 push (@undoStack, sub { print "Undoing rename of \"$from\" -> \"$to\"...\n"; rename ($to, $from) or die; }); |
|
182 } |
|
183 |
|
184 __END__ |
|
185 |
|
186 =head1 NAME |
|
187 |
|
188 wsp - A tool for enabling / disabling the Symbian OS WinSock protocol module |
|
189 |
|
190 =head1 SYNOPSIS |
|
191 |
|
192 wsp [options] (enable | e | disable | d | status | s) |
|
193 |
|
194 options: |
|
195 |
|
196 -h help |
|
197 -v verbose output |
|
198 |
|
199 =head1 DESCRIPTION |
|
200 |
|
201 The WinSock protocol module can be used with the Symbian OS emulator as a replacement for TCPIP6, PPP and NT-RAS. The various commands have the following meaning: |
|
202 |
|
203 =over 4 |
|
204 |
|
205 =item * enable (e) |
|
206 |
|
207 Rename / copy the necessary files to enable the WinSock protocol module. |
|
208 |
|
209 =item * disable (d) |
|
210 |
|
211 Delete / rename the necessary files to disable the WinSock protocol module. |
|
212 |
|
213 =item * status (s) |
|
214 |
|
215 Display the current status (either 'enabled' or 'disabled'). |
|
216 |
|
217 =item * refresh (r) |
|
218 |
|
219 Only used during development. |
|
220 |
|
221 =back |
|
222 |
|
223 =head1 KNOWN BUGS |
|
224 |
|
225 None. |
|
226 |
|
227 =head1 COPYRIGHT |
|
228 |
|
229 Copyright (c) 2002-2010 Accenture. All rights reserved. |
|
230 |
|
231 =cut |