Added methods to find additional headers and set/get header parameters.

git-svn-id: http://voip.null.ro/svn/yate@1610 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2008-01-09 13:17:59 +00:00
parent 03335a7dcb
commit 3350f4a56c
2 changed files with 83 additions and 0 deletions

View File

@ -321,6 +321,53 @@ MimeBody::~MimeBody()
DDebug(DebugAll,"MimeBody::~MimeBody() '%s' [%p]",m_type.c_str(),this);
}
// Find an additional header line by its name
MimeHeaderLine* MimeBody::findHdr(const char* name, const MimeHeaderLine* start) const
{
ObjList* o = m_headers.skipNull();
if (!o)
return 0;
// Find start point
if (start)
for (; o; o = o->skipNext())
if (start == o->get()) {
o = o->skipNext();
break;
}
// Find the header
for (; o; o = o->skipNext()) {
MimeHeaderLine* hdr = static_cast<MimeHeaderLine*>(o->get());
if (hdr->name() &= name)
return hdr;
}
return 0;
}
// Replace the value of an existing parameter or add a new one
bool MimeBody::setParam(const char* name, const char* value, const char* header)
{
MimeHeaderLine* hdr = (!(header && *header)) ? &m_type : findHdr(header);
if (hdr)
hdr->setParam(name,value);
return (hdr != 0);
}
// Remove a header parameter
bool MimeBody::delParam(const char* name, const char* header)
{
MimeHeaderLine* hdr = (!(header && *header)) ? &m_type : findHdr(header);
if (hdr)
hdr->delParam(name);
return (hdr != 0);
}
// Get a header parameter
const NamedString* MimeBody::getParam(const char* name, const char* header) const
{
const MimeHeaderLine* hdr = (!(header && *header)) ? &m_type : findHdr(header);
return hdr ? hdr->getParam(name) : 0;
}
const DataBlock& MimeBody::getBody() const
{
if (m_body.null())

View File

@ -256,6 +256,42 @@ public:
inline void removeHdr(MimeHeaderLine* hdr)
{ if (hdr) m_headers.remove(hdr); }
/**
* Find an additional header line by its name. The names are compared case insensitive
* @param name The name of the header to find
* @param start The starting point in the list. 0 to start from the beginning
* @return Pointer to MimeHeaderLine or 0 if not found
*/
MimeHeaderLine* findHdr(const char* name, const MimeHeaderLine* start = 0) const;
/**
* Replace the value of an existing parameter or add a new one
* @param name Parameter's name
* @param value Parameter's value
* @param header Header whose parameter will be changed.
* Set to 0 to use the body's content type header
* @return False if the header doesn't exist
*/
bool setParam(const char* name, const char* value = 0, const char* header = 0);
/**
* Remove a header parameter
* @param name Parameter's name
* @param header Header whose parameter will be removed.
* Set to 0 to use the body's content type header
* @return False if the header doesn't exist
*/
bool delParam(const char* name, const char* header = 0);
/**
* Get a header parameter
* @param name Parameter's name
* @param header Header whose parameter will be retrived.
* Set to 0 to use the body's content type header
* @return Pointer to the desired parameter or 0 if not found
*/
const NamedString* getParam(const char* name, const char* header = 0) const;
/**
* Retrive the binary encoding of this MIME body
* @return Block of binary data