3 /// Record parsing class for the folders database.
7 Copyright (C) 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)
8 Copyright (C) 2007, Brian Edginton
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
24 #include "record-internal.h"
25 #include "protostructs.h"
35 using namespace Barry::Protocol
;
40 ///////////////////////////////////////////////////////////////////////////////
41 // Folder Class, static members
44 // Note! These functions currently only pass the same values through.
45 // In actuality, these are technically two different values:
46 // one on the raw protocol side, and the other part of the
47 // guaranteed Barry API. If the Blackberry ever changes the
48 // meanings for these codes, do the translation here.
51 Folder::FolderType
Folder::TypeProto2Rec(uint8_t t
)
56 uint8_t Folder::TypeRec2Proto(FolderType t
)
63 ///////////////////////////////////////////////////////////////////////////////
68 #define FFC_NUMBER 0x0a
69 #define FFC_LEVEL 0x0b
71 #define FFC_ADDRESS1 0x0d
72 #define FFC_ADDRESS2 0x0e
74 #define FFC_END 0xffff
78 #define SEPARATOR 0x2f
79 #define ROOT_SEPARATOR 0x3a
81 static FieldLink
<Folder
> FolderFieldLinks
[] = {
82 { FFC_NAME
, "FolderName", 0, 0, &Folder::Name
, 0, 0, 0, 0, true },
83 { FFC_END
, "End of List", 0, 0, 0, 0, 0, 0, 0, false },
96 const unsigned char* Folder::ParseField(const unsigned char *begin
,
97 const unsigned char *end
,
100 const CommonField
*field
= (const CommonField
*) begin
;
102 // advance and check size
103 begin
+= COMMON_FIELD_HEADER_SIZE
+ btohs(field
->size
);
104 if( begin
> end
) // if begin==end, we are ok
107 if( !btohs(field
->size
) ) // if field has no size, something's up
110 // cycle through the type table
111 for( FieldLink
<Folder
> *b
= FolderFieldLinks
;
115 if( b
->type
== field
->type
) {
117 std::string
&s
= this->*(b
->strMember
);
118 s
= ParseFieldString(field
);
119 if( b
->iconvNeeded
&& ic
)
121 return begin
; // done!
123 else if( b
->timeMember
&& btohs(field
->size
) == 4 ) {
124 time_t &t
= this->*(b
->timeMember
);
125 t
= min2time(field
->u
.min1900
);
130 // handle special cases
131 switch( field
->type
)
134 Type
= TypeProto2Rec(field
->u
.raw
[0]);
137 Number
= field
->u
.raw
[0]; // two's complement
140 Level
= field
->u
.raw
[0];
144 // if still not handled, add to the Unknowns list
146 uf
.type
= field
->type
;
147 uf
.data
.assign((const char*)field
->u
.raw
, btohs(field
->size
));
148 Unknowns
.push_back(uf
);
150 // return new pointer for next field
154 void Folder::ParseHeader(const Data
&data
, size_t &offset
)
156 // no header in Folder records
159 void Folder::ParseFields(const Data
&data
, size_t &offset
, const IConverter
*ic
)
161 const unsigned char *finish
= ParseCommonFields(*this,
162 data
.GetData() + offset
, data
.GetData() + data
.GetSize(), ic
);
163 offset
+= finish
- (data
.GetData() + offset
);
168 RecType
= GetDefaultRecType();
175 Type
= FolderSubtree
;
180 std::string
Folder::GetDescription() const
183 oss
<< Name
<< " (" << Level
<< ")";
187 void Folder::Dump(std::ostream
&os
) const
189 static const char *FolderTypeString
[] = { "Subtree", "Deleted", "Inbox", "Outbox", "Sent", "Other"};
190 // static const char *FolderStatusString[] = { "Orphan", "Unfiled", "Filed" };
192 os
<< "Folder Records\n\n";
193 os
<< "Folder Name: " << Name
<< "\n";
194 os
<< "Folder Type: ";
195 if( Type
< FolderDraft
)
196 os
<< FolderTypeString
[Type
] << "\n";
197 else if( Type
== FolderDraft
)
200 os
<< "Unknown (" << std::hex
<< Type
<< ")\n";
201 os
<< "Folder Number: " << std::dec
<< Number
<< "\n";
202 os
<< "Folder Level: " << std::dec
<< Level
<< "\n";