Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

mutableserverrequest.cpp

Go to the documentation of this file.
00001 // mutableserverrequest.cpp: implementation of the MutableServerRequest class.
00002 //
00004 
00005 #include "mutableserverrequest.h"
00006 
00007 
00009 // Construction/Destruction
00011 
00012 MutableServerRequest::MutableServerRequest()
00013 {
00014 
00015 }
00016 //
00017 // --------------------------------------------------------------------
00018 //
00019 long MutableServerRequest::BufferInitAlloc()
00020 {
00021    long r_size = MutableServerMessage::BufferInitAlloc();
00022 
00023    for ( int _p = 0, _sz = Passport.size() ; _p < _sz ; _p++ )
00024    {
00025       r_size += Passport[_p].length();
00026       r_size += 1;  // line-terminating '\n'
00027    }
00028    return r_size;
00029 }
00030 //
00031 // --------------------------------------------------------------------
00032 //
00033 void MutableServerRequest::FormatDerivativeData()
00034 {
00035    MutableServerMessage::FormatDerivativeData();
00036 
00037    for ( int _p = 0, _sz = Passport.size() ; _p < _sz ; _p++ )
00038    {
00039       MessageBuffer.append( MSR_PASSPORT_TAG );
00040       MessageBuffer.append( Passport[_p] );
00041       MessageBuffer.append( "\n" );
00042    }
00043    // flag the start of the data
00044    //
00045       MessageBuffer.append( MSR_DATASTART_LINE );
00046       MessageBuffer.append( "\n" );
00047 }
00048 //
00049 // --------------------------------------------------------------------
00050 //
00051 void MutableServerRequest::ParseDerivativeData()
00052 {
00053    MutableServerMessage::ParseDerivativeData();
00054 
00055    ClearPassport();
00056 
00057    bool _parsing = true;
00058 
00059    long _index;
00060 
00061    std::string _ppline; // passport line
00062 
00063    do
00064    {
00065       if ( (_index = MessageBuffer.find("\n")) == MessageBuffer.npos )
00066       {
00067          throw worm_exception("Unterminated message while parsing passport");
00068       }
00069 
00070 // DEBUG remove this?
00071       // - 1 to exclude '\n'
00072 
00073       _ppline = MessageBuffer.substr( 0 , _index );
00074 
00075 
00076       // Remove this line from the buffer
00077       // + 1 to include '\n'
00078 
00079       MessageBuffer.erase( 0 , _index + 1 );
00080 
00081       // check for start of data
00082 
00083       if ( _ppline.compare( MSR_DATASTART_LINE ) == 0 )
00084       {
00085          _parsing = false;
00086          continue;
00087       }
00088 
00089       // minimally validate the passport line format
00090 
00091       
00092       if ( _ppline.compare( 0, strlen(MSR_PASSPORT_TAG),  MSR_PASSPORT_TAG ) != 0 )
00093       {
00094          worm_exception _expt("Invalid passport line: >");
00095                         _expt += _ppline;
00096                         _expt += "<";
00097          throw _expt;
00098       }
00099 
00100       // remove the tag from the line
00101 
00102       _ppline.erase( 0 , strlen(MSR_PASSPORT_TAG) );
00103 
00104       // Add the line to the passport
00105 
00106       AddPassportLine( _ppline );
00107 
00108    } while( _parsing );
00109    
00110 }
00111 //
00112 // --------------------------------------------------------------------
00113 //
00114 void MutableServerRequest::ClearPassport() { Passport.clear(); }
00115 //
00116 // --------------------------------------------------------------------
00117 //
00118 void MutableServerRequest::AddPassportLine( const char * p_line )
00119 {
00120    if ( p_line != NULL )
00121    {
00122       std::string _pp = p_line;
00123       Passport.push_back(_pp);
00124    }
00125 }
00126 //
00127 // --------------------------------------------------------------------
00128 //
00129 void MutableServerRequest::AddPassportLine( std::string p_line )
00130 {
00131    Passport.push_back(p_line);
00132 }
00133 //
00134 // --------------------------------------------------------------------
00135 //
00136 int MutableServerRequest::GetPassportLineCount() { return Passport.size(); }
00137 //
00138 // --------------------------------------------------------------------
00139 //
00140 const char * MutableServerRequest::GetPassportLine( int p_index )
00141 {
00142    if ( 0 <= p_index && p_index < Passport.size() )
00143    {
00144       return Passport[p_index].c_str();
00145    }
00146    else
00147    {
00148       return (char *)NULL;
00149    }
00150 }
00151 //
00152 // --------------------------------------------------------------------
00153 //

Generated on Tue May 6 09:16:06 2003 for Earthworm Libs by doxygen1.3-rc3