- added raw data version of BuildField() to record-internal.h
[barry.git] / src / record-internal.h
blob9d32c600bd716b76ca4228bcdd8474f47664015c
1 ///
2 /// \file record-internal.h
3 /// Support functions, types, and templates for the
4 /// general record parsing classes in r_*.h files.
5 /// This header is NOT installed for applications to
6 /// use, so it is safe to put library-specific things
7 /// in here.
8 ///
11 Copyright (C) 2005-2007, Net Direct Inc. (http://www.netdirect.ca/)
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 See the GNU General Public License in the COPYING file at the
23 root directory of this project for more details.
26 #ifndef __BARRY_RECORD_INTERNAL_H__
27 #define __BARRY_RECORD_INTERNAL_H__
29 #include <string>
30 #include "protostructs.h"
31 #include "error.h"
32 #include "endian.h"
34 // forward declarations
35 namespace Barry { class Data; }
37 namespace Barry {
39 template <class RecordT>
40 const unsigned char* ParseCommonFields(RecordT &rec, const void *begin, const void *end)
42 const unsigned char *b = (const unsigned char*) begin;
43 const unsigned char *e = (const unsigned char*) end;
45 while( (b + COMMON_FIELD_HEADER_SIZE) < e )
46 b = rec.ParseField(b, e);
47 return b;
50 // Use templates here to guarantee types are converted in the strictest manner.
51 template <class SizeT>
52 inline SizeT ConvertHtoB(SizeT s)
54 throw Error("Not implemented.");
57 // specializations for specific sizes
58 template <> inline uint8_t ConvertHtoB<uint8_t>(uint8_t s) { return s; }
59 template <> inline uint16_t ConvertHtoB<uint16_t>(uint16_t s) { return htobs(s); }
60 template <> inline uint32_t ConvertHtoB<uint32_t>(uint32_t s) { return htobl(s); }
61 template <> inline uint64_t ConvertHtoB<uint64_t>(uint64_t s) { return htobll(s); }
64 template <class RecordT>
65 struct FieldLink
67 int type;
68 char *name;
69 char *ldif;
70 char *objectClass;
71 std::string RecordT::* strMember; // FIXME - find a more general
72 EmailAddress RecordT::* addrMember; // way to do this...
73 time_t RecordT::* timeMember;
74 PostalAddress RecordT::* postMember;
75 std::string PostalAddress::* postField;
78 void BuildField1900(Data &data, size_t &size, uint8_t type, time_t t);
79 void BuildField(Data &data, size_t &size, uint8_t type, char c);
80 void BuildField(Data &data, size_t &size, uint8_t type, const std::string &str);
81 void BuildField(Data &data, size_t &size, uint8_t type, const void *buf, size_t bufsize);
82 void BuildField(Data &data, size_t &size, uint8_t type, const Barry::Protocol::GroupLink &link);
83 std::string ParseFieldString(const Barry::Protocol::CommonField *field);
84 std::string ParseFieldString(const void *data, uint16_t maxlen);
86 } // namespace Barry
88 #endif