summaryrefslogtreecommitdiff
path: root/noncore/settings/aqpkg/server.cpp
authorandyq <andyq>2002-09-28 23:22:41 (UTC)
committer andyq <andyq>2002-09-28 23:22:41 (UTC)
commit8ebc71609e5263d096f7331a5e0fa95b41eb1d77 (patch) (unidiff)
treeb51cc78a419a8735d4bc447229b4561b5c6edbe5 /noncore/settings/aqpkg/server.cpp
parente78460a23cb8bea25f45cdd01f74e8c1d07da1a8 (diff)
downloadopie-8ebc71609e5263d096f7331a5e0fa95b41eb1d77.zip
opie-8ebc71609e5263d096f7331a5e0fa95b41eb1d77.tar.gz
opie-8ebc71609e5263d096f7331a5e0fa95b41eb1d77.tar.bz2
*** empty log message ***
Diffstat (limited to 'noncore/settings/aqpkg/server.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/server.cpp266
1 files changed, 266 insertions, 0 deletions
diff --git a/noncore/settings/aqpkg/server.cpp b/noncore/settings/aqpkg/server.cpp
new file mode 100644
index 0000000..0069a60
--- a/dev/null
+++ b/noncore/settings/aqpkg/server.cpp
@@ -0,0 +1,266 @@
1/***************************************************************************
2 server.cpp - description
3 -------------------
4 begin : Mon Aug 26 2002
5 copyright : (C) 2002 by Andy Qua
6 email : andy.qua@blueyonder.co.uk
7 description : This class holds details about a server
8 : e.g. all the packages that contained on the server
9 : the installation status
10 ***************************************************************************/
11
12/***************************************************************************
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 ***************************************************************************/
20
21
22#include <stdio.h>
23#include <string.h>
24#include <stdlib.h>
25
26#include <iostream>
27#include <fstream>
28using namespace std;
29
30#include "server.h"
31
32#ifdef QWS
33#include <qpe/global.h>
34#include <qpe/applnk.h>
35#include <qlist.h>
36#endif
37
38#include "utils.h"
39
40#include "global.h"
41
42Server :: Server( const char *name, const char *url )
43{
44 serverName = name;
45 serverUrl = url;
46 packageFile = IPKG_DIR;
47 packageFile += "lists/" + serverName;
48}
49
50Server :: ~Server()
51{
52 cleanUp();
53}
54
55void Server :: cleanUp()
56{
57 packageList.clear();
58}
59
60void Server :: readStatusFile( vector<Destination> &destList )
61{
62 cleanUp();
63
64 vector<Destination>::iterator dit;
65 bool rootRead = false;
66 for ( dit = destList.begin() ; dit != destList.end() ; ++dit )
67 {
68 bool installingToRoot = false;
69
70 QString path = dit->getDestinationPath();
71 if ( path.right( 1 ) != "/" )
72 path += "/";
73
74 if ( path == "/" )
75 {
76 rootRead = true;
77 installingToRoot = true;
78 }
79
80 packageFile = path + "usr/lib/ipkg/status";
81 readPackageFile( 0, false, installingToRoot );
82 }
83
84 // Ensure that the root status file is read
85 if ( !rootRead )
86 {
87 cout << "Reading status file " << "/usr/lib/ipkg/status" << endl;
88 packageFile = "/usr/lib/ipkg/status";
89 readPackageFile( 0, false, true );
90 }
91}
92
93void Server :: readLocalIpks( Server *local )
94{
95 cleanUp();
96
97#ifdef QWS
98 // First, get any local IPKGs in the documents area
99 // Only applicable to Qtopie/Opie
100
101 DocLnkSet files;
102 Global::findDocuments( &files, "application/ipkg" );
103
104 // Now add the items to the list
105 QListIterator<DocLnk> it( files.children() );
106
107 for ( ; it.current() ; ++it )
108 {
109 // OK, we have a local IPK file, I think the standard naming conventions
110 // for these are packagename_version_arm.ipk
111 QString file = (*it)->file();
112
113 QString packageName = Utils::getPackageNameFromIpkFilename( file );
114 QString ver = Utils::getPackageVersionFromIpkFilename( file );
115 packageList.push_back( Package( packageName ) );
116 packageList.back().setVersion( ver );
117 packageList.back().setFilename( file );
118 packageList.back().setPackageStoredLocally( true );
119
120 }
121#else
122 QString names[] = { "advancedfm_0.9.1-20020811_arm.ipk", "libopie_0.9.1-20020811_arm.ipk", "libopieobex_0.9.1-20020811.1_arm.ipk", "opie-addressbook_0.9.1-20020811_arm.ipk" };
123 for ( int i = 0 ; i < 4 ; ++i )
124 {
125 // OK, we have a local IPK file, I think the standard naming conventions
126 // for these are packagename_version_arm.ipk
127 QString file = names[i];
128 int p = file.find( "_" );
129 QString tmp = file.mid( 0, p );
130 packageList.push_back( Package( tmp ) );
131 int p2 = file.find( "_", p+1 );
132 tmp = file.mid( p+1, p2-(p+1) );
133 packageList.back().setVersion( tmp );
134 packageList.back().setPackageStoredLocally( true );
135 }
136#endif
137
138 // build local packages
139 buildLocalPackages( local );
140}
141
142void Server :: readPackageFile( Server *local, bool clearAll, bool installingToRoot )
143{
144 ifstream in( packageFile );
145 if ( !in.is_open() )
146 return;
147
148 char line[1001];
149 char k[21];
150 char v[1001];
151 QString key;
152 QString value;
153
154 if ( clearAll )
155 cleanUp();
156 Package *currPackage = 0;
157
158 bool newPackage = true;
159 do
160 {
161 in.getline( line, 1000 );
162 if ( in.eof() )
163 continue;
164
165 k[0] = '\0';
166 v[0] = '\0';
167
168 sscanf( line, "%[^:]: %[^\n]", k, v );
169 key = k;
170 value = v;
171 key.stripWhiteSpace();
172 if ( key == "Package" && newPackage )
173 {
174 newPackage = false;
175
176 currPackage = getPackage( value );
177 if ( !currPackage )
178 {
179 packageList.push_back( Package( value ) );
180 currPackage = &(packageList.back());
181
182 if ( installingToRoot )
183 currPackage->setInstalledToRoot( true );
184 }
185 }
186 else if ( key == "Version" )
187 {
188 if ( currPackage )
189 currPackage->setVersion( value );
190 }
191 else if ( key == "Status" )
192 {
193 if ( currPackage )
194 currPackage->setStatus( value );
195 }
196 else if ( key == "Description" )
197 {
198 if ( currPackage )
199 currPackage->setDescription( value );
200 }
201 else if ( key == "Filename" )
202 {
203 if ( currPackage )
204 currPackage->setFilename( value );
205 }
206 else if ( key == "" )
207 {
208 newPackage = true;
209 }
210 } while ( !in.eof() );
211
212 in.close();
213
214 // build local packages
215 buildLocalPackages( local );
216}
217
218void Server :: buildLocalPackages( Server *local )
219{
220 for ( unsigned int i = 0 ; i < packageList.size() ; ++i )
221 {
222 QString name = packageList[i].getPackageName();
223 if ( local )
224 packageList[i].setLocalPackage( local->getPackage( name ) );
225 else
226 packageList[i].setLocalPackage( 0 );
227 }
228
229}
230
231Package *Server :: getPackage( QString &name )
232{
233 return getPackage( (const char *)name );
234}
235
236Package *Server :: getPackage( const char *name )
237{
238 Package *ret = 0;
239
240 for ( unsigned int i = 0 ; i < packageList.size() && ret == 0; ++i )
241 {
242 if ( packageList[i].getPackageName() == name )
243 ret = &packageList[i];
244 }
245
246 return ret;
247}
248
249QString Server :: toString()
250{
251 QString ret = "Server\n name - " + serverName +
252 "\n url - " + serverUrl +
253 "\n";
254
255 for ( unsigned int i = 0 ; i < packageList.size() ; ++i )
256 ret += "\n " + packageList[i].toString();
257
258
259 return ret;
260}
261
262vector<Package> &Server::getPackageList()
263{
264 return packageList;
265}
266