record-internal.h

Go to the documentation of this file.
00001 ///
00002 /// \file       record-internal.h
00003 ///             Support functions, types, and templates for the
00004 ///             general record parsing classes in r_*.h files.
00005 ///             This header is NOT installed for applications to
00006 ///             use, so it is safe to put library-specific things
00007 ///             in here.
00008 ///
00009 
00010 /*
00011     Copyright (C) 2005-2008, Net Direct Inc. (http://www.netdirect.ca/)
00012 
00013     This program is free software; you can redistribute it and/or modify
00014     it under the terms of the GNU General Public License as published by
00015     the Free Software Foundation; either version 2 of the License, or
00016     (at your option) any later version.
00017 
00018     This program is distributed in the hope that it will be useful,
00019     but WITHOUT ANY WARRANTY; without even the implied warranty of
00020     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00021 
00022     See the GNU General Public License in the COPYING file at the
00023     root directory of this project for more details.
00024 */
00025 
00026 #ifndef __BARRY_RECORD_INTERNAL_H__
00027 #define __BARRY_RECORD_INTERNAL_H__
00028 
00029 #include <string>
00030 #include "protostructs.h"
00031 #include "error.h"
00032 #include "endian.h"
00033 #include "record.h"
00034 
00035 // forward declarations
00036 namespace Barry { class Data; }
00037 
00038 namespace Barry {
00039 
00040 template <class RecordT>
00041 const unsigned char*  ParseCommonFields(RecordT &rec, const void *begin, const void *end)
00042 {
00043         const unsigned char *b = (const unsigned char*) begin;
00044         const unsigned char *e = (const unsigned char*) end;
00045 
00046         while( (b + COMMON_FIELD_HEADER_SIZE) < e )
00047                 b = rec.ParseField(b, e);
00048         return b;
00049 }
00050 
00051 // Use templates here to guarantee types are converted in the strictest manner.
00052 template <class SizeT>
00053 inline SizeT ConvertHtoB(SizeT s)
00054 {
00055         throw Error("Not implemented.");
00056 }
00057 
00058 // specializations for specific sizes
00059 template <> inline uint8_t ConvertHtoB<uint8_t>(uint8_t s)    { return s; }
00060 template <> inline uint16_t ConvertHtoB<uint16_t>(uint16_t s) { return htobs(s); }
00061 template <> inline uint32_t ConvertHtoB<uint32_t>(uint32_t s) { return htobl(s); }
00062 template <> inline uint64_t ConvertHtoB<uint64_t>(uint64_t s) { return htobll(s); }
00063 
00064 
00065 template <class RecordT>
00066 struct FieldLink
00067 {
00068         int type;
00069         const char *name;
00070         const char *ldif;
00071         const char *objectClass;
00072         std::string RecordT::* strMember;       // FIXME - find a more general
00073         EmailAddress RecordT::* addrMember;     // way to do this...
00074         time_t RecordT::* timeMember;
00075         PostalAddress RecordT::* postMember;
00076         std::string PostalAddress::* postField;
00077 };
00078 
00079 void BuildField1900(Data &data, size_t &size, uint8_t type, time_t t);
00080 void BuildField(Data &data, size_t &size, uint8_t type, char c);
00081 void BuildField(Data &data, size_t &size, uint8_t type, uint16_t value);
00082 void BuildField(Data &data, size_t &size, uint8_t type, const std::string &str);
00083 void BuildField(Data &data, size_t &size, uint8_t type, const void *buf, size_t bufsize);
00084 void BuildField(Data &data, size_t &size, const Barry::UnknownField &field);
00085 void BuildField(Data &data, size_t &size, uint8_t type, const Barry::Protocol::GroupLink &link);
00086 std::string ParseFieldString(const Barry::Protocol::CommonField *field);
00087 std::string ParseFieldString(const void *data, uint16_t maxlen);
00088 
00089 } // namespace Barry
00090 
00091 #endif
00092 

Generated on Wed Sep 24 21:27:32 2008 for Barry by  doxygen 1.5.1