# 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-2011, 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 {
    00037         class Data;
    00038         class IConverter;
    00039 }
    00040
    00041 namespace Barry {
    00042
    00043 template <class RecordT>
    00044 const unsigned char*  ParseCommonFields(RecordT &rec,
    00045                                         const void *begin,
    00046                                         const void *end,
    00047                                         const IConverter *ic = 0)
    00048 {
    00049         const unsigned char *b = (const unsigned char*) begin;
    00050         const unsigned char *e = (const unsigned char*) end;
    00051
    00052         while( (b + COMMON_FIELD_HEADER_SIZE) < e )
    00053                 b = rec.ParseField(b, e, ic);
    00054         return b;
    00055 }
    00056
    00057 // Use templates here to guarantee types are converted in the strictest manner.
    00058 template <class SizeT>
    00059 inline SizeT ConvertHtoB(SizeT s)
    00060 {
    00061         throw Error("Not implemented.");
    00062 }
    00063
    00064 // specializations for specific sizes
    00065 template <> inline uint8_t ConvertHtoB<uint8_t>(uint8_t s)    { return s; }
    00066 template <> inline uint16_t ConvertHtoB<uint16_t>(uint16_t s) { return htobs(s); }
    00067 template <> inline uint32_t ConvertHtoB<uint32_t>(uint32_t s) { return htobl(s); }
    00068 template <> inline uint64_t ConvertHtoB<uint64_t>(uint64_t s) { return htobll(s); }
    00069
    00070
    00071 template <class RecordT>
    00072 struct FieldLink
    00073 {
    00074         int type;
    00075         const char *name;
    00076         const char *ldif;
    00077         const char *objectClass;
    00078         std::string RecordT::* strMember;       // FIXME - find a more general
    00079         EmailAddressList RecordT::* addrMember; // way to do this...
    00080         time_t RecordT::* timeMember;
    00081         PostalAddress RecordT::* postMember;
    00082         std::string PostalAddress::* postField;
    00083         bool iconvNeeded;
    00084 };
    00085
    00086 void BuildField1900(Data &data, size_t &size, uint8_t type, time_t t);
    00087 void BuildField(Data &data, size_t &size, uint8_t type, char c);
    00088 void BuildField(Data &data, size_t &size, uint8_t type, uint8_t c);
    00089 void BuildField(Data &data, size_t &size, uint8_t type, uint16_t value);
    00090 void BuildField(Data &data, size_t &size, uint8_t type, uint32_t value);
    00091 void BuildField(Data &data, size_t &size, uint8_t type, uint64_t value);
    00092 void BuildField(Data &data, size_t &size, uint8_t type, const std::string &str);
    00093 void BuildField(Data &data, size_t &size, uint8_t type, const void *buf, size_t bufsize);
    00094 void BuildField(Data &data, size_t &size, const Barry::UnknownField &field);
    00095 void BuildField(Data &data, size_t &size, uint8_t type, const Barry::Protocol::GroupLink &link);
    00096 std::string ParseFieldString(const Barry::Protocol::CommonField *field);
    00097 std::string ParseFieldString(const void *data, uint16_t maxlen);
    00098
    00099
    00100 // Functions to help build JDWP command packets
    00101 void AddJDWByte(Barry::Data &data, size_t &size, const uint8_t value);
    00102 void AddJDWInt(Barry::Data &data, size_t &size, const uint32_t value);
    00103 void AddJDWChar(Barry::Data &data, size_t &size, const void *buf, size_t bufsize);
    00104 void AddJDWString(Barry::Data &data, size_t &size, const std::string &str);
    00105
    00106 } // namespace Barry
    00107
    00108 #endif
    00109