3 /// Record parsing class for the memo database.
7 Copyright (C) 2005-2008, 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"
32 using namespace Barry::Protocol
;
36 ///////////////////////////////////////////////////////////////////////////////
40 #define MEMFC_TITLE 0x01
41 #define MEMFC_BODY 0x02
42 #define MEMFC_MEMO_TYPE 0x03
43 #define MEMFC_CATEGORY 0x04
44 #define MEMFC_END 0xffff
46 FieldLink
<Memo
> MemoFieldLinks
[] = {
47 { MEMFC_TITLE
, "Title", 0, 0, &Memo::Title
, 0, 0 },
48 { MEMFC_BODY
, "Body", 0, 0, &Memo::Body
, 0, 0 },
49 { MEMFC_CATEGORY
, "Category", 0, 0, &Memo::Category
, 0, 0 },
50 { MEMFC_END
, "End of List", 0, 0, 0, 0, 0 }
62 const unsigned char* Memo::ParseField(const unsigned char *begin
,
63 const unsigned char *end
)
65 const CommonField
*field
= (const CommonField
*) begin
;
67 // advance and check size
68 begin
+= COMMON_FIELD_HEADER_SIZE
+ btohs(field
->size
);
69 if( begin
> end
) // if begin==end, we are ok
72 if( !btohs(field
->size
) ) // if field has no size, something's up
75 if( field
->type
== MEMFC_MEMO_TYPE
) {
76 if( ( MemoType
= field
->u
.raw
[0] ) != 'm' ) {
77 throw Error( "Memo::ParseField: MemoType is not 'm'" );
83 // cycle through the type table
84 for( FieldLink
<Memo
> *b
= MemoFieldLinks
;
88 if( b
->type
== field
->type
) {
90 std::string
&s
= this->*(b
->strMember
);
91 s
= ParseFieldString(field
);
92 return begin
; // done!
94 else if( b
->timeMember
&& btohs(field
->size
) == 4 ) {
95 time_t &t
= this->*(b
->timeMember
);
96 t
= min2time(field
->u
.min1900
);
102 // if still not handled, add to the Unknowns list
104 uf
.type
= field
->type
;
105 uf
.data
.assign((const char*)field
->u
.raw
, btohs(field
->size
));
106 Unknowns
.push_back(uf
);
108 // return new pointer for next field
112 void Memo::ParseHeader(const Data
&data
, size_t &offset
)
114 // no header in Memo records
117 void Memo::ParseFields(const Data
&data
, size_t &offset
)
119 const unsigned char *finish
= ParseCommonFields(*this,
120 data
.GetData() + offset
, data
.GetData() + data
.GetSize());
121 offset
+= finish
- (data
.GetData() + offset
);
125 void Memo::Dump(std::ostream
&os
) const
127 os
<< "Memo entry: 0x" << setbase(16) << RecordId
128 << " (" << (unsigned int)RecType
<< ")\n";
129 os
<< " Title: " << Title
<< "\n";
130 os
<< " Body: " << Body
<< "\n";
131 os
<< " Category: " << Category
<< "\n";