From 370f3ee133b11e45699ea7ff6c053e814f9c76fa Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Thu, 1 May 2008 20:06:56 -0400 Subject: [PATCH] Made UnknownField's data member into its own type. This is so that when building records, unknown data doesn't get processed like a null terminated string. Also added more BuildField() helper functions for accuracy and ease of use. --- ChangeLog | 4 ++++ src/r_calendar.cc | 2 +- src/r_contact.cc | 2 +- src/record-internal.h | 2 ++ src/record.cc | 22 ++++++++++++++++++++++ src/record.h | 12 +++++++++++- src/s11n-boost.h | 2 +- 7 files changed, 42 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f33401c1..8f0d2878 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,10 @@ Release: version 0.13 - 2008/05/?? in src/probe.cc, since some devices, like the 8700 have both RIM_UsbSerData mode and IpModem mode. - fixed serialization code for Calendar record class, in s11n-boost.h + - made UnknownField's data member into its own type, + so that when building records, it doesn't get processed + like a null terminated string... also added more + BuildField() helper functions for accuracy 2008/04/29 - applied Jason Thomas's ACLOCAL_FLAGS patch to make autoreconf work again... Thanks! diff --git a/src/r_calendar.cc b/src/r_calendar.cc index b4c62ee2..dd3461a1 100644 --- a/src/r_calendar.cc +++ b/src/r_calendar.cc @@ -366,7 +366,7 @@ void Calendar::BuildFields(Data &data, size_t &offset) const UnknownsType::const_iterator ub = Unknowns.begin(), ue = Unknowns.end(); for( ; ub != ue; ub++ ) { - BuildField(data, offset, ub->type, ub->data); + BuildField(data, offset, *ub); } data.ReleaseBuffer(offset); diff --git a/src/r_contact.cc b/src/r_contact.cc index 32be3ab0..a547a8ca 100644 --- a/src/r_contact.cc +++ b/src/r_contact.cc @@ -315,7 +315,7 @@ void Contact::BuildFields(Data &data, size_t &offset) const UnknownsType::const_iterator ub = Unknowns.begin(), ue = Unknowns.end(); for( ; ub != ue; ub++ ) { - BuildField(data, offset, ub->type, ub->data.c_str(), ub->data.size()); + BuildField(data, offset, *ub); } data.ReleaseBuffer(offset); diff --git a/src/record-internal.h b/src/record-internal.h index 69c9ff51..1bebdbf2 100644 --- a/src/record-internal.h +++ b/src/record-internal.h @@ -78,8 +78,10 @@ struct FieldLink void BuildField1900(Data &data, size_t &size, uint8_t type, time_t t); void BuildField(Data &data, size_t &size, uint8_t type, char c); +void BuildField(Data &data, size_t &size, uint8_t type, uint16_t value); void BuildField(Data &data, size_t &size, uint8_t type, const std::string &str); void BuildField(Data &data, size_t &size, uint8_t type, const void *buf, size_t bufsize); +void BuildField(Data &data, size_t &size, const Barry::UnknownField &field); void BuildField(Data &data, size_t &size, uint8_t type, const Barry::Protocol::GroupLink &link); std::string ParseFieldString(const Barry::Protocol::CommonField *field); std::string ParseFieldString(const void *data, uint16_t maxlen); diff --git a/src/record.cc b/src/record.cc index 154d97ce..7a9c524a 100644 --- a/src/record.cc +++ b/src/record.cc @@ -76,6 +76,22 @@ void BuildField(Data &data, size_t &size, uint8_t type, char c) size += fieldsize; } +void BuildField(Data &data, size_t &size, uint8_t type, uint16_t value) +{ + size_t strsize = 2; + size_t fieldsize = COMMON_FIELD_HEADER_SIZE + strsize; + unsigned char *pd = data.GetBuffer(size + fieldsize) + size; + CommonField *field = (CommonField *) pd; + + field->size = htobs(strsize); + field->type = type; + + uint16_t store = htobs(value); + memcpy(field->u.raw, &store, strsize); + + size += fieldsize; +} + void BuildField(Data &data, size_t &size, uint8_t type, const std::string &str) { // include null terminator @@ -97,6 +113,12 @@ void BuildField(Data &data, size_t &size, uint8_t type, size += fieldsize; } +void BuildField(Data &data, size_t &size, const Barry::UnknownField &field) +{ + BuildField(data, size, field.type, + field.data.raw_data.data(), field.data.raw_data.size()); +} + void BuildField(Data &data, size_t &size, uint8_t type, const Barry::Protocol::GroupLink &link) { size_t linksize = sizeof(Barry::Protocol::GroupLink); diff --git a/src/record.h b/src/record.h index 3c6a388e..c697d0c7 100644 --- a/src/record.h +++ b/src/record.h @@ -171,10 +171,20 @@ BXEXPORT inline std::ostream& operator<<(std::ostream &os, const DatabaseDatabas return os; } +struct UnknownData +{ + std::string raw_data; + + const std::string::value_type* data() const { return raw_data.data(); } + std::string::size_type size() const { return raw_data.size(); } + void assign(const std::string::value_type *s, std::string::size_type n) + { raw_data.assign(s, n); } +}; + struct BXEXPORT UnknownField { uint8_t type; - std::string data; + UnknownData data; }; BXEXPORT std::ostream& operator<< (std::ostream &os, const std::vector &unknowns); diff --git a/src/s11n-boost.h b/src/s11n-boost.h index 8b90e377..065d1076 100644 --- a/src/s11n-boost.h +++ b/src/s11n-boost.h @@ -49,7 +49,7 @@ template void serialize(ArchiveT &ar, Barry::UnknownField &uf, const unsigned int ver) { ar & make_nvp("type", uf.type); - ar & make_nvp("data", uf.data); + ar & make_nvp("data", uf.data.raw_data); } template -- 2.11.4.GIT