equal
deleted
inserted
replaced
13 * |
13 * |
14 * Description: JavaCommonUtils |
14 * Description: JavaCommonUtils |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 #include <errno.h> |
|
19 #include <fcntl.h> |
19 #include <iostream> |
20 #include <iostream> |
20 #include <sstream> |
21 #include <sstream> |
|
22 #include <unistd.h> |
21 #include <vector> |
23 #include <vector> |
22 |
24 |
23 #include <string.h> |
25 #include <string.h> |
24 |
26 |
25 #include <openssl/bio.h> |
27 #include <openssl/bio.h> |
30 #include "javacommonutils.h" |
32 #include "javacommonutils.h" |
31 #include "exceptionbase.h" |
33 #include "exceptionbase.h" |
32 #include "convertutf.h" |
34 #include "convertutf.h" |
33 |
35 |
34 using namespace java::util; |
36 using namespace java::util; |
|
37 |
|
38 // In Symbian working directory should be initalized to C:\private\<UID> by OpenC |
|
39 // But for some reason this does not seem to work if process binary is in rom. |
|
40 #ifdef __SYMBIAN32__ |
|
41 const char* const FIRST_BOOT_FILE = "c:\\private\\102033E6\\first_boot_done.dat"; |
|
42 #else |
|
43 const char* const FIRST_BOOT_FILE = "first_boot_done.dat"; |
|
44 #endif /* __SYMBIAN32__ */ |
|
45 |
|
46 bool JavaCommonUtils::mFirstBoot = false; |
35 |
47 |
36 OS_EXPORT int JavaCommonUtils::stringToInt(const std::string& str) |
48 OS_EXPORT int JavaCommonUtils::stringToInt(const std::string& str) |
37 { |
49 { |
38 // JELOG2(EUtils); |
50 // JELOG2(EUtils); |
39 // value = boost::lexical_cast<int>( str ); |
51 // value = boost::lexical_cast<int>( str ); |
275 BIO_free_all(b64); |
287 BIO_free_all(b64); |
276 |
288 |
277 return result; |
289 return result; |
278 } |
290 } |
279 |
291 |
|
292 OS_EXPORT std::wstring JavaCommonUtils::wbase64encode(const std::wstring& aData) |
|
293 { |
|
294 BIO* b64 = BIO_new(BIO_f_base64()); |
|
295 if (NULL == b64) |
|
296 { |
|
297 return L""; |
|
298 } |
|
299 BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); |
|
300 BIO* bmem = BIO_new(BIO_s_mem()); |
|
301 |
|
302 b64 = BIO_push(b64, bmem); |
|
303 BIO_write(b64, aData.c_str(), aData.length() * 2); |
|
304 BIO_flush(b64); |
|
305 |
|
306 BUF_MEM* bptr; |
|
307 BIO_get_mem_ptr(b64, &bptr); |
|
308 |
|
309 std::wstring result; |
|
310 // convert each char to wchar |
|
311 for (int i = 0; i < bptr->length; i++) |
|
312 { |
|
313 result.push_back((wchar_t)*(bptr->data + i)); |
|
314 } |
|
315 BIO_free_all(b64); |
|
316 |
|
317 return result; |
|
318 } |
|
319 |
280 OS_EXPORT std::string JavaCommonUtils::base64decode(const std::string& aData) |
320 OS_EXPORT std::string JavaCommonUtils::base64decode(const std::string& aData) |
281 { |
321 { |
282 BIO* b64 = BIO_new(BIO_f_base64()); |
322 BIO* b64 = BIO_new(BIO_f_base64()); |
283 if (NULL == b64) |
323 if (NULL == b64) |
284 { |
324 { |
342 |
382 |
343 return res; |
383 return res; |
344 } |
384 } |
345 |
385 |
346 |
386 |
|
387 OS_EXPORT int JavaCommonUtils::initIsFirstBoot() |
|
388 { |
|
389 struct stat fileStatBuf; |
|
390 if (stat(FIRST_BOOT_FILE, &fileStatBuf) == 0) |
|
391 { |
|
392 mFirstBoot = false; |
|
393 } |
|
394 else |
|
395 { |
|
396 mFirstBoot = true; |
|
397 |
|
398 // Create flag file so that next time we detect that first boot |
|
399 // has already been done |
|
400 int fd = open(FIRST_BOOT_FILE, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); |
|
401 if (fd < 0) |
|
402 { |
|
403 return errno; |
|
404 } |
|
405 else |
|
406 { |
|
407 close(fd); |
|
408 } |
|
409 } |
|
410 |
|
411 return 0; |
|
412 } |
|
413 |
|
414 |
|
415 OS_EXPORT bool JavaCommonUtils::isFirstBoot() |
|
416 { |
|
417 return mFirstBoot; |
|
418 } |
|
419 |
|
420 |
347 char JavaCommonUtils::decodeOnePercentSeq(wchar_t first, wchar_t sec) |
421 char JavaCommonUtils::decodeOnePercentSeq(wchar_t first, wchar_t sec) |
348 { |
422 { |
349 // Handle one encoded %XY |
423 // Handle one encoded %XY |
350 char decodedCh = 0; |
424 char decodedCh = 0; |
351 wchar_t ch = first; |
425 wchar_t ch = first; |