author | andyq <andyq> | 2002-11-20 21:20:13 (UTC) |
---|---|---|
committer | andyq <andyq> | 2002-11-20 21:20:13 (UTC) |
commit | 726a5ade50098f208f9169176ff1ca099d8f0852 (patch) (unidiff) | |
tree | d97fc08e447dd156b2db5c8ee4a7b6f8a87acecb | |
parent | 19cec7475afb19b9a3096a5e01a87ae80690ce21 (diff) | |
download | opie-726a5ade50098f208f9169176ff1ca099d8f0852.zip opie-726a5ade50098f208f9169176ff1ca099d8f0852.tar.gz opie-726a5ade50098f208f9169176ff1ca099d8f0852.tar.bz2 |
Now keeps proxy settings if set
-rw-r--r-- | noncore/settings/aqpkg/datamgr.cpp | 51 | ||||
-rw-r--r-- | noncore/settings/aqpkg/datamgr.h | 4 |
2 files changed, 51 insertions, 4 deletions
diff --git a/noncore/settings/aqpkg/datamgr.cpp b/noncore/settings/aqpkg/datamgr.cpp index 1420242..e7fb75a 100644 --- a/noncore/settings/aqpkg/datamgr.cpp +++ b/noncore/settings/aqpkg/datamgr.cpp | |||
@@ -9,211 +9,254 @@ | |||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | #include <fstream> | 17 | #include <fstream> |
18 | #include <iostream> | 18 | #include <iostream> |
19 | using namespace std; | 19 | using namespace std; |
20 | 20 | ||
21 | #ifdef QWS | 21 | #ifdef QWS |
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | #endif | 23 | #endif |
24 | 24 | ||
25 | #include <stdio.h> | 25 | #include <stdio.h> |
26 | 26 | ||
27 | #include "datamgr.h" | 27 | #include "datamgr.h" |
28 | #include "global.h" | 28 | #include "global.h" |
29 | 29 | ||
30 | 30 | ||
31 | QString DataManager::availableCategories = ""; | 31 | QString DataManager::availableCategories = ""; |
32 | DataManager::DataManager() | 32 | DataManager::DataManager() |
33 | { | 33 | { |
34 | activeServer = ""; | 34 | activeServer = ""; |
35 | availableCategories = "#"; | 35 | availableCategories = "#"; |
36 | } | 36 | } |
37 | 37 | ||
38 | DataManager::~DataManager() | 38 | DataManager::~DataManager() |
39 | { | 39 | { |
40 | } | 40 | } |
41 | 41 | ||
42 | Server *DataManager :: getServer( const char *name ) | 42 | Server *DataManager :: getServer( const char *name ) |
43 | { | 43 | { |
44 | Server *s = 0; | 44 | Server *s = 0; |
45 | vector<Server>::iterator it = serverList.begin(); | 45 | vector<Server>::iterator it = serverList.begin(); |
46 | while ( it != serverList.end() && s == 0 ) | 46 | while ( it != serverList.end() && s == 0 ) |
47 | { | 47 | { |
48 | if ( it->getServerName() == name ) | 48 | if ( it->getServerName() == name ) |
49 | s = &(*it); | 49 | s = &(*it); |
50 | 50 | ||
51 | ++it; | 51 | ++it; |
52 | } | 52 | } |
53 | 53 | ||
54 | return s; | 54 | return s; |
55 | } | 55 | } |
56 | 56 | ||
57 | Destination *DataManager :: getDestination( const char *name ) | 57 | Destination *DataManager :: getDestination( const char *name ) |
58 | { | 58 | { |
59 | Destination *d = 0; | 59 | Destination *d = 0; |
60 | vector<Destination>::iterator it = destList.begin(); | 60 | vector<Destination>::iterator it = destList.begin(); |
61 | while ( it != destList.end() && d == 0 ) | 61 | while ( it != destList.end() && d == 0 ) |
62 | { | 62 | { |
63 | if ( it->getDestinationName() == name ) | 63 | if ( it->getDestinationName() == name ) |
64 | d = &(*it); | 64 | d = &(*it); |
65 | 65 | ||
66 | ++it; | 66 | ++it; |
67 | } | 67 | } |
68 | 68 | ||
69 | return d; | 69 | return d; |
70 | } | 70 | } |
71 | 71 | ||
72 | void DataManager :: loadServers() | 72 | void DataManager :: loadServers() |
73 | { | 73 | { |
74 | // First add our local server - not really a server but | 74 | // First add our local server - not really a server but |
75 | // the local config (which packages are installed) | 75 | // the local config (which packages are installed) |
76 | serverList.push_back( Server( LOCAL_SERVER, "" ) ); | 76 | serverList.push_back( Server( LOCAL_SERVER, "" ) ); |
77 | serverList.push_back( Server( LOCAL_IPKGS, "" ) ); | 77 | serverList.push_back( Server( LOCAL_IPKGS, "" ) ); |
78 | 78 | ||
79 | #ifdef QWS | 79 | #ifdef QWS |
80 | Config cfg( "aqpkg" ); | 80 | Config cfg( "aqpkg" ); |
81 | cfg.setGroup( "destinations" ); | 81 | cfg.setGroup( "destinations" ); |
82 | #endif | 82 | #endif |
83 | 83 | ||
84 | // Read file from /etc/ipkg.conf | 84 | // Read file from /etc/ipkg.conf |
85 | QString ipkg_conf = IPKG_CONF; | 85 | QString ipkg_conf = IPKG_CONF; |
86 | FILE *fp; | 86 | FILE *fp; |
87 | fp = fopen( ipkg_conf, "r" ); | 87 | fp = fopen( ipkg_conf, "r" ); |
88 | char line[130]; | 88 | char line[130]; |
89 | QString lineStr; | 89 | QString lineStr; |
90 | if ( fp == NULL ) | 90 | if ( fp == NULL ) |
91 | { | 91 | { |
92 | cout << "Couldn't open " << ipkg_conf << "! err = " << fp << endl; | 92 | cout << "Couldn't open " << ipkg_conf << "! err = " << fp << endl; |
93 | return; | 93 | return; |
94 | } | 94 | } |
95 | else | 95 | else |
96 | { | 96 | { |
97 | while ( fgets( line, sizeof line, fp) != NULL ) | 97 | while ( fgets( line, sizeof line, fp) != NULL ) |
98 | { | 98 | { |
99 | lineStr = line; | 99 | lineStr = line; |
100 | if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) ) | 100 | if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) ) |
101 | { | 101 | { |
102 | char alias[20]; | 102 | char alias[20]; |
103 | char url[100]; | 103 | char url[100]; |
104 | 104 | ||
105 | |||
106 | // Looks a little wierd but read up to the r of src (throwing it away), | 105 | // Looks a little wierd but read up to the r of src (throwing it away), |
107 | // then read up to the next space and throw that away, the alias | 106 | // then read up to the next space and throw that away, the alias |
108 | // is next. | 107 | // is next. |
109 | // Should Handle #src, # src, src, and combinations of | 108 | // Should Handle #src, # src, src, and combinations of |
110 | sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url ); | 109 | sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url ); |
111 | Server s( alias, url ); | 110 | Server s( alias, url ); |
112 | if ( lineStr.startsWith( "src" ) ) | 111 | if ( lineStr.startsWith( "src" ) ) |
113 | s.setActive( true ); | 112 | s.setActive( true ); |
114 | else | 113 | else |
115 | s.setActive( false ); | 114 | s.setActive( false ); |
116 | 115 | ||
117 | serverList.push_back( s ); | 116 | serverList.push_back( s ); |
118 | 117 | ||
119 | } | 118 | } |
120 | else if ( lineStr.startsWith( "dest" ) ) | 119 | else if ( lineStr.startsWith( "dest" ) ) |
121 | { | 120 | { |
122 | char alias[20]; | 121 | char alias[20]; |
123 | char path[50]; | 122 | char path[50]; |
124 | sscanf( lineStr, "%*[^ ] %s %s", alias, path ); | 123 | sscanf( lineStr, "%*[^ ] %s %s", alias, path ); |
125 | Destination d( alias, path ); | 124 | Destination d( alias, path ); |
126 | bool linkToRoot = true; | 125 | bool linkToRoot = true; |
127 | #ifdef QWS | 126 | #ifdef QWS |
128 | QString key = alias; | 127 | QString key = alias; |
129 | key += "_linkToRoot"; | 128 | key += "_linkToRoot"; |
130 | linkToRoot = cfg.readBoolEntry( key, true ); | 129 | linkToRoot = cfg.readBoolEntry( key, true ); |
131 | #endif | 130 | #endif |
132 | d.linkToRoot( linkToRoot ); | 131 | d.linkToRoot( linkToRoot ); |
133 | 132 | ||
134 | destList.push_back( d ); | 133 | destList.push_back( d ); |
135 | } | 134 | } |
135 | else if ( lineStr.startsWith( "option" ) ) | ||
136 | { | ||
137 | char type[20]; | ||
138 | char val[100]; | ||
139 | sscanf( lineStr, "%*[^ ] %s %s", type, val ); | ||
140 | if ( stricmp( type, "http_proxy" ) == 0 ) | ||
141 | httpProxy = val; | ||
142 | if ( stricmp( type, "ftp_proxy" ) == 0 ) | ||
143 | ftpProxy = val; | ||
144 | if ( stricmp( type, "proxy_username" ) == 0 ) | ||
145 | proxyUsername = val; | ||
146 | if ( stricmp( type, "proxy_password" ) == 0 ) | ||
147 | proxyPassword = val; | ||
148 | } | ||
136 | } | 149 | } |
137 | } | 150 | } |
138 | fclose( fp ); | 151 | fclose( fp ); |
139 | 152 | ||
153 | cout << "httpProxy = " << httpProxy << endl; | ||
154 | cout << "ftpProxy = " << ftpProxy << endl; | ||
155 | cout << "proxyUsername = " << proxyUsername << endl; | ||
156 | cout << "proxyPassword = " << proxyPassword << endl; | ||
157 | |||
140 | reloadServerData( ); | 158 | reloadServerData( ); |
141 | } | 159 | } |
142 | 160 | ||
143 | void DataManager :: reloadServerData( ) | 161 | void DataManager :: reloadServerData( ) |
144 | { | 162 | { |
145 | vector<Server>::iterator it = serverList.begin(); | 163 | vector<Server>::iterator it = serverList.begin(); |
146 | for ( it = serverList.begin() ; it != serverList.end() ; ++it ) | 164 | for ( it = serverList.begin() ; it != serverList.end() ; ++it ) |
147 | { | 165 | { |
148 | // Now we've read the config file in we need to read the servers | 166 | // Now we've read the config file in we need to read the servers |
149 | // The local server is a special case. This holds the contents of the | 167 | // The local server is a special case. This holds the contents of the |
150 | // status files the number of which depends on how many destinations | 168 | // status files the number of which depends on how many destinations |
151 | // we've set up | 169 | // we've set up |
152 | // The other servers files hold the contents of the server package list | 170 | // The other servers files hold the contents of the server package list |
153 | if ( it->getServerName() == LOCAL_SERVER ) | 171 | if ( it->getServerName() == LOCAL_SERVER ) |
154 | it->readStatusFile( destList ); | 172 | it->readStatusFile( destList ); |
155 | else if ( it->getServerName() == LOCAL_IPKGS ) | 173 | else if ( it->getServerName() == LOCAL_IPKGS ) |
156 | it->readLocalIpks( getServer( LOCAL_SERVER ) ); | 174 | it->readLocalIpks( getServer( LOCAL_SERVER ) ); |
157 | else | 175 | else |
158 | it->readPackageFile( getServer( LOCAL_SERVER ) ); | 176 | it->readPackageFile( getServer( LOCAL_SERVER ) ); |
159 | } | 177 | } |
160 | } | 178 | } |
161 | 179 | ||
162 | void DataManager :: writeOutIpkgConf() | 180 | void DataManager :: writeOutIpkgConf() |
163 | { | 181 | { |
164 | QString ipkg_conf = IPKG_CONF; | 182 | QString ipkg_conf = IPKG_CONF; |
165 | ofstream out( ipkg_conf ); | 183 | ofstream out( ipkg_conf ); |
166 | 184 | ||
167 | out << "# Written by AQPkg" << endl; | 185 | out << "# Written by AQPkg" << endl; |
168 | out << "# Must have one or more source entries of the form:" << endl; | 186 | out << "# Must have one or more source entries of the form:" << endl; |
169 | out << "#" << endl; | 187 | out << "#" << endl; |
170 | out << "# src <src-name> <source-url>" << endl; | 188 | out << "# src <src-name> <source-url>" << endl; |
171 | out << "#" << endl; | 189 | out << "#" << endl; |
172 | out << "# and one or more destination entries of the form:" << endl; | 190 | out << "# and one or more destination entries of the form:" << endl; |
173 | out << "#" << endl; | 191 | out << "#" << endl; |
174 | out << "# dest <dest-name> <target-path>" << endl; | 192 | out << "# dest <dest-name> <target-path>" << endl; |
175 | out << "#" << endl; | 193 | out << "#" << endl; |
176 | out << "# where <src-name> and <dest-names> are identifiers that" << endl; | 194 | out << "# where <src-name> and <dest-names> are identifiers that" << endl; |
177 | out << "# should match [a-zA-Z0-9._-]+, <source-url> should be a" << endl; | 195 | out << "# should match [a-zA-Z0-9._-]+, <source-url> should be a" << endl; |
178 | out << "# URL that points to a directory containing a Familiar" << endl; | 196 | out << "# URL that points to a directory containing a Familiar" << endl; |
179 | out << "# Packages file, and <target-path> should be a directory" << endl; | 197 | out << "# Packages file, and <target-path> should be a directory" << endl; |
180 | out << "# that exists on the target system." << endl << endl; | 198 | out << "# that exists on the target system." << endl << endl; |
181 | 199 | ||
182 | // Write out servers | 200 | // Write out servers |
183 | vector<Server>::iterator it = serverList.begin(); | 201 | vector<Server>::iterator it = serverList.begin(); |
184 | while ( it != serverList.end() ) | 202 | while ( it != serverList.end() ) |
185 | { | 203 | { |
186 | QString alias = it->getServerName(); | 204 | QString alias = it->getServerName(); |
187 | // Don't write out local as its a dummy | 205 | // Don't write out local as its a dummy |
188 | if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS ) | 206 | if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS ) |
189 | { | 207 | { |
190 | QString url = it->getServerUrl();; | 208 | QString url = it->getServerUrl();; |
191 | 209 | ||
192 | if ( !it->isServerActive() ) | 210 | if ( !it->isServerActive() ) |
193 | out << "#"; | 211 | out << "#"; |
194 | out << "src " << alias << " " << url << endl; | 212 | out << "src " << alias << " " << url << endl; |
195 | } | 213 | } |
196 | 214 | ||
197 | it++; | 215 | it++; |
198 | } | 216 | } |
199 | 217 | ||
200 | out << endl; | 218 | out << endl; |
201 | 219 | ||
202 | // Write out destinations | 220 | // Write out destinations |
203 | vector<Destination>::iterator it2 = destList.begin(); | 221 | vector<Destination>::iterator it2 = destList.begin(); |
204 | while ( it2 != destList.end() ) | 222 | while ( it2 != destList.end() ) |
205 | { | 223 | { |
206 | out << "dest " << it2->getDestinationName() << " " << it2->getDestinationPath() << endl; | 224 | out << "dest " << it2->getDestinationName() << " " << it2->getDestinationPath() << endl; |
207 | it2++; | 225 | it2++; |
208 | } | 226 | } |
209 | 227 | ||
228 | out << "# Proxy Support" << endl; | ||
229 | out << "#" << endl; | ||
230 | |||
231 | if ( httpProxy == "" ) | ||
232 | out << "#option http_proxy http://proxy.tld:3128" << endl; | ||
233 | else | ||
234 | out << "option http_proxy " << httpProxy << endl; | ||
235 | |||
236 | if ( ftpProxy == "" ) | ||
237 | out << "#option ftp_proxy http://proxy.tld:3128" << endl; | ||
238 | else | ||
239 | out << "option ftp_proxy " << ftpProxy << endl; | ||
240 | if ( proxyUsername == "" ) | ||
241 | out << "#option proxy_username <username>" << endl; | ||
242 | else | ||
243 | out << "option proxy_username " << proxyUsername << endl; | ||
244 | if ( proxyPassword == "" ) | ||
245 | out << "#option proxy_password <password>" << endl << endl; | ||
246 | else | ||
247 | out << "option proxy_password " << proxyPassword << endl<< endl; | ||
248 | |||
249 | out << "# Offline mode (for use in constructing flash images offline)" << endl; | ||
250 | out << "#option offline_root target" << endl; | ||
251 | |||
252 | |||
210 | out.close(); | 253 | out.close(); |
211 | } | 254 | } |
212 | 255 | ||
213 | 256 | ||
214 | void DataManager :: setAvailableCategories( QString section ) | 257 | void DataManager :: setAvailableCategories( QString section ) |
215 | { | 258 | { |
216 | section = section.lower(); | 259 | section = section.lower(); |
217 | if ( availableCategories.find( "#" + section + "#" ) == -1 ) | 260 | if ( availableCategories.find( "#" + section + "#" ) == -1 ) |
218 | availableCategories += section + "#"; | 261 | availableCategories += section + "#"; |
219 | } | 262 | } |
diff --git a/noncore/settings/aqpkg/datamgr.h b/noncore/settings/aqpkg/datamgr.h index 3a64d92..14b0b2f 100644 --- a/noncore/settings/aqpkg/datamgr.h +++ b/noncore/settings/aqpkg/datamgr.h | |||
@@ -1,69 +1,73 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | datamgr.h - description | 2 | datamgr.h - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Thu Aug 29 2002 | 4 | begin : Thu Aug 29 2002 |
5 | copyright : (C) 2002 by Andy Qua | 5 | copyright : (C) 2002 by Andy Qua |
6 | email : andy.qua@blueyonder.co.uk | 6 | email : andy.qua@blueyonder.co.uk |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | 17 | ||
18 | #ifndef DATAMGR_H | 18 | #ifndef DATAMGR_H |
19 | #define DATAMGR_H | 19 | #define DATAMGR_H |
20 | 20 | ||
21 | #include <map> | 21 | #include <map> |
22 | using namespace std; | 22 | using namespace std; |
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | 25 | ||
26 | #include "server.h" | 26 | #include "server.h" |
27 | #include "destination.h" | 27 | #include "destination.h" |
28 | 28 | ||
29 | #define LOCAL_SERVER "Installed Pkgs" | 29 | #define LOCAL_SERVER "Installed Pkgs" |
30 | #define LOCAL_IPKGS "local IPKG" | 30 | #define LOCAL_IPKGS "local IPKG" |
31 | 31 | ||
32 | /** | 32 | /** |
33 | *@author Andy Qua | 33 | *@author Andy Qua |
34 | */ | 34 | */ |
35 | 35 | ||
36 | 36 | ||
37 | class DataManager | 37 | class DataManager |
38 | { | 38 | { |
39 | public: | 39 | public: |
40 | DataManager(); | 40 | DataManager(); |
41 | ~DataManager(); | 41 | ~DataManager(); |
42 | 42 | ||
43 | void setActiveServer( const QString &act ) { activeServer = act; } | 43 | void setActiveServer( const QString &act ) { activeServer = act; } |
44 | QString &getActiveServer( ) { return activeServer; } | 44 | QString &getActiveServer( ) { return activeServer; } |
45 | 45 | ||
46 | Server *getLocalServer() { return getServer( LOCAL_SERVER ); } | 46 | Server *getLocalServer() { return getServer( LOCAL_SERVER ); } |
47 | vector<Server> &getServerList() { return serverList; } | 47 | vector<Server> &getServerList() { return serverList; } |
48 | Server *getServer( const char *name ); | 48 | Server *getServer( const char *name ); |
49 | 49 | ||
50 | vector<Destination> &getDestinationList() { return destList; } | 50 | vector<Destination> &getDestinationList() { return destList; } |
51 | Destination *getDestination( const char *name ); | 51 | Destination *getDestination( const char *name ); |
52 | 52 | ||
53 | void loadServers(); | 53 | void loadServers(); |
54 | void reloadServerData( ); | 54 | void reloadServerData( ); |
55 | 55 | ||
56 | void writeOutIpkgConf(); | 56 | void writeOutIpkgConf(); |
57 | 57 | ||
58 | static QString getAvailableCategories() { return availableCategories; } | 58 | static QString getAvailableCategories() { return availableCategories; } |
59 | static void setAvailableCategories( QString section ); | 59 | static void setAvailableCategories( QString section ); |
60 | 60 | ||
61 | private: | 61 | private: |
62 | static QString availableCategories; | 62 | static QString availableCategories; |
63 | QString activeServer; | 63 | QString activeServer; |
64 | QString httpProxy; | ||
65 | QString ftpProxy; | ||
66 | QString proxyUsername; | ||
67 | QString proxyPassword; | ||
64 | 68 | ||
65 | vector<Server> serverList; | 69 | vector<Server> serverList; |
66 | vector<Destination> destList; | 70 | vector<Destination> destList; |
67 | }; | 71 | }; |
68 | 72 | ||
69 | #endif | 73 | #endif |