reSIProcate/stack  9694
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
resip::SipFrag Class Reference

SIP body type for holding SipFrag contents (MIME content-type message/sipfrag). More...

#include <SipFrag.hxx>

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

List of all members.

Public Member Functions

 SipFrag (const Mime &contentsType=getStaticType())
 SipFrag (const HeaderFieldValue &hfv, const Mime &contentsType)
 SipFrag (const Data &data, const Mime &contentsType)
 SipFrag (const SipFrag &rhs)
virtual ~SipFrag ()
SipFragoperator= (const SipFrag &rhs)
virtual Contentsclone () const
 duplicate an SipFrag object
SipMessagemessage ()
const SipMessagemessage () const
virtual EncodeStreamencodeParsed (EncodeStream &str) const
virtual void parse (ParseBuffer &pb)

Static Public Member Functions

static const MimegetStaticType ()
static bool init ()

Private Member Functions

bool hasStartLine (char *buffer, int size)

Private Attributes

SipMessagemMessage
char scratchpad [4]

Detailed Description

SIP body type for holding SipFrag contents (MIME content-type message/sipfrag).

Definition at line 21 of file SipFrag.hxx.


Constructor & Destructor Documentation

SipFrag::SipFrag ( const Mime contentsType = getStaticType())

Definition at line 25 of file SipFrag.cxx.

Referenced by clone().

   : Contents(contentsType),
     mMessage(new SipMessage())
{}
SipFrag::SipFrag ( const HeaderFieldValue hfv,
const Mime contentsType 
)

Definition at line 30 of file SipFrag.cxx.

   : Contents(hfv, HeaderFieldValue::CopyPadding, contentsType),
     mMessage(0)
{
}
resip::SipFrag::SipFrag ( const Data data,
const Mime contentsType 
)
SipFrag::SipFrag ( const SipFrag rhs)

Definition at line 36 of file SipFrag.cxx.

SipFrag::~SipFrag ( ) [virtual]

Definition at line 42 of file SipFrag.cxx.

References mMessage.

{
   delete mMessage;
}

Member Function Documentation

Contents * SipFrag::clone ( ) const [virtual]

duplicate an SipFrag object

Returns:
pointer to a new SipFrag object

Implements resip::Contents.

Reimplemented in resip::ApplicationSip, and resip::ExternalBodyContents.

Definition at line 68 of file SipFrag.cxx.

References SipFrag().

{
   return new SipFrag(*this);
}

Here is the call graph for this function:

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

Implements resip::LazyParser.

Definition at line 96 of file SipFrag.cxx.

References resip::SipMessage::encodeSipFrag(), and mMessage.

{
   mMessage->encodeSipFrag(str);

   return str;
}

Here is the call graph for this function:

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

Reimplemented in resip::ApplicationSip, and resip::ExternalBodyContents.

Definition at line 74 of file SipFrag.cxx.

References type.

{
   static Mime type("message", "sipfrag");
   //static Mime type("application", "sipfrag");
   return type;
}
bool SipFrag::hasStartLine ( char *  buffer,
int  size 
) [private]

dcm! -- better approach, remove above if this is proven to be correct

Definition at line 104 of file SipFrag.cxx.

References resip::Symbols::CRLF, resip::ParseBuffer::end(), resip::ParseBuffer::eof(), resip::ParseBuffer::position(), resip::ParseBuffer::skipBackToChar(), resip::ParseBuffer::skipChar(), resip::ParseBuffer::skipToChars(), resip::ParseBuffer::skipToOneOf(), resip::ParseBuffer::skipWhitespace(), resip::Symbols::SPACE, and resip::ParseBuffer::start().

Referenced by parse().

{
#if 0

   //difficult. Better here than in the MsgHeaderScanner. There's also proabably a
   //way to make a header that matches the requestLine check which isn't a
   //request line.

   ParseBuffer pbCheck(buffer, size);
   pbCheck.skipWhitespace(); //gratuitous?

   if ((pbCheck.end() - pbCheck.position()) > 4 &&
      strncmp(pbCheck.position(), "SIP/", 4) == 0)
   {
      return true;
   }
   else
   {
      pbCheck.skipToChars(Symbols::CRLF);
      if (pbCheck.eof()) 
      {
         //false positive, let MsgHeaderScanner sort the exact error out
         return true; 
      }
      
      pbCheck.skipBackToChar(Symbols::SPACE[0]);
      if (pbCheck.position() == pbCheck.start()) 
      {
         return false;
      }
         
      if ((pbCheck.end() - pbCheck.position()) > 4 &&
          strncmp(pbCheck.position(), "SIP/", 4) == 0)
      {
         return true;
      }
      else
      {
         return false;
      }
   }
#else   

   ParseBuffer pbCheck(buffer, size);
   pbCheck.skipWhitespace(); //gratuitous?
   pbCheck.skipToOneOf(" \t:\r\n");
   while(!pbCheck.eof())
   {
      switch(*pbCheck.position())
      {
         case ':':
            return false;
         case ' ':
         case '\t':
            pbCheck.skipChar();
            break;             
         case '\r':
         case '\n':
            return false;
         default:
            return true;
      }
   }
   return true;  //false positive, let MsgHeaderScanner sort the exact error out
#endif
}

