-rw-r--r-- | libopie2/opiecore/oglobal.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/libopie2/opiecore/oglobal.cpp b/libopie2/opiecore/oglobal.cpp index 2968a7d..706ac6c 100644 --- a/libopie2/opiecore/oglobal.cpp +++ b/libopie2/opiecore/oglobal.cpp | |||
@@ -1,272 +1,273 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. Copyright (C) 2004 Holger 'zecke' Freyther <zecke@handhelds.org> | 4 | =. Copyright (C) 2004 Holger 'zecke' Freyther <zecke@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include <opie2/oglobal.h> | 30 | #include <opie2/oglobal.h> |
31 | 31 | ||
32 | #include <qtextstream.h> | 32 | #include <qtextstream.h> |
33 | #include <qdir.h> | 33 | #include <qdir.h> |
34 | #include <qpe/mimetype.h> | 34 | #include <qpe/mimetype.h> |
35 | #include <qpe/qpeapplication.h> | 35 | #include <qpe/qpeapplication.h> |
36 | #include <qpe/storage.h> | 36 | #include <qpe/storage.h> |
37 | 37 | ||
38 | #include <unistd.h> | 38 | #include <unistd.h> |
39 | #include <sys/types.h> | 39 | #include <sys/types.h> |
40 | 40 | ||
41 | using namespace Opie::Core; | 41 | using namespace Opie::Core; |
42 | 42 | ||
43 | static const char Base64EncMap[64] = | 43 | static const char Base64EncMap[64] = |
44 | { | 44 | { |
45 | 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | 45 | 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, |
46 | 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, | 46 | 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, |
47 | 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, | 47 | 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, |
48 | 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, | 48 | 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, |
49 | 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, | 49 | 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, |
50 | 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, | 50 | 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, |
51 | 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, | 51 | 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, |
52 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F | 52 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F |
53 | }; | 53 | }; |
54 | 54 | ||
55 | static char Base64DecMap[128] = | 55 | static char Base64DecMap[128] = |
56 | { | 56 | { |
57 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 57 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
58 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 58 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
59 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 59 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
60 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 60 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
62 | 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F, | 62 | 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F, |
63 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, | 63 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, |
64 | 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 64 | 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
65 | 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, | 65 | 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, |
66 | 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, | 66 | 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, |
67 | 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, | 67 | 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, |
68 | 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, | 68 | 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, |
69 | 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, | 69 | 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, |
70 | 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, | 70 | 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, |
71 | 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, | 71 | 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, |
72 | 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00 | 72 | 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00 |
73 | }; | 73 | }; |
74 | 74 | ||
75 | 75 | ||
76 | OConfig* OGlobal::_config = 0; | 76 | OConfig* OGlobal::_config = 0; |
77 | OConfig* OGlobal::_qpe_config = 0; | 77 | OConfig* OGlobal::_qpe_config = 0; |
78 | 78 | ||
79 | void OGlobal::clean_up() { | 79 | void OGlobal::clean_up() |
80 | qWarning( "Oglobal clean up" ); | 80 | { |
81 | qDebug( "Oglobal clean up" ); | ||
81 | delete OGlobal::_config; | 82 | delete OGlobal::_config; |
82 | delete OGlobal::_qpe_config; | 83 | delete OGlobal::_qpe_config; |
83 | OGlobal::_config = 0; | 84 | OGlobal::_config = 0; |
84 | OGlobal::_qpe_config = 0; | 85 | OGlobal::_qpe_config = 0; |
85 | } | 86 | } |
86 | 87 | ||
87 | OConfig* OGlobal::config() | 88 | OConfig* OGlobal::config() |
88 | { | 89 | { |
89 | if ( !OGlobal::_config ) | 90 | if ( !OGlobal::_config ) |
90 | { | 91 | { |
91 | // odebug classes are reading config, so can't use them here! | 92 | // odebug classes are reading config, so can't use them here! |
92 | qAddPostRoutine( OGlobal::clean_up ); | 93 | qAddPostRoutine( OGlobal::clean_up ); |
93 | qDebug( "OGlobal::creating global configuration instance." ); | 94 | qDebug( "OGlobal::creating global configuration instance." ); |
94 | OGlobal::_config = new OConfig( "global" ); | 95 | OGlobal::_config = new OConfig( "global" ); |
95 | } | 96 | } |
96 | return OGlobal::_config; | 97 | return OGlobal::_config; |
97 | } | 98 | } |
98 | 99 | ||
99 | 100 | ||
100 | /** | 101 | /** |
101 | * Return the internal builtin Global::Command object | 102 | * Return the internal builtin Global::Command object |
102 | * | 103 | * |
103 | */ | 104 | */ |
104 | Global::Command* OGlobal::builtinCommands() { | 105 | Global::Command* OGlobal::builtinCommands() { |
105 | return builtin; | 106 | return builtin; |
106 | } | 107 | } |
107 | 108 | ||
108 | 109 | ||
109 | /** | 110 | /** |
110 | * Return the internal builtin QGuardedPtr<QWidget> object | 111 | * Return the internal builtin QGuardedPtr<QWidget> object |
111 | */ | 112 | */ |
112 | QGuardedPtr<QWidget>* OGlobal::builtinRunning() { | 113 | QGuardedPtr<QWidget>* OGlobal::builtinRunning() { |
113 | return running; | 114 | return running; |
114 | } | 115 | } |
115 | 116 | ||
116 | 117 | ||
117 | /** | 118 | /** |
118 | * \brief generate a new UUID as QString | 119 | * \brief generate a new UUID as QString |
119 | * Return a new UUID as QString. UUID are global unique | 120 | * Return a new UUID as QString. UUID are global unique |
120 | * | 121 | * |
121 | * | 122 | * |
122 | * @return the UUID or QString::null | 123 | * @return the UUID or QString::null |
123 | */ | 124 | */ |
124 | QString OGlobal::generateUuid() { | 125 | QString OGlobal::generateUuid() { |
125 | QFile file( "/proc/sys/kernel/random/uuid" ); | 126 | QFile file( "/proc/sys/kernel/random/uuid" ); |
126 | if (!file.open(IO_ReadOnly ) ) | 127 | if (!file.open(IO_ReadOnly ) ) |
127 | return QString::null; | 128 | return QString::null; |
128 | 129 | ||
129 | QTextStream stream(&file); | 130 | QTextStream stream(&file); |
130 | 131 | ||
131 | return "{" + stream.read().stripWhiteSpace() + "}"; | 132 | return "{" + stream.read().stripWhiteSpace() + "}"; |
132 | } | 133 | } |
133 | 134 | ||
134 | 135 | ||
135 | /** | 136 | /** |
136 | * \brief Encode a QByteArray in base64 | 137 | * \brief Encode a QByteArray in base64 |
137 | * | 138 | * |
138 | * An Implementation of the RF1521 base64 encoding. | 139 | * An Implementation of the RF1521 base64 encoding. |
139 | * | 140 | * |
140 | * The boolean argument determines if the encoded data is | 141 | * The boolean argument determines if the encoded data is |
141 | * going to be restricted to 76 characters or less per line | 142 | * going to be restricted to 76 characters or less per line |
142 | * as specified by RFC 2045. If @p insertLFs is true, then | 143 | * as specified by RFC 2045. If @p insertLFs is true, then |
143 | * there will be 76 characters or less per line. | 144 | * there will be 76 characters or less per line. |
144 | * | 145 | * |
145 | * If you use this to create a QCString remember that it is null terminated! | 146 | * If you use this to create a QCString remember that it is null terminated! |
146 | * \code | 147 | * \code |
147 | * QByteArray ar = OGlobal::encodeBase64(&array); | 148 | * QByteArray ar = OGlobal::encodeBase64(&array); |
148 | * QCString str(ar.data(),ar.size()+1); // the NUL at the end | 149 | * QCString str(ar.data(),ar.size()+1); // the NUL at the end |
149 | * | 150 | * |
150 | * \endcode | 151 | * \endcode |
151 | * | 152 | * |
152 | * @param in The QByteArray to encode | 153 | * @param in The QByteArray to encode |
153 | * @param insertLFs Limit number of characters per line | 154 | * @param insertLFs Limit number of characters per line |
154 | * @return The argument as base64 encoded or QByteArray() if in.isEmpty() | 155 | * @return The argument as base64 encoded or QByteArray() if in.isEmpty() |
155 | * @see QByteArray | 156 | * @see QByteArray |
156 | * @see QArray | 157 | * @see QArray |
157 | * @see QMemArray | 158 | * @see QMemArray |
158 | * @see QCString | 159 | * @see QCString |
159 | */ | 160 | */ |
160 | /* | 161 | /* |
161 | * LGPL by Rik Hemsely of the KDE Project. taken from kmdcodec.cpp | 162 | * LGPL by Rik Hemsely of the KDE Project. taken from kmdcodec.cpp |
162 | */ | 163 | */ |
163 | QByteArray OGlobal::encodeBase64(const QByteArray& in, bool insertLFs ) { | 164 | QByteArray OGlobal::encodeBase64(const QByteArray& in, bool insertLFs ) { |
164 | if ( in.isEmpty() ) | 165 | if ( in.isEmpty() ) |
165 | return QByteArray(); | 166 | return QByteArray(); |
166 | 167 | ||
167 | unsigned int sidx = 0; | 168 | unsigned int sidx = 0; |
168 | unsigned int didx = 0; | 169 | unsigned int didx = 0; |
169 | const char* data = in.data(); | 170 | const char* data = in.data(); |
170 | const unsigned int len = in.size(); | 171 | const unsigned int len = in.size(); |
171 | 172 | ||
172 | unsigned int out_len = ((len+2)/3)*4; | 173 | unsigned int out_len = ((len+2)/3)*4; |
173 | 174 | ||
174 | // Deal with the 76 characters or less per | 175 | // Deal with the 76 characters or less per |
175 | // line limit specified in RFC 2045 on a | 176 | // line limit specified in RFC 2045 on a |
176 | // pre request basis. | 177 | // pre request basis. |
177 | insertLFs = (insertLFs && out_len > 76); | 178 | insertLFs = (insertLFs && out_len > 76); |
178 | if ( insertLFs ) | 179 | if ( insertLFs ) |
179 | out_len += ((out_len-1)/76); | 180 | out_len += ((out_len-1)/76); |
180 | 181 | ||
181 | int count = 0; | 182 | int count = 0; |
182 | QByteArray out( out_len ); | 183 | QByteArray out( out_len ); |
183 | 184 | ||
184 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion | 185 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion |
185 | if ( len > 1 ) | 186 | if ( len > 1 ) |
186 | { | 187 | { |
187 | while (sidx < len-2) | 188 | while (sidx < len-2) |
188 | { | 189 | { |
189 | if ( insertLFs ) | 190 | if ( insertLFs ) |
190 | { | 191 | { |
191 | if ( count && (count%76) == 0 ) | 192 | if ( count && (count%76) == 0 ) |
192 | out[didx++] = '\n'; | 193 | out[didx++] = '\n'; |
193 | count += 4; | 194 | count += 4; |
194 | } | 195 | } |
195 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; | 196 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; |
196 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | | 197 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | |
197 | (data[sidx] << 4) & 077]; | 198 | (data[sidx] << 4) & 077]; |
198 | out[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 | | 199 | out[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 | |
199 | (data[sidx+1] << 2) & 077]; | 200 | (data[sidx+1] << 2) & 077]; |
200 | out[didx++] = Base64EncMap[data[sidx+2] & 077]; | 201 | out[didx++] = Base64EncMap[data[sidx+2] & 077]; |
201 | sidx += 3; | 202 | sidx += 3; |
202 | } | 203 | } |
203 | } | 204 | } |
204 | 205 | ||
205 | if (sidx < len) | 206 | if (sidx < len) |
206 | { | 207 | { |
207 | if ( insertLFs && (count > 0) && (count%76) == 0 ) | 208 | if ( insertLFs && (count > 0) && (count%76) == 0 ) |
208 | out[didx++] = '\n'; | 209 | out[didx++] = '\n'; |
209 | 210 | ||
210 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; | 211 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; |
211 | if (sidx < len-1) | 212 | if (sidx < len-1) |
212 | { | 213 | { |
213 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | | 214 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | |
214 | (data[sidx] << 4) & 077]; | 215 | (data[sidx] << 4) & 077]; |
215 | out[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077]; | 216 | out[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077]; |
216 | } | 217 | } |
217 | else | 218 | else |
218 | { | 219 | { |
219 | out[didx++] = Base64EncMap[(data[sidx] << 4) & 077]; | 220 | out[didx++] = Base64EncMap[(data[sidx] << 4) & 077]; |
220 | } | 221 | } |
221 | } | 222 | } |
222 | 223 | ||
223 | // Add padding | 224 | // Add padding |
224 | while (didx < out.size()) | 225 | while (didx < out.size()) |
225 | { | 226 | { |
226 | out[didx] = '='; | 227 | out[didx] = '='; |
227 | didx++; | 228 | didx++; |
228 | } | 229 | } |
229 | 230 | ||
230 | return out; | 231 | return out; |
231 | } | 232 | } |
232 | 233 | ||
233 | /** | 234 | /** |
234 | * Decodes the given data that was encoded with the base64 | 235 | * Decodes the given data that was encoded with the base64 |
235 | * algorithm. | 236 | * algorithm. |
236 | * | 237 | * |
237 | * | 238 | * |
238 | * @param in the encoded data to be decoded. | 239 | * @param in the encoded data to be decoded. |
239 | * @return the decoded QByteArray or QByteArray() in case of failure | 240 | * @return the decoded QByteArray or QByteArray() in case of failure |
240 | * @see OGlobal::encodeBase64 | 241 | * @see OGlobal::encodeBase64 |
241 | */ | 242 | */ |
242 | QByteArray OGlobal::decodeBase64( const QByteArray& in) { | 243 | QByteArray OGlobal::decodeBase64( const QByteArray& in) { |
243 | if ( in.isEmpty() ) | 244 | if ( in.isEmpty() ) |
244 | return QByteArray(); | 245 | return QByteArray(); |
245 | 246 | ||
246 | QByteArray out; | 247 | QByteArray out; |
247 | unsigned int count = 0; | 248 | unsigned int count = 0; |
248 | unsigned int len = in.size(), tail = len; | 249 | unsigned int len = in.size(), tail = len; |
249 | const char* data = in.data(); | 250 | const char* data = in.data(); |
250 | 251 | ||
251 | // Deal with possible *nix "BEGIN" marker!! | 252 | // Deal with possible *nix "BEGIN" marker!! |
252 | while ( count < len && (data[count] == '\n' || data[count] == '\r' || | 253 | while ( count < len && (data[count] == '\n' || data[count] == '\r' || |
253 | data[count] == '\t' || data[count] == ' ') ) | 254 | data[count] == '\t' || data[count] == ' ') ) |
254 | count++; | 255 | count++; |
255 | 256 | ||
256 | if ( strncasecmp(data+count, "begin", 5) == 0 ) | 257 | if ( strncasecmp(data+count, "begin", 5) == 0 ) |
257 | { | 258 | { |
258 | count += 5; | 259 | count += 5; |
259 | while ( count < len && data[count] != '\n' && data[count] != '\r' ) | 260 | while ( count < len && data[count] != '\n' && data[count] != '\r' ) |
260 | count++; | 261 | count++; |
261 | 262 | ||
262 | while ( count < len && (data[count] == '\n' || data[count] == '\r') ) | 263 | while ( count < len && (data[count] == '\n' || data[count] == '\r') ) |
263 | count ++; | 264 | count ++; |
264 | 265 | ||
265 | data += count; | 266 | data += count; |
266 | tail = (len -= count); | 267 | tail = (len -= count); |
267 | } | 268 | } |
268 | 269 | ||
269 | // Find the tail end of the actual encoded data even if | 270 | // Find the tail end of the actual encoded data even if |
270 | // there is/are trailing CR and/or LF. | 271 | // there is/are trailing CR and/or LF. |
271 | while ( data[tail-1] == '=' || data[tail-1] == '\n' || | 272 | while ( data[tail-1] == '=' || data[tail-1] == '\n' || |
272 | data[tail-1] == '\r' ) | 273 | data[tail-1] == '\r' ) |