From 5578f5ce60947d9561b3126ea1290edfda7c5f70 Mon Sep 17 00:00:00 2001 From: paulc Date: Wed, 2 Jul 2014 07:34:19 +0000 Subject: [PATCH] Added hashing support for MimeSdpBody. Speed up MimeSdpBody::addLine() and made it return the added line. git-svn-id: http://yate.null.ro/svn/yate/trunk@5860 acf43c95-373e-0410-b603-e72c3f656dc1 --- engine/Mime.cpp | 28 +++++++++++++++++++++------- yatemime.h | 17 ++++++++++++++--- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/engine/Mime.cpp b/engine/Mime.cpp index 97ad06a5..76033267 100644 --- a/engine/Mime.cpp +++ b/engine/Mime.cpp @@ -885,32 +885,37 @@ bool MimeMultipartBody::getBoundary(String& boundary) const */ YCLASSIMP(MimeSdpBody,MimeBody) -MimeSdpBody::MimeSdpBody() - : MimeBody("application/sdp") +MimeSdpBody::MimeSdpBody(bool hashing) + : MimeBody("application/sdp"), + m_lineAppend(&m_lines), m_hash(0), m_hashing(hashing) { } MimeSdpBody::MimeSdpBody(const String& type, const char* buf, int len) - : MimeBody(type) + : MimeBody(type), + m_lineAppend(&m_lines), m_hash(0), m_hashing(false) { buildLines(buf,len); } MimeSdpBody::MimeSdpBody(const MimeHeaderLine& type, const char* buf, int len) - : MimeBody(type) + : MimeBody(type), + m_lineAppend(&m_lines), m_hash(0), m_hashing(false) { buildLines(buf,len); } MimeSdpBody::MimeSdpBody(const MimeSdpBody& original) - : MimeBody(original.getType()) + : MimeBody(original.getType()), + m_lineAppend(&m_lines), m_hash(original.m_hash), m_hashing(false) { const ObjList* l = &original.m_lines; for (; l; l = l->next()) { const NamedString* t = static_cast(l->get()); if (t) - m_lines.append(new NamedString(t->name(),*t)); + addLine(t->name(),*t); } + m_hashing = original.m_hashing; } MimeSdpBody::~MimeSdpBody() @@ -965,6 +970,15 @@ const NamedString* MimeSdpBody::getNextLine(const NamedString* line) const return 0; } +NamedString* MimeSdpBody::addLine(const char* name, const char* value) +{ + if (m_hashing) + m_hash = String::hash(value,String::hash(name,m_hash)); + NamedString* line = new NamedString(name,value); + m_lineAppend = m_lineAppend->append(line); + return line; +} + // Build the lines from a data buffer void MimeSdpBody::buildLines(const char* buf, int len) { @@ -972,7 +986,7 @@ void MimeSdpBody::buildLines(const char* buf, int len) String* line = getUnfoldedLine(buf,len); int eq = line->find('='); if (eq > 0) - m_lines.append(new NamedString(line->substr(0,eq),line->substr(eq+1))); + addLine(line->substr(0,eq),line->substr(eq+1)); line->destruct(); } } diff --git a/yatemime.h b/yatemime.h index 4eb480d4..3d240cd4 100644 --- a/yatemime.h +++ b/yatemime.h @@ -558,8 +558,9 @@ class YATE_API MimeSdpBody : public MimeBody public: /** * Default constructor, builds an empty application/sdp + * @param hashing Enable hashing the content lines */ - MimeSdpBody(); + MimeSdpBody(bool hashing = false); /** * Constructor from block of data @@ -609,13 +610,20 @@ public: inline const ObjList& lines() const { return m_lines; } + /** + * Retrieve the hash of body lines + * @return Hash of body, zero if hashing not enabled + */ + inline unsigned int hash() const + { return m_hash; } + /** * Append a new name=value line of SDP data * @param name Name of the line, should be one character * @param value Text of the line + * @return Pointer to new added line */ - inline void addLine(const char* name, const char* value = 0) - { m_lines.append(new NamedString(name,value)); } + NamedString* addLine(const char* name, const char* value = 0); /** * Retrieve the first line matching a name @@ -647,6 +655,9 @@ private: void buildLines(const char* buf, int len); ObjList m_lines; + ObjList* m_lineAppend; + unsigned int m_hash; + bool m_hashing; }; /**