summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/datamgr.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/settings/aqpkg/datamgr.cpp b/noncore/settings/aqpkg/datamgr.cpp
index 3933a22..0159a79 100644
--- a/noncore/settings/aqpkg/datamgr.cpp
+++ b/noncore/settings/aqpkg/datamgr.cpp
@@ -1,275 +1,275 @@
1/*************************************************************************** 1/***************************************************************************
2 datamgr.cpp - description 2 datamgr.cpp - 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#include <fstream> 17#include <fstream>
18#include <iostream> 18#include <iostream>
19using namespace std; 19using 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
31QString DataManager::availableCategories = ""; 31QString DataManager::availableCategories = "";
32DataManager::DataManager() 32DataManager::DataManager()
33{ 33{
34 activeServer = ""; 34 activeServer = "";
35 availableCategories = "#"; 35 availableCategories = "#";
36} 36}
37 37
38DataManager::~DataManager() 38DataManager::~DataManager()
39{ 39{
40} 40}
41 41
42vector<Server>::iterator DataManager :: getServer( const char *name ) 42vector<Server>::iterator DataManager :: getServer( const char *name )
43{ 43{
44 vector<Server>::iterator it = serverList.begin(); 44 vector<Server>::iterator it = serverList.begin();
45 while ( it != serverList.end() ) 45 while ( it != serverList.end() )
46 { 46 {
47 if ( it->getServerName() == name ) 47 if ( it->getServerName() == name )
48 return it; 48 return it;
49 49
50 ++it; 50 ++it;
51 } 51 }
52 52
53 return serverList.end(); 53 return serverList.end();
54} 54}
55 55
56vector<Destination>::iterator DataManager :: getDestination( const char *name ) 56vector<Destination>::iterator DataManager :: getDestination( const char *name )
57{ 57{
58 vector<Destination>::iterator it = destList.begin(); 58 vector<Destination>::iterator it = destList.begin();
59 while ( it != destList.end() ) 59 while ( it != destList.end() )
60 { 60 {
61 if ( it->getDestinationName() == name ) 61 if ( it->getDestinationName() == name )
62 return it; 62 return it;
63 63
64 ++it; 64 ++it;
65 } 65 }
66 66
67 return destList.end(); 67 return destList.end();
68} 68}
69 69
70void DataManager :: loadServers() 70void DataManager :: loadServers()
71{ 71{
72 // First add our local server - not really a server but 72 // First add our local server - not really a server but
73 // the local config (which packages are installed) 73 // the local config (which packages are installed)
74 serverList.push_back( Server( LOCAL_SERVER, "" ) ); 74 serverList.push_back( Server( LOCAL_SERVER, "" ) );
75 serverList.push_back( Server( LOCAL_IPKGS, "" ) ); 75 serverList.push_back( Server( LOCAL_IPKGS, "" ) );
76 76
77#ifdef QWS 77#ifdef QWS
78 Config cfg( "aqpkg" ); 78 Config cfg( "aqpkg" );
79 cfg.setGroup( "destinations" ); 79 cfg.setGroup( "destinations" );
80#endif 80#endif
81 81
82 // Read file from /etc/ipkg.conf 82 // Read file from /etc/ipkg.conf
83 QString ipkg_conf = IPKG_CONF; 83 QString ipkg_conf = IPKG_CONF;
84 FILE *fp; 84 FILE *fp;
85 fp = fopen( ipkg_conf, "r" ); 85 fp = fopen( ipkg_conf, "r" );
86 char line[130]; 86 char line[130];
87 QString lineStr; 87 QString lineStr;
88 if ( fp == NULL ) 88 if ( fp == NULL )
89 { 89 {
90 cout << "Couldn't open " << ipkg_conf << "! err = " << fp << endl; 90 cout << "Couldn't open " << ipkg_conf << "! err = " << fp << endl;
91 return; 91 return;
92 } 92 }
93 else 93 else
94 { 94 {
95 while ( fgets( line, sizeof line, fp) != NULL ) 95 while ( fgets( line, sizeof line, fp) != NULL )
96 { 96 {
97 lineStr = line; 97 lineStr = line;
98 if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) ) 98 if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) )
99 { 99 {
100 char alias[20]; 100 char alias[20];
101 char url[100]; 101 char url[100];
102 102
103 // Looks a little wierd but read up to the r of src (throwing it away), 103 // Looks a little wierd but read up to the r of src (throwing it away),
104 // then read up to the next space and throw that away, the alias 104 // then read up to the next space and throw that away, the alias
105 // is next. 105 // is next.
106 // Should Handle #src, # src, src, and combinations of 106 // Should Handle #src, # src, src, and combinations of
107 sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url ); 107 sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url );
108 Server s( alias, url ); 108 Server s( alias, url );
109 if ( lineStr.startsWith( "src" ) ) 109 if ( lineStr.startsWith( "src" ) )
110 s.setActive( true ); 110 s.setActive( true );
111 else 111 else
112 s.setActive( false ); 112 s.setActive( false );
113 113
114 serverList.push_back( s ); 114 serverList.push_back( s );
115 115
116 } 116 }
117 else if ( lineStr.startsWith( "dest" ) ) 117 else if ( lineStr.startsWith( "dest" ) )
118 { 118 {
119 char alias[20]; 119 char alias[20];
120 char path[50]; 120 char path[50];
121 sscanf( lineStr, "%*[^ ] %s %s", alias, path ); 121 sscanf( lineStr, "%*[^ ] %s %s", alias, path );
122 Destination d( alias, path ); 122 Destination d( alias, path );
123 bool linkToRoot = true; 123 bool linkToRoot = true;
124#ifdef QWS 124#ifdef QWS
125 QString key = alias; 125 QString key = alias;
126 key += "_linkToRoot"; 126 key += "_linkToRoot";
127 linkToRoot = cfg.readBoolEntry( key, true ); 127 linkToRoot = cfg.readBoolEntry( key, true );
128#endif 128#endif
129 d.linkToRoot( linkToRoot ); 129 d.linkToRoot( linkToRoot );
130 130
131 destList.push_back( d ); 131 destList.push_back( d );
132 } 132 }
133 else if ( lineStr.startsWith( "option" ) || lineStr.startsWith( "#option" ) ) 133 else if ( lineStr.startsWith( "option" ) || lineStr.startsWith( "#option" ) )
134 { 134 {
135 char type[20]; 135 char type[20];
136 char val[100]; 136 char val[100];
137 sscanf( lineStr, "%*[^ ] %s %s", type, val ); 137 sscanf( lineStr, "%*[^ ] %s %s", type, val );
138 if ( stricmp( type, "http_proxy" ) == 0 ) 138 if ( stricmp( type, "http_proxy" ) == 0 )
139 { 139 {
140 httpProxy = val; 140 httpProxy = val;
141 if ( lineStr.startsWith( "#" ) ) 141 if ( lineStr.startsWith( "#" ) )
142 httpProxyEnabled = false; 142 httpProxyEnabled = false;
143 else 143 else
144 httpProxyEnabled = true; 144 httpProxyEnabled = true;
145 } 145 }
146 if ( stricmp( type, "ftp_proxy" ) == 0 ) 146 if ( stricmp( type, "ftp_proxy" ) == 0 )
147 { 147 {
148 ftpProxy = val; 148 ftpProxy = val;
149 if ( lineStr.startsWith( "#" ) ) 149 if ( lineStr.startsWith( "#" ) )
150 ftpProxyEnabled = false; 150 ftpProxyEnabled = false;
151 else 151 else
152 ftpProxyEnabled = true; 152 ftpProxyEnabled = true;
153 } 153 }
154 if ( stricmp( type, "proxy_username" ) == 0 ) 154 if ( stricmp( type, "proxy_username" ) == 0 )
155 proxyUsername = val; 155 proxyUsername = val;
156 if ( stricmp( type, "proxy_password" ) == 0 ) 156 if ( stricmp( type, "proxy_password" ) == 0 )
157 proxyPassword = val; 157 proxyPassword = val;
158 } 158 }
159 } 159 }
160 } 160 }
161 fclose( fp ); 161 fclose( fp );
162 162
163 reloadServerData( ); 163 reloadServerData( );
164} 164}
165 165
166void DataManager :: reloadServerData( ) 166void DataManager :: reloadServerData( )
167{ 167{
168 vector<Server>::iterator it = serverList.begin(); 168 vector<Server>::iterator it = serverList.begin();
169 for ( it = serverList.begin() ; it != serverList.end() ; ++it ) 169 for ( it = serverList.begin() ; it != serverList.end() ; ++it )
170 { 170 {
171 // Now we've read the config file in we need to read the servers 171 // Now we've read the config file in we need to read the servers
172 // The local server is a special case. This holds the contents of the 172 // The local server is a special case. This holds the contents of the
173 // status files the number of which depends on how many destinations 173 // status files the number of which depends on how many destinations
174 // we've set up 174 // we've set up
175 // The other servers files hold the contents of the server package list 175 // The other servers files hold the contents of the server package list
176 if ( it->getServerName() == LOCAL_SERVER ) 176 if ( it->getServerName() == LOCAL_SERVER )
177 it->readStatusFile( destList ); 177 it->readStatusFile( destList );
178 else if ( it->getServerName() == LOCAL_IPKGS ) 178 else if ( it->getServerName() == LOCAL_IPKGS )
179 it->readLocalIpks( &( *getServer( LOCAL_SERVER ) ) ); 179 it->readLocalIpks( &( *getServer( LOCAL_SERVER ) ) );
180 else 180 else
181 it->readPackageFile( &( *getServer( LOCAL_SERVER ) ) ); 181 it->readPackageFile( &( *getServer( LOCAL_SERVER ) ) );
182 } 182 }
183} 183}
184 184
185void DataManager :: writeOutIpkgConf() 185void DataManager :: writeOutIpkgConf()
186{ 186{
187 QString ipkg_conf = IPKG_CONF; 187 QString ipkg_conf = IPKG_CONF;
188 ofstream out( ipkg_conf ); 188 ofstream out( ipkg_conf );
189 189
190 out << "# Written by AQPkg" << endl; 190 out << "# Written by AQPkg" << endl;
191 out << "# Must have one or more source entries of the form:" << endl; 191 out << "# Must have one or more source entries of the form:" << endl;
192 out << "#" << endl; 192 out << "#" << endl;
193 out << "# src <src-name> <source-url>" << endl; 193 out << "# src <src-name> <source-url>" << endl;
194 out << "#" << endl; 194 out << "#" << endl;
195 out << "# and one or more destination entries of the form:" << endl; 195 out << "# and one or more destination entries of the form:" << endl;
196 out << "#" << endl; 196 out << "#" << endl;
197 out << "# dest <dest-name> <target-path>" << endl; 197 out << "# dest <dest-name> <target-path>" << endl;
198 out << "#" << endl; 198 out << "#" << endl;
199 out << "# where <src-name> and <dest-names> are identifiers that" << endl; 199 out << "# where <src-name> and <dest-names> are identifiers that" << endl;
200 out << "# should match [a-zA-Z0-9._-]+, <source-url> should be a" << endl; 200 out << "# should match [a-zA-Z0-9._-]+, <source-url> should be a" << endl;
201 out << "# URL that points to a directory containing a Familiar" << endl; 201 out << "# URL that points to a directory containing a Familiar" << endl;
202 out << "# Packages file, and <target-path> should be a directory" << endl; 202 out << "# Packages file, and <target-path> should be a directory" << endl;
203 out << "# that exists on the target system." << endl << endl; 203 out << "# that exists on the target system." << endl << endl;
204 204
205 // Write out servers 205 // Write out servers
206 vector<Server>::iterator it = serverList.begin(); 206 vector<Server>::iterator it = serverList.begin();
207 while ( it != serverList.end() ) 207 while ( it != serverList.end() )
208 { 208 {
209 QString alias = it->getServerName(); 209 QString alias = it->getServerName();
210 // Don't write out local as its a dummy 210 // Don't write out local as its a dummy
211 if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS ) 211 if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS )
212 { 212 {
213 QString url = it->getServerUrl();; 213 QString url = it->getServerUrl();;
214 214
215 if ( !it->isServerActive() ) 215 if ( !it->isServerActive() )
216 out << "#"; 216 out << "#";
217 out << "src " << alias << " " << url << endl; 217 out << "src " << alias << " " << url << endl;
218 } 218 }
219 219
220 it++; 220 it++;
221 } 221 }
222 222
223 out << endl; 223 out << endl;
224 224
225 // Write out destinations 225 // Write out destinations
226 vector<Destination>::iterator it2 = destList.begin(); 226 vector<Destination>::iterator it2 = destList.begin();
227 while ( it2 != destList.end() ) 227 while ( it2 != destList.end() )
228 { 228 {
229 out << "dest " << it2->getDestinationName() << " " << it2->getDestinationPath() << endl; 229 out << "dest " << it2->getDestinationName() << " " << it2->getDestinationPath() << endl;
230 it2++; 230 it2++;
231 } 231 }
232 232
233 out << endl; 233 out << endl;
234 out << "# Proxy Support" << endl; 234 out << "# Proxy Support" << endl;
235 235
236 if ( !httpProxyEnabled && httpProxy == "" ) 236 if ( !httpProxyEnabled && httpProxy == "" )
237 out << "#option http_proxy http://proxy.tld:3128" << endl; 237 out << "#option http_proxy http://proxy.tld:3128" << endl;
238 else 238 else
239 { 239 {
240 if ( !httpProxyEnabled ) 240 if ( !httpProxyEnabled )
241 out << "#"; 241 out << "#";
242 out << "option http_proxy " << httpProxy << endl; 242 out << "option http_proxy " << httpProxy << endl;
243 } 243 }
244 244
245 if ( !ftpProxyEnabled && ftpProxy == "" ) 245 if ( !ftpProxyEnabled && ftpProxy == "" )
246 out << "#option ftp_proxy http://proxy.tld:3128" << endl; 246 out << "#option ftp_proxy http://proxy.tld:3128" << endl;
247 else 247 else
248 { 248 {
249 if ( !ftpProxyEnabled ) 249 if ( !ftpProxyEnabled )
250 out << "#"; 250 out << "#";
251 out << "option ftp_proxy " << ftpProxy << endl; 251 out << "option ftp_proxy " << ftpProxy << endl;
252 } 252 }
253 if ( proxyUsername == "" ) 253 if ( proxyUsername == "" || (!httpProxyEnabled && !ftpProxyEnabled) )
254 out << "#option proxy_username <username>" << endl; 254 out << "#option proxy_username <username>" << endl;
255 else 255 else
256 out << "option proxy_username " << proxyUsername << endl; 256 out << "option proxy_username " << proxyUsername << endl;
257 if ( proxyPassword == "" ) 257 if ( proxyPassword == "" || (!httpProxyEnabled && !ftpProxyEnabled) )
258 out << "#option proxy_password <password>" << endl << endl; 258 out << "#option proxy_password <password>" << endl << endl;
259 else 259 else
260 out << "option proxy_password " << proxyPassword << endl<< endl; 260 out << "option proxy_password " << proxyPassword << endl<< endl;
261 261
262 out << "# Offline mode (for use in constructing flash images offline)" << endl; 262 out << "# Offline mode (for use in constructing flash images offline)" << endl;
263 out << "#option offline_root target" << endl; 263 out << "#option offline_root target" << endl;
264 264
265 265
266 out.close(); 266 out.close();
267} 267}
268 268
269 269
270void DataManager :: setAvailableCategories( QString section ) 270void DataManager :: setAvailableCategories( QString section )
271{ 271{
272 section = section.lower(); 272 section = section.lower();
273 if ( availableCategories.find( "#" + section + "#" ) == -1 ) 273 if ( availableCategories.find( "#" + section + "#" ) == -1 )
274 availableCategories += section + "#"; 274 availableCategories += section + "#";
275} 275}