3 /// Record parsing class for the folders database.
7 Copyright (C) 2005-2012, 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.
25 #include "record-internal.h"
26 #include "protostructs.h"
34 #include "ios_state.h"
37 using namespace Barry::Protocol
;
42 ///////////////////////////////////////////////////////////////////////////////
43 // Folder Class, static members
46 // Note! These functions currently only pass the same values through.
47 // In actuality, these are technically two different values:
48 // one on the raw protocol side, and the other part of the
49 // guaranteed Barry API. If the Blackberry ever changes the
50 // meanings for these codes, do the translation here.
53 Folder::FolderType
Folder::TypeProto2Rec(uint8_t t
)
58 uint8_t Folder::TypeRec2Proto(FolderType t
)
65 ///////////////////////////////////////////////////////////////////////////////
70 #define FFC_NUMBER 0x0a
71 #define FFC_LEVEL 0x0b
73 #define FFC_ADDRESS1 0x0d
74 #define FFC_ADDRESS2 0x0e
76 #define FFC_END 0xffff
80 #define SEPARATOR 0x2f
81 #define ROOT_SEPARATOR 0x3a
83 static FieldLink
<Folder
> FolderFieldLinks
[] = {
84 { FFC_NAME
, N_("FolderName"), 0, 0, &Folder::Name
, 0, 0, 0, 0, true },
85 { FFC_END
, N_("End of List"), 0, 0, 0, 0, 0, 0, 0, false },
98 const unsigned char* Folder::ParseField(const unsigned char *begin
,
99 const unsigned char *end
,
100 const IConverter
*ic
)
102 const CommonField
*field
= (const CommonField
*) begin
;
104 // advance and check size
105 begin
+= COMMON_FIELD_HEADER_SIZE
+ btohs(field
->size
);
106 if( begin
> end
) // if begin==end, we are ok
109 if( !btohs(field
->size
) ) // if field has no size, something's up
112 // cycle through the type table
113 for( FieldLink
<Folder
> *b
= FolderFieldLinks
;
117 if( b
->type
== field
->type
) {
119 std::string
&s
= this->*(b
->strMember
);
120 s
= ParseFieldString(field
);
121 if( b
->iconvNeeded
&& ic
)
123 return begin
; // done!
125 else if( b
->timeMember
&& btohs(field
->size
) == 4 ) {
126 TimeT
&t
= this->*(b
->timeMember
);
127 t
.Time
= min2time(field
->u
.min1900
);
132 // handle special cases
133 switch( field
->type
)
136 Type
= TypeProto2Rec(field
->u
.raw
[0]);
139 Number
= field
->u
.raw
[0]; // two's complement
142 Level
= field
->u
.raw
[0];
146 // if still not handled, add to the Unknowns list
148 uf
.type
= field
->type
;
149 uf
.data
.assign((const char*)field
->u
.raw
, btohs(field
->size
));
150 Unknowns
.push_back(uf
);
152 // return new pointer for next field
156 void Folder::ParseHeader(const Data
&data
, size_t &offset
)
158 // no header in Folder records
161 void Folder::ParseFields(const Data
&data
, size_t &offset
, const IConverter
*ic
)
163 const unsigned char *finish
= ParseCommonFields(*this,
164 data
.GetData() + offset
, data
.GetData() + data
.GetSize(), ic
);
165 offset
+= finish
- (data
.GetData() + offset
);
168 void Folder::Validate() const
172 void Folder::BuildHeader(Data
&data
, size_t &offset
) const
174 // not yet implemented
177 void Folder::BuildFields(Data
&data
, size_t &offset
, const IConverter
*ic
) const
179 // not yet implemented
184 RecType
= GetDefaultRecType();
191 Type
= FolderSubtree
;
196 const FieldHandle
<Folder
>::ListT
& Folder::GetFieldHandles()
198 static FieldHandle
<Folder
>::ListT fhv
;
203 #undef CONTAINER_OBJECT_NAME
204 #define CONTAINER_OBJECT_NAME fhv
206 #undef RECORD_CLASS_NAME
207 #define RECORD_CLASS_NAME Folder
209 FHP(RecType
, _("Record Type Code"));
210 FHP(RecordId
, _("Unique Record ID"));
212 FHD(Name
, _("Folder Name"), FFC_NAME
, true);
213 FHD(Number
, _("Order Number"), FFC_NUMBER
, false);
214 FHD(Level
, _("Folder Level"), FFC_LEVEL
, false);
216 FHE(ft
, FolderType
, Type
, _("Folder Type"));
217 FHE_CONST(ft
, FolderSubtree
, _("Subtree"));
218 FHE_CONST(ft
, FolderDeleted
, _("Deleted"));
219 FHE_CONST(ft
, FolderInbox
, _("Inbox"));
220 FHE_CONST(ft
, FolderOutbox
, _("Outbox"));
221 FHE_CONST(ft
, FolderSent
, _("Sent"));
222 FHE_CONST(ft
, FolderOther
, _("Other"));
223 FHE_CONST(ft
, FolderDraft
, _("Draft"));
225 // Not yet implemented
226 // FHE(fst, FolderStatusType, ..., _("Folder Status"));
227 // FHE_CONST(fst, FolderOrphan, _("Orphan"));
228 // FHE_CONST(fst, FolderUnfiled, _("Unfiled"));
229 // FHE_CONST(fst, FolderFiled, _("Filed"));
231 FHP(Unknowns
, _("Unknown Fields"));
236 std::string
Folder::GetDescription() const
239 oss
<< Name
<< " (" << Level
<< ")";
243 void Folder::Dump(std::ostream
&os
) const
245 ios_format_state
state(os
);
247 static const char *FolderTypeString
[] = {
255 // static const char *FolderStatusString[] = { "Orphan", "Unfiled", "Filed" };
257 os
<< _("Folder Records\n\n");
258 os
<< _("Folder Name: ") << Name
<< "\n";
259 os
<< _("Folder Type: ");
260 if( Type
< FolderDraft
)
261 os
<< gettext( FolderTypeString
[Type
] ) << "\n";
262 else if( Type
== FolderDraft
)
265 os
<< _("Unknown") << " (" << std::hex
<< Type
<< ")\n";
266 os
<< _("Folder Number: ") << std::dec
<< Number
<< "\n";
267 os
<< _("Folder Level: ") << std::dec
<< Level
<< "\n";