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
This commit is contained in:
paulc 2014-07-02 07:34:19 +00:00
parent ce97d09aa4
commit 5578f5ce60
2 changed files with 35 additions and 10 deletions

View File

@ -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<NamedString*>(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();
}
}

View File

@ -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;
};
/**