summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp29
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.cpp30
2 files changed, 57 insertions, 2 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
index bc51996..24b69fe 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
@@ -2,48 +2,75 @@
2#include <fcntl.h> 2#include <fcntl.h>
3 3
4#include <stdio.h> 4#include <stdio.h>
5#include <stdlib.h> 5#include <stdlib.h>
6 6
7#include <sys/types.h> 7#include <sys/types.h>
8#include <sys/mman.h> 8#include <sys/mman.h>
9#include <sys/stat.h> 9#include <sys/stat.h>
10 10
11#include <unistd.h> 11#include <unistd.h>
12 12
13#include <qasciidict.h> 13#include <qasciidict.h>
14#include <qfile.h> 14#include <qfile.h>
15 15
16#include <qtopia/global.h> 16#include <qtopia/global.h>
17#include <qtopia/stringutil.h> 17#include <qtopia/stringutil.h>
18#include <qtopia/timeconversion.h> 18#include <qtopia/timeconversion.h>
19 19
20#include "opimnotifymanager.h" 20#include "opimnotifymanager.h"
21#include "orecur.h" 21#include "orecur.h"
22#include "otimezone.h" 22#include "otimezone.h"
23#include "odatebookaccessbackend_xml.h" 23#include "odatebookaccessbackend_xml.h"
24 24
25namespace { 25namespace {
26 // FROM TT again
27char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
28{
29 char needleChar;
30 char haystackChar;
31 if (!needle || !haystack || !hLen || !nLen)
32 return 0;
33
34 const char* hsearch = haystack;
35
36 if ((needleChar = *needle++) != 0) {
37 nLen--; //(to make up for needle++)
38 do {
39 do {
40 if ((haystackChar = *hsearch++) == 0)
41 return (0);
42 if (hsearch >= haystack + hLen)
43 return (0);
44 } while (haystackChar != needleChar);
45 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0);
46 hsearch--;
47 }
48 return ((char *)hsearch);
49}
50}
51
52namespace {
26 time_t start, end, created, rp_end; 53 time_t start, end, created, rp_end;
27 ORecur* rec; 54 ORecur* rec;
28 ORecur* recur() { 55 ORecur* recur() {
29 if (!rec) 56 if (!rec)
30 rec = new ORecur; 57 rec = new ORecur;
31 58
32 return rec; 59 return rec;
33 } 60 }
34 int alarmTime; 61 int alarmTime;
35 int snd; 62 int snd;
36 enum Attribute{ 63 enum Attribute{
37 FDescription = 0, 64 FDescription = 0,
38 FLocation, 65 FLocation,
39 FCategories, 66 FCategories,
40 FUid, 67 FUid,
41 FType, 68 FType,
42 FAlarm, 69 FAlarm,
43 FSound, 70 FSound,
44 FRType, 71 FRType,
45 FRWeekdays, 72 FRWeekdays,
46 FRPosition, 73 FRPosition,
47 FRFreq, 74 FRFreq,
48 FRHasEndDate, 75 FRHasEndDate,
49 FREndDate, 76 FREndDate,
@@ -321,49 +348,49 @@ bool ODateBookAccessBackend_XML::loadFile() {
321 dict.insert( "alarm", new int(FAlarm) ); 348 dict.insert( "alarm", new int(FAlarm) );
322 dict.insert( "sound", new int(FSound) ); 349 dict.insert( "sound", new int(FSound) );
323 dict.insert( "rtype", new int(FRType) ); 350 dict.insert( "rtype", new int(FRType) );
324 dict.insert( "rweekdays", new int(FRWeekdays) ); 351 dict.insert( "rweekdays", new int(FRWeekdays) );
325 dict.insert( "rposition", new int(FRPosition) ); 352 dict.insert( "rposition", new int(FRPosition) );
326 dict.insert( "rfreq", new int(FRFreq) ); 353 dict.insert( "rfreq", new int(FRFreq) );
327 dict.insert( "rhasenddate", new int(FRHasEndDate) ); 354 dict.insert( "rhasenddate", new int(FRHasEndDate) );
328 dict.insert( "enddt", new int(FREndDate) ); 355 dict.insert( "enddt", new int(FREndDate) );
329 dict.insert( "start", new int(FRStart) ); 356 dict.insert( "start", new int(FRStart) );
330 dict.insert( "end", new int(FREnd) ); 357 dict.insert( "end", new int(FREnd) );
331 dict.insert( "note", new int(FNote) ); 358 dict.insert( "note", new int(FNote) );
332 dict.insert( "created", new int(FCreated) ); 359 dict.insert( "created", new int(FCreated) );
333 dict.insert( "recparent", new int(FRecParent) ); 360 dict.insert( "recparent", new int(FRecParent) );
334 dict.insert( "recchildren", new int(FRecChildren) ); 361 dict.insert( "recchildren", new int(FRecChildren) );
335 dict.insert( "exceptions", new int(FExceptions) ); 362 dict.insert( "exceptions", new int(FExceptions) );
336 dict.insert( "timezone", new int(FTimeZone) ); 363 dict.insert( "timezone", new int(FTimeZone) );
337 364
338 char* dt = (char*)map_addr; 365 char* dt = (char*)map_addr;
339 int len = attribute.st_size; 366 int len = attribute.st_size;
340 int i = 0; 367 int i = 0;
341 char* point; 368 char* point;
342 const char* collectionString = "<event "; 369 const char* collectionString = "<event ";
343 int strLen = ::strlen(collectionString); 370 int strLen = ::strlen(collectionString);
344 int *find; 371 int *find;
345 while ( dt + 1 != 0 && (( point = ::strstr( dt+i, collectionString ) ) != 0 ) ) { 372 while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) {
346 i = point -dt; 373 i = point -dt;
347 i+= strLen; 374 i+= strLen;
348 375
349 alarmTime = -1; 376 alarmTime = -1;
350 snd = 0; // silent 377 snd = 0; // silent
351 378
352 OEvent ev; 379 OEvent ev;
353 rec = 0; 380 rec = 0;
354 381
355 while ( TRUE ) { 382 while ( TRUE ) {
356 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) 383 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
357 ++i; 384 ++i;
358 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) 385 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
359 break; 386 break;
360 387
361 388
362 // we have another attribute, read it. 389 // we have another attribute, read it.
363 int j = i; 390 int j = i;
364 while ( j < len && dt[j] != '=' ) 391 while ( j < len && dt[j] != '=' )
365 ++j; 392 ++j;
366 QCString attr( dt+i, j-i+1); 393 QCString attr( dt+i, j-i+1);
367 394
368 i = ++j; // skip = 395 i = ++j; // skip =
369 396
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp
index 22b2469..cda300b 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.cpp
+++ b/libopie2/opiepim/backend/otodoaccessxml.cpp
@@ -1,43 +1,71 @@
1#include <errno.h> 1#include <errno.h>
2#include <fcntl.h> 2#include <fcntl.h>
3 3
4#include <sys/mman.h> 4#include <sys/mman.h>
5#include <sys/stat.h> 5#include <sys/stat.h>
6#include <sys/types.h> 6#include <sys/types.h>
7 7
8#include <unistd.h> 8#include <unistd.h>
9 9
10 10
11#include <qfile.h> 11#include <qfile.h>
12#include <qvector.h> 12#include <qvector.h>
13 13
14#include <qpe/global.h> 14#include <qpe/global.h>
15#include <qpe/stringutil.h> 15#include <qpe/stringutil.h>
16#include <qpe/timeconversion.h> 16#include <qpe/timeconversion.h>
17 17
18#include "otodoaccessxml.h" 18#include "otodoaccessxml.h"
19 19
20namespace {
21 // FROM TT again
22char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
23{
24 char needleChar;
25 char haystackChar;
26 if (!needle || !haystack || !hLen || !nLen)
27 return 0;
28
29 const char* hsearch = haystack;
30
31 if ((needleChar = *needle++) != 0) {
32 nLen--; //(to make up for needle++)
33 do {
34 do {
35 if ((haystackChar = *hsearch++) == 0)
36 return (0);
37 if (hsearch >= haystack + hLen)
38 return (0);
39 } while (haystackChar != needleChar);
40 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0);
41 hsearch--;
42 }
43 return ((char *)hsearch);
44}
45}
46
47
20OTodoAccessXML::OTodoAccessXML( const QString& appName, 48OTodoAccessXML::OTodoAccessXML( const QString& appName,
21 const QString& fileName ) 49 const QString& fileName )
22 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) 50 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false )
23{ 51{
24 if (!fileName.isEmpty() ) 52 if (!fileName.isEmpty() )
25 m_file = fileName; 53 m_file = fileName;
26 else 54 else
27 m_file = Global::applicationFileName( "todolist", "todolist.xml" ); 55 m_file = Global::applicationFileName( "todolist", "todolist.xml" );
28} 56}
29OTodoAccessXML::~OTodoAccessXML() { 57OTodoAccessXML::~OTodoAccessXML() {
30 58
31} 59}
32bool OTodoAccessXML::load() { 60bool OTodoAccessXML::load() {
33 m_opened = true; 61 m_opened = true;
34 m_changed = false; 62 m_changed = false;
35 /* initialize dict */ 63 /* initialize dict */
36 /* 64 /*
37 * UPDATE dict if you change anything!!! 65 * UPDATE dict if you change anything!!!
38 */ 66 */
39 QAsciiDict<int> dict(21); 67 QAsciiDict<int> dict(21);
40 dict.setAutoDelete( TRUE ); 68 dict.setAutoDelete( TRUE );
41 dict.insert("Categories" , new int(OTodo::Category) ); 69 dict.insert("Categories" , new int(OTodo::Category) );
42 dict.insert("Uid" , new int(OTodo::Uid) ); 70 dict.insert("Uid" , new int(OTodo::Uid) );
43 dict.insert("HasDate" , new int(OTodo::HasDate) ); 71 dict.insert("HasDate" , new int(OTodo::HasDate) );
@@ -64,49 +92,49 @@ bool OTodoAccessXML::load() {
64 int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); 92 int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY );
65 struct stat attribut; 93 struct stat attribut;
66 if ( fd < 0 ) return false; 94 if ( fd < 0 ) return false;
67 95
68 if ( fstat(fd, &attribut ) == -1 ) { 96 if ( fstat(fd, &attribut ) == -1 ) {
69 ::close( fd ); 97 ::close( fd );
70 return false; 98 return false;
71 } 99 }
72 void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); 100 void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 );
73 if ( map_addr == ( (caddr_t)-1) ) { 101 if ( map_addr == ( (caddr_t)-1) ) {
74 ::close(fd ); 102 ::close(fd );
75 return false; 103 return false;
76 } 104 }
77 /* advise the kernel who we want to read it */ 105 /* advise the kernel who we want to read it */
78 ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); 106 ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL );
79 /* we do not the file any more */ 107 /* we do not the file any more */
80 ::close( fd ); 108 ::close( fd );
81 109
82 char* dt = (char*)map_addr; 110 char* dt = (char*)map_addr;
83 int len = attribut.st_size; 111 int len = attribut.st_size;
84 int i = 0; 112 int i = 0;
85 char *point; 113 char *point;
86 const char* collectionString = "<Task "; 114 const char* collectionString = "<Task ";
87 int strLen = strlen(collectionString); 115 int strLen = strlen(collectionString);
88 while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) { 116 while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) {
89 i = point -dt; 117 i = point -dt;
90 i+= strLen; 118 i+= strLen;
91 qWarning("Found a start at %d %d", i, (point-dt) ); 119 qWarning("Found a start at %d %d", i, (point-dt) );
92 120
93 OTodo ev; 121 OTodo ev;
94 m_year = m_month = m_day = 0; 122 m_year = m_month = m_day = 0;
95 123
96 while ( TRUE ) { 124 while ( TRUE ) {
97 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) 125 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
98 ++i; 126 ++i;
99 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) 127 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
100 break; 128 break;
101 129
102 // we have another attribute, read it. 130 // we have another attribute, read it.
103 int j = i; 131 int j = i;
104 while ( j < len && dt[j] != '=' ) 132 while ( j < len && dt[j] != '=' )
105 ++j; 133 ++j;
106 QCString attr( dt+i, j-i+1); 134 QCString attr( dt+i, j-i+1);
107 135
108 i = ++j; // skip = 136 i = ++j; // skip =
109 137
110 // find the start of quotes 138 // find the start of quotes
111 while ( i < len && dt[i] != '"' ) 139 while ( i < len && dt[i] != '"' )
112 ++i; 140 ++i;