Here is the call graph for this function:

bool SipFrag::init ( ) [static]

Reimplemented from resip::Contents.

Reimplemented in resip::ApplicationSip, and resip::ExternalBodyContents.

Definition at line 18 of file SipFrag.cxx.

{
   static ContentsFactory<SipFrag> factory;
   (void)factory;
   return true;
}
SipMessage & SipFrag::message ( )

Definition at line 82 of file SipFrag.cxx.

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

Referenced by main(), and resip::TuIM::processSipFrag().

{
   checkParsed(); 
   return *mMessage;
}

Here is the call graph for this function:

const SipMessage & SipFrag::message ( ) const

Definition at line 89 of file SipFrag.cxx.

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

{
   checkParsed(); 
   return *mMessage;
}

Here is the call graph for this function:

SipFrag & SipFrag::operator= ( const SipFrag rhs)

Definition at line 48 of file SipFrag.cxx.

References mMessage.

{
   if (this != &rhs)
   {
      Contents::operator=(rhs);
      delete mMessage;
      if (rhs.mMessage)
      {
         mMessage = new SipMessage(*rhs.mMessage);
      }
      else
      {
         mMessage = 0;
      }
   }
   
   return *this;
}
void SipFrag::parse ( ParseBuffer pb) [virtual]

Implements resip::LazyParser.

Definition at line 173 of file SipFrag.cxx.

References resip::ParseBuffer::assertNotEof(), CerrLog, resip::Symbols::CRLF, resip::ParseBuffer::end(), resip::SipMessage::exists(), resip::ParseBuffer::fail(), hasStartLine(), mMessage, resip::ParseBuffer::position(), resip::MsgHeaderScanner::prepareForFrag(), resip::ParseBuffer::reset(), resip::MsgHeaderScanner::scanChunk(), scratchpad, resip::MsgHeaderScanner::scrEnd, resip::SipMessage::setBody(), and resip::ParseBuffer::skipChars().

{
//   DebugLog(<< "SipFrag::parse: " << pb.position());

   mMessage = new SipMessage();

   pb.assertNotEof();
   const char *constBuffer = pb.position();
   char *buffer = const_cast<char *>(constBuffer);

   size_t size = pb.end() - pb.position();

   // !ah! removed size check .. process() cannot process more
   // than size bytes of the message.


   MsgHeaderScanner msgHeaderScanner;
   msgHeaderScanner.prepareForFrag(mMessage, hasStartLine(buffer, (int)size));
   enum { sentinelLength = 4 };  // Two carriage return / line feed pairs.
   //char saveTermCharArray[sentinelLength];
   static const char* sentinel="\r\n\r\n";
   char *termCharArray = buffer + size;
   memcpy(scratchpad,termCharArray,4);
   
   /*saveTermCharArray[0] = termCharArray[0];
   saveTermCharArray[1] = termCharArray[1];
   saveTermCharArray[2] = termCharArray[2];
   saveTermCharArray[3] = termCharArray[3];*/
   
   memcpy(termCharArray,sentinel,4);
   /*termCharArray[0] = '\r';
   termCharArray[1] = '\n';
   termCharArray[2] = '\r';
   termCharArray[3] = '\n';*/
   char *scanTermCharPtr;
   MsgHeaderScanner::ScanChunkResult scanChunkResult =
       msgHeaderScanner.scanChunk(buffer,
                                  (unsigned int)(size + sentinelLength),
                                  &scanTermCharPtr);
   
   memcpy(termCharArray,scratchpad,4);
   /*termCharArray[0] = saveTermCharArray[0];
   termCharArray[1] = saveTermCharArray[1];
   termCharArray[2] = saveTermCharArray[2];
   termCharArray[3] = saveTermCharArray[3];*/
   
   // !dlb! not at all clear what to do here
   // see: "// tests end of message problem (MsgHeaderScanner?)"
   //      in test/testSipFrag.cxx
   if (false && scanChunkResult != MsgHeaderScanner::scrEnd) 
   {
      CerrLog(<< "not MsgHeaderScanner::scrEnd");
      pb.fail(__FILE__, __LINE__);
   } 
   else 
   {
      size_t used = scanTermCharPtr - buffer;

      // !ah! I think this is broken .. if we are UDP then the 
      // remainder is the SigFrag, not the Content-Length... ??
      if (mMessage->exists(h_ContentLength))
      {
         mMessage->setBody(scanTermCharPtr,
                           static_cast<int>(size - used));
      }
      else
      {
         // !ah! So the headers weren't complete. Why are we here?
         // !dlb! 
         if (mMessage->exists(h_ContentLength))
         {
            pb.reset(buffer + used);
            pb.skipChars(Symbols::CRLF);
            mMessage->setBody(pb.position(),int(pb.end()-pb.position()) );
         }
      }
      pb.reset(pb.end());
   }
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 48 of file SipFrag.hxx.

Referenced by encodeParsed(), message(), operator=(), parse(), and ~SipFrag().

char resip::SipFrag::scratchpad[4] [private]

Definition at line 49 of file SipFrag.hxx.

Referenced by parse().


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