reSIProcate/stack  9694
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
resip::MultipartMixedContents Class Reference

SIP body type for holding Multipart-Mixed body contents (MIME content-type multipart/mixed). More...

#include <MultipartMixedContents.hxx>

Inheritance diagram for resip::MultipartMixedContents:
Inheritance graph
[legend]
Collaboration diagram for resip::MultipartMixedContents:
Collaboration graph
[legend]

List of all members.

Classes

class  Exception
 Thrown when there is an error parsing a multi-part mixed contents envelope. More...

Public Types

typedef std::vector< Contents * > Parts

Public Member Functions

 MultipartMixedContents ()
 MultipartMixedContents (const Mime &contentType)
 MultipartMixedContents (const HeaderFieldValue &hfv, const Mime &contentType)
 MultipartMixedContents (const MultipartMixedContents &rhs)
virtual ~MultipartMixedContents ()
MultipartMixedContentsoperator= (const MultipartMixedContents &rhs)
virtual Contentsclone () const
 duplicate an MultipartMixedContents object
virtual EncodeStreamencodeParsed (EncodeStream &str) const
virtual void parse (ParseBuffer &pb)
Partsparts ()
const Partsparts () const
void setBoundary (const Data &boundary)

Static Public Member Functions

static const MimegetStaticType ()
static bool init ()

Protected Member Functions

void clear ()

Private Member Functions

void setBoundary ()

Private Attributes

std::vector< Contents * > mContents

Detailed Description

SIP body type for holding Multipart-Mixed body contents (MIME content-type multipart/mixed).

Definition at line 19 of file MultipartMixedContents.hxx.


Member Typedef Documentation

Definition at line 39 of file MultipartMixedContents.hxx.


Constructor & Destructor Documentation

MultipartMixedContents::MultipartMixedContents ( )

Definition at line 26 of file MultipartMixedContents.cxx.

References setBoundary().

Referenced by clone().

Here is the call graph for this function:

MultipartMixedContents::MultipartMixedContents ( const Mime contentType) [explicit]

Definition at line 33 of file MultipartMixedContents.cxx.

References resip::Mime::exists(), resip::Contents::mType, and setBoundary().

   : Contents(contentsType),
     mContents()
{
   if (!mType.exists(p_boundary))
   {
      setBoundary();
   }
}

Here is the call graph for this function:

MultipartMixedContents::MultipartMixedContents ( const HeaderFieldValue hfv,
const Mime contentType 
)

Definition at line 43 of file MultipartMixedContents.cxx.

References resip::Mime::exists(), resip::Contents::mType, and setBoundary().

   : Contents(hfv, contentsType),
     mContents()
{
   if (!mType.exists(p_boundary))
   {
      setBoundary();
   }
}

Here is the call graph for this function:

MultipartMixedContents::MultipartMixedContents ( const MultipartMixedContents rhs)

Definition at line 53 of file MultipartMixedContents.cxx.

References mContents.

   : Contents(rhs),
     mContents()
{
   vector<Contents*>::const_iterator j;

   // .bwc. Don't trigger a parse of the original by calling parts()
   const vector<Contents*>& list = rhs.mContents;
   
   for ( j = list.begin(); 
         j != list.end(); ++j)
   {
      assert( *j );
      mContents.push_back( (*j)->clone() );
   }
}
MultipartMixedContents::~MultipartMixedContents ( ) [virtual]

Definition at line 93 of file MultipartMixedContents.cxx.

References clear().

{
   clear();
}

Here is the call graph for this function:


Member Function Documentation

void MultipartMixedContents::clear ( void  ) [protected]
Todo:
!bwc! Calls freeMem(), then reverts members to a default state (including setting pointers to 0)

Reimplemented from resip::Contents.

Definition at line 84 of file MultipartMixedContents.cxx.

References mContents.

Referenced by operator=(), and ~MultipartMixedContents().

