3 /// Record parsing class for the memo database.
7 Copyright (C) 2005-2009, 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"
33 using namespace Barry::Protocol
;
37 ///////////////////////////////////////////////////////////////////////////////
41 #define MEMFC_TITLE 0x01
42 #define MEMFC_BODY 0x02
43 #define MEMFC_MEMO_TYPE 0x03
44 #define MEMFC_CATEGORY 0x04
45 #define MEMFC_END 0xffff
47 static FieldLink
<Memo
> MemoFieldLinks
[] = {
48 { MEMFC_TITLE
, "Title", 0, 0, &Memo::Title
, 0, 0, 0, 0, true },
49 { MEMFC_BODY
, "Body", 0, 0, &Memo::Body
, 0, 0, 0, 0, true },
50 { MEMFC_CATEGORY
, "Category", 0, 0, &Memo::Category
, 0, 0, 0, 0, true },
51 { MEMFC_END
, "End of List", 0, 0, 0, 0, 0, 0, 0, false }
63 const unsigned char* Memo::ParseField(const unsigned char *begin
,
64 const unsigned char *end
,
67 const CommonField
*field
= (const CommonField
*) begin
;
69 // advance and check size
70 begin
+= COMMON_FIELD_HEADER_SIZE
+ btohs(field
->size
);
71 if( begin
> end
) // if begin==end, we are ok
74 if( !btohs(field
->size
) ) // if field has no size, something's up
77 if( field
->type
== MEMFC_MEMO_TYPE
) {
78 if( ( MemoType
= field
->u
.raw
[0] ) != 'm' ) {
79 throw Error( "Memo::ParseField: MemoType is not 'm'" );
85 // cycle through the type table
86 for( FieldLink
<Memo
> *b
= MemoFieldLinks
;
90 if( b
->type
== field
->type
) {
92 std::string
&s
= this->*(b
->strMember
);
93 s
= ParseFieldString(field
);
94 if( b
->iconvNeeded
&& ic
)
96 return begin
; // done!
98 else if( b
->timeMember
&& btohs(field
->size
) == 4 ) {
99 time_t &t
= this->*(b
->timeMember
);
100 t
= min2time(field
->u
.min1900
);
106 // if still not handled, add to the Unknowns list
108 uf
.type
= field
->type
;
109 uf
.data
.assign((const char*)field
->u
.raw
, btohs(field
->size
));
110 Unknowns
.push_back(uf
);
112 // return new pointer for next field
116 void Memo::ParseHeader(const Data
&data
, size_t &offset
)
118 // no header in Memo records
121 void Memo::ParseFields(const Data
&data
, size_t &offset
, const IConverter
*ic
)
123 const unsigned char *finish
= ParseCommonFields(*this,
124 data
.GetData() + offset
, data
.GetData() + data
.GetSize(), ic
);
125 offset
+= finish
- (data
.GetData() + offset
);
129 void Memo::Dump(std::ostream
&os
) const
131 os
<< "Memo entry: 0x" << setbase(16) << RecordId
132 << " (" << (unsigned int)RecType
<< ")\n";
133 os
<< " Title: " << Title
<< "\n";
134 os
<< " Body: " << Body
<< "\n";
135 os
<< " Category: " << Category
<< "\n";