{
   for (vector<Contents*>::iterator i = mContents.begin(); 
        i != mContents.end(); ++i)
   {
      delete *i;
   }
}
Contents * MultipartMixedContents::clone ( ) const [virtual]

duplicate an MultipartMixedContents object

Returns:
pointer to a new MultipartMixedContents object

Implements resip::Contents.

Reimplemented in resip::MultipartSignedContents, resip::MultipartAlternativeContents, and resip::MultipartRelatedContents.

Definition at line 116 of file MultipartMixedContents.cxx.

References MultipartMixedContents().

{
   return new MultipartMixedContents(*this);
}

Here is the call graph for this function:

EncodeStream & MultipartMixedContents::encodeParsed ( EncodeStream str) const [virtual]

Implements resip::LazyParser.

Definition at line 129 of file MultipartMixedContents.cxx.

References resip::Symbols::CRLF, CRLF, resip::Symbols::DASHDASH, mContents, resip::Contents::mType, resip::ParserCategory::param(), resip::Data::Preallocate, resip::Data::replace(), and resip::Data::size().

{
   const Data& boundaryToken = mType.param(p_boundary);
   Data boundary(boundaryToken.size() + 2, Data::Preallocate);
   boundary = Symbols::DASHDASH;
   boundary += boundaryToken;
   boundary.replace("\"", ""); // remove quotes

   assert( mContents.size() > 0 );
   
   bool first = true;
   for (vector<Contents*>::const_iterator i = mContents.begin(); 
        i != mContents.end(); ++i)
   {
      if (!first)
      {
         str << Symbols::CRLF;
      }
      else
      {
         first = false;
      }
      str << boundary << Symbols::CRLF;
      (*i)->encodeHeaders(str);
      (*i)->encode(str);
   }

   str << Symbols::CRLF << boundary << Symbols::DASHDASH;
   return str;
}

Here is the call graph for this function:

const Mime & MultipartMixedContents::getStaticType ( ) [static]

Reimplemented in resip::MultipartSignedContents, resip::MultipartAlternativeContents, and resip::MultipartRelatedContents.

Definition at line 122 of file MultipartMixedContents.cxx.

References type.

{
   static Mime type("multipart","mixed");
   return type;
}
bool MultipartMixedContents::init ( ) [static]

Reimplemented from resip::Contents.

Reimplemented in resip::MultipartSignedContents, resip::MultipartAlternativeContents, and resip::MultipartRelatedContents.

Definition at line 19 of file MultipartMixedContents.cxx.

{
   static ContentsFactory<MultipartMixedContents> factory;
   (void)factory;
   return true;
}
MultipartMixedContents & MultipartMixedContents::operator= ( const MultipartMixedContents rhs)

Definition at line 99 of file MultipartMixedContents.cxx.

References clear(), and mContents.

{
   if (this != &rhs)
   {
      Contents::operator=(rhs);
      clear();
      
      for (vector<Contents*>::iterator i = mContents.begin(); 
           i != mContents.end(); ++i)
      {
         mContents.push_back( (*i)->clone() );
      }
   }
   return *this;
}

Here is the call graph for this function:

void MultipartMixedContents::parse ( ParseBuffer pb) [virtual]

Implements resip::LazyParser.

Definition at line 164 of file MultipartMixedContents.cxx.

References resip::ParseBuffer::assertNotEof(), resip::Symbols::COLON, resip::Symbols::CR, resip::Contents::createContents(), CRLF, resip::Symbols::CRLFCRLF, resip::Symbols::DASHDASH, resip::ParseBuffer::data(), resip::ParseBuffer::eof(), resip::Symbols::LF, mContents, resip::Contents::mType, resip::ParserCategory::param(), resip::Mime::parse(), resip::ParseBuffer::position(), resip::Data::Preallocate, resip::ParseBuffer::reset(), resip::Data::size(), resip::ParseBuffer::skipChar(), resip::ParseBuffer::skipN(), resip::ParseBuffer::skipToChar(), resip::ParseBuffer::skipToChars(), resip::ParseBuffer::skipToTermCRLF(), and resip::ParseBuffer::skipWhitespace().

{
   const Data& boundaryToken = mType.param(p_boundary);
   
   Data boundary(boundaryToken.size() + 4, Data::Preallocate);
   boundary += Symbols::CRLF;
   boundary += Symbols::DASHDASH;
   boundary += boundaryToken;

   Data boundaryNoCRLF(boundaryToken.size() + 2, Data::Preallocate);
   boundaryNoCRLF += Symbols::DASHDASH;
   boundaryNoCRLF += boundaryToken;

   pb.skipToChars(boundaryNoCRLF);
   pb.skipN((int)boundaryNoCRLF.size());
   pb.assertNotEof();

   do
   {
      // skip over boundary
 
      if( pb.eof() || *pb.position() != Symbols::CR[0] )
      {
         throw Exception("Invalid line ending, missing CR",__FILE__,__LINE__);
      }
      pb.skipChar();
      if( pb.eof() || *pb.position() != Symbols::LF[0] )
      {
         throw Exception("Invalid line ending, missing LF",__FILE__,__LINE__);
      }
      pb.skipChar();
      
      pb.assertNotEof();

      const char* headerStart = pb.position();

      // pull out contents type only
      pb.skipToChars("Content-Type");
      if (pb.eof())
      {
         pb.reset(headerStart);
         pb.skipToChars("CONTENT-TYPE");
      }
      pb.assertNotEof();

      pb.skipToChar(Symbols::COLON[0]);
      pb.skipChar();
      pb.assertNotEof();
      
      pb.skipWhitespace();
      const char* typeStart = pb.position();
      pb.assertNotEof();
      
      // determine contents-type header buffer
      pb.skipToTermCRLF();
      pb.assertNotEof();

      ParseBuffer subPb(typeStart, pb.position() - typeStart);
      Mime contentType;
      contentType.parse(subPb);
      
      pb.assertNotEof();

      // determine body start
      pb.reset(typeStart);
      const char* bodyStart = pb.skipToChars(Symbols::CRLFCRLF);
      pb.assertNotEof();
      bodyStart += 4;

      // determine contents body buffer
      pb.skipToChars(boundary);
      pb.assertNotEof();
      Data tmp;
      pb.data(tmp, bodyStart);
      // create contents against body
      mContents.push_back(createContents(contentType, tmp));
      // pre-parse headers
      ParseBuffer headersPb(headerStart, bodyStart-4-headerStart);
      mContents.back()->preParseHeaders(headersPb);

      pb.skipN((int)boundary.size());

      const char* loc = pb.position();
      pb.skipChar();
      pb.skipChar();
      Data next;
      pb.data(next, loc);

      if ( next == Symbols::DASHDASH )
      {
         break;
      }
      pb.reset( loc );
   }
   while ( !pb.eof() );

}

Here is the call graph for this function:

Parts& resip::MultipartMixedContents::parts ( ) [inline]
const Parts& resip::MultipartMixedContents::parts ( ) const [inline]

Definition at line 41 of file MultipartMixedContents.hxx.

References resip::LazyParser::checkParsed(), and mContents.

{checkParsed(); return mContents;}

Here is the call graph for this function:

void MultipartMixedContents::setBoundary ( const Data boundary)

Definition at line 78 of file MultipartMixedContents.cxx.

References resip::Contents::mType, and resip::ParserCategory::param().

{
    mType.param(p_boundary) = boundary;
}

Here is the call graph for this function:

void MultipartMixedContents::setBoundary ( ) [private]

Definition at line 71 of file MultipartMixedContents.cxx.

References resip::Random::getRandomHex(), resip::Contents::mType, and resip::ParserCategory::param().

Referenced by MultipartMixedContents().

{
   Data boundaryToken = Random::getRandomHex(8);
   mType.param(p_boundary) = boundaryToken;
}

Here is the call graph for this function:


Member Data Documentation


The documentation for this class was generated from the following files: