reSIProcate/stack  9694
RFC4475TortureTests.cxx
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <memory>
00003 
00004 #include "resip/stack/Contents.hxx"
00005 #include "resip/stack/SdpContents.hxx"
00006 #include "resip/stack/SipMessage.hxx"
00007 #include "resip/stack/ExtensionHeader.hxx"
00008 #include "resip/stack/ExtensionParameter.hxx"
00009 #include "resip/stack/ParserCategories.hxx"
00010 #include "resip/stack/ParameterTypes.hxx"
00011 #include "resip/stack/Uri.hxx"
00012 #include "rutil/Logger.hxx"
00013 #include "tassert.h"
00014 
00015 #define RESIPROCATE_SUBSYSTEM resip::Subsystem::TEST
00016 
00017 void
00018 wsinv()
00019 {
00020 /*
00021    This short, relatively human-readable message contains:
00022 
00023    o  line folding all over.
00024 
00025    o  escaped characters within quotes.
00026 
00027    o  an empty subject.
00028 
00029    o  LWS between colons, semicolons, header field values, and other
00030       fields.
00031 
00032    o  both comma separated and separately listed header field values.
00033 
00034    o  a mix of short and long form for the same header field name.
00035 
00036    o  unknown Request-URI parameter.
00037 
00038    o  unknown header fields.
00039 
00040    o  an unknown header field with a value that would be syntactically
00041       invalid if it were defined in terms of generic-param.
00042 
00043    o  unusual header field ordering.
00044 
00045    o  unusual header field name character case.
00046 
00047    o  unknown parameters of a known header field.
00048 
00049    o  a uri parameter with no value.
00050 
00051    o  a header parameter with no value.
00052 
00053    o  integer fields (Max-Forwards and CSeq) with leading zeros.
00054 
00055    All elements should treat this as a well-formed request.
00056 
00057    The UnknownHeaderWithUnusualValue header field deserves special
00058    attention.  If this header field were defined in terms of comma-
00059    separated values with semicolon-separated parameters (as would many
00060    of the existing defined header fields), this would be invalid.
00061    However, since the receiving element does not know the definition of
00062    the syntax for this field, it must parse it as a header value.
00063    Proxies would forward this header field unchanged.  Endpoints would
00064    ignore the header field.
00065 
00066 INVITE sip:vivekg@chair-dnrc.example.com;unknownparam SIP/2.0
00067 TO :
00068  sip:vivekg@chair-dnrc.example.com ;   tag    = 1918181833n
00069 from   : "J Rosenberg \\\""       <sip:jdrosen@example.com>
00070   ;
00071   tag = 98asjd8
00072 MaX-fOrWaRdS: 0068
00073 Call-ID: wsinv.ndaksdj@192.0.2.1
00074 Content-Length   : 150
00075 cseq: 0009
00076   INVITE
00077 Via  : SIP  /   2.0
00078  /UDP
00079     192.0.2.2;branch=390skdjuw
00080 s :
00081 NewFangledHeader:   newfangled value
00082  continued newfangled value
00083 UnknownHeaderWithUnusualValue: ;;,,;;,;
00084 Content-Type: application/sdp
00085 Route:
00086  <sip:services.example.com;lr;unknownwith=value;unknown-no-value>
00087 v:  SIP  / 2.0  / TCP     spindle.example.com   ;
00088   branch  =   z9hG4bK9ikj8  ,
00089  SIP  /    2.0   / UDP  192.168.255.111   ; branch=
00090  z9hG4bK30239
00091 m:"Quoted string \"\"" <sip:jdrosen@example.com> ; newparam =
00092       newvalue ;
00093   secondparam ; q = 0.33
00094 
00095 v=0
00096 o=mhandley 29739 7272939 IN IP4 192.0.2.3
00097 s=-
00098 c=IN IP4 192.0.2.4
00099 t=0 0
00100 m=audio 49217 RTP/AVP 0 12
00101 m=video 3227 RTP/AVP 31
00102 a=rtpmap:31 LPC
00103 
00104 */
00105    FILE* fid= fopen("wsinv.dat","r");
00106    tassert(fid);
00107    resip::Data txt;
00108    char mBuf[1024];
00109    int result;
00110    while(!feof(fid))
00111    {
00112       result = fread(&mBuf,1,1024,fid);
00113       txt += resip::Data(mBuf,result);
00114    }
00115    fclose(fid);
00116    resip::SipMessage* msg = resip::SipMessage::make(txt);
00117    tassert_reset();
00118    tassert(msg);
00119    tassert_reset();
00120    if(!msg)
00121    {
00122       return;
00123    }
00124 
00125    std::auto_ptr<resip::SipMessage> message(msg);
00126    msg->parseAllHeaders();
00127 
00128    resip::SipMessage copy(*msg);
00129 
00130    resip::Data encoded;
00131    {
00132       resip::oDataStream str(encoded);
00133       msg->encode(str);
00134    }
00135    resip::Data copyEncoded;
00136    {
00137       resip::oDataStream str(copyEncoded);
00138       copy.encode(str);
00139    }
00140    
00141    // Request Line
00142    tassert(msg->header(resip::h_RequestLine).method()==resip::INVITE);
00143    tassert(msg->header(resip::h_RequestLine).unknownMethodName()=="INVITE");
00144    tassert(msg->header(resip::h_RequestLine).uri().scheme()=="sip");
00145    tassert(msg->header(resip::h_RequestLine).uri().user()=="vivekg");
00146    tassert(msg->header(resip::h_RequestLine).uri().host()=="chair-dnrc.example.com");
00147    tassert(msg->header(resip::h_RequestLine).uri().port()==0);
00148    tassert(msg->header(resip::h_RequestLine).uri().password().empty());
00149    tassert(!(msg->header(resip::h_RequestLine).uri().hasEmbedded()));
00150    tassert(msg->header(resip::h_RequestLine).uri().numKnownParams()==0);
00151    tassert(msg->header(resip::h_RequestLine).uri().numUnknownParams()==1);
00152    resip::ExtensionParameter p_unknownparam("unknownparam");
00153    tassert(msg->header(resip::h_RequestLine).uri().exists(p_unknownparam));
00154    tassert(msg->header(resip::h_RequestLine).getSipVersion()=="SIP/2.0");
00155    
00156    //To
00157    tassert(msg->exists(resip::h_To));
00158    tassert(msg->header(resip::h_To).displayName().empty());
00159    tassert(msg->header(resip::h_To).numKnownParams()==1);
00160    tassert(msg->header(resip::h_To).numUnknownParams()==0);
00161    tassert(msg->header(resip::h_To).exists(resip::p_tag));
00162    tassert(msg->header(resip::h_To).param(resip::p_tag)=="1918181833n");
00163    tassert(!(msg->header(resip::h_To).isAllContacts()));
00164    tassert(msg->header(resip::h_To).uri().scheme()=="sip");
00165    tassert(msg->header(resip::h_To).uri().user()=="vivekg");
00166    tassert(msg->header(resip::h_To).uri().host()=="chair-dnrc.example.com");
00167    tassert(msg->header(resip::h_To).uri().port()==0);
00168    tassert(msg->header(resip::h_To).uri().password().empty());
00169    tassert(!(msg->header(resip::h_To).uri().hasEmbedded()));
00170    tassert(msg->header(resip::h_To).uri().numKnownParams()==0);
00171    tassert(msg->header(resip::h_To).uri().numUnknownParams()==0);
00172 
00173    //From
00174    tassert(msg->exists(resip::h_From));
00175    tassert(msg->header(resip::h_From).displayName()=="J Rosenberg \\\\\\\"");
00176    tassert(msg->header(resip::h_From).numKnownParams()==1);
00177    tassert(msg->header(resip::h_From).numUnknownParams()==0);
00178    tassert(msg->header(resip::h_From).exists(resip::p_tag));
00179    tassert(msg->header(resip::h_From).param(resip::p_tag)=="98asjd8");
00180    tassert(!(msg->header(resip::h_From).isAllContacts()));
00181    tassert(msg->header(resip::h_From).uri().scheme()=="sip");
00182    tassert(msg->header(resip::h_From).uri().user()=="jdrosen");
00183    tassert(msg->header(resip::h_From).uri().host()=="example.com");
00184    tassert(msg->header(resip::h_From).uri().port()==0);
00185    tassert(msg->header(resip::h_From).uri().password().empty());
00186    tassert(!(msg->header(resip::h_From).uri().hasEmbedded()));
00187    tassert(msg->header(resip::h_From).uri().numKnownParams()==0);
00188    tassert(msg->header(resip::h_From).uri().numUnknownParams()==0);
00189    
00190    //Max-Forwards
00191    tassert(msg->exists(resip::h_MaxForwards));
00192    tassert(msg->header(resip::h_MaxForwards).value()==68);
00193    tassert(msg->header(resip::h_MaxForwards).numKnownParams()==0);
00194    tassert(msg->header(resip::h_MaxForwards).numUnknownParams()==0);
00195    
00196    
00197    //Call-ID
00198    tassert(msg->exists(resip::h_CallID));
00199    tassert(msg->header(resip::h_CallID).value()=="wsinv.ndaksdj@192.0.2.1");
00200    tassert(msg->header(resip::h_CallID).numKnownParams()==0);
00201    tassert(msg->header(resip::h_CallID).numUnknownParams()==0);
00202    
00203    //Content-Length
00204    tassert(msg->exists(resip::h_ContentLength));
00205    tassert(msg->header(resip::h_ContentLength).value()==150);
00206    tassert(msg->header(resip::h_ContentLength).numKnownParams()==0);
00207    tassert(msg->header(resip::h_ContentLength).numUnknownParams()==0);
00208    
00209    //CSeq
00210    tassert(msg->exists(resip::h_CSeq));
00211    tassert(msg->header(resip::h_CSeq).method()==resip::INVITE);
00212    tassert(msg->header(resip::h_CSeq).unknownMethodName()=="INVITE");
00213    tassert(msg->header(resip::h_CSeq).sequence()==9);
00214    tassert(msg->header(resip::h_CSeq).numKnownParams()==0);
00215    tassert(msg->header(resip::h_CSeq).numUnknownParams()==0);
00216    
00217    //Vias
00218    tassert(msg->exists(resip::h_Vias));
00219    tassert(msg->header(resip::h_Vias).size()==3);
00220    resip::ParserContainer<resip::Via>::iterator i=msg->header(resip::h_Vias).begin();
00221    
00222    tassert(i->numKnownParams()==1);
00223    tassert(i->numUnknownParams()==0);
00224    tassert(i->protocolName()=="SIP");
00225    tassert(i->protocolVersion()=="2.0");
00226    tassert(i->transport()=="UDP");
00227    tassert(i->sentHost()=="192.0.2.2");
00228    tassert(i->sentPort()==0);
00229    
00230    tassert(i->exists(resip::p_branch));
00231    tassert(!(i->param(resip::p_branch).hasMagicCookie()));
00232    tassert(i->param(resip::p_branch).getTransactionId()=="390skdjuw");
00233    tassert(i->param(resip::p_branch).clientData().empty());
00234    
00235    i++;
00236    
00237    tassert(i->numKnownParams()==1);
00238    tassert(i->numUnknownParams()==0);
00239    tassert(i->protocolName()=="SIP");
00240    tassert(i->protocolVersion()=="2.0");
00241    tassert(i->transport()=="TCP");
00242    tassert(i->sentHost()=="spindle.example.com");
00243    tassert(i->sentPort()==0);
00244    
00245    tassert(i->exists(resip::p_branch));
00246    tassert(i->param(resip::p_branch).hasMagicCookie());
00247    tassert(i->param(resip::p_branch).getTransactionId()=="9ikj8");
00248    tassert(i->param(resip::p_branch).clientData().empty());
00249       
00250    i++;
00251    
00252    tassert(i->numKnownParams()==1);
00253    tassert(i->numUnknownParams()==0);
00254    tassert(i->protocolName()=="SIP");
00255    tassert(i->protocolVersion()=="2.0");
00256    tassert(i->transport()=="UDP");
00257    tassert(i->sentHost()=="192.168.255.111");
00258    tassert(i->sentPort()==0);
00259    
00260    tassert(i->exists(resip::p_branch));
00261    tassert(i->param(resip::p_branch).hasMagicCookie());
00262    tassert(i->param(resip::p_branch).getTransactionId()=="30239");
00263    tassert(i->param(resip::p_branch).clientData().empty());
00264    
00265    
00266    //Subject
00267    tassert(msg->exists(resip::h_Subject));
00268    tassert(msg->header(resip::h_Subject).value()=="");
00269    tassert(msg->header(resip::h_Subject).numKnownParams()==0);
00270    tassert(msg->header(resip::h_Subject).numUnknownParams()==0);
00271    
00272 
00273    // Unknown headers
00274    resip::ExtensionHeader h_NewFangledHeader("NewFangledHeader");
00275    
00276    tassert(msg->exists(h_NewFangledHeader));
00277    tassert(msg->header(h_NewFangledHeader).size()==1);
00278    tassert(msg->header(h_NewFangledHeader).begin()->value()=="newfangled value\r\n continued newfangled value");
00279    tassert(msg->header(h_NewFangledHeader).begin()->numKnownParams()==0);
00280    tassert(msg->header(h_NewFangledHeader).begin()->numUnknownParams()==0);
00281    
00282    resip::ExtensionHeader h_UnknownHeaderWithUnusualValue("UnknownHeaderWithUnusualValue");
00283    
00284    tassert(msg->exists(h_UnknownHeaderWithUnusualValue));
00285    tassert(msg->header(h_UnknownHeaderWithUnusualValue).size()==1);
00286    tassert(msg->header(h_UnknownHeaderWithUnusualValue).begin()->value()==";;,,;;,;");
00287    tassert(msg->header(h_UnknownHeaderWithUnusualValue).begin()->numKnownParams()==0);
00288    tassert(msg->header(h_UnknownHeaderWithUnusualValue).begin()->numUnknownParams()==0);
00289    
00290    //Content-Type
00291    tassert(msg->exists(resip::h_ContentType));
00292    tassert(msg->header(resip::h_ContentType).type()=="application");
00293    tassert(msg->header(resip::h_ContentType).subType()=="sdp");
00294    tassert(msg->header(resip::h_ContentType).numKnownParams()==0);
00295    tassert(msg->header(resip::h_ContentType).numUnknownParams()==0);
00296    
00297    //Contact
00298    tassert(msg->exists(resip::h_Contacts));
00299    tassert(msg->header(resip::h_Contacts).size()==1);
00300    tassert(msg->header(resip::h_Contacts).begin()->displayName()=="Quoted string \\\"\\\"");
00301    tassert(msg->header(resip::h_Contacts).begin()->numKnownParams()==1);
00302    tassert(msg->header(resip::h_Contacts).begin()->numUnknownParams()==2);
00303    tassert(!(msg->header(resip::h_Contacts).begin()->isAllContacts()));
00304    tassert(msg->header(resip::h_Contacts).begin()->uri().numKnownParams()==0);
00305    tassert(msg->header(resip::h_Contacts).begin()->uri().numUnknownParams()==0);
00306    tassert(msg->header(resip::h_Contacts).begin()->uri().scheme()=="sip");
00307    tassert(msg->header(resip::h_Contacts).begin()->uri().user()=="jdrosen");
00308    tassert(msg->header(resip::h_Contacts).begin()->uri().host()=="example.com");
00309    tassert(msg->header(resip::h_Contacts).begin()->uri().port()==0);
00310    tassert(msg->header(resip::h_Contacts).begin()->uri().password().empty());
00311    tassert(!(msg->header(resip::h_Contacts).begin()->uri().hasEmbedded()));
00312 
00313    resip::ExtensionParameter p_newparam("newparam");
00314    tassert(msg->header(resip::h_Contacts).begin()->exists(p_newparam));
00315    tassert(msg->header(resip::h_Contacts).begin()->param(p_newparam)=="newvalue");
00316    
00317    resip::ExtensionParameter p_secondparam("secondparam");
00318    tassert(msg->header(resip::h_Contacts).begin()->exists(p_secondparam));
00319    tassert(msg->header(resip::h_Contacts).begin()->param(p_secondparam)=="");
00320    
00321    tassert(msg->header(resip::h_Contacts).begin()->exists(resip::p_q));
00322    tassert(msg->header(resip::h_Contacts).begin()->param(resip::p_q)==330);
00323    
00324    
00325    
00326    
00327 
00328    InfoLog(<< "In case wsinv:" );
00329    InfoLog(<< "Original text:" << std::endl << txt );
00330    InfoLog(<< "Encoded form:" << std::endl << encoded );
00331    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
00332 
00333 
00334 
00335 
00336 }
00337 
00338 
00339 void
00340 intmeth()
00341 {
00342 #if 0
00343 /*
00344    This message exercises a wider range of characters in several key
00345    syntactic elements than implementations usually see.  In particular,
00346    note the following:
00347 
00348    o  The Method contains non-alpha characters from token.  Note that %
00349       is not an escape character for this field.  A method of IN%56ITE
00350       is an unknown method.  It is not the same as a method of INVITE.
00351 
00352    o  The Request-URI contains unusual, but legal, characters.
00353 
00354    o  A branch parameter contains all non-alphanum characters from
00355       token.
00356 
00357    o  The To header field value's quoted string contains quoted-pair
00358       expansions, including a quoted NULL character.
00359 
00360    o  The name part of name-addr in the From header field value contains
00361       multiple tokens (instead of a quoted string) with all non-alphanum
00362       characters from the token production rule.  That value also has an
00363       unknown header parameter whose name contains the non-alphanum
00364       token characters and whose value is a non-ascii range UTF-8
00365       encoded string.  The tag parameter on this value contains the
00366       non-alphanum token characters.
00367 
00368    o  The Call-ID header field value contains the non-alphanum
00369       characters from word.  Notice that in this production:
00370 
00371       *  % is not an escape character.  It is only an escape character
00372          in productions matching the rule "escaped".
00373 
00374       *  " does not start a quoted string.  None of ',` or " imply that
00375          there will be a matching symbol later in the string.
00376 
00377       *  The characters []{}()<> do not have any grouping semantics.
00378          They are not required to appear in balanced pairs.
00379 
00380    o  There is an unknown header field (matching extension-header) with
00381       non-alphanum token characters in its name and a UTF8-NONASCII
00382       value.
00383 
00384    If this unusual URI has been defined at a proxy, the proxy will
00385    forward this request normally.  Otherwise, a proxy will generate a
00386    404.  Endpoints will generate a 501 listing the methods they
00387    understand in an Allow header field.
00388 
00389 
00390 !interesting-Method0123456789_*+`.%indeed'~ sip:1_unusual.URI~(to-be!sure)&isn't+it$/crazy?,/;;*:&it+has=1,weird!*pas$wo~d_too.(doesn't-it)@example.com SIP/2.0
00391 Via: SIP/2.0/TCP host1.example.com;branch=z9hG4bK-.!%66*_+`'~
00392 To: "BEL:\ NUL:\  DEL:\" <sip:1_unusual.URI~(to-be!sure)&isn't+it$/crazy?,/;;*@example.com>
00393 From: token1~` token2'+_ token3*%!.- <sip:mundane@example.com>;fromParam''~+*_!.-%="работающий";tag=_token~1'+`*%!-.
00394 Call-ID: intmeth.word%ZK-!.*_+'@word`~)(><:\/"][?}{
00395 CSeq: 139122385 !interesting-Method0123456789_*+`.%indeed'~
00396 Max-Forwards: 255
00397 extensionHeader-!.%*+_`'~:大停電
00398 Content-Length: 0
00399 
00400 
00401 */
00402 #endif
00403 
00404    FILE* fid= fopen("intmeth.dat","r");
00405    tassert(fid);
00406    resip::Data txt;
00407    char mBuf[1024];
00408    int result;
00409    while(!feof(fid))
00410    {
00411       result = fread(&mBuf,1,1024,fid);
00412       txt += resip::Data(mBuf,result);
00413    }
00414    fclose(fid);
00415    resip::SipMessage* msg = resip::SipMessage::make(txt);
00416    tassert_reset();
00417    tassert(msg);
00418    tassert_reset();
00419    if(!msg)
00420    {
00421       return;
00422    }
00423 
00424    std::auto_ptr<resip::SipMessage> message(msg);
00425    msg->parseAllHeaders();
00426 
00427    resip::SipMessage copy(*msg);
00428 
00429    resip::Data encoded;
00430    {
00431       resip::oDataStream str(encoded);
00432       msg->encode(str);
00433    }
00434    resip::Data copyEncoded;
00435    {
00436       resip::oDataStream str(copyEncoded);
00437       copy.encode(str);
00438    }
00439 
00440    // Request Line
00441    tassert(msg->header(resip::h_RequestLine).method()==resip::UNKNOWN);
00442    tassert(msg->header(resip::h_RequestLine).unknownMethodName()=="!interesting-Method0123456789_*+`.%indeed'~");
00443    tassert(msg->header(resip::h_RequestLine).uri().scheme()=="sip");
00444    tassert(msg->header(resip::h_RequestLine).uri().user()=="1_unusual.URI~(to-be!sure)&isn't+it$/crazy?,/;;*");
00445    tassert(msg->header(resip::h_RequestLine).uri().password()=="&it+has=1,weird!*pas$wo~d_too.(doesn't-it)");
00446    tassert(msg->header(resip::h_RequestLine).uri().host()=="example.com");
00447    tassert(msg->header(resip::h_RequestLine).uri().port()==0);
00448    tassert(!(msg->header(resip::h_RequestLine).uri().hasEmbedded()));
00449    tassert(msg->header(resip::h_RequestLine).uri().numKnownParams()==0);
00450    tassert(msg->header(resip::h_RequestLine).uri().numUnknownParams()==0);
00451    tassert(msg->header(resip::h_RequestLine).getSipVersion()=="SIP/2.0");
00452    
00453    //To
00454    tassert(msg->exists(resip::h_To));
00455    tassert(msg->header(resip::h_To).numKnownParams()==0);
00456    tassert(msg->header(resip::h_To).numUnknownParams()==0);
00457    resip::Data dispName;
00458    dispName+="BEL:\\";
00459    dispName+=(char)0x07;
00460    dispName+=" NUL:\\";
00461    dispName+=(char)0x00;
00462    dispName+=" DEL:\\";
00463    dispName+=(char)0x7F;   
00464    tassert(msg->header(resip::h_To).displayName()==dispName);
00465    tassert(!(msg->header(resip::h_To).isAllContacts()));
00466 
00467    tassert(msg->header(resip::h_To).uri().scheme()=="sip");
00468    tassert(msg->header(resip::h_To).uri().user()=="1_unusual.URI~(to-be!sure)&isn't+it$/crazy?,/;;*");
00469    tassert(msg->header(resip::h_To).uri().password().empty());
00470    tassert(msg->header(resip::h_To).uri().host()=="example.com");
00471    tassert(msg->header(resip::h_To).uri().port()==0);
00472    tassert(!(msg->header(resip::h_To).uri().hasEmbedded()));
00473    tassert(msg->header(resip::h_To).uri().numKnownParams()==0);
00474    tassert(msg->header(resip::h_To).uri().numUnknownParams()==0);
00475 
00476    //From
00477    tassert(msg->exists(resip::h_From));
00478    tassert(msg->header(resip::h_From).numKnownParams()==1);
00479    tassert(msg->header(resip::h_From).numUnknownParams()==1);
00480    tassert(msg->header(resip::h_From).exists(resip::p_tag));
00481    tassert(msg->header(resip::h_From).param(resip::p_tag)=="_token~1'+`*%!-.");
00482    
00483    resip::ExtensionParameter p_oddball("fromParam''~+*_!.-%");
00484    tassert(msg->header(resip::h_From).exists(p_oddball));
00485    resip::Data binaryParamVal;
00486    binaryParamVal+=(char)0xD1;
00487    binaryParamVal+=(char)0x80;
00488    binaryParamVal+=(char)0xD0;
00489    binaryParamVal+=(char)0xB0;
00490    binaryParamVal+=(char)0xD0;
00491    binaryParamVal+=(char)0xB1;
00492    binaryParamVal+=(char)0xD0;
00493    binaryParamVal+=(char)0xBE;
00494    binaryParamVal+=(char)0xD1;
00495    binaryParamVal+=(char)0x82;
00496    binaryParamVal+=(char)0xD0;
00497    binaryParamVal+=(char)0xB0;
00498    binaryParamVal+=(char)0xD1;
00499    binaryParamVal+=(char)0x8E;
00500    binaryParamVal+=(char)0xD1;
00501    binaryParamVal+=(char)0x89;
00502    binaryParamVal+=(char)0xD0;
00503    binaryParamVal+=(char)0xB8;
00504    binaryParamVal+=(char)0xD0;
00505    binaryParamVal+=(char)0xB9;
00506    tassert(msg->header(resip::h_From).param(p_oddball)==binaryParamVal);
00507    tassert(msg->header(resip::h_From).displayName()=="token1~` token2'+_ token3*%!.-");
00508    tassert(!(msg->header(resip::h_From).isAllContacts()));
00509 
00510    tassert(msg->header(resip::h_From).uri().scheme()=="sip");
00511    tassert(msg->header(resip::h_From).uri().user()=="mundane");
00512    tassert(msg->header(resip::h_From).uri().password().empty());
00513    tassert(msg->header(resip::h_From).uri().host()=="example.com");
00514    tassert(msg->header(resip::h_From).uri().port()==0);
00515    tassert(!(msg->header(resip::h_From).uri().hasEmbedded()));
00516    tassert(msg->header(resip::h_From).uri().numKnownParams()==0);
00517    tassert(msg->header(resip::h_From).uri().numUnknownParams()==0);
00518    
00519    
00520    //Max-Forwards
00521    tassert(msg->exists(resip::h_MaxForwards));
00522    tassert(msg->header(resip::h_MaxForwards).value()==255);
00523    tassert(msg->header(resip::h_MaxForwards).numKnownParams()==0);
00524    tassert(msg->header(resip::h_MaxForwards).numUnknownParams()==0);
00525    
00526    //Call-ID
00527    tassert(msg->exists(resip::h_CallID));
00528    tassert(msg->header(resip::h_CallID).value()=="intmeth.word%ZK-!.*_+'@word`~)(><:\\/\"][?}{");
00529    tassert(msg->header(resip::h_CallID).numKnownParams()==0);
00530    tassert(msg->header(resip::h_CallID).numUnknownParams()==0);
00531    
00532    //Content-Length
00533    tassert(msg->exists(resip::h_ContentLength));
00534    tassert(msg->header(resip::h_ContentLength).value()==0);
00535    tassert(msg->header(resip::h_ContentLength).numKnownParams()==0);
00536    tassert(msg->header(resip::h_ContentLength).numUnknownParams()==0);
00537    
00538    //CSeq
00539    tassert(msg->exists(resip::h_CSeq));
00540    tassert(msg->header(resip::h_CSeq).method()==resip::UNKNOWN);
00541    tassert(msg->header(resip::h_CSeq).unknownMethodName()=="!interesting-Method0123456789_*+`.%indeed'~");
00542    tassert(msg->header(resip::h_CSeq).sequence()==139122385);
00543    tassert(msg->header(resip::h_CSeq).numKnownParams()==0);
00544    tassert(msg->header(resip::h_CSeq).numUnknownParams()==0);
00545    
00546    //Vias
00547    tassert(msg->exists(resip::h_Vias));
00548    tassert(msg->header(resip::h_Vias).size()==1);
00549    resip::ParserContainer<resip::Via>::iterator i=msg->header(resip::h_Vias).begin();
00550    
00551    tassert(i->protocolName()=="SIP");
00552    tassert(i->protocolVersion()=="2.0");
00553    tassert(i->transport()=="TCP");
00554    tassert(i->sentHost()=="host1.example.com");
00555    tassert(i->sentPort()==0);
00556    
00557    tassert(i->numKnownParams()==1);
00558    tassert(i->numUnknownParams()==0);
00559    tassert(i->exists(resip::p_branch));
00560    tassert(i->param(resip::p_branch).hasMagicCookie());
00561    tassert(i->param(resip::p_branch).getTransactionId()=="-.!%66*_+`'~");
00562    tassert(i->param(resip::p_branch).clientData().empty());
00563    
00564 
00565    
00566    // Unknown headers
00567    resip::ExtensionHeader h_extensionHeader("extensionHeader-!.%*+_`'~");
00568    
00569    tassert(msg->exists(h_extensionHeader));
00570    tassert(msg->header(h_extensionHeader).size()==1);
00571    resip::Data binaryHfv;
00572    binaryHfv+=(char)0xEF;
00573    binaryHfv+=(char)0xBB;
00574    binaryHfv+=(char)0xBF;
00575    binaryHfv+=(char)0xE5;
00576    binaryHfv+=(char)0xA4;
00577    binaryHfv+=(char)0xA7;
00578    binaryHfv+=(char)0xE5;
00579    binaryHfv+=(char)0x81;
00580    binaryHfv+=(char)0x9C;
00581    binaryHfv+=(char)0xE9;
00582    binaryHfv+=(char)0x9B;
00583    binaryHfv+=(char)0xBB;
00584    tassert(msg->header(h_extensionHeader).begin()->value()==binaryHfv);
00585    tassert(msg->header(h_extensionHeader).begin()->numKnownParams()==0);
00586    tassert(msg->header(h_extensionHeader).begin()->numUnknownParams()==0);
00587    
00588    
00589    InfoLog(<< "In case intmeth:" );
00590    InfoLog(<< "Original text:" << std::endl << txt );
00591    InfoLog(<< "Encoded form:" << std::endl << encoded );
00592    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
00593 
00594 
00595 
00596 
00597 }
00598 
00599 
00600 void
00601 esc01()
00602 {
00603 /*
00604    This INVITE exercises the % HEX HEX escaping mechanism in several
00605    places.  The request is syntactically valid.  Interesting features
00606    include the following:
00607 
00608    o  The request-URI has sips:user@example.com embedded in its
00609       userpart.  What that might mean to example.net is beyond the scope
00610       of this document.
00611 
00612    o  The From and To URIs have escaped characters in their userparts.
00613 
00614    o  The Contact URI has escaped characters in the URI parameters.
00615       Note that the "name" uri-parameter has a value of "value%41",
00616       which is NOT equivalent to "valueA".  Per [RFC3986], unescaping
00617       URI components is never performed recursively.
00618 
00619    A parser must accept this as a well-formed message.  The application
00620    using the message must treat the % HEX HEX expansions as equivalent
00621    to the character being encoded.  The application must not try to
00622    interpret % as an escape character in those places where % HEX HEX
00623    ("escaped" in the grammar) is not a valid part of the construction.
00624    In [RFC3261], "escaped" only occurs in the expansions of SIP-URI,
00625    SIPS-URI, and Reason-Phrase.
00626    
00627    
00628 INVITE sip:sips%3Auser%40example.com@example.net SIP/2.0
00629 To: sip:%75se%72@example.com
00630 From: <sip:I%20have%20spaces@example.net>;tag=938
00631 Max-Forwards: 87
00632 i: esc01.239409asdfakjkn23onasd0-3234
00633 CSeq: 234234 INVITE
00634 Via: SIP/2.0/UDP host5.example.net;branch=z9hG4bKkdjuw
00635 C: application/sdp
00636 Contact:
00637   <sip:cal%6Cer@host5.example.net;%6C%72;n%61me=v%61lue%25%34%31>
00638 Content-Length: 150
00639 
00640 v=0
00641 o=mhandley 29739 7272939 IN IP4 192.0.2.1
00642 s=-
00643 c=IN IP4 192.0.2.1
00644 t=0 0
00645 m=audio 49217 RTP/AVP 0 12
00646 m=video 3227 RTP/AVP 31
00647 a=rtpmap:31 LPC
00648 
00649 */
00650    FILE* fid= fopen("esc01.dat","r");
00651    tassert(fid);
00652    resip::Data txt;
00653    char mBuf[1024];
00654    int result;
00655    while(!feof(fid))
00656    {
00657       result = fread(&mBuf,1,1024,fid);
00658       txt += resip::Data(mBuf,result);
00659    }
00660    fclose(fid);
00661    resip::SipMessage* msg = resip::SipMessage::make(txt);
00662    tassert_reset();
00663    tassert(msg);
00664    tassert_reset();
00665    if(!msg)
00666    {
00667       return;
00668    }
00669 
00670    std::auto_ptr<resip::SipMessage> message(msg);
00671    msg->parseAllHeaders();
00672 
00673    resip::SipMessage copy(*msg);
00674 
00675    resip::Data encoded;
00676    {
00677       resip::oDataStream str(encoded);
00678       msg->encode(str);
00679    }
00680    resip::Data copyEncoded;
00681    {
00682       resip::oDataStream str(copyEncoded);
00683       copy.encode(str);
00684    }
00685 
00686    // Request Line
00687    tassert(msg->header(resip::h_RequestLine).method()==resip::INVITE);
00688    tassert(msg->header(resip::h_RequestLine).unknownMethodName()=="INVITE");
00689    tassert(msg->header(resip::h_RequestLine).uri().scheme()=="sip");
00690    // ?bwc? Is it appropriate to use a one-size-fits-all approach to unescaping
00691    // parsed components? ('@' is not legal in a userpart, but the internal
00692    // representation contains it)
00693    // What is the best approach: all (unescape everything that is printable),
00694    // none (leave escaping exactly as found), or context sensitive (escape
00695    // everything that is legal for a given field)?
00696    tassert(msg->header(resip::h_RequestLine).uri().user()=="sips%3Auser%40example.com");
00697    tassert_reset();
00698    tassert(msg->header(resip::h_RequestLine).uri().password().empty());
00699    tassert(msg->header(resip::h_RequestLine).uri().host()=="example.net");
00700    tassert(msg->header(resip::h_RequestLine).uri().port()==0);
00701    tassert(msg->header(resip::h_RequestLine).uri().numKnownParams()==0);
00702    tassert(msg->header(resip::h_RequestLine).uri().numUnknownParams()==0);
00703    tassert(!(msg->header(resip::h_RequestLine).uri().hasEmbedded()));
00704    tassert(msg->header(resip::h_RequestLine).getSipVersion()=="SIP/2.0");
00705    
00706    //To
00707    tassert(msg->exists(resip::h_To));
00708    tassert(msg->header(resip::h_To).displayName().empty());
00709    tassert(!(msg->header(resip::h_To).isAllContacts()));
00710    tassert(msg->header(resip::h_To).uri().scheme()=="sip");
00711    tassert(msg->header(resip::h_To).uri().user()=="user");
00712    tassert(msg->header(resip::h_To).uri().password().empty());
00713    tassert(msg->header(resip::h_To).uri().host()=="example.com");
00714    tassert(msg->header(resip::h_To).uri().port()==0);
00715    tassert(!(msg->header(resip::h_To).uri().hasEmbedded()));
00716    tassert(msg->header(resip::h_To).uri().numKnownParams()==0);
00717    tassert(msg->header(resip::h_To).uri().numUnknownParams()==0);
00718    tassert(msg->header(resip::h_To).numKnownParams()==0);
00719    tassert(msg->header(resip::h_To).numUnknownParams()==0);
00720 
00721    //From
00722    tassert(msg->exists(resip::h_From));
00723    tassert(msg->header(resip::h_From).displayName().empty());
00724    tassert(!(msg->header(resip::h_From).isAllContacts()));
00725    tassert(msg->header(resip::h_From).uri().scheme()=="sip");
00726    // ?bwc? ' ' is not legal in a userpart, but the internal
00727    // representation contains it. Is this appropriate?
00728    tassert(msg->header(resip::h_From).uri().user()=="I%20have%20spaces");
00729    tassert_reset();
00730    tassert(msg->header(resip::h_From).uri().password().empty());
00731    tassert(msg->header(resip::h_From).uri().host()=="example.net");
00732    tassert(msg->header(resip::h_From).uri().port()==0);
00733    tassert(!(msg->header(resip::h_From).uri().hasEmbedded()));
00734    tassert(msg->header(resip::h_From).uri().numKnownParams()==0);
00735    tassert(msg->header(resip::h_From).uri().numUnknownParams()==0);
00736    tassert(msg->header(resip::h_From).numKnownParams()==1);
00737    tassert(msg->header(resip::h_From).numUnknownParams()==0);
00738    tassert(msg->header(resip::h_From).exists(resip::p_tag));
00739    tassert(msg->header(resip::h_From).param(resip::p_tag)=="938");
00740    
00741    //Max-Forwards
00742    tassert(msg->exists(resip::h_MaxForwards));
00743    tassert(msg->header(resip::h_MaxForwards).value()==87);
00744    tassert(msg->header(resip::h_MaxForwards).numKnownParams()==0);
00745    tassert(msg->header(resip::h_MaxForwards).numUnknownParams()==0);
00746    
00747    //Call-ID
00748    tassert(msg->exists(resip::h_CallID));
00749    tassert(msg->header(resip::h_CallID).value()=="esc01.239409asdfakjkn23onasd0-3234");
00750    tassert(msg->header(resip::h_CallID).numKnownParams()==0);
00751    tassert(msg->header(resip::h_CallID).numUnknownParams()==0);
00752    
00753    //Content-Length
00754    tassert(msg->exists(resip::h_ContentLength));
00755    tassert(msg->header(resip::h_ContentLength).value()==150);
00756    tassert(msg->header(resip::h_ContentLength).numKnownParams()==0);
00757    tassert(msg->header(resip::h_ContentLength).numUnknownParams()==0);
00758    
00759    //CSeq
00760    tassert(msg->exists(resip::h_CSeq));
00761    tassert(msg->header(resip::h_CSeq).method()==resip::INVITE);
00762    tassert(msg->header(resip::h_CSeq).unknownMethodName()=="INVITE");
00763    tassert(msg->header(resip::h_CSeq).sequence()==234234);
00764    tassert(msg->header(resip::h_CSeq).numKnownParams()==0);
00765    tassert(msg->header(resip::h_CSeq).numUnknownParams()==0);
00766    
00767    //Vias
00768    tassert(msg->exists(resip::h_Vias));
00769    tassert(msg->header(resip::h_Vias).size()==1);
00770    resip::ParserContainer<resip::Via>::iterator i=msg->header(resip::h_Vias).begin();
00771    
00772    tassert(i->protocolName()=="SIP");
00773    tassert(i->protocolVersion()=="2.0");
00774    tassert(i->transport()=="UDP");
00775    tassert(i->sentHost()=="host5.example.net");
00776    tassert(i->sentPort()==0);
00777    
00778    tassert(i->numKnownParams()==1);
00779    tassert(i->numUnknownParams()==0);
00780 
00781    tassert(i->exists(resip::p_branch));
00782    tassert(i->param(resip::p_branch).hasMagicCookie());
00783    tassert(i->param(resip::p_branch).getTransactionId()=="kdjuw");
00784    tassert(i->param(resip::p_branch).clientData().empty());
00785    
00786    
00787    
00788    //Content-Type
00789    tassert(msg->exists(resip::h_ContentType));
00790    tassert(msg->header(resip::h_ContentType).type()=="application");
00791    tassert(msg->header(resip::h_ContentType).subType()=="sdp");
00792    tassert(msg->header(resip::h_ContentType).numKnownParams()==0);
00793    tassert(msg->header(resip::h_ContentType).numUnknownParams()==0);
00794    
00795    //Contact
00796    tassert(msg->exists(resip::h_Contacts));
00797    tassert(msg->header(resip::h_Contacts).size()==1);
00798    tassert(msg->header(resip::h_Contacts).begin()->displayName().empty());
00799    tassert(!(msg->header(resip::h_Contacts).begin()->isAllContacts()));
00800    tassert(msg->header(resip::h_Contacts).begin()->uri().scheme()=="sip");
00801    tassert(msg->header(resip::h_Contacts).begin()->uri().user()=="caller");
00802    tassert(msg->header(resip::h_Contacts).begin()->uri().password().empty());
00803    tassert(msg->header(resip::h_Contacts).begin()->uri().host()=="host5.example.net");
00804    tassert(msg->header(resip::h_Contacts).begin()->uri().port()==0);
00805    tassert(!(msg->header(resip::h_Contacts).begin()->uri().hasEmbedded()));
00806 
00807    tassert(msg->header(resip::h_Contacts).begin()->uri().numKnownParams()==0);
00808    tassert(msg->header(resip::h_Contacts).begin()->uri().numUnknownParams()==2);
00809 
00810    // ?bwc? These params have escaped stuff in them; is it mandatory that we
00811    // treat escaped and unescaped versions of the same parameter as identical?
00812    
00813    resip::ExtensionParameter p_wonky1("%6C%72");
00814    resip::ExtensionParameter p_wonky2("n%61me");
00815    tassert(msg->header(resip::h_Contacts).begin()->uri().exists(p_wonky1));
00816    tassert(msg->header(resip::h_Contacts).begin()->uri().param(p_wonky1)=="");
00817    tassert(msg->header(resip::h_Contacts).begin()->uri().exists(p_wonky2));
00818    tassert(msg->header(resip::h_Contacts).begin()->uri().param(p_wonky2)=="v%61lue%25%34%31");
00819 
00820 
00821    tassert(msg->header(resip::h_Contacts).begin()->numKnownParams()==0);
00822    tassert(msg->header(resip::h_Contacts).begin()->numUnknownParams()==0);
00823 
00824    tassert_reset();
00825 
00826    InfoLog(<< "In case esc01:" );
00827    InfoLog(<< "Original text:" << std::endl << txt );
00828    InfoLog(<< "Encoded form:" << std::endl << encoded );
00829    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
00830 
00831 
00832 
00833 
00834 }
00835 
00836 
00837 void
00838 escnull()
00839 {
00840 /*
00841    This register request contains several URIs with nulls in the
00842    userpart.  The message is well formed - parsers must accept this
00843    message.  Implementations must take special care when unescaping the
00844    Address-of-Record (AOR) in this request so as to not prematurely
00845    shorten the username.  This request registers two distinct contact
00846    URIs.
00847 
00848 REGISTER sip:example.com SIP/2.0
00849 To: sip:null-%00-null@example.com
00850 From: sip:null-%00-null@example.com;tag=839923423
00851 Max-Forwards: 70
00852 Call-ID: escnull.39203ndfvkjdasfkq3w4otrq0adsfdfnavd
00853 CSeq: 14398234 REGISTER
00854 Via: SIP/2.0/UDP host5.example.com;branch=z9hG4bKkdjuw
00855 Contact: <sip:%00@host5.example.com>
00856 Contact: <sip:%00%00@host5.example.com>
00857 L:0
00858 
00859 
00860 */
00861    FILE* fid= fopen("escnull.dat","r");
00862    tassert(fid);
00863    resip::Data txt;
00864    char mBuf[1024];
00865    int result;
00866    while(!feof(fid))
00867    {
00868       result = fread(&mBuf,1,1024,fid);
00869       txt += resip::Data(mBuf,result);
00870    }
00871    fclose(fid);
00872    resip::SipMessage* msg = resip::SipMessage::make(txt);
00873    tassert_reset();
00874    tassert(msg);
00875    tassert_reset();
00876    if(!msg)
00877    {
00878       return;
00879    }
00880 
00881    std::auto_ptr<resip::SipMessage> message(msg);
00882    msg->parseAllHeaders();
00883 
00884    resip::SipMessage copy(*msg);
00885 
00886    resip::Data encoded;
00887    {
00888       resip::oDataStream str(encoded);
00889       msg->encode(str);
00890    }
00891    resip::Data copyEncoded;
00892    {
00893       resip::oDataStream str(copyEncoded);
00894       copy.encode(str);
00895    }
00896 
00897    // Request Line
00898    //REGISTER sip:example.com SIP/2.0
00899    tassert(msg->header(resip::h_RequestLine).method()==resip::REGISTER);
00900    tassert(msg->header(resip::h_RequestLine).unknownMethodName()=="REGISTER");
00901    tassert(msg->header(resip::h_RequestLine).uri().scheme()=="sip");
00902    tassert(msg->header(resip::h_RequestLine).uri().user()=="");
00903    tassert(msg->header(resip::h_RequestLine).uri().password().empty());
00904    tassert(msg->header(resip::h_RequestLine).uri().host()=="example.com");
00905    tassert(msg->header(resip::h_RequestLine).uri().port()==0);
00906    tassert(!(msg->header(resip::h_RequestLine).uri().hasEmbedded()));
00907    tassert(msg->header(resip::h_RequestLine).uri().numKnownParams()==0);
00908    tassert(msg->header(resip::h_RequestLine).uri().numUnknownParams()==0);
00909    tassert(msg->header(resip::h_RequestLine).getSipVersion()=="SIP/2.0");
00910    
00911    //To: sip:null-%00-null@example.com
00912    tassert(msg->exists(resip::h_To));
00913    tassert(msg->header(resip::h_To).displayName().empty());
00914    tassert(msg->header(resip::h_To).numKnownParams()==0);
00915    tassert(msg->header(resip::h_To).numUnknownParams()==0);
00916    tassert(!(msg->header(resip::h_To).isAllContacts()));
00917    tassert(msg->header(resip::h_To).uri().scheme()=="sip");
00918    tassert(msg->header(resip::h_To).uri().user()=="null-%00-null");
00919    tassert(msg->header(resip::h_To).uri().password().empty());
00920    tassert(msg->header(resip::h_To).uri().host()=="example.com");
00921    tassert(msg->header(resip::h_To).uri().port()==0);
00922    tassert(!(msg->header(resip::h_To).uri().hasEmbedded()));
00923    tassert(msg->header(resip::h_To).uri().numKnownParams()==0);
00924    tassert(msg->header(resip::h_To).uri().numUnknownParams()==0);
00925 
00926    //From: sip:null-%00-null@example.com;tag=839923423
00927    tassert(msg->exists(resip::h_From));
00928    tassert(msg->header(resip::h_From).displayName()=="");
00929    tassert(msg->header(resip::h_From).numKnownParams()==1);
00930    tassert(msg->header(resip::h_From).numUnknownParams()==0);
00931    tassert(msg->header(resip::h_From).exists(resip::p_tag));
00932    tassert(msg->header(resip::h_From).param(resip::p_tag)=="839923423");
00933    tassert(!(msg->header(resip::h_From).isAllContacts()));
00934    tassert(msg->header(resip::h_From).uri().scheme()=="sip");
00935    tassert(msg->header(resip::h_From).uri().user()=="null-%00-null");
00936    tassert(msg->header(resip::h_From).uri().password().empty());
00937    tassert(msg->header(resip::h_From).uri().host()=="example.com");
00938    tassert(msg->header(resip::h_From).uri().port()==0);
00939    tassert(!(msg->header(resip::h_From).uri().hasEmbedded()));
00940    tassert(msg->header(resip::h_From).uri().numKnownParams()==0);
00941    tassert(msg->header(resip::h_From).uri().numUnknownParams()==0);
00942    
00943    //Max-Forwards: 70
00944    tassert(msg->exists(resip::h_MaxForwards));
00945    tassert(msg->header(resip::h_MaxForwards).value()==70);
00946    tassert(msg->header(resip::h_MaxForwards).numKnownParams()==0);
00947    tassert(msg->header(resip::h_MaxForwards).numUnknownParams()==0);
00948    
00949    
00950    //Call-ID: escnull.39203ndfvkjdasfkq3w4otrq0adsfdfnavd
00951    tassert(msg->exists(resip::h_CallID));
00952    tassert(msg->header(resip::h_CallID).value()=="escnull.39203ndfvkjdasfkq3w4otrq0adsfdfnavd");
00953    tassert(msg->header(resip::h_CallID).numKnownParams()==0);
00954    tassert(msg->header(resip::h_CallID).numUnknownParams()==0);
00955    
00956    //CSeq: 14398234 REGISTER
00957    tassert(msg->exists(resip::h_CSeq));
00958    tassert(msg->header(resip::h_CSeq).method()==resip::REGISTER);
00959    tassert(msg->header(resip::h_CSeq).unknownMethodName()=="REGISTER");
00960    tassert(msg->header(resip::h_CSeq).sequence()==14398234);
00961    tassert(msg->header(resip::h_CSeq).numKnownParams()==0);
00962    tassert(msg->header(resip::h_CSeq).numUnknownParams()==0);
00963    
00964    //Via: SIP/2.0/UDP host5.example.com;branch=z9hG4bKkdjuw
00965    tassert(msg->exists(resip::h_Vias));
00966    tassert(msg->header(resip::h_Vias).size()==1);
00967    resip::ParserContainer<resip::Via>::iterator i=msg->header(resip::h_Vias).begin();
00968    
00969    tassert(i->numKnownParams()==1);
00970    tassert(i->numUnknownParams()==0);
00971    tassert(i->protocolName()=="SIP");
00972    tassert(i->protocolVersion()=="2.0");
00973    tassert(i->transport()=="UDP");
00974    tassert(i->sentHost()=="host5.example.com");
00975    tassert(i->sentPort()==0);
00976    
00977    tassert(i->exists(resip::p_branch));
00978    tassert(i->param(resip::p_branch).hasMagicCookie());
00979    tassert(i->param(resip::p_branch).getTransactionId()=="kdjuw");
00980    tassert(i->param(resip::p_branch).clientData().empty());
00981       
00982    //Contact: <sip:%00@host5.example.com>
00983    //Contact: <sip:%00%00@host5.example.com>
00984    tassert(msg->exists(resip::h_Contacts));
00985    tassert(msg->header(resip::h_Contacts).size()==2);
00986    resip::ParserContainer<resip::NameAddr>::iterator j=msg->header(resip::h_Contacts).begin();
00987    
00988    tassert(j->displayName()=="");
00989    tassert(j->numKnownParams()==0);
00990    tassert(j->numUnknownParams()==0);
00991    tassert(!(j->isAllContacts()));
00992    tassert(j->uri().numKnownParams()==0);
00993    tassert(j->uri().numUnknownParams()==0);
00994    tassert(j->uri().scheme()=="sip");
00995    tassert(j->uri().user()=="%00");
00996    tassert(j->uri().password().empty());
00997    tassert(j->uri().host()=="host5.example.com");
00998    tassert(j->uri().port()==0);
00999    tassert(!(j->uri().hasEmbedded()));
01000 
01001    j++;
01002    
01003    tassert(j->displayName()=="");
01004    tassert(j->numKnownParams()==0);
01005    tassert(j->numUnknownParams()==0);
01006    tassert(!(j->isAllContacts()));
01007    tassert(j->uri().numKnownParams()==0);
01008    tassert(j->uri().numUnknownParams()==0);
01009    tassert(j->uri().scheme()=="sip");
01010    tassert(j->uri().user()=="%00%00");
01011    tassert(j->uri().password().empty());
01012    tassert(j->uri().host()=="host5.example.com");
01013    tassert(j->uri().port()==0);
01014    tassert(!(j->uri().hasEmbedded()));
01015 
01016    //L:0
01017    tassert(msg->exists(resip::h_ContentLength));
01018    tassert(msg->header(resip::h_ContentLength).value()==0);
01019    tassert(msg->header(resip::h_ContentLength).numKnownParams()==0);
01020    tassert(msg->header(resip::h_ContentLength).numUnknownParams()==0);
01021    
01022    
01023 
01024 
01025    InfoLog(<< "In case escnull:" );
01026    InfoLog(<< "Original text:" << std::endl << txt );
01027    InfoLog(<< "Encoded form:" << std::endl << encoded );
01028    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
01029 
01030 
01031 
01032 
01033 }
01034 
01035 
01036 void
01037 esc02()
01038 {
01039 /*
01040    In most of the places % can appear in a SIP message, it is not an
01041    escape character.  This can surprise the unwary implementor.  The
01042    following well-formed request has these properties:
01043 
01044    o  The request method is unknown.  It is NOT equivalent to REGISTER.
01045 
01046    o  The display name portion of the To and From header fields is
01047       "%Z%45".  Note that this is not the same as %ZE.
01048 
01049    o  This message has two Contact header field values, not three.
01050       <sip:alias2@host2.example.com> is a C%6Fntact header field value.
01051 
01052    A parser should accept this message as well formed.  A proxy would
01053    forward or reject the message depending on what the Request-URI meant
01054    to it.  An endpoint would reject this message with a 501.
01055 
01056 
01057 RE%47IST%45R sip:registrar.example.com SIP/2.0
01058 To: "%Z%45" <sip:resource@example.com>
01059 From: "%Z%45" <sip:resource@example.com>;tag=f232jadfj23
01060 Call-ID: esc02.asdfnqwo34rq23i34jrjasdcnl23nrlknsdf
01061 Via: SIP/2.0/TCP host.example.com;branch=z9hG4bK209%fzsnel234
01062 CSeq: 29344 RE%47IST%45R
01063 Max-Forwards: 70
01064 Contact: <sip:alias1@host1.example.com>
01065 C%6Fntact: <sip:alias2@host2.example.com>
01066 Contact: <sip:alias3@host3.example.com>
01067 l: 0
01068 
01069 
01070 */
01071    FILE* fid= fopen("esc02.dat","r");
01072    tassert(fid);
01073    resip::Data txt;
01074    char mBuf[1024];
01075    int result;
01076    while(!feof(fid))
01077    {
01078       result = fread(&mBuf,1,1024,fid);
01079       txt += resip::Data(mBuf,result);
01080    }
01081    fclose(fid);
01082    resip::SipMessage* msg = resip::SipMessage::make(txt);
01083    tassert_reset();
01084    tassert(msg);
01085    tassert_reset();
01086    if(!msg)
01087    {
01088       return;
01089    }
01090 
01091    std::auto_ptr<resip::SipMessage> message(msg);
01092    msg->parseAllHeaders();
01093 
01094    resip::SipMessage copy(*msg);
01095 
01096    resip::Data encoded;
01097    {
01098       resip::oDataStream str(encoded);
01099       msg->encode(str);
01100    }
01101    resip::Data copyEncoded;
01102    {
01103       resip::oDataStream str(copyEncoded);
01104       copy.encode(str);
01105    }
01106 
01107    //RE%47IST%45R sip:registrar.example.com SIP/2.0
01108    tassert(msg->header(resip::h_RequestLine).method()==resip::UNKNOWN);
01109    tassert(msg->header(resip::h_RequestLine).unknownMethodName()=="RE%47IST%45R");
01110    tassert(msg->header(resip::h_RequestLine).uri().scheme()=="sip");
01111    tassert(msg->header(resip::h_RequestLine).uri().user()=="");
01112    tassert(msg->header(resip::h_RequestLine).uri().password().empty());
01113    tassert(msg->header(resip::h_RequestLine).uri().host()=="registrar.example.com");
01114    tassert(msg->header(resip::h_RequestLine).uri().port()==0);
01115    tassert(!(msg->header(resip::h_RequestLine).uri().hasEmbedded()));
01116    tassert(msg->header(resip::h_RequestLine).uri().numKnownParams()==0);
01117    tassert(msg->header(resip::h_RequestLine).uri().numUnknownParams()==0);
01118    tassert(msg->header(resip::h_RequestLine).getSipVersion()=="SIP/2.0");
01119 
01120    //To: "%Z%45" <sip:resource@example.com>
01121    tassert(msg->exists(resip::h_To));
01122    tassert(msg->header(resip::h_To).displayName()=="%Z%45");
01123    tassert(msg->header(resip::h_To).numKnownParams()==0);
01124    tassert(msg->header(resip::h_To).numUnknownParams()==0);
01125    tassert(!(msg->header(resip::h_To).isAllContacts()));
01126    tassert(msg->header(resip::h_To).uri().scheme()=="sip");
01127    tassert(msg->header(resip::h_To).uri().user()=="resource");
01128    tassert(msg->header(resip::h_To).uri().password().empty());
01129    tassert(msg->header(resip::h_To).uri().host()=="example.com");
01130    tassert(msg->header(resip::h_To).uri().port()==0);
01131    tassert(!(msg->header(resip::h_To).uri().hasEmbedded()));
01132    tassert(msg->header(resip::h_To).uri().numKnownParams()==0);
01133    tassert(msg->header(resip::h_To).uri().numUnknownParams()==0);
01134 
01135    //From: "%Z%45" <sip:resource@example.com>;tag=f232jadfj23
01136    tassert(msg->exists(resip::h_From));
01137    tassert(msg->header(resip::h_From).displayName()=="%Z%45");
01138    tassert(msg->header(resip::h_From).numKnownParams()==1);
01139    tassert(msg->header(resip::h_From).numUnknownParams()==0);
01140    tassert(msg->header(resip::h_From).exists(resip::p_tag));
01141    tassert(msg->header(resip::h_From).param(resip::p_tag)=="f232jadfj23");
01142    tassert(!(msg->header(resip::h_From).isAllContacts()));
01143    tassert(msg->header(resip::h_From).uri().scheme()=="sip");
01144    tassert(msg->header(resip::h_From).uri().user()=="resource");
01145    tassert(msg->header(resip::h_From).uri().password().empty());
01146    tassert(msg->header(resip::h_From).uri().host()=="example.com");
01147    tassert(msg->header(resip::h_From).uri().port()==0);
01148    tassert(!(msg->header(resip::h_From).uri().hasEmbedded()));
01149    tassert(msg->header(resip::h_From).uri().numKnownParams()==0);
01150    tassert(msg->header(resip::h_From).uri().numUnknownParams()==0);
01151 
01152    //Call-ID: esc02.asdfnqwo34rq23i34jrjasdcnl23nrlknsdf
01153    tassert(msg->exists(resip::h_CallID));
01154    tassert(msg->header(resip::h_CallID).value()=="esc02.asdfnqwo34rq23i34jrjasdcnl23nrlknsdf");
01155    tassert(msg->header(resip::h_CallID).numKnownParams()==0);
01156    tassert(msg->header(resip::h_CallID).numUnknownParams()==0);
01157 
01158    //Via: SIP/2.0/TCP host.example.com;branch=z9hG4bK209%fzsnel234
01159    tassert(msg->exists(resip::h_Vias));
01160    tassert(msg->header(resip::h_Vias).size()==1);
01161    resip::ParserContainer<resip::Via>::iterator i=msg->header(resip::h_Vias).begin();
01162    
01163    tassert(i->numKnownParams()==1);
01164    tassert(i->numUnknownParams()==0);
01165    tassert(i->protocolName()=="SIP");
01166    tassert(i->protocolVersion()=="2.0");
01167    tassert(i->transport()=="TCP");
01168    tassert(i->sentHost()=="host.example.com");
01169    tassert(i->sentPort()==0);
01170    
01171    tassert(i->exists(resip::p_branch));
01172    tassert(i->param(resip::p_branch).hasMagicCookie());
01173    tassert(i->param(resip::p_branch).getTransactionId()=="209%fzsnel234");
01174    tassert(i->param(resip::p_branch).clientData().empty());
01175    
01176    //CSeq: 29344 RE%47IST%45R
01177    tassert(msg->exists(resip::h_CSeq));
01178    tassert(msg->header(resip::h_CSeq).method()==resip::UNKNOWN);
01179    tassert(msg->header(resip::h_CSeq).unknownMethodName()=="RE%47IST%45R");
01180    tassert(msg->header(resip::h_CSeq).sequence()==29344);
01181    tassert(msg->header(resip::h_CSeq).numKnownParams()==0);
01182    tassert(msg->header(resip::h_CSeq).numUnknownParams()==0);
01183 
01184    //Max-Forwards: 70
01185    tassert(msg->exists(resip::h_MaxForwards));
01186    tassert(msg->header(resip::h_MaxForwards).value()==70);
01187    tassert(msg->header(resip::h_MaxForwards).numKnownParams()==0);
01188    tassert(msg->header(resip::h_MaxForwards).numUnknownParams()==0);
01189 
01190    //Contact: <sip:alias1@host1.example.com>
01191    //Contact: <sip:alias3@host3.example.com>
01192    tassert(msg->exists(resip::h_Contacts));
01193    tassert(msg->header(resip::h_Contacts).size()==2);
01194    resip::ParserContainer<resip::NameAddr>::iterator j=msg->header(resip::h_Contacts).begin();
01195    
01196    tassert(j->displayName()=="");
01197    tassert(j->numKnownParams()==0);
01198    tassert(j->numUnknownParams()==0);
01199    tassert(!(j->isAllContacts()));
01200    tassert(j->uri().numKnownParams()==0);
01201    tassert(j->uri().numUnknownParams()==0);
01202    tassert(j->uri().scheme()=="sip");
01203    tassert(j->uri().user()=="alias1");
01204    tassert(j->uri().password().empty());
01205    tassert(j->uri().host()=="host1.example.com");
01206    tassert(j->uri().port()==0);
01207    tassert(!(j->uri().hasEmbedded()));
01208 
01209    j++;
01210    
01211    tassert(j->displayName()=="");
01212    tassert(j->numKnownParams()==0);
01213    tassert(j->numUnknownParams()==0);
01214    tassert(!(j->isAllContacts()));
01215    tassert(j->uri().numKnownParams()==0);
01216    tassert(j->uri().numUnknownParams()==0);
01217    tassert(j->uri().scheme()=="sip");
01218    tassert(j->uri().user()=="alias3");
01219    tassert(j->uri().password().empty());
01220    tassert(j->uri().host()=="host3.example.com");
01221    tassert(j->uri().port()==0);
01222    tassert(!(j->uri().hasEmbedded()));
01223 
01224    //C%6Fntact: <sip:alias2@host2.example.com>
01225    resip::ExtensionHeader p_fakeContact("C%6Fntact");
01226    tassert(msg->exists(p_fakeContact));
01227    tassert(msg->header(p_fakeContact).size()==1);
01228    tassert(msg->header(p_fakeContact).begin()->value()=="<sip:alias2@host2.example.com>");
01229    
01230    //l: 0
01231    tassert(msg->exists(resip::h_ContentLength));
01232    tassert(msg->header(resip::h_ContentLength).value()==0);
01233    tassert(msg->header(resip::h_ContentLength).numKnownParams()==0);
01234    tassert(msg->header(resip::h_ContentLength).numUnknownParams()==0);
01235 
01236 
01237    InfoLog(<< "In case esc02:" );
01238    InfoLog(<< "Original text:" << std::endl << txt );
01239    InfoLog(<< "Encoded form:" << std::endl << encoded );
01240    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
01241 
01242 
01243 
01244 
01245 }
01246 
01247 
01248 void
01249 lwsdisp()
01250 {
01251 /*
01252    This OPTIONS request is not valid per the grammar in RFC 3261 since
01253    there is no LWS between the token in the display name and < in the
01254    From header field value.  This has been identified as a specification
01255    bug that will be removed when RFC 3261 is revised.  Elements should
01256    accept this request as well formed.
01257 
01258 OPTIONS sip:user@example.com SIP/2.0
01259 To: sip:user@example.com
01260 From: caller<sip:caller@example.com>;tag=323
01261 Max-Forwards: 70
01262 Call-ID: lwsdisp.1234abcd@funky.example.com
01263 CSeq: 60 OPTIONS
01264 Via: SIP/2.0/UDP funky.example.com;branch=z9hG4bKkdjuw
01265 l: 0
01266 
01267 
01268 */
01269    FILE* fid= fopen("lwsdisp.dat","r");
01270    tassert(fid);
01271    resip::Data txt;
01272    char mBuf[1024];
01273    int result;
01274    while(!feof(fid))
01275    {
01276       result = fread(&mBuf,1,1024,fid);
01277       txt += resip::Data(mBuf,result);
01278    }
01279    fclose(fid);
01280    resip::SipMessage* msg = resip::SipMessage::make(txt);
01281    tassert_reset();
01282    tassert(msg);
01283    tassert_reset();
01284    if(!msg)
01285    {
01286       return;
01287    }
01288 
01289    std::auto_ptr<resip::SipMessage> message(msg);
01290    msg->parseAllHeaders();
01291 
01292    resip::SipMessage copy(*msg);
01293 
01294    resip::Data encoded;
01295    {
01296       resip::oDataStream str(encoded);
01297       msg->encode(str);
01298    }
01299    resip::Data copyEncoded;
01300    {
01301       resip::oDataStream str(copyEncoded);
01302       copy.encode(str);
01303    }
01304 
01305    //Request-Line
01306    //OPTIONS sip:user@example.com SIP/2.0
01307    tassert(msg->header(resip::h_RequestLine).method()==resip::OPTIONS);
01308    tassert(msg->header(resip::h_RequestLine).unknownMethodName()=="OPTIONS");
01309    tassert(msg->header(resip::h_RequestLine).uri().scheme()=="sip");
01310    tassert(msg->header(resip::h_RequestLine).uri().user()=="user");
01311    tassert(msg->header(resip::h_RequestLine).uri().password().empty());
01312    tassert(msg->header(resip::h_RequestLine).uri().host()=="example.com");
01313    tassert(msg->header(resip::h_RequestLine).uri().port()==0);
01314    tassert(!(msg->header(resip::h_RequestLine).uri().hasEmbedded()));
01315    tassert(msg->header(resip::h_RequestLine).uri().numKnownParams()==0);
01316    tassert(msg->header(resip::h_RequestLine).uri().numUnknownParams()==0);
01317    tassert(msg->header(resip::h_RequestLine).getSipVersion()=="SIP/2.0");
01318 
01319    //To: sip:user@example.com
01320    tassert(msg->exists(resip::h_To));
01321    tassert(msg->header(resip::h_To).displayName()=="");
01322    tassert(msg->header(resip::h_To).numKnownParams()==0);
01323    tassert(msg->header(resip::h_To).numUnknownParams()==0);
01324    tassert(!(msg->header(resip::h_To).isAllContacts()));
01325    tassert(msg->header(resip::h_To).uri().scheme()=="sip");
01326    tassert(msg->header(resip::h_To).uri().user()=="user");
01327    tassert(msg->header(resip::h_To).uri().password().empty());
01328    tassert(msg->header(resip::h_To).uri().host()=="example.com");
01329    tassert(msg->header(resip::h_To).uri().port()==0);
01330    tassert(!(msg->header(resip::h_To).uri().hasEmbedded()));
01331    tassert(msg->header(resip::h_To).uri().numKnownParams()==0);
01332    tassert(msg->header(resip::h_To).uri().numUnknownParams()==0);
01333 
01334    //From: caller<sip:caller@example.com>;tag=323
01335    tassert(msg->exists(resip::h_From));
01336    tassert(msg->header(resip::h_From).displayName()=="caller");
01337    tassert(msg->header(resip::h_From).numKnownParams()==1);
01338    tassert(msg->header(resip::h_From).numUnknownParams()==0);
01339    tassert(msg->header(resip::h_From).exists(resip::p_tag));
01340    tassert(msg->header(resip::h_From).param(resip::p_tag)=="323");
01341    tassert(!(msg->header(resip::h_From).isAllContacts()));
01342    tassert(msg->header(resip::h_From).uri().scheme()=="sip");
01343    tassert(msg->header(resip::h_From).uri().user()=="caller");
01344    tassert(msg->header(resip::h_From).uri().password().empty());
01345    tassert(msg->header(resip::h_From).uri().host()=="example.com");
01346    tassert(msg->header(resip::h_From).uri().port()==0);
01347    tassert(!(msg->header(resip::h_From).uri().hasEmbedded()));
01348    tassert(msg->header(resip::h_From).uri().numKnownParams()==0);
01349    tassert(msg->header(resip::h_From).uri().numUnknownParams()==0);
01350 
01351    //Max-Forwards: 70
01352    tassert(msg->exists(resip::h_MaxForwards));
01353    tassert(msg->header(resip::h_MaxForwards).value()==70);
01354    tassert(msg->header(resip::h_MaxForwards).numKnownParams()==0);
01355    tassert(msg->header(resip::h_MaxForwards).numUnknownParams()==0);
01356 
01357    //Call-ID: lwsdisp.1234abcd@funky.example.com
01358    tassert(msg->exists(resip::h_CallID));
01359    tassert(msg->header(resip::h_CallID).value()=="lwsdisp.1234abcd@funky.example.com");
01360    tassert(msg->header(resip::h_CallID).numKnownParams()==0);
01361    tassert(msg->header(resip::h_CallID).numUnknownParams()==0);
01362 
01363    //CSeq: 60 OPTIONS
01364    tassert(msg->exists(resip::h_CSeq));
01365    tassert(msg->header(resip::h_CSeq).method()==resip::OPTIONS);
01366    tassert(msg->header(resip::h_CSeq).unknownMethodName()=="OPTIONS");
01367    tassert(msg->header(resip::h_CSeq).sequence()==60);
01368    tassert(msg->header(resip::h_CSeq).numKnownParams()==0);
01369    tassert(msg->header(resip::h_CSeq).numUnknownParams()==0);
01370 
01371    //Via: SIP/2.0/UDP funky.example.com;branch=z9hG4bKkdjuw
01372    tassert(msg->exists(resip::h_Vias));
01373    tassert(msg->header(resip::h_Vias).size()==1);
01374    resip::ParserContainer<resip::Via>::iterator i=msg->header(resip::h_Vias).begin();
01375    
01376    tassert(i->numKnownParams()==1);
01377    tassert(i->numUnknownParams()==0);
01378    tassert(i->protocolName()=="SIP");
01379    tassert(i->protocolVersion()=="2.0");
01380    tassert(i->transport()=="UDP");
01381    tassert(i->sentHost()=="funky.example.com");
01382    tassert(i->sentPort()==0);
01383    
01384    tassert(i->exists(resip::p_branch));
01385    tassert(i->param(resip::p_branch).hasMagicCookie());
01386    tassert(i->param(resip::p_branch).getTransactionId()=="kdjuw");
01387    tassert(i->param(resip::p_branch).clientData().empty());
01388 
01389    //l: 0
01390    tassert(msg->exists(resip::h_ContentLength));
01391    tassert(msg->header(resip::h_ContentLength).value()==0);
01392    tassert(msg->header(resip::h_ContentLength).numKnownParams()==0);
01393    tassert(msg->header(resip::h_ContentLength).numUnknownParams()==0);
01394 
01395    InfoLog(<< "In case lwsdisp:" );
01396    InfoLog(<< "Original text:" << std::endl << txt );
01397    InfoLog(<< "Encoded form:" << std::endl << encoded );
01398    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
01399 
01400 
01401 
01402 
01403 }
01404 
01405 
01406 void
01407 longreq()
01408 {
01409 /*
01410    This well-formed request contains header fields with many values and
01411    values that are very long.  Features include the following:
01412 
01413    o  The To header field has a long display name, and long uri
01414       parameter names and values.
01415 
01416    o  The From header field has long header parameter names and values,
01417       in particular, a very long tag.
01418 
01419    o  The Call-ID is one long token.
01420 
01421 INVITE sip:user@example.com SIP/2.0
01422 To: "I have a user name of extremeextremeextremeextremeextremeextremeextremeextremeextremeextreme proportion"<sip:user@example.com:6000;unknownparam1=verylonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongvalue;longparamnamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamename=shortvalue;verylonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongParameterNameWithNoValue>
01423 F: sip:amazinglylongcallernameamazinglylongcallernameamazinglylongcallernameamazinglylongcallernameamazinglylongcallername@example.net;tag=12982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982424;unknownheaderparamnamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamename=unknowheaderparamvaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevalue;unknownValuelessparamnameparamnameparamnameparamnameparamnameparamnameparamnameparamnameparamnameparamname
01424 Call-ID: longreq.onereallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongcallid
01425 CSeq: 3882340 INVITE
01426 Unknown-LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong-Name: unknown-longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong-value; unknown-longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong-parameter-name = unknown-longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong-parameter-value
01427 Via: SIP/2.0/TCP sip33.example.com
01428 v: SIP/2.0/TCP sip32.example.com
01429 V: SIP/2.0/TCP sip31.example.com
01430 Via: SIP/2.0/TCP sip30.example.com
01431 ViA: SIP/2.0/TCP sip29.example.com
01432 VIa: SIP/2.0/TCP sip28.example.com
01433 VIA: SIP/2.0/TCP sip27.example.com
01434 via: SIP/2.0/TCP sip26.example.com
01435 viA: SIP/2.0/TCP sip25.example.com
01436 vIa: SIP/2.0/TCP sip24.example.com
01437 vIA: SIP/2.0/TCP sip23.example.com
01438 V :  SIP/2.0/TCP sip22.example.com
01439 v :  SIP/2.0/TCP sip21.example.com
01440 V  : SIP/2.0/TCP sip20.example.com
01441 v  : SIP/2.0/TCP sip19.example.com
01442 Via : SIP/2.0/TCP sip18.example.com
01443 Via  : SIP/2.0/TCP sip17.example.com
01444 Via: SIP/2.0/TCP sip16.example.com
01445 Via: SIP/2.0/TCP sip15.example.com
01446 Via: SIP/2.0/TCP sip14.example.com
01447 Via: SIP/2.0/TCP sip13.example.com
01448 Via: SIP/2.0/TCP sip12.example.com
01449 Via: SIP/2.0/TCP sip11.example.com
01450 Via: SIP/2.0/TCP sip10.example.com
01451 Via: SIP/2.0/TCP sip9.example.com
01452 Via: SIP/2.0/TCP sip8.example.com
01453 Via: SIP/2.0/TCP sip7.example.com
01454 Via: SIP/2.0/TCP sip6.example.com
01455 Via: SIP/2.0/TCP sip5.example.com
01456 Via: SIP/2.0/TCP sip4.example.com
01457 Via: SIP/2.0/TCP sip3.example.com
01458 Via: SIP/2.0/TCP sip2.example.com
01459 Via: SIP/2.0/TCP sip1.example.com
01460 Via: SIP/2.0/TCP host.example.com;received=192.0.2.5;branch=verylonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongbranchvalue
01461 Max-Forwards: 70
01462 Contact: <sip:amazinglylongcallernameamazinglylongcallernameamazinglylongcallernameamazinglylongcallernameamazinglylongcallername@host5.example.net>
01463 Content-Type: application/sdp
01464 l: 150
01465 
01466 v=0
01467 o=mhandley 29739 7272939 IN IP4 192.0.2.1
01468 s=-
01469 c=IN IP4 192.0.2.1
01470 t=0 0
01471 m=audio 49217 RTP/AVP 0 12
01472 m=video 3227 RTP/AVP 31
01473 a=rtpmap:31 LPC
01474 
01475 */
01476    FILE* fid= fopen("longreq.dat","r");
01477    tassert(fid);
01478    resip::Data txt;
01479    char mBuf[1024];
01480    int result;
01481    while(!feof(fid))
01482    {
01483       result = fread(&mBuf,1,1024,fid);
01484       txt += resip::Data(mBuf,result);
01485    }
01486    fclose(fid);
01487    resip::SipMessage* msg = resip::SipMessage::make(txt);
01488    tassert_reset();
01489    tassert(msg);
01490    tassert_reset();
01491    if(!msg)
01492    {
01493       return;
01494    }
01495 
01496    std::auto_ptr<resip::SipMessage> message(msg);
01497    msg->parseAllHeaders();
01498 
01499    resip::SipMessage copy(*msg);
01500 
01501    resip::Data encoded;
01502    {
01503       resip::oDataStream str(encoded);
01504       msg->encode(str);
01505    }
01506    resip::Data copyEncoded;
01507    {
01508       resip::oDataStream str(copyEncoded);
01509       copy.encode(str);
01510    }
01511 
01512    //Request Line
01513    //INVITE sip:user@example.com SIP/2.0
01514    tassert(msg->header(resip::h_RequestLine).method()==resip::INVITE);
01515    tassert(msg->header(resip::h_RequestLine).unknownMethodName()=="INVITE");
01516    tassert(msg->header(resip::h_RequestLine).uri().scheme()=="sip");
01517    tassert(msg->header(resip::h_RequestLine).uri().user()=="user");
01518    tassert(msg->header(resip::h_RequestLine).uri().password().empty());
01519    tassert(msg->header(resip::h_RequestLine).uri().host()=="example.com");
01520    tassert(msg->header(resip::h_RequestLine).uri().port()==0);
01521    tassert(!(msg->header(resip::h_RequestLine).uri().hasEmbedded()));
01522    tassert(msg->header(resip::h_RequestLine).uri().numKnownParams()==0);
01523    tassert(msg->header(resip::h_RequestLine).uri().numUnknownParams()==0);
01524    tassert(msg->header(resip::h_RequestLine).getSipVersion()=="SIP/2.0");
01525 
01526    //To: "I have a user name of extremeextremeextremeextremeextremeextremeextremeextremeextremeextreme proportion"<sip:user@example.com:6000;unknownparam1=verylonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongvalue;longparamnamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamename=shortvalue;verylonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongParameterNameWithNoValue>
01527    tassert(msg->exists(resip::h_To));
01528    tassert(msg->header(resip::h_To).displayName()=="I have a user name of extremeextremeextremeextremeextremeextremeextremeextremeextremeextreme proportion");
01529    tassert(msg->header(resip::h_To).numKnownParams()==0);
01530    tassert(msg->header(resip::h_To).numUnknownParams()==0);
01531    tassert(!(msg->header(resip::h_To).isAllContacts()));
01532    tassert(msg->header(resip::h_To).uri().scheme()=="sip");
01533    tassert(msg->header(resip::h_To).uri().user()=="user");
01534    tassert(msg->header(resip::h_To).uri().password().empty());
01535    tassert(msg->header(resip::h_To).uri().host()=="example.com");
01536    tassert(msg->header(resip::h_To).uri().port()==6000);
01537    tassert(!(msg->header(resip::h_To).uri().hasEmbedded()));
01538    tassert(msg->header(resip::h_To).uri().numKnownParams()==0);
01539    tassert(msg->header(resip::h_To).uri().numUnknownParams()==3);
01540 
01541    resip::ExtensionParameter p_unknownparam1("unknownparam1");
01542    tassert(msg->header(resip::h_To).uri().exists(p_unknownparam1));
01543    tassert(msg->header(resip::h_To).uri().param(p_unknownparam1)=="verylonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongvalue");
01544 
01545    resip::ExtensionParameter p_long("longparamnamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamename");
01546    tassert(msg->header(resip::h_To).uri().exists(p_long));
01547    tassert(msg->header(resip::h_To).uri().param(p_long)=="shortvalue");
01548 
01549    resip::ExtensionParameter p_verylong("verylonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongParameterNameWithNoValue");
01550    tassert(msg->header(resip::h_To).uri().exists(p_verylong));
01551    tassert(msg->header(resip::h_To).uri().param(p_verylong)=="");
01552 
01553    //F: sip:amazinglylongcallernameamazinglylongcallernameamazinglylongcallernameamazinglylongcallernameamazinglylongcallername@example.net;tag=12982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982424;unknownheaderparamnamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamename=unknowheaderparamvaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevalue;unknownValuelessparamnameparamnameparamnameparamnameparamnameparamnameparamnameparamnameparamnameparamname
01554    tassert(msg->exists(resip::h_From));
01555    tassert(msg->header(resip::h_From).displayName()=="");
01556    tassert(msg->header(resip::h_From).numKnownParams()==1);
01557    tassert(msg->header(resip::h_From).numUnknownParams()==2);
01558    tassert(msg->header(resip::h_From).exists(resip::p_tag));
01559    tassert(msg->header(resip::h_From).param(resip::p_tag)=="12982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982424");
01560    
01561    resip::ExtensionParameter p_unknownheaderparameternameXalot("unknownheaderparamnamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamename");
01562    tassert(msg->header(resip::h_From).exists(p_unknownheaderparameternameXalot));
01563    tassert(msg->header(resip::h_From).param(p_unknownheaderparameternameXalot)=="unknowheaderparamvaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevalue");
01564 
01565    resip::ExtensionParameter p_unknownvalueless("unknownValuelessparamnameparamnameparamnameparamnameparamnameparamnameparamnameparamnameparamnameparamname");
01566    tassert(msg->header(resip::h_From).exists(p_unknownvalueless));
01567    tassert(msg->header(resip::h_From).param(p_unknownvalueless)=="");
01568 
01569    tassert(!(msg->header(resip::h_From).isAllContacts()));
01570    tassert(msg->header(resip::h_From).uri().scheme()=="sip");
01571    tassert(msg->header(resip::h_From).uri().user()=="amazinglylongcallernameamazinglylongcallernameamazinglylongcallernameamazinglylongcallernameamazinglylongcallername");
01572    tassert(msg->header(resip::h_From).uri().password().empty());
01573    tassert(msg->header(resip::h_From).uri().host()=="example.net");
01574    tassert(msg->header(resip::h_From).uri().port()==0);
01575    tassert(!(msg->header(resip::h_From).uri().hasEmbedded()));
01576    tassert(msg->header(resip::h_From).uri().numKnownParams()==0);
01577    tassert(msg->header(resip::h_From).uri().numUnknownParams()==0);
01578 
01579    //Call-ID: longreq.onereallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongcallid
01580    tassert(msg->exists(resip::h_CallID));
01581    tassert(msg->header(resip::h_CallID).value()=="longreq.onereallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongcallid");
01582    tassert(msg->header(resip::h_CallID).numKnownParams()==0);
01583    tassert(msg->header(resip::h_CallID).numUnknownParams()==0);
01584 
01585    //CSeq: 3882340 INVITE
01586    tassert(msg->exists(resip::h_CSeq));
01587    tassert(msg->header(resip::h_CSeq).method()==resip::INVITE);
01588    tassert(msg->header(resip::h_CSeq).unknownMethodName()=="INVITE");
01589    tassert(msg->header(resip::h_CSeq).sequence()==3882340);
01590    tassert(msg->header(resip::h_CSeq).numKnownParams()==0);
01591    tassert(msg->header(resip::h_CSeq).numUnknownParams()==0);
01592 
01593    //Unknown headers
01594    //Unknown-LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong-Name: unknown-longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong-value; unknown-longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong-parameter-name = unknown-longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong-parameter-value
01595    resip::ExtensionHeader h_UnknownLong("Unknown-LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong-Name");
01596    
01597    tassert(msg->exists(h_UnknownLong));
01598    tassert(msg->header(h_UnknownLong).size()==1);
01599    tassert(msg->header(h_UnknownLong).begin()->value()=="unknown-longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong-value; unknown-longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong-parameter-name = unknown-longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong-parameter-value");
01600    tassert(msg->header(h_UnknownLong).begin()->numKnownParams()==0);
01601    tassert(msg->header(h_UnknownLong).begin()->numUnknownParams()==0);
01602    
01603    //Vias
01604 
01605    //Via: SIP/2.0/TCP sip33.example.com
01606    //v: SIP/2.0/TCP sip32.example.com
01607    //V: SIP/2.0/TCP sip31.example.com
01608    //Via: SIP/2.0/TCP sip30.example.com
01609    //ViA: SIP/2.0/TCP sip29.example.com
01610    //VIa: SIP/2.0/TCP sip28.example.com
01611    //VIA: SIP/2.0/TCP sip27.example.com
01612    //via: SIP/2.0/TCP sip26.example.com
01613    //viA: SIP/2.0/TCP sip25.example.com
01614    //vIa: SIP/2.0/TCP sip24.example.com
01615    //vIA: SIP/2.0/TCP sip23.example.com
01616    //V :  SIP/2.0/TCP sip22.example.com
01617    //v :  SIP/2.0/TCP sip21.example.com
01618    //V  : SIP/2.0/TCP sip20.example.com
01619    //v  : SIP/2.0/TCP sip19.example.com
01620    //Via : SIP/2.0/TCP sip18.example.com
01621    //Via  : SIP/2.0/TCP sip17.example.com
01622    //Via: SIP/2.0/TCP sip16.example.com
01623    //Via: SIP/2.0/TCP sip15.example.com
01624    //Via: SIP/2.0/TCP sip14.example.com
01625    //Via: SIP/2.0/TCP sip13.example.com
01626    //Via: SIP/2.0/TCP sip12.example.com
01627    //Via: SIP/2.0/TCP sip11.example.com
01628    //Via: SIP/2.0/TCP sip10.example.com
01629    //Via: SIP/2.0/TCP sip9.example.com
01630    //Via: SIP/2.0/TCP sip8.example.com
01631    //Via: SIP/2.0/TCP sip7.example.com
01632    //Via: SIP/2.0/TCP sip6.example.com
01633    //Via: SIP/2.0/TCP sip5.example.com
01634    //Via: SIP/2.0/TCP sip4.example.com
01635    //Via: SIP/2.0/TCP sip3.example.com
01636    //Via: SIP/2.0/TCP sip2.example.com
01637    //Via: SIP/2.0/TCP sip1.example.com
01638    //Via: SIP/2.0/TCP host.example.com;received=192.0.2.5;branch=verylonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongbranchvalue
01639 
01640    tassert(msg->exists(resip::h_Vias));
01641    tassert(msg->header(resip::h_Vias).size()==34);
01642    
01643    int i=33;
01644    resip::Vias::iterator iter;
01645    for(iter=msg->header(resip::h_Vias).begin();
01646          iter!=msg->header(resip::h_Vias).end(); iter++)
01647    {
01648       if(i==0)
01649       {
01650          break;
01651       }
01652       tassert(iter->numKnownParams()==0);
01653       tassert(iter->numUnknownParams()==0);
01654       tassert(iter->protocolName()=="SIP");
01655       tassert(iter->protocolVersion()=="2.0");
01656       tassert(iter->transport()=="TCP");
01657       tassert(iter->sentHost()==resip::Data("sip")+resip::Data(i)+resip::Data(".example.com"));
01658       tassert(iter->sentPort()==0);
01659       i--;
01660    }
01661    
01662    tassert(iter->numKnownParams()==2);
01663    tassert(iter->numUnknownParams()==0);
01664    tassert(iter->protocolName()=="SIP");
01665    tassert(iter->protocolVersion()=="2.0");
01666    tassert(iter->transport()=="TCP");
01667    tassert(iter->sentHost()=="host.example.com");
01668    tassert(iter->sentPort()==0);
01669    
01670    tassert(iter->exists(resip::p_branch));
01671    tassert(!(iter->param(resip::p_branch).hasMagicCookie()));
01672    tassert(iter->param(resip::p_branch).getTransactionId()=="verylonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongbranchvalue");
01673    tassert(iter->param(resip::p_branch).clientData().empty());
01674 
01675    tassert(iter->exists(resip::p_received));
01676    tassert(iter->param(resip::p_received)=="192.0.2.5");
01677 
01678    //Max-Forwards: 70
01679    tassert(msg->exists(resip::h_MaxForwards));
01680    tassert(msg->header(resip::h_MaxForwards).value()==70);
01681    tassert(msg->header(resip::h_MaxForwards).numKnownParams()==0);
01682    tassert(msg->header(resip::h_MaxForwards).numUnknownParams()==0);
01683 
01684    //Contact: <sip:amazinglylongcallernameamazinglylongcallernameamazinglylongcallernameamazinglylongcallernameamazinglylongcallername@host5.example.net>
01685    tassert(msg->exists(resip::h_Contacts));
01686    tassert(msg->header(resip::h_Contacts).size()==1);
01687    resip::ParserContainer<resip::NameAddr>::iterator j=msg->header(resip::h_Contacts).begin();
01688    
01689    tassert(j->displayName()=="");
01690    tassert(j->numKnownParams()==0);
01691    tassert(j->numUnknownParams()==0);
01692    tassert(!(j->isAllContacts()));
01693    tassert(j->uri().numKnownParams()==0);
01694    tassert(j->uri().numUnknownParams()==0);
01695    tassert(j->uri().scheme()=="sip");
01696    tassert(j->uri().user()=="amazinglylongcallernameamazinglylongcallernameamazinglylongcallernameamazinglylongcallernameamazinglylongcallername");
01697    tassert(j->uri().password().empty());
01698    tassert(j->uri().host()=="host5.example.net");
01699    tassert(j->uri().port()==0);
01700    tassert(!(j->uri().hasEmbedded()));
01701 
01702    //Content-Type: application/sdp
01703    tassert(msg->exists(resip::h_ContentType));
01704    tassert(msg->header(resip::h_ContentType).type()=="application");
01705    tassert(msg->header(resip::h_ContentType).subType()=="sdp");
01706    tassert(msg->header(resip::h_ContentType).numKnownParams()==0);
01707    tassert(msg->header(resip::h_ContentType).numUnknownParams()==0);
01708    
01709    //l: 150
01710    tassert(msg->exists(resip::h_ContentLength));
01711    tassert(msg->header(resip::h_ContentLength).value()==150);
01712    tassert(msg->header(resip::h_ContentLength).numKnownParams()==0);
01713    tassert(msg->header(resip::h_ContentLength).numUnknownParams()==0);
01714 
01715    InfoLog(<< "In case longreq:" );
01716    InfoLog(<< "Original text:" << std::endl << txt );
01717    InfoLog(<< "Encoded form:" << std::endl << encoded );
01718    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
01719 
01720 
01721 
01722 
01723 }
01724 
01725 
01726 void
01727 dblreq()
01728 {
01729 /*
01730    This message contains a single SIP REGISTER request, which ostensibly
01731    arrived over UDP in a single datagram.  The packet contains extra
01732    octets after the body (which in this case has zero length).  The
01733    extra octets happen to look like a SIP INVITE request, but (per
01734    section 18.3 of [RFC3261]) they are just spurious noise that must be
01735    ignored.
01736 
01737    A SIP element receiving this datagram would handle the REGISTER
01738    request normally and ignore the extra bits that look like an INVITE
01739    request.  If the element is a proxy choosing to forward the REGISTER,
01740    the INVITE octets would not appear in the forwarded request.
01741 
01742 
01743 
01744 REGISTER sip:example.com SIP/2.0
01745 To: sip:j.user@example.com
01746 From: sip:j.user@example.com;tag=43251j3j324
01747 Max-Forwards: 8
01748 I: dblreq.0ha0isndaksdj99sdfafnl3lk233412
01749 Contact: sip:j.user@host.example.com
01750 CSeq: 8 REGISTER
01751 Via: SIP/2.0/UDP 192.0.2.125;branch=z9hG4bKkdjuw23492
01752 Content-Length: 0
01753 
01754 
01755 INVITE sip:joe@example.com SIP/2.0
01756 t: sip:joe@example.com
01757 From: sip:caller@example.net;tag=141334
01758 Max-Forwards: 8
01759 Call-ID: dblreq.0ha0isnda977644900765@192.0.2.15
01760 CSeq: 8 INVITE
01761 Via: SIP/2.0/UDP 192.0.2.15;branch=z9hG4bKkdjuw380234
01762 Content-Type: application/sdp
01763 Content-Length: 150
01764 
01765 v=0
01766 o=mhandley 29739 7272939 IN IP4 192.0.2.15
01767 s=-
01768 c=IN IP4 192.0.2.15
01769 t=0 0
01770 m=audio 49217 RTP/AVP 0 12
01771 m =video 3227 RTP/AVP 31
01772 a=rtpmap:31 LPC
01773 
01774 
01775 */
01776    FILE* fid= fopen("dblreq.dat","r");
01777    tassert(fid);
01778    resip::Data txt;
01779    char mBuf[1024];
01780    int result;
01781    while(!feof(fid))
01782    {
01783       result = fread(&mBuf,1,1024,fid);
01784       txt += resip::Data(mBuf,result);
01785    }
01786    fclose(fid);
01787    resip::SipMessage* msg = resip::SipMessage::make(txt);
01788    tassert_reset();
01789    tassert(msg);
01790    tassert_reset();
01791    if(!msg)
01792    {
01793       return;
01794    }
01795 
01796    std::auto_ptr<resip::SipMessage> message(msg);
01797    msg->parseAllHeaders();
01798 
01799    resip::SipMessage copy(*msg);
01800 
01801    resip::Data encoded;
01802    {
01803       resip::oDataStream str(encoded);
01804       msg->encode(str);
01805    }
01806    resip::Data copyEncoded;
01807    {
01808       resip::oDataStream str(copyEncoded);
01809       copy.encode(str);
01810    }
01811    
01812    //Request Line
01813    //REGISTER sip:example.com SIP/2.0
01814    tassert(msg->header(resip::h_RequestLine).method()==resip::REGISTER);
01815    tassert(msg->header(resip::h_RequestLine).unknownMethodName()=="REGISTER");
01816    tassert(msg->header(resip::h_RequestLine).uri().scheme()=="sip");
01817    tassert(msg->header(resip::h_RequestLine).uri().user()=="");
01818    tassert(msg->header(resip::h_RequestLine).uri().password().empty());
01819    tassert(msg->header(resip::h_RequestLine).uri().host()=="example.com");
01820    tassert(msg->header(resip::h_RequestLine).uri().port()==0);
01821    tassert(!(msg->header(resip::h_RequestLine).uri().hasEmbedded()));
01822    tassert(msg->header(resip::h_RequestLine).uri().numKnownParams()==0);
01823    tassert(msg->header(resip::h_RequestLine).uri().numUnknownParams()==0);
01824    tassert(msg->header(resip::h_RequestLine).getSipVersion()=="SIP/2.0");
01825 
01826    //To: sip:j.user@example.com
01827    tassert(msg->exists(resip::h_To));
01828    tassert(msg->header(resip::h_To).displayName()=="");
01829    tassert(msg->header(resip::h_To).numKnownParams()==0);
01830    tassert(msg->header(resip::h_To).numUnknownParams()==0);
01831    tassert(!(msg->header(resip::h_To).isAllContacts()));
01832    tassert(msg->header(resip::h_To).uri().scheme()=="sip");
01833    tassert(msg->header(resip::h_To).uri().user()=="j.user");
01834    tassert(msg->header(resip::h_To).uri().password().empty());
01835    tassert(msg->header(resip::h_To).uri().host()=="example.com");
01836    tassert(msg->header(resip::h_To).uri().port()==0);
01837    tassert(!(msg->header(resip::h_To).uri().hasEmbedded()));
01838    tassert(msg->header(resip::h_To).uri().numKnownParams()==0);
01839    tassert(msg->header(resip::h_To).uri().numUnknownParams()==0);
01840 
01841    //From: sip:j.user@example.com;tag=43251j3j324
01842    tassert(msg->exists(resip::h_From));
01843    tassert(msg->header(resip::h_From).displayName()=="");
01844    tassert(msg->header(resip::h_From).numKnownParams()==1);
01845    tassert(msg->header(resip::h_From).numUnknownParams()==0);
01846    tassert(msg->header(resip::h_From).exists(resip::p_tag));
01847    tassert(msg->header(resip::h_From).param(resip::p_tag)=="43251j3j324");
01848    tassert(!(msg->header(resip::h_From).isAllContacts()));
01849    tassert(msg->header(resip::h_From).uri().scheme()=="sip");
01850    tassert(msg->header(resip::h_From).uri().user()=="j.user");
01851    tassert(msg->header(resip::h_From).uri().password().empty());
01852    tassert(msg->header(resip::h_From).uri().host()=="example.com");
01853    tassert(msg->header(resip::h_From).uri().port()==0);
01854    tassert(!(msg->header(resip::h_From).uri().hasEmbedded()));
01855    tassert(msg->header(resip::h_From).uri().numKnownParams()==0);
01856    tassert(msg->header(resip::h_From).uri().numUnknownParams()==0);
01857 
01858    //Max-Forwards: 8
01859    tassert(msg->exists(resip::h_MaxForwards));
01860    tassert(msg->header(resip::h_MaxForwards).value()==8);
01861    tassert(msg->header(resip::h_MaxForwards).numKnownParams()==0);
01862    tassert(msg->header(resip::h_MaxForwards).numUnknownParams()==0);
01863 
01864    //I: dblreq.0ha0isndaksdj99sdfafnl3lk233412
01865    tassert(msg->exists(resip::h_CallID));
01866    tassert(msg->header(resip::h_CallID).value()=="dblreq.0ha0isndaksdj99sdfafnl3lk233412");
01867    tassert(msg->header(resip::h_CallID).numKnownParams()==0);
01868    tassert(msg->header(resip::h_CallID).numUnknownParams()==0);
01869 
01870    //Contact: sip:j.user@host.example.com
01871    tassert(msg->exists(resip::h_Contacts));
01872    tassert(msg->header(resip::h_Contacts).size()==1);
01873    resip::ParserContainer<resip::NameAddr>::iterator j=msg->header(resip::h_Contacts).begin();
01874    
01875    tassert(j->displayName()=="");
01876    tassert(j->numKnownParams()==0);
01877    tassert(j->numUnknownParams()==0);
01878    tassert(!(j->isAllContacts()));
01879    tassert(j->uri().numKnownParams()==0);
01880    tassert(j->uri().numUnknownParams()==0);
01881    tassert(j->uri().scheme()=="sip");
01882    tassert(j->uri().user()=="j.user");
01883    tassert(j->uri().password().empty());
01884    tassert(j->uri().host()=="host.example.com");
01885    tassert(j->uri().port()==0);
01886    tassert(!(j->uri().hasEmbedded()));
01887 
01888    //CSeq: 8 REGISTER
01889    tassert(msg->exists(resip::h_CSeq));
01890    tassert(msg->header(resip::h_CSeq).method()==resip::REGISTER);
01891    tassert(msg->header(resip::h_CSeq).unknownMethodName()=="REGISTER");
01892    tassert(msg->header(resip::h_CSeq).sequence()==8);
01893    tassert(msg->header(resip::h_CSeq).numKnownParams()==0);
01894    tassert(msg->header(resip::h_CSeq).numUnknownParams()==0);
01895 
01896    //Via: SIP/2.0/UDP 192.0.2.125;branch=z9hG4bKkdjuw23492
01897    tassert(msg->exists(resip::h_Vias));
01898    tassert(msg->header(resip::h_Vias).size()==1);
01899    resip::ParserContainer<resip::Via>::iterator i=msg->header(resip::h_Vias).begin();
01900    
01901    tassert(i->numKnownParams()==1);
01902    tassert(i->numUnknownParams()==0);
01903    tassert(i->protocolName()=="SIP");
01904    tassert(i->protocolVersion()=="2.0");
01905    tassert(i->transport()=="UDP");
01906    tassert(i->sentHost()=="192.0.2.125");
01907    tassert(i->sentPort()==0);
01908    
01909    tassert(i->exists(resip::p_branch));
01910    tassert(i->param(resip::p_branch).hasMagicCookie());
01911    tassert(i->param(resip::p_branch).getTransactionId()=="kdjuw23492");
01912    tassert(i->param(resip::p_branch).clientData().empty());
01913 
01914    //Content-Length: 0
01915    tassert(msg->exists(resip::h_ContentLength));
01916    // .bwc. We configured SipMessage to take the Content-Length seriously
01917    tassert(msg->header(resip::h_ContentLength).value()==0);
01918    tassert(msg->header(resip::h_ContentLength).numKnownParams()==0);
01919    tassert(msg->header(resip::h_ContentLength).numUnknownParams()==0);
01920 
01921 
01922 
01923    InfoLog(<< "In case dblreq:" );
01924    InfoLog(<< "Original text:" << std::endl << txt );
01925    InfoLog(<< "Encoded form:" << std::endl << encoded );
01926    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
01927 
01928 
01929 
01930 
01931 }
01932 
01933 
01934 void
01935 semiuri()
01936 {
01937 /*
01938    This request has a semicolon-separated parameter contained in the
01939    "user" part of the Request-URI (whose value contains an escaped @
01940    symbol).  Receiving elements will accept this as a well-formed
01941    message.  The Request-URI will parse so that the user part is
01942    "user;par=u@example.net".
01943 
01944 OPTIONS sip:user;par=u%40example.net@example.com SIP/2.0
01945 To: sip:j_user@example.com
01946 From: sip:caller@example.org;tag=33242
01947 Max-Forwards: 3
01948 Call-ID: semiuri.0ha0isndaksdj
01949 CSeq: 8 OPTIONS
01950 Accept: application/sdp, application/pkcs7-mime,
01951         multipart/mixed, multipart/signed,
01952         message/sip, message/sipfrag
01953 Via: SIP/2.0/UDP 192.0.2.1;branch=z9hG4bKkdjuw
01954 l: 0
01955 
01956 
01957 */
01958    FILE* fid= fopen("semiuri.dat","r");
01959    tassert(fid);
01960    resip::Data txt;
01961    char mBuf[1024];
01962    int result;
01963    while(!feof(fid))
01964    {
01965       result = fread(&mBuf,1,1024,fid);
01966       txt += resip::Data(mBuf,result);
01967    }
01968    fclose(fid);
01969    resip::SipMessage* msg = resip::SipMessage::make(txt);
01970    tassert_reset();
01971    tassert(msg);
01972    tassert_reset();
01973    if(!msg)
01974    {
01975       return;
01976    }
01977 
01978    std::auto_ptr<resip::SipMessage> message(msg);
01979    msg->parseAllHeaders();
01980 
01981    resip::SipMessage copy(*msg);
01982 
01983    resip::Data encoded;
01984    {
01985       resip::oDataStream str(encoded);
01986       msg->encode(str);
01987    }
01988    resip::Data copyEncoded;
01989    {
01990       resip::oDataStream str(copyEncoded);
01991       copy.encode(str);
01992    }
01993 
01994    //Request Line
01995    //OPTIONS sip:user;par=u%40example.net@example.com SIP/2.0
01996    tassert(msg->header(resip::h_RequestLine).method()==resip::OPTIONS);
01997    tassert(msg->header(resip::h_RequestLine).unknownMethodName()=="OPTIONS");
01998    tassert(msg->header(resip::h_RequestLine).uri().scheme()=="sip");
01999    // ?bwc? Need to determine how escaped stuff should be represented internally
02000    tassert(msg->header(resip::h_RequestLine).uri().user()=="user;par=u%40example.net");
02001    tassert_reset();
02002    tassert(msg->header(resip::h_RequestLine).uri().password().empty());
02003    tassert(msg->header(resip::h_RequestLine).uri().host()=="example.com");
02004    tassert(msg->header(resip::h_RequestLine).uri().port()==0);
02005    tassert(!(msg->header(resip::h_RequestLine).uri().hasEmbedded()));
02006    tassert(msg->header(resip::h_RequestLine).uri().numKnownParams()==0);
02007    tassert(msg->header(resip::h_RequestLine).uri().numUnknownParams()==0);
02008    tassert(msg->header(resip::h_RequestLine).getSipVersion()=="SIP/2.0");
02009 
02010    //To: sip:j_user@example.com
02011    tassert(msg->exists(resip::h_To));
02012    tassert(msg->header(resip::h_To).displayName()=="");
02013    tassert(msg->header(resip::h_To).numKnownParams()==0);
02014    tassert(msg->header(resip::h_To).numUnknownParams()==0);
02015    tassert(!(msg->header(resip::h_To).isAllContacts()));
02016    tassert(msg->header(resip::h_To).uri().scheme()=="sip");
02017    tassert(msg->header(resip::h_To).uri().user()=="j_user");
02018    tassert(msg->header(resip::h_To).uri().password().empty());
02019    tassert(msg->header(resip::h_To).uri().host()=="example.com");
02020    tassert(msg->header(resip::h_To).uri().port()==0);
02021    tassert(!(msg->header(resip::h_To).uri().hasEmbedded()));
02022    tassert(msg->header(resip::h_To).uri().numKnownParams()==0);
02023    tassert(msg->header(resip::h_To).uri().numUnknownParams()==0);
02024 
02025    //From: sip:caller@example.org;tag=33242
02026    tassert(msg->exists(resip::h_From));
02027    tassert(msg->header(resip::h_From).displayName()=="");
02028    tassert(msg->header(resip::h_From).numKnownParams()==1);
02029    tassert(msg->header(resip::h_From).numUnknownParams()==0);
02030    tassert(msg->header(resip::h_From).exists(resip::p_tag));
02031    tassert(msg->header(resip::h_From).param(resip::p_tag)=="33242");
02032    tassert(!(msg->header(resip::h_From).isAllContacts()));
02033    tassert(msg->header(resip::h_From).uri().scheme()=="sip");
02034    tassert(msg->header(resip::h_From).uri().user()=="caller");
02035    tassert(msg->header(resip::h_From).uri().password().empty());
02036    tassert(msg->header(resip::h_From).uri().host()=="example.org");
02037    tassert(msg->header(resip::h_From).uri().port()==0);
02038    tassert(!(msg->header(resip::h_From).uri().hasEmbedded()));
02039    tassert(msg->header(resip::h_From).uri().numKnownParams()==0);
02040    tassert(msg->header(resip::h_From).uri().numUnknownParams()==0);
02041 
02042    //Max-Forwards: 3
02043    tassert(msg->exists(resip::h_MaxForwards));
02044    tassert(msg->header(resip::h_MaxForwards).value()==3);
02045    tassert(msg->header(resip::h_MaxForwards).numKnownParams()==0);
02046    tassert(msg->header(resip::h_MaxForwards).numUnknownParams()==0);
02047 
02048    //Call-ID: semiuri.0ha0isndaksdj
02049    tassert(msg->exists(resip::h_CallID));
02050    tassert(msg->header(resip::h_CallID).value()=="semiuri.0ha0isndaksdj");
02051    tassert(msg->header(resip::h_CallID).numKnownParams()==0);
02052    tassert(msg->header(resip::h_CallID).numUnknownParams()==0);
02053 
02054    //CSeq: 8 OPTIONS
02055    tassert(msg->exists(resip::h_CSeq));
02056    tassert(msg->header(resip::h_CSeq).method()==resip::OPTIONS);
02057    tassert(msg->header(resip::h_CSeq).unknownMethodName()=="OPTIONS");
02058    tassert(msg->header(resip::h_CSeq).sequence()==8);
02059    tassert(msg->header(resip::h_CSeq).numKnownParams()==0);
02060    tassert(msg->header(resip::h_CSeq).numUnknownParams()==0);
02061 
02062    //Accept: application/sdp, application/pkcs7-mime,
02063    //        multipart/mixed, multipart/signed,
02064    //        message/sip, message/sipfrag
02065    tassert(msg->exists(resip::h_Accepts));
02066    tassert(msg->header(resip::h_Accepts).size()==6);
02067    
02068    resip::Mimes::iterator a=msg->header(resip::h_Accepts).begin();
02069    
02070    tassert(a->type()=="application");
02071    tassert(a->subType()=="sdp");
02072    tassert(a->numKnownParams()==0);
02073    tassert(a->numUnknownParams()==0);
02074    a++;
02075 
02076    tassert(a->type()=="application");
02077    tassert(a->subType()=="pkcs7-mime");
02078    tassert(a->numKnownParams()==0);
02079    tassert(a->numUnknownParams()==0);
02080    a++;
02081 
02082    tassert(a->type()=="multipart");
02083    tassert(a->subType()=="mixed");
02084    tassert(a->numKnownParams()==0);
02085    tassert(a->numUnknownParams()==0);
02086    a++;
02087 
02088    tassert(a->type()=="multipart");
02089    tassert(a->subType()=="signed");
02090    tassert(a->numKnownParams()==0);
02091    tassert(a->numUnknownParams()==0);
02092    a++;
02093 
02094    tassert(a->type()=="message");
02095    tassert(a->subType()=="sip");
02096    tassert(a->numKnownParams()==0);
02097    tassert(a->numUnknownParams()==0);
02098    a++;
02099 
02100    tassert(a->type()=="message");
02101    tassert(a->subType()=="sipfrag");
02102    tassert(a->numKnownParams()==0);
02103    tassert(a->numUnknownParams()==0);
02104 
02105    //Via: SIP/2.0/UDP 192.0.2.1;branch=z9hG4bKkdjuw
02106    tassert(msg->exists(resip::h_Vias));
02107    tassert(msg->header(resip::h_Vias).size()==1);
02108    resip::ParserContainer<resip::Via>::iterator i=msg->header(resip::h_Vias).begin();
02109    
02110    tassert(i->numKnownParams()==1);
02111    tassert(i->numUnknownParams()==0);
02112    tassert(i->protocolName()=="SIP");
02113    tassert(i->protocolVersion()=="2.0");
02114    tassert(i->transport()=="UDP");
02115    tassert(i->sentHost()=="192.0.2.1");
02116    tassert(i->sentPort()==0);
02117    
02118    tassert(i->exists(resip::p_branch));
02119    tassert(i->param(resip::p_branch).hasMagicCookie());
02120    tassert(i->param(resip::p_branch).getTransactionId()=="kdjuw");
02121    tassert(i->param(resip::p_branch).clientData().empty());
02122 
02123    //l: 0
02124    tassert(msg->exists(resip::h_ContentLength));
02125    tassert(msg->header(resip::h_ContentLength).value()==0);
02126    tassert(msg->header(resip::h_ContentLength).numKnownParams()==0);
02127    tassert(msg->header(resip::h_ContentLength).numUnknownParams()==0);
02128 
02129 
02130 
02131    InfoLog(<< "In case semiuri:" );
02132    InfoLog(<< "Original text:" << std::endl << txt );
02133    InfoLog(<< "Encoded form:" << std::endl << encoded );
02134    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
02135 
02136 
02137 
02138 
02139 }
02140 
02141 
02142 void
02143 transports()
02144 {
02145 /*
02146    This request contains Via header field values with all known
02147    transport types and exercises the transport extension mechanism.
02148    Parsers must accept this message as well formed.  Elements receiving
02149    this message would process it exactly as if the 2nd and subsequent
02150    header field values specified UDP (or other transport).
02151 
02152 OPTIONS sip:user@example.com SIP/2.0
02153 To: sip:user@example.com
02154 From: <sip:caller@example.com>;tag=323
02155 Max-Forwards: 70
02156 Call-ID:  transports.kijh4akdnaqjkwendsasfdj
02157 Accept: application/sdp
02158 CSeq: 60 OPTIONS
02159 Via: SIP/2.0/UDP t1.example.com;branch=z9hG4bKkdjuw
02160 Via: SIP/2.0/SCTP t2.example.com;branch=z9hG4bKklasjdhf
02161 Via: SIP/2.0/TLS t3.example.com;branch=z9hG4bK2980unddj
02162 Via: SIP/2.0/UNKNOWN t4.example.com;branch=z9hG4bKasd0f3en
02163 Via: SIP/2.0/TCP t5.example.com;branch=z9hG4bK0a9idfnee
02164 l: 0
02165 
02166 
02167 */
02168    FILE* fid= fopen("transports.dat","r");
02169    tassert(fid);
02170    resip::Data txt;
02171    char mBuf[1024];
02172    int result;
02173    while(!feof(fid))
02174    {
02175       result = fread(&mBuf,1,1024,fid);
02176       txt += resip::Data(mBuf,result);
02177    }
02178    fclose(fid);
02179    resip::SipMessage* msg = resip::SipMessage::make(txt);
02180    tassert_reset();
02181    tassert(msg);
02182    tassert_reset();
02183    if(!msg)
02184    {
02185       return;
02186    }
02187 
02188    std::auto_ptr<resip::SipMessage> message(msg);
02189    msg->parseAllHeaders();
02190 
02191    resip::SipMessage copy(*msg);
02192 
02193    resip::Data encoded;
02194    {
02195       resip::oDataStream str(encoded);
02196       msg->encode(str);
02197    }
02198    resip::Data copyEncoded;
02199    {
02200       resip::oDataStream str(copyEncoded);
02201       copy.encode(str);
02202    }
02203 
02204    //Request Line
02205    //OPTIONS sip:user@example.com SIP/2.0
02206    tassert(msg->header(resip::h_RequestLine).method()==resip::OPTIONS);
02207    tassert(msg->header(resip::h_RequestLine).unknownMethodName()=="OPTIONS");
02208    tassert(msg->header(resip::h_RequestLine).uri().scheme()=="sip");
02209    tassert(msg->header(resip::h_RequestLine).uri().user()=="user");
02210    tassert_reset();
02211    tassert(msg->header(resip::h_RequestLine).uri().password().empty());
02212    tassert(msg->header(resip::h_RequestLine).uri().host()=="example.com");
02213    tassert(msg->header(resip::h_RequestLine).uri().port()==0);
02214    tassert(!(msg->header(resip::h_RequestLine).uri().hasEmbedded()));
02215    tassert(msg->header(resip::h_RequestLine).uri().numKnownParams()==0);
02216    tassert(msg->header(resip::h_RequestLine).uri().numUnknownParams()==0);
02217    tassert(msg->header(resip::h_RequestLine).getSipVersion()=="SIP/2.0");
02218 
02219    //To: sip:user@example.com
02220    tassert(msg->exists(resip::h_To));
02221    tassert(msg->header(resip::h_To).displayName()=="");
02222    tassert(msg->header(resip::h_To).numKnownParams()==0);
02223    tassert(msg->header(resip::h_To).numUnknownParams()==0);
02224    tassert(!(msg->header(resip::h_To).isAllContacts()));
02225    tassert(msg->header(resip::h_To).uri().scheme()=="sip");
02226    tassert(msg->header(resip::h_To).uri().user()=="user");
02227    tassert(msg->header(resip::h_To).uri().password().empty());
02228    tassert(msg->header(resip::h_To).uri().host()=="example.com");
02229    tassert(msg->header(resip::h_To).uri().port()==0);
02230    tassert(!(msg->header(resip::h_To).uri().hasEmbedded()));
02231    tassert(msg->header(resip::h_To).uri().numKnownParams()==0);
02232    tassert(msg->header(resip::h_To).uri().numUnknownParams()==0);
02233 
02234    //From: <sip:caller@example.com>;tag=323
02235    tassert(msg->exists(resip::h_From));
02236    tassert(msg->header(resip::h_From).displayName()=="");
02237    tassert(msg->header(resip::h_From).numKnownParams()==1);
02238    tassert(msg->header(resip::h_From).numUnknownParams()==0);
02239    tassert(msg->header(resip::h_From).exists(resip::p_tag));
02240    tassert(msg->header(resip::h_From).param(resip::p_tag)=="323");
02241    tassert(!(msg->header(resip::h_From).isAllContacts()));
02242    tassert(msg->header(resip::h_From).uri().scheme()=="sip");
02243    tassert(msg->header(resip::h_From).uri().user()=="caller");
02244    tassert(msg->header(resip::h_From).uri().password().empty());
02245    tassert(msg->header(resip::h_From).uri().host()=="example.com");
02246    tassert(msg->header(resip::h_From).uri().port()==0);
02247    tassert(!(msg->header(resip::h_From).uri().hasEmbedded()));
02248    tassert(msg->header(resip::h_From).uri().numKnownParams()==0);
02249    tassert(msg->header(resip::h_From).uri().numUnknownParams()==0);
02250 
02251    //Max-Forwards: 70
02252    tassert(msg->exists(resip::h_MaxForwards));
02253    tassert(msg->header(resip::h_MaxForwards).value()==70);
02254    tassert(msg->header(resip::h_MaxForwards).numKnownParams()==0);
02255    tassert(msg->header(resip::h_MaxForwards).numUnknownParams()==0);
02256 
02257    //Call-ID:  transports.kijh4akdnaqjkwendsasfdj
02258    tassert(msg->exists(resip::h_CallID));
02259    tassert(msg->header(resip::h_CallID).value()=="transports.kijh4akdnaqjkwendsasfdj");
02260    tassert(msg->header(resip::h_CallID).numKnownParams()==0);
02261    tassert(msg->header(resip::h_CallID).numUnknownParams()==0);
02262 
02263    //Accept: application/sdp
02264    tassert(msg->exists(resip::h_Accepts));
02265    tassert(msg->header(resip::h_Accepts).size()==1);
02266    
02267    resip::Mimes::iterator a=msg->header(resip::h_Accepts).begin();
02268    
02269    tassert(a->type()=="application");
02270    tassert(a->subType()=="sdp");
02271    tassert(a->numKnownParams()==0);
02272    tassert(a->numUnknownParams()==0);
02273 
02274    //CSeq: 60 OPTIONS
02275    tassert(msg->exists(resip::h_CSeq));
02276    tassert(msg->header(resip::h_CSeq).method()==resip::OPTIONS);
02277    tassert(msg->header(resip::h_CSeq).unknownMethodName()=="OPTIONS");
02278    tassert(msg->header(resip::h_CSeq).sequence()==60);
02279    tassert(msg->header(resip::h_CSeq).numKnownParams()==0);
02280    tassert(msg->header(resip::h_CSeq).numUnknownParams()==0);
02281 
02282    //Vias
02283    tassert(msg->exists(resip::h_Vias));
02284    tassert(msg->header(resip::h_Vias).size()==5);
02285    resip::ParserContainer<resip::Via>::iterator v=msg->header(resip::h_Vias).begin();
02286 
02287    //Via: SIP/2.0/UDP t1.example.com;branch=z9hG4bKkdjuw
02288    tassert(v->numKnownParams()==1);
02289    tassert(v->numUnknownParams()==0);
02290    tassert(v->protocolName()=="SIP");
02291    tassert(v->protocolVersion()=="2.0");
02292    tassert(v->transport()=="UDP");
02293    tassert(v->sentHost()=="t1.example.com");
02294    tassert(v->sentPort()==0);
02295    
02296    tassert(v->exists(resip::p_branch));
02297    tassert(v->param(resip::p_branch).hasMagicCookie());
02298    tassert(v->param(resip::p_branch).getTransactionId()=="kdjuw");
02299    tassert(v->param(resip::p_branch).clientData().empty());
02300    
02301    v++;
02302    //Via: SIP/2.0/SCTP t2.example.com;branch=z9hG4bKklasjdhf
02303    tassert(v->numKnownParams()==1);
02304    tassert(v->numUnknownParams()==0);
02305    tassert(v->protocolName()=="SIP");
02306    tassert(v->protocolVersion()=="2.0");
02307    tassert(v->transport()=="SCTP");
02308    tassert(v->sentHost()=="t2.example.com");
02309    tassert(v->sentPort()==0);
02310    
02311    tassert(v->exists(resip::p_branch));
02312    tassert(v->param(resip::p_branch).hasMagicCookie());
02313    tassert(v->param(resip::p_branch).getTransactionId()=="klasjdhf");
02314    tassert(v->param(resip::p_branch).clientData().empty());
02315    
02316    v++;
02317    //Via: SIP/2.0/TLS t3.example.com;branch=z9hG4bK2980unddj
02318    tassert(v->numKnownParams()==1);
02319    tassert(v->numUnknownParams()==0);
02320    tassert(v->protocolName()=="SIP");
02321    tassert(v->protocolVersion()=="2.0");
02322    tassert(v->transport()=="TLS");
02323    tassert(v->sentHost()=="t3.example.com");
02324    tassert(v->sentPort()==0);
02325    
02326    tassert(v->exists(resip::p_branch));
02327    tassert(v->param(resip::p_branch).hasMagicCookie());
02328    tassert(v->param(resip::p_branch).getTransactionId()=="2980unddj");
02329    tassert(v->param(resip::p_branch).clientData().empty());
02330    
02331    v++;
02332    //Via: SIP/2.0/UNKNOWN t4.example.com;branch=z9hG4bKasd0f3en
02333    tassert(v->numKnownParams()==1);
02334    tassert(v->numUnknownParams()==0);
02335    tassert(v->protocolName()=="SIP");
02336    tassert(v->protocolVersion()=="2.0");
02337    tassert(v->transport()=="UNKNOWN");
02338    tassert(v->sentHost()=="t4.example.com");
02339    tassert(v->sentPort()==0);
02340    
02341    tassert(v->exists(resip::p_branch));
02342    tassert(v->param(resip::p_branch).hasMagicCookie());
02343    tassert(v->param(resip::p_branch).getTransactionId()=="asd0f3en");
02344    tassert(v->param(resip::p_branch).clientData().empty());
02345    
02346    v++;
02347    //Via: SIP/2.0/TCP t5.example.com;branch=z9hG4bK0a9idfnee
02348    tassert(v->numKnownParams()==1);
02349    tassert(v->numUnknownParams()==0);
02350    tassert(v->protocolName()=="SIP");
02351    tassert(v->protocolVersion()=="2.0");
02352    tassert(v->transport()=="TCP");
02353    tassert(v->sentHost()=="t5.example.com");
02354    tassert(v->sentPort()==0);
02355    
02356    tassert(v->exists(resip::p_branch));
02357    tassert(v->param(resip::p_branch).hasMagicCookie());
02358    tassert(v->param(resip::p_branch).getTransactionId()=="0a9idfnee");
02359    tassert(v->param(resip::p_branch).clientData().empty());
02360    
02361    //l: 0
02362    tassert(msg->exists(resip::h_ContentLength));
02363    tassert(msg->header(resip::h_ContentLength).value()==0);
02364    tassert(msg->header(resip::h_ContentLength).numKnownParams()==0);
02365    tassert(msg->header(resip::h_ContentLength).numUnknownParams()==0);
02366 
02367    InfoLog(<< "In case transports:" );
02368    InfoLog(<< "Original text:" << std::endl << txt );
02369    InfoLog(<< "Encoded form:" << std::endl << encoded );
02370    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
02371 
02372 
02373 
02374 
02375 }
02376 
02377 
02378 void
02379 mpart01()
02380 {
02381 #if 0
02382 /*
02383    This MESSAGE request contains two body parts.  The second part is
02384    binary encoded and contains null (0x00) characters.  Receivers must
02385    take care to frame the received message properly.
02386 
02387    Parsers must accept this message as well formed, even if the
02388    application above the parser does not support multipart/signed.
02389 
02390    Additional examples of multipart/mime messages, in particular S/MIME
02391    messages, are available in the security call flow examples document
02392    [SIP-SEC].
02393 
02394 MESSAGE sip:kumiko@example.org SIP/2.0
02395 Via: SIP/2.0/UDP 127.0.0.1:5070;branch=z9hG4bK-d87543-4dade06d0bdb11ee-1--d87543-;rport
02396 Max-Forwards: 70
02397 Route: <sip:127.0.0.1:5080>
02398 Identity: r5mwreLuyDRYBi/0TiPwEsY3rEVsk/G2WxhgTV1PF7hHuLIK0YWVKZhKv9Mj8UeXqkMVbnVq37CD+813gvYjcBUaZngQmXc9WNZSDNGCzA+fWl9MEUHWIZo1CeJebdY/XlgKeTa0Olvq0rt70Q5jiSfbqMJmQFteeivUhkMWYUA=
02399 Contact: <sip:fluffy@127.0.0.1:5070>
02400 To: <sip:kumiko@example.org>
02401 From: <sip:fluffy@example.com>;tag=2fb0dcc9
02402 Call-ID: 3d9485ad0c49859b@Zmx1ZmZ5LW1hYy0xNi5sb2NhbA..
02403 CSeq: 1 MESSAGE
02404 Content-Transfer-Encoding: binary
02405 Content-Type: multipart/mixed;boundary=7a9cbec02ceef655
02406 Date: Sat, 15 Oct 2005 04:44:56 GMT
02407 User-Agent: SIPimp.org/0.2.5 (curses)
02408 Content-Length: 553
02409 
02410 --7a9cbec02ceef655
02411 Content-Type: text/plain
02412 Content-Transfer-Encoding: binary
02413 
02414 Hello
02415 --7a9cbec02ceef655
02416 Content-Type: application/octet-stream
02417 Content-Transfer-Encoding: binary
02418 
02419 0R   *H
02420 C0?1 0+0    *H
02421 1 00|0p10   UUS10U
02422 California10USan Jose10U
02423 sipit1)0'U Sipit Test Certificate Authority q30+0
02424        *H
02425  fHR-嗎fYqb*5
02426 h<+udY=G(b At3
02427 ۓB.{rҜɮ./;~O'Tm䶪:>f]K-O{e
02428 --7a9cbec02ceef655--
02429 
02430 */
02431 #endif
02432 
02433    FILE* fid= fopen("mpart01.dat","r");
02434    tassert(fid);
02435    resip::Data txt;
02436    char mBuf[1024];
02437    int result;
02438    while(!feof(fid))
02439    {
02440       result = fread(&mBuf,1,1024,fid);
02441       txt += resip::Data(mBuf,result);
02442    }
02443    fclose(fid);
02444    resip::SipMessage* msg = resip::SipMessage::make(txt);
02445    tassert_reset();
02446    tassert(msg);
02447    tassert_reset();
02448    if(!msg)
02449    {
02450       return;
02451    }
02452 
02453    std::auto_ptr<resip::SipMessage> message(msg);
02454    msg->parseAllHeaders();
02455 
02456    resip::SipMessage copy(*msg);
02457 
02458    resip::Data encoded;
02459    {
02460       resip::oDataStream str(encoded);
02461       msg->encode(str);
02462    }
02463    resip::Data copyEncoded;
02464    {
02465       resip::oDataStream str(copyEncoded);
02466       copy.encode(str);
02467    }
02468 
02469    //Request Line
02470    //MESSAGE sip:kumiko@example.org SIP/2.0
02471    tassert(msg->header(resip::h_RequestLine).method()==resip::MESSAGE);
02472    tassert(msg->header(resip::h_RequestLine).unknownMethodName()=="MESSAGE");
02473    tassert(msg->header(resip::h_RequestLine).uri().scheme()=="sip");
02474    tassert(msg->header(resip::h_RequestLine).uri().user()=="kumiko");
02475    tassert(msg->header(resip::h_RequestLine).uri().password().empty());
02476    tassert(msg->header(resip::h_RequestLine).uri().host()=="example.org");
02477    tassert(msg->header(resip::h_RequestLine).uri().port()==0);
02478    tassert(!(msg->header(resip::h_RequestLine).uri().hasEmbedded()));
02479    tassert(msg->header(resip::h_RequestLine).uri().numKnownParams()==0);
02480    tassert(msg->header(resip::h_RequestLine).uri().numUnknownParams()==0);
02481    tassert(msg->header(resip::h_RequestLine).getSipVersion()=="SIP/2.0");
02482 
02483    //Vias
02484    tassert(msg->exists(resip::h_Vias));
02485    tassert(msg->header(resip::h_Vias).size()==1);
02486    resip::ParserContainer<resip::Via>::iterator v=msg->header(resip::h_Vias).begin();
02487 
02488    //Via: SIP/2.0/UDP 127.0.0.1:5070;branch=z9hG4bK-d87543-4dade06d0bdb11ee-1--d87543-;rport
02489    tassert(v->numKnownParams()==2);
02490    tassert(v->numUnknownParams()==0);
02491    tassert(v->protocolName()=="SIP");
02492    tassert(v->protocolVersion()=="2.0");
02493    tassert(v->transport()=="UDP");
02494    tassert(v->sentHost()=="127.0.0.1");
02495    tassert(v->sentPort()==5070);
02496    
02497    tassert(v->exists(resip::p_branch));
02498    tassert(v->param(resip::p_branch).hasMagicCookie());
02499    // .bwc. This branch parameter has old resip-specific tokens in it. The 
02500    // "d87543" used to be the resip cookie, but the resip cookie has since 
02501    // changed. So, the whole branch param is taken as the transaction id.
02502    tassert(v->param(resip::p_branch).getTransactionId()==
02503                                  "-d87543-4dade06d0bdb11ee-1--d87543-");
02504    tassert(v->param(resip::p_branch).clientData().empty());
02505    
02506    tassert(v->exists(resip::p_rport));
02507    tassert(!(v->param(resip::p_rport).hasValue()));
02508    tassert(v->param(resip::p_rport).port()==0);
02509 
02510    //Max-Forwards: 70
02511    tassert(msg->exists(resip::h_MaxForwards));
02512    tassert(msg->header(resip::h_MaxForwards).value()==70);
02513    tassert(msg->header(resip::h_MaxForwards).numKnownParams()==0);
02514    tassert(msg->header(resip::h_MaxForwards).numUnknownParams()==0);
02515 
02516    //Route: <sip:127.0.0.1:5080>
02517    tassert(msg->exists(resip::h_Routes));
02518    tassert(msg->header(resip::h_Routes).size()==1);
02519    resip::ParserContainer<resip::NameAddr>::iterator r=msg->header(resip::h_Routes).begin();
02520    
02521    tassert(r->numKnownParams()==0);
02522    tassert(r->numUnknownParams()==0);
02523    tassert(r->displayName()=="");
02524    tassert(r->uri().scheme()=="sip");
02525    tassert(r->uri().user()=="");
02526    tassert(r->uri().password()=="");
02527    tassert(r->uri().host()=="127.0.0.1");
02528    tassert(r->uri().port()==5080);
02529    tassert(!(r->uri().hasEmbedded()));
02530    tassert(r->uri().numKnownParams()==0);
02531    tassert(r->uri().numUnknownParams()==0);
02532    
02533 
02534    //Identity: r5mwreLuyDRYBi/0TiPwEsY3rEVsk/G2WxhgTV1PF7hHuLIK0YWVKZhKv9Mj8UeXqkMVbnVq37CD+813gvYjcBUaZngQmXc9WNZSDNGCzA+fWl9MEUHWIZo1CeJebdY/XlgKeTa0Olvq0rt70Q5jiSfbqMJmQFteeivUhkMWYUA=
02535    tassert(msg->exists(resip::h_Identity));
02536    tassert(msg->header(resip::h_Identity).value()=="r5mwreLuyDRYBi/0TiPwEsY3rEVsk/G2WxhgTV1PF7hHuLIK0YWVKZhKv9Mj8UeXqkMVbnVq37CD+813gvYjcBUaZngQmXc9WNZSDNGCzA+fWl9MEUHWIZo1CeJebdY/XlgKeTa0Olvq0rt70Q5jiSfbqMJmQFteeivUhkMWYUA=");
02537    tassert(msg->header(resip::h_Identity).numKnownParams()==0);
02538    tassert(msg->header(resip::h_Identity).numUnknownParams()==0);
02539    
02540    //Contact: <sip:fluffy@127.0.0.1:5070>
02541    tassert(msg->exists(resip::h_Contacts));
02542    tassert(msg->header(resip::h_Contacts).size()==1);
02543    resip::ParserContainer<resip::NameAddr>::iterator m=msg->header(resip::h_Contacts).begin();
02544    
02545    tassert(m->displayName()=="");
02546    tassert(m->numKnownParams()==0);
02547    tassert(m->numUnknownParams()==0);
02548    tassert(!(m->isAllContacts()));
02549    tassert(m->uri().numKnownParams()==0);
02550    tassert(m->uri().numUnknownParams()==0);
02551    tassert(m->uri().scheme()=="sip");
02552    tassert(m->uri().user()=="fluffy");
02553    tassert(m->uri().password().empty());
02554    tassert(m->uri().host()=="127.0.0.1");
02555    tassert(m->uri().port()==5070);
02556    tassert(!(m->uri().hasEmbedded()));
02557 
02558    //To: <sip:kumiko@example.org>
02559    tassert(msg->exists(resip::h_To));
02560    tassert(msg->header(resip::h_To).displayName()=="");
02561    tassert(msg->header(resip::h_To).numKnownParams()==0);
02562    tassert(msg->header(resip::h_To).numUnknownParams()==0);
02563    tassert(!(msg->header(resip::h_To).isAllContacts()));
02564    tassert(msg->header(resip::h_To).uri().scheme()=="sip");
02565    tassert(msg->header(resip::h_To).uri().user()=="kumiko");
02566    tassert(msg->header(resip::h_To).uri().password().empty());
02567    tassert(msg->header(resip::h_To).uri().host()=="example.org");
02568    tassert(msg->header(resip::h_To).uri().port()==0);
02569    tassert(!(msg->header(resip::h_To).uri().hasEmbedded()));
02570    tassert(msg->header(resip::h_To).uri().numKnownParams()==0);
02571    tassert(msg->header(resip::h_To).uri().numUnknownParams()==0);
02572 
02573    //From: <sip:fluffy@example.com>;tag=2fb0dcc9
02574    tassert(msg->exists(resip::h_From));
02575    tassert(msg->header(resip::h_From).displayName()=="");
02576    tassert(msg->header(resip::h_From).numKnownParams()==1);
02577    tassert(msg->header(resip::h_From).numUnknownParams()==0);
02578    tassert(msg->header(resip::h_From).exists(resip::p_tag));
02579    tassert(msg->header(resip::h_From).param(resip::p_tag)=="2fb0dcc9");
02580    tassert(!(msg->header(resip::h_From).isAllContacts()));
02581    tassert(msg->header(resip::h_From).uri().scheme()=="sip");
02582    tassert(msg->header(resip::h_From).uri().user()=="fluffy");
02583    tassert(msg->header(resip::h_From).uri().password().empty());
02584    tassert(msg->header(resip::h_From).uri().host()=="example.com");
02585    tassert(msg->header(resip::h_From).uri().port()==0);
02586    tassert(!(msg->header(resip::h_From).uri().hasEmbedded()));
02587    tassert(msg->header(resip::h_From).uri().numKnownParams()==0);
02588    tassert(msg->header(resip::h_From).uri().numUnknownParams()==0);
02589 
02590    //Call-ID: 3d9485ad0c49859b@Zmx1ZmZ5LW1hYy0xNi5sb2NhbA..
02591    tassert(msg->exists(resip::h_CallID));
02592    tassert(msg->header(resip::h_CallID).value()=="3d9485ad0c49859b@Zmx1ZmZ5LW1hYy0xNi5sb2NhbA..");
02593    tassert(msg->header(resip::h_CallID).numKnownParams()==0);
02594    tassert(msg->header(resip::h_CallID).numUnknownParams()==0);
02595 
02596    //CSeq: 1 MESSAGE
02597    tassert(msg->exists(resip::h_CSeq));
02598    tassert(msg->header(resip::h_CSeq).method()==resip::MESSAGE);
02599    tassert(msg->header(resip::h_CSeq).unknownMethodName()=="MESSAGE");
02600    tassert(msg->header(resip::h_CSeq).sequence()==1);
02601    tassert(msg->header(resip::h_CSeq).numKnownParams()==0);
02602    tassert(msg->header(resip::h_CSeq).numUnknownParams()==0);
02603 
02604    // .bwc. There appears to be some controversy over how this particular
02605    // header should be implemented...
02606    //Content-Transfer-Encoding: binary
02607    tassert(msg->exists(resip::h_ContentTransferEncoding));
02608    tassert(msg->header(resip::h_ContentTransferEncoding).value()=="binary");
02609    tassert(msg->header(resip::h_ContentTransferEncoding).numKnownParams()==0);
02610    tassert(msg->header(resip::h_ContentTransferEncoding).numUnknownParams()==0);
02611    
02612    //Content-Type: multipart/mixed;boundary=7a9cbec02ceef655
02613    tassert(msg->exists(resip::h_ContentType));
02614    tassert(msg->header(resip::h_ContentType).type()=="multipart");
02615    tassert(msg->header(resip::h_ContentType).subType()=="mixed");
02616    tassert(msg->header(resip::h_ContentType).numKnownParams()==1);
02617    tassert(msg->header(resip::h_ContentType).numUnknownParams()==0);
02618    
02619    tassert(msg->header(resip::h_ContentType).exists(resip::p_boundary));
02620    tassert(msg->header(resip::h_ContentType).param(resip::p_boundary)=="7a9cbec02ceef655");
02621 
02622    //Date: Sat, 15 Oct 2005 04:44:56 GMT
02623    tassert(msg->exists(resip::h_Date));
02624    tassert(msg->header(resip::h_Date).dayOfWeek()==resip::Sat);
02625    tassert(msg->header(resip::h_Date).dayOfMonth()==15);
02626    tassert(msg->header(resip::h_Date).month()==resip::Oct);
02627    tassert(msg->header(resip::h_Date).year()==2005);
02628    tassert(msg->header(resip::h_Date).hour()==4);
02629    tassert(msg->header(resip::h_Date).minute()==44);
02630    tassert(msg->header(resip::h_Date).second()==56);
02631    tassert(msg->header(resip::h_Date).numKnownParams()==0);
02632    tassert(msg->header(resip::h_Date).numUnknownParams()==0);
02633    
02634    //User-Agent: SIPimp.org/0.2.5 (curses)
02635    tassert(msg->exists(resip::h_UserAgent));
02636    tassert(msg->header(resip::h_UserAgent).value()=="SIPimp.org/0.2.5 (curses)");
02637    tassert(msg->header(resip::h_UserAgent).numKnownParams()==0);
02638    tassert(msg->header(resip::h_UserAgent).numUnknownParams()==0);
02639    
02640    //Content-Length: 553
02641    tassert(msg->exists(resip::h_ContentLength));
02642    tassert(msg->header(resip::h_ContentLength).value()==553);
02643    tassert(msg->header(resip::h_ContentLength).numKnownParams()==0);
02644    tassert(msg->header(resip::h_ContentLength).numUnknownParams()==0);
02645 
02646 
02647    InfoLog(<< "In case mpart01:" );
02648    InfoLog(<< "Original text:" << std::endl << txt );
02649    InfoLog(<< "Encoded form:" << std::endl << encoded );
02650    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
02651 
02652 
02653 
02654 
02655 }
02656 
02657 
02658 void
02659 unreason()
02660 {
02661 /*
02662    This 200 response contains a reason phrase other than "OK".  The
02663    reason phrase is intended for human consumption and may contain any
02664    string produced by
02665 
02666        Reason-Phrase   =  *(reserved / unreserved / escaped
02667                           / UTF8-NONASCII / UTF8-CONT / SP / HTAB)
02668 
02669    This particular response contains unreserved and non-ascii UTF-8
02670    characters.  This response is well formed.  A parser must accept this
02671    message.
02672 
02673 
02674 SIP/2.0 200 = 2**3 * 5**2 но сто девяносто девять - простое
02675 Via: SIP/2.0/UDP 192.0.2.198;branch=z9hG4bK1324923
02676 Call-ID: unreason.1234ksdfak3j2erwedfsASdf
02677 CSeq: 35 INVITE
02678 From: sip:user@example.com;tag=11141343
02679 To: sip:user@example.edu;tag=2229
02680 Content-Length: 154
02681 Content-Type: application/sdp
02682 Contact: <sip:user@host198.example.com>
02683 
02684 v=0
02685 o=mhandley 29739 7272939 IN IP4 192.0.2.198
02686 s=-
02687 c=IN IP4 192.0.2.198
02688 t=0 0
02689 m=audio 49217 RTP/AVP 0 12
02690 m=video 3227 RTP/AVP 31
02691 a=rtpmap:31 LPC
02692 
02693 */
02694    FILE* fid= fopen("unreason.dat","r");
02695    tassert(fid);
02696    resip::Data txt;
02697    char mBuf[1024];
02698    int result;
02699    while(!feof(fid))
02700    {
02701       result = fread(&mBuf,1,1024,fid);
02702       txt += resip::Data(mBuf,result);
02703    }
02704    fclose(fid);
02705    resip::SipMessage* msg = resip::SipMessage::make(txt);
02706    tassert_reset();
02707    tassert(msg);
02708    tassert_reset();
02709    if(!msg)
02710    {
02711       return;
02712    }
02713 
02714    std::auto_ptr<resip::SipMessage> message(msg);
02715    msg->parseAllHeaders();
02716 
02717    resip::SipMessage copy(*msg);
02718 
02719    resip::Data encoded;
02720    {
02721       resip::oDataStream str(encoded);
02722       msg->encode(str);
02723    }
02724    resip::Data copyEncoded;
02725    {
02726       resip::oDataStream str(copyEncoded);
02727       copy.encode(str);
02728    }
02729    
02730    //Status Line
02731    //SIP/2.0 200 = 2**3 * 5**2 но сто девяносто девять - простое
02732    tassert(msg->header(resip::h_StatusLine).responseCode()==200);
02733    tassert(msg->header(resip::h_StatusLine).getSipVersion()=="SIP/2.0");
02734    
02735    resip::Data binaryReason("= 2**3 * 5**2 ");
02736    binaryReason+=(char)0xD0;
02737    binaryReason+=(char)0xBD;
02738    binaryReason+=(char)0xD0;
02739    binaryReason+=(char)0xBE;
02740    binaryReason+=(char)0x20;
02741    binaryReason+=(char)0xD1;
02742    binaryReason+=(char)0x81;
02743    binaryReason+=(char)0xD1;
02744    binaryReason+=(char)0x82;
02745    binaryReason+=(char)0xD0;
02746    binaryReason+=(char)0xBE;
02747    binaryReason+=(char)0x20;
02748    binaryReason+=(char)0xD0;
02749    binaryReason+=(char)0xB4;
02750    binaryReason+=(char)0xD0;
02751    binaryReason+=(char)0xB5;
02752    binaryReason+=(char)0xD0;
02753    binaryReason+=(char)0xB2;
02754    binaryReason+=(char)0xD1;
02755    binaryReason+=(char)0x8F;
02756    binaryReason+=(char)0xD0;
02757    binaryReason+=(char)0xBD;
02758    binaryReason+=(char)0xD0;
02759    binaryReason+=(char)0xBE;
02760    binaryReason+=(char)0xD1;
02761    binaryReason+=(char)0x81;
02762    binaryReason+=(char)0xD1;
02763    binaryReason+=(char)0x82;
02764    binaryReason+=(char)0xD0;
02765    binaryReason+=(char)0xBE;
02766    binaryReason+=(char)0x20;
02767    binaryReason+=(char)0xD0;
02768    binaryReason+=(char)0xB4;
02769    binaryReason+=(char)0xD0;
02770    binaryReason+=(char)0xB5;
02771    binaryReason+=(char)0xD0;
02772    binaryReason+=(char)0xB2;
02773    binaryReason+=(char)0xD1;
02774    binaryReason+=(char)0x8F;
02775    binaryReason+=(char)0xD1;
02776    binaryReason+=(char)0x82;
02777    binaryReason+=(char)0xD1;
02778    binaryReason+=(char)0x8C;
02779    binaryReason+=(char)0x20;
02780    binaryReason+=(char)0x2D;
02781    binaryReason+=(char)0x20;
02782    binaryReason+=(char)0xD0;
02783    binaryReason+=(char)0xBF;
02784    binaryReason+=(char)0xD1;
02785    binaryReason+=(char)0x80;
02786    binaryReason+=(char)0xD0;
02787    binaryReason+=(char)0xBE;
02788    binaryReason+=(char)0xD1;
02789    binaryReason+=(char)0x81;
02790    binaryReason+=(char)0xD1;
02791    binaryReason+=(char)0x82;
02792    binaryReason+=(char)0xD0;
02793    binaryReason+=(char)0xBE;
02794    binaryReason+=(char)0xD0;
02795    binaryReason+=(char)0xB5;   
02796    tassert(msg->header(resip::h_StatusLine).reason()==binaryReason);
02797    
02798    //Vias
02799    tassert(msg->exists(resip::h_Vias));
02800    tassert(msg->header(resip::h_Vias).size()==1);
02801    resip::ParserContainer<resip::Via>::iterator v=msg->header(resip::h_Vias).begin();
02802 
02803    //Via: SIP/2.0/UDP 192.0.2.198;branch=z9hG4bK1324923
02804    tassert(v->numKnownParams()==1);
02805    tassert(v->numUnknownParams()==0);
02806    tassert(v->protocolName()=="SIP");
02807    tassert(v->protocolVersion()=="2.0");
02808    tassert(v->transport()=="UDP");
02809    tassert(v->sentHost()=="192.0.2.198");
02810    tassert(v->sentPort()==0);
02811    
02812    tassert(v->exists(resip::p_branch));
02813    tassert(v->param(resip::p_branch).hasMagicCookie());
02814    tassert(v->param(resip::p_branch).getTransactionId()=="1324923");
02815    tassert(v->param(resip::p_branch).clientData().empty());
02816    
02817    //Call-ID: unreason.1234ksdfak3j2erwedfsASdf
02818    tassert(msg->exists(resip::h_CallID));
02819    tassert(msg->header(resip::h_CallID).value()=="unreason.1234ksdfak3j2erwedfsASdf");
02820    tassert(msg->header(resip::h_CallID).numKnownParams()==0);
02821    tassert(msg->header(resip::h_CallID).numUnknownParams()==0);
02822 
02823    //CSeq: 35 INVITE
02824    tassert(msg->exists(resip::h_CSeq));
02825    tassert(msg->header(resip::h_CSeq).method()==resip::INVITE);
02826    tassert(msg->header(resip::h_CSeq).unknownMethodName()=="INVITE");
02827    tassert(msg->header(resip::h_CSeq).sequence()==35);
02828    tassert(msg->header(resip::h_CSeq).numKnownParams()==0);
02829    tassert(msg->header(resip::h_CSeq).numUnknownParams()==0);
02830 
02831    //From: sip:user@example.com;tag=11141343
02832    tassert(msg->exists(resip::h_From));
02833    tassert(msg->header(resip::h_From).displayName()=="");
02834    tassert(msg->header(resip::h_From).numKnownParams()==1);
02835    tassert(msg->header(resip::h_From).numUnknownParams()==0);
02836    tassert(msg->header(resip::h_From).exists(resip::p_tag));
02837    tassert(msg->header(resip::h_From).param(resip::p_tag)=="11141343");
02838    tassert(!(msg->header(resip::h_From).isAllContacts()));
02839    tassert(msg->header(resip::h_From).uri().scheme()=="sip");
02840    tassert(msg->header(resip::h_From).uri().user()=="user");
02841    tassert(msg->header(resip::h_From).uri().password().empty());
02842    tassert(msg->header(resip::h_From).uri().host()=="example.com");
02843    tassert(msg->header(resip::h_From).uri().port()==0);
02844    tassert(!(msg->header(resip::h_From).uri().hasEmbedded()));
02845    tassert(msg->header(resip::h_From).uri().numKnownParams()==0);
02846    tassert(msg->header(resip::h_From).uri().numUnknownParams()==0);
02847 
02848    //To: sip:user@example.edu;tag=2229
02849    tassert(msg->exists(resip::h_To));
02850    tassert(msg->header(resip::h_To).displayName()=="");
02851    tassert(msg->header(resip::h_To).numKnownParams()==1);
02852    tassert(msg->header(resip::h_To).numUnknownParams()==0);
02853    tassert(msg->header(resip::h_To).exists(resip::p_tag));
02854    tassert(msg->header(resip::h_To).param(resip::p_tag)=="2229");
02855    tassert(!(msg->header(resip::h_To).isAllContacts()));
02856    tassert(msg->header(resip::h_To).uri().scheme()=="sip");
02857    tassert(msg->header(resip::h_To).uri().user()=="user");
02858    tassert(msg->header(resip::h_To).uri().password().empty());
02859    tassert(msg->header(resip::h_To).uri().host()=="example.edu");
02860    tassert(msg->header(resip::h_To).uri().port()==0);
02861    tassert(!(msg->header(resip::h_To).uri().hasEmbedded()));
02862    tassert(msg->header(resip::h_To).uri().numKnownParams()==0);
02863    tassert(msg->header(resip::h_To).uri().numUnknownParams()==0);
02864 
02865    //Content-Length: 154
02866    tassert(msg->exists(resip::h_ContentLength));
02867    tassert(msg->header(resip::h_ContentLength).value()==154);
02868    tassert(msg->header(resip::h_ContentLength).numKnownParams()==0);
02869    tassert(msg->header(resip::h_ContentLength).numUnknownParams()==0);
02870 
02871    //Content-Type: application/sdp
02872    tassert(msg->exists(resip::h_ContentType));
02873    tassert(msg->header(resip::h_ContentType).type()=="application");
02874    tassert(msg->header(resip::h_ContentType).subType()=="sdp");
02875    tassert(msg->header(resip::h_ContentType).numKnownParams()==0);
02876    tassert(msg->header(resip::h_ContentType).numUnknownParams()==0);
02877 
02878    //Contact: <sip:user@host198.example.com>
02879    tassert(msg->exists(resip::h_Contacts));
02880    tassert(msg->header(resip::h_Contacts).size()==1);
02881    resip::ParserContainer<resip::NameAddr>::iterator m=msg->header(resip::h_Contacts).begin();
02882    
02883    tassert(m->displayName()=="");
02884    tassert(m->numKnownParams()==0);
02885    tassert(m->numUnknownParams()==0);
02886    tassert(!(m->isAllContacts()));
02887    tassert(m->uri().numKnownParams()==0);
02888    tassert(m->uri().numUnknownParams()==0);
02889    tassert(m->uri().scheme()=="sip");
02890    tassert(m->uri().user()=="user");
02891    tassert(m->uri().password().empty());
02892    tassert(m->uri().host()=="host198.example.com");
02893    tassert(m->uri().port()==0);
02894    tassert(!(m->uri().hasEmbedded()));
02895 
02896 
02897    InfoLog(<< "In case unreason:" );
02898    InfoLog(<< "Original text:" << std::endl << txt );
02899    InfoLog(<< "Encoded form:" << std::endl << encoded );
02900    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
02901 
02902 
02903 
02904 
02905 }
02906 
02907 
02908 void
02909 noreason()
02910 {
02911 /*
02912 
02913    This well-formed response contains no reason phrase.  A parser must
02914    accept this message.  The space character after the reason code is
02915    required.  If it were not present, this message could be rejected as
02916    invalid (a liberal receiver would accept it anyway).
02917 
02918 SIP/2.0 100 
02919 Via: SIP/2.0/UDP 192.0.2.105;branch=z9hG4bK2398ndaoe
02920 Call-ID: noreason.asndj203insdf99223ndf
02921 CSeq: 35 INVITE
02922 From: <sip:user@example.com>;tag=39ansfi3
02923 To: <sip:user@example.edu>;tag=902jndnke3
02924 Content-Length: 0
02925 Contact: <sip:user@host105.example.com>
02926 
02927 
02928 */
02929    FILE* fid= fopen("noreason.dat","r");
02930    tassert(fid);
02931    resip::Data txt;
02932    char mBuf[1024];
02933    int result;
02934    while(!feof(fid))
02935    {
02936       result = fread(&mBuf,1,1024,fid);
02937       txt += resip::Data(mBuf,result);
02938    }
02939    fclose(fid);
02940    resip::SipMessage* msg = resip::SipMessage::make(txt);
02941    tassert_reset();
02942    tassert(msg);
02943    tassert_reset();
02944    if(!msg)
02945    {
02946       return;
02947    }
02948 
02949    std::auto_ptr<resip::SipMessage> message(msg);
02950    msg->parseAllHeaders();
02951 
02952    resip::SipMessage copy(*msg);
02953 
02954    resip::Data encoded;
02955    {
02956       resip::oDataStream str(encoded);
02957       msg->encode(str);
02958    }
02959    resip::Data copyEncoded;
02960    {
02961       resip::oDataStream str(copyEncoded);
02962       copy.encode(str);
02963    }
02964 
02965    //Status Line
02966    //SIP/2.0 100 
02967    tassert(msg->header(resip::h_StatusLine).responseCode()==100);
02968    tassert(msg->header(resip::h_StatusLine).getSipVersion()=="SIP/2.0");
02969    tassert(msg->header(resip::h_StatusLine).reason()=="");
02970 
02971    //Vias
02972    tassert(msg->exists(resip::h_Vias));
02973    tassert(msg->header(resip::h_Vias).size()==1);
02974    resip::ParserContainer<resip::Via>::iterator v=msg->header(resip::h_Vias).begin();
02975 
02976    //Via: SIP/2.0/UDP 192.0.2.105;branch=z9hG4bK2398ndaoe
02977    tassert(v->numKnownParams()==1);
02978    tassert(v->numUnknownParams()==0);
02979    tassert(v->protocolName()=="SIP");
02980    tassert(v->protocolVersion()=="2.0");
02981    tassert(v->transport()=="UDP");
02982    tassert(v->sentHost()=="192.0.2.105");
02983    tassert(v->sentPort()==0);
02984    
02985    tassert(v->exists(resip::p_branch));
02986    tassert(v->param(resip::p_branch).hasMagicCookie());
02987    tassert(v->param(resip::p_branch).getTransactionId()=="2398ndaoe");
02988    tassert(v->param(resip::p_branch).clientData().empty());
02989 
02990    //Call-ID: noreason.asndj203insdf99223ndf
02991    tassert(msg->exists(resip::h_CallID));
02992    tassert(msg->header(resip::h_CallID).value()=="noreason.asndj203insdf99223ndf");
02993    tassert(msg->header(resip::h_CallID).numKnownParams()==0);
02994    tassert(msg->header(resip::h_CallID).numUnknownParams()==0);
02995 
02996    //CSeq: 35 INVITE
02997    tassert(msg->exists(resip::h_CSeq));
02998    tassert(msg->header(resip::h_CSeq).method()==resip::INVITE);
02999    tassert(msg->header(resip::h_CSeq).unknownMethodName()=="INVITE");
03000    tassert(msg->header(resip::h_CSeq).sequence()==35);
03001    tassert(msg->header(resip::h_CSeq).numKnownParams()==0);
03002    tassert(msg->header(resip::h_CSeq).numUnknownParams()==0);
03003 
03004    //From: <sip:user@example.com>;tag=39ansfi3
03005    tassert(msg->exists(resip::h_From));
03006    tassert(msg->header(resip::h_From).displayName()=="");
03007    tassert(msg->header(resip::h_From).numKnownParams()==1);
03008    tassert(msg->header(resip::h_From).numUnknownParams()==0);
03009    tassert(msg->header(resip::h_From).exists(resip::p_tag));
03010    tassert(msg->header(resip::h_From).param(resip::p_tag)=="39ansfi3");
03011    tassert(!(msg->header(resip::h_From).isAllContacts()));
03012    tassert(msg->header(resip::h_From).uri().scheme()=="sip");
03013    tassert(msg->header(resip::h_From).uri().user()=="user");
03014    tassert(msg->header(resip::h_From).uri().password().empty());
03015    tassert(msg->header(resip::h_From).uri().host()=="example.com");
03016    tassert(msg->header(resip::h_From).uri().port()==0);
03017    tassert(!(msg->header(resip::h_From).uri().hasEmbedded()));
03018    tassert(msg->header(resip::h_From).uri().numKnownParams()==0);
03019    tassert(msg->header(resip::h_From).uri().numUnknownParams()==0);
03020 
03021    //To: <sip:user@example.edu>;tag=902jndnke3
03022    tassert(msg->exists(resip::h_To));
03023    tassert(msg->header(resip::h_To).displayName()=="");
03024    tassert(msg->header(resip::h_To).numKnownParams()==1);
03025    tassert(msg->header(resip::h_To).numUnknownParams()==0);
03026    tassert(msg->header(resip::h_To).exists(resip::p_tag));
03027    tassert(msg->header(resip::h_To).param(resip::p_tag)=="902jndnke3");
03028    tassert(!(msg->header(resip::h_To).isAllContacts()));
03029    tassert(msg->header(resip::h_To).uri().scheme()=="sip");
03030    tassert(msg->header(resip::h_To).uri().user()=="user");
03031    tassert(msg->header(resip::h_To).uri().password().empty());
03032    tassert(msg->header(resip::h_To).uri().host()=="example.edu");
03033    tassert(msg->header(resip::h_To).uri().port()==0);
03034    tassert(!(msg->header(resip::h_To).uri().hasEmbedded()));
03035    tassert(msg->header(resip::h_To).uri().numKnownParams()==0);
03036    tassert(msg->header(resip::h_To).uri().numUnknownParams()==0);
03037 
03038    //Content-Length: 0
03039    tassert(msg->exists(resip::h_ContentLength));
03040    tassert(msg->header(resip::h_ContentLength).value()==0);
03041    tassert(msg->header(resip::h_ContentLength).numKnownParams()==0);
03042    tassert(msg->header(resip::h_ContentLength).numUnknownParams()==0);
03043 
03044    //Contact: <sip:user@host105.example.com>
03045    tassert(msg->exists(resip::h_Contacts));
03046    tassert(msg->header(resip::h_Contacts).size()==1);
03047    resip::ParserContainer<resip::NameAddr>::iterator m=msg->header(resip::h_Contacts).begin();
03048    
03049    tassert(m->displayName()=="");
03050    tassert(m->numKnownParams()==0);
03051    tassert(m->numUnknownParams()==0);
03052    tassert(!(m->isAllContacts()));
03053    tassert(m->uri().numKnownParams()==0);
03054    tassert(m->uri().numUnknownParams()==0);
03055    tassert(m->uri().scheme()=="sip");
03056    tassert(m->uri().user()=="user");
03057    tassert(m->uri().password().empty());
03058    tassert(m->uri().host()=="host105.example.com");
03059    tassert(m->uri().port()==0);
03060    tassert(!(m->uri().hasEmbedded()));
03061 
03062 
03063    InfoLog(<< "In case noreason:" );
03064    InfoLog(<< "Original text:" << std::endl << txt );
03065    InfoLog(<< "Encoded form:" << std::endl << encoded );
03066    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
03067 
03068 
03069 
03070 
03071 }
03072 
03073 
03074 void
03075 badinv01()
03076 {
03077 /*
03078 
03079    The Via header field of this request contains additional semicolons
03080    and commas without parameters or values.  The Contact header field
03081    contains additional semicolons without parameters.  This message is
03082    syntactically invalid.
03083 
03084    An element receiving this request should respond with a 400 Bad
03085    Request error.
03086 
03087 INVITE sip:user@example.com SIP/2.0
03088 To: sip:j.user@example.com
03089 From: sip:caller@example.net;tag=134161461246
03090 Max-Forwards: 7
03091 Call-ID: badinv01.0ha0isndaksdjasdf3234nas
03092 CSeq: 8 INVITE
03093 Via: SIP/2.0/UDP 192.0.2.15;;,;,,
03094 Contact: "Joe" <sip:joe@example.org>;;;;
03095 Content-Length: 152
03096 Content-Type: application/sdp
03097 
03098 v=0
03099 o=mhandley 29739 7272939 IN IP4 192.0.2.15
03100 s=-
03101 c=IN IP4 192.0.2.15
03102 t=0 0
03103 m=audio 49217 RTP/AVP 0 12
03104 m=video 3227 RTP/AVP 31
03105 a=rtpmap:31 LPC
03106 
03107 */
03108    FILE* fid= fopen("badinv01.dat","r");
03109    tassert(fid);
03110    resip::Data txt;
03111    char mBuf[1024];
03112    int result;
03113    while(!feof(fid))
03114    {
03115       result = fread(&mBuf,1,1024,fid);
03116       txt += resip::Data(mBuf,result);
03117    }
03118    fclose(fid);
03119    resip::SipMessage* msg = resip::SipMessage::make(txt);
03120    tassert_reset();
03121    if(!msg)
03122    {
03123       return;
03124    }
03125 
03126    std::auto_ptr<resip::SipMessage> message(msg);
03127    msg->parseAllHeaders();
03128 
03129    resip::SipMessage copy(*msg);
03130 
03131    resip::Data encoded;
03132    {
03133       resip::oDataStream str(encoded);
03134       msg->encode(str);
03135    }
03136    resip::Data copyEncoded;
03137    {
03138       resip::oDataStream str(copyEncoded);
03139       copy.encode(str);
03140    }
03141 
03142    InfoLog(<< "In case badinv01:" );
03143    InfoLog(<< "Original text:" << std::endl << txt );
03144    InfoLog(<< "Encoded form:" << std::endl << encoded );
03145    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
03146 
03147 
03148 
03149 
03150 }
03151 
03152 
03153 void
03154 clerr()
03155 {
03156 /*
03157 
03158    This is a request message with a Content Length that is larger than
03159    the actual length of the body.
03160 
03161    When sent over UDP (as this message ostensibly was), the receiving
03162    element should respond with a 400 Bad Request error.  If this message
03163    arrived over a stream-based transport, such as TCP, there's not much
03164    the receiving party could do but wait for more data on the stream and
03165    close the connection if none is forthcoming within a reasonable
03166    period of time.
03167 
03168 INVITE sip:user@example.com SIP/2.0
03169 Max-Forwards: 80
03170 To: sip:j.user@example.com
03171 From: sip:caller@example.net;tag=93942939o2
03172 Contact: <sip:caller@hungry.example.net>
03173 Call-ID: clerr.0ha0isndaksdjweiafasdk3
03174 CSeq: 8 INVITE
03175 Via: SIP/2.0/UDP host5.example.com;branch=z9hG4bK-39234-23523
03176 Content-Type: application/sdp
03177 Content-Length: 9999
03178 
03179 v=0
03180 o=mhandley 29739 7272939 IN IP4 192.0.2.155
03181 s=-
03182 c=IN IP4 192.0.2.155
03183 t=0 0
03184 m=audio 49217 RTP/AVP 0 12
03185 m=video 3227 RTP/AVP 31
03186 a=rtpmap:31 LPC
03187 
03188 */
03189    FILE* fid= fopen("clerr.dat","r");
03190    tassert(fid);
03191    resip::Data txt;
03192    char mBuf[1024];
03193    int result;
03194    while(!feof(fid))
03195    {
03196       result = fread(&mBuf,1,1024,fid);
03197       txt += resip::Data(mBuf,result);
03198    }
03199    fclose(fid);
03200    resip::SipMessage* msg = resip::SipMessage::make(txt);
03201    tassert_reset();
03202 
03203    if(!msg)
03204    {
03205       return;
03206    }
03207 
03208    std::auto_ptr<resip::SipMessage> message(msg);
03209    msg->parseAllHeaders();
03210 
03211    resip::SipMessage copy(*msg);
03212 
03213    resip::Data encoded;
03214    {
03215       resip::oDataStream str(encoded);
03216       msg->encode(str);
03217    }
03218    resip::Data copyEncoded;
03219    {
03220       resip::oDataStream str(copyEncoded);
03221       copy.encode(str);
03222    }
03223 
03224    InfoLog(<< "In case clerr:" );
03225    InfoLog(<< "Original text:" << std::endl << txt );
03226    InfoLog(<< "Encoded form:" << std::endl << encoded );
03227    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
03228 
03229 
03230 
03231 
03232 }
03233 
03234 
03235 void
03236 ncl()
03237 {
03238 /*
03239 
03240    This request has a negative value for Content-Length.
03241 
03242    An element receiving this message should respond with an error.  This
03243    request appeared over UDP, so the remainder of the datagram can
03244    simply be discarded.  If a request like this arrives over TCP, the
03245    framing error is not recoverable, and the connection should be
03246    closed.  The same behavior is appropriate for messages that arrive
03247    without a numeric value in the Content-Length header field, such as
03248    the following:
03249 
03250       Content-Length: five
03251 
03252    Implementors should take extra precautions if the technique they
03253    choose for converting this ascii field into an integral form can
03254    return a negative value.  In particular, the result must not be used
03255    as a counter or array index.
03256 
03257 
03258 INVITE sip:user@example.com SIP/2.0
03259 Max-Forwards: 254
03260 To: sip:j.user@example.com
03261 From: sip:caller@example.net;tag=32394234
03262 Call-ID: ncl.0ha0isndaksdj2193423r542w35
03263 CSeq: 0 INVITE
03264 Via: SIP/2.0/UDP 192.0.2.53;branch=z9hG4bKkdjuw
03265 Contact: <sip:caller@example53.example.net>
03266 Content-Type: application/sdp
03267 Content-Length: -999
03268 
03269 v=0
03270 o=mhandley 29739 7272939 IN IP4 192.0.2.53
03271 s=-
03272 c=IN IP4 192.0.2.53
03273 t=0 0
03274 m=audio 49217 RTP/AVP 0 12
03275 m=video 3227 RTP/AVP 31
03276 a=rtpmap:31 LPC
03277 
03278 */
03279    FILE* fid= fopen("ncl.dat","r");
03280    tassert(fid);
03281    resip::Data txt;
03282    char mBuf[1024];
03283    int result;
03284    while(!feof(fid))
03285    {
03286       result = fread(&mBuf,1,1024,fid);
03287       txt += resip::Data(mBuf,result);
03288    }
03289    fclose(fid);
03290    resip::SipMessage* msg = resip::SipMessage::make(txt);
03291    tassert_reset();
03292    if(!msg)
03293    {
03294       return;
03295    }
03296 
03297    std::auto_ptr<resip::SipMessage> message(msg);
03298    msg->parseAllHeaders();
03299 
03300    resip::SipMessage copy(*msg);
03301 
03302    resip::Data encoded;
03303    {
03304       resip::oDataStream str(encoded);
03305       msg->encode(str);
03306    }
03307    resip::Data copyEncoded;
03308    {
03309       resip::oDataStream str(copyEncoded);
03310       copy.encode(str);
03311    }
03312 
03313    InfoLog(<< "In case ncl:" );
03314    InfoLog(<< "Original text:" << std::endl << txt );
03315    InfoLog(<< "Encoded form:" << std::endl << encoded );
03316    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
03317 
03318 
03319 
03320 
03321 }
03322 
03323 
03324 void
03325 scalar02()
03326 {
03327 /*
03328 
03329    This request contains several scalar header field values outside
03330    their legal range.
03331 
03332       o  The CSeq sequence number is >2**32-1.
03333 
03334       o  The Max-Forwards value is >255.
03335 
03336       o  The Expires value is >2**32-1.
03337 
03338       o  The Contact expires parameter value is >2**32-1.
03339 
03340    An element receiving this request should respond with a 400 Bad
03341    Request due to the CSeq error.  If only the Max-Forwards field were
03342    in error, the element could choose to process the request as if the
03343    field were absent.  If only the expiry values were in error, the
03344    element could treat them as if they contained the default values for
03345    expiration (3600 in this case).
03346 
03347    Other scalar request fields that may contain aberrant values include,
03348    but are not limited to, the Contact q value, the Timestamp value, and
03349    the Via ttl parameter.
03350 
03351 
03352 REGISTER sip:example.com SIP/2.0
03353 Via: SIP/2.0/TCP host129.example.com;branch=z9hG4bK342sdfoi3
03354 To: <sip:user@example.com>
03355 From: <sip:user@example.com>;tag=239232jh3
03356 CSeq: 36893488147419103232 REGISTER
03357 Call-ID: scalar02.23o0pd9vanlq3wnrlnewofjas9ui32
03358 Max-Forwards: 300
03359 Expires: 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
03360 Contact: <sip:user@host129.example.com>
03361   ;expires=280297596632815
03362 Content-Length: 0
03363 
03364 
03365 */
03366    FILE* fid= fopen("scalar02.dat","r");
03367    tassert(fid);
03368    resip::Data txt;
03369    char mBuf[1024];
03370    int result;
03371    while(!feof(fid))
03372    {
03373       result = fread(&mBuf,1,1024,fid);
03374       txt += resip::Data(mBuf,result);
03375    }
03376    fclose(fid);
03377    resip::SipMessage* msg = resip::SipMessage::make(txt);
03378    tassert_reset();
03379    if(!msg)
03380    {
03381       return;
03382    }
03383 
03384    std::auto_ptr<resip::SipMessage> message(msg);
03385    msg->parseAllHeaders();
03386 
03387    resip::SipMessage copy(*msg);
03388 
03389    resip::Data encoded;
03390    {
03391       resip::oDataStream str(encoded);
03392       msg->encode(str);
03393    }
03394    resip::Data copyEncoded;
03395    {
03396       resip::oDataStream str(copyEncoded);
03397       copy.encode(str);
03398    }
03399 
03400    InfoLog(<< "In case scalar02:" );
03401    InfoLog(<< "Original text:" << std::endl << txt );
03402    InfoLog(<< "Encoded form:" << std::endl << encoded );
03403    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
03404 
03405 
03406 
03407 
03408 }
03409 
03410 
03411 void
03412 scalarlg()
03413 {
03414 /*
03415 
03416    This response contains several scalar header field values outside
03417    their legal range.
03418 
03419    o  The CSeq sequence number is >2**32-1.
03420 
03421    o  The Retry-After field is unreasonably large (note that RFC 3261
03422       does not define a legal range for this field).
03423 
03424    o  The Warning field has a warning-value with more than 3 digits.
03425 
03426    An element receiving this response will simply discard it.
03427 
03428 SIP/2.0 503 Service Unavailable
03429 Via: SIP/2.0/TCP host129.example.com;branch=z9hG4bKzzxdiwo34sw;received=192.0.2.129
03430 To: <sip:user@example.com>
03431 From: <sip:other@example.net>;tag=2easdjfejw
03432 CSeq: 9292394834772304023312 OPTIONS
03433 Call-ID: scalarlg.noase0of0234hn2qofoaf0232aewf2394r
03434 Retry-After: 949302838503028349304023988
03435 Warning: 1812 overture "In Progress"
03436 Content-Length: 0
03437 
03438 
03439 */
03440    FILE* fid= fopen("scalarlg.dat","r");
03441    tassert(fid);
03442    resip::Data txt;
03443    char mBuf[1024];
03444    int result;
03445    while(!feof(fid))
03446    {
03447       result = fread(&mBuf,1,1024,fid);
03448       txt += resip::Data(mBuf,result);
03449    }
03450    fclose(fid);
03451    resip::SipMessage* msg = resip::SipMessage::make(txt);
03452    tassert_reset();
03453    if(!msg)
03454    {
03455       return;
03456    }
03457 
03458    std::auto_ptr<resip::SipMessage> message(msg);
03459    msg->parseAllHeaders();
03460 
03461    resip::SipMessage copy(*msg);
03462 
03463    resip::Data encoded;
03464    {
03465       resip::oDataStream str(encoded);
03466       msg->encode(str);
03467    }
03468    resip::Data copyEncoded;
03469    {
03470       resip::oDataStream str(copyEncoded);
03471       copy.encode(str);
03472    }
03473 
03474    InfoLog(<< "In case scalarlg:" );
03475    InfoLog(<< "Original text:" << std::endl << txt );
03476    InfoLog(<< "Encoded form:" << std::endl << encoded );
03477    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
03478 
03479 
03480 
03481 
03482 }
03483 
03484 
03485 void
03486 quotbal()
03487 {
03488 /*
03489 
03490    This is a request with an unterminated quote in the display name of
03491    the To field.  An element receiving this request should return a 400
03492    Bad Request error.
03493 
03494    An element could attempt to infer a terminating quote and accept the
03495    message.  Such an element needs to take care that it makes a
03496    reasonable inference when it encounters
03497 
03498       To: "Mr J. User <sip:j.user@example.com> <sip:realj@example.net>
03499 
03500 INVITE sip:user@example.com SIP/2.0
03501 To: "Mr. J. User <sip:j.user@example.com>
03502 From: sip:caller@example.net;tag=93334
03503 Max-Forwards: 10
03504 Call-ID: quotbal.aksdj
03505 Contact: <sip:caller@host59.example.net>
03506 CSeq: 8 INVITE
03507 Via: SIP/2.0/UDP 192.0.2.59:5050;branch=z9hG4bKkdjuw39234
03508 Content-Type: application/sdp
03509 Content-Length: 152
03510 
03511 v=0
03512 o=mhandley 29739 7272939 IN IP4 192.0.2.15
03513 s=-
03514 c=IN IP4 192.0.2.15
03515 t=0 0
03516 m=audio 49217 RTP/AVP 0 12
03517 m=video 3227 RTP/AVP 31
03518 a=rtpmap:31 LPC
03519 
03520 */
03521    FILE* fid= fopen("quotbal.dat","r");
03522    tassert(fid);
03523    resip::Data txt;
03524    char mBuf[1024];
03525    int result;
03526    while(!feof(fid))
03527    {
03528       result = fread(&mBuf,1,1024,fid);
03529       txt += resip::Data(mBuf,result);
03530    }
03531    fclose(fid);
03532    resip::SipMessage* msg = resip::SipMessage::make(txt);
03533    tassert_reset();
03534    if(!msg)
03535    {
03536       return;
03537    }
03538 
03539    std::auto_ptr<resip::SipMessage> message(msg);
03540    msg->parseAllHeaders();
03541 
03542    resip::SipMessage copy(*msg);
03543 
03544    resip::Data encoded;
03545    {
03546       resip::oDataStream str(encoded);
03547       msg->encode(str);
03548    }
03549    resip::Data copyEncoded;
03550    {
03551       resip::oDataStream str(copyEncoded);
03552       copy.encode(str);
03553    }
03554 
03555    InfoLog(<< "In case quotbal:" );
03556    InfoLog(<< "Original text:" << std::endl << txt );
03557    InfoLog(<< "Encoded form:" << std::endl << encoded );
03558    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
03559 
03560 
03561 
03562 
03563 }
03564 
03565 
03566 void
03567 ltgtruri()
03568 {
03569 /*
03570 
03571    This INVITE request is invalid because the Request-URI has been
03572    enclosed within in "<>".
03573 
03574    It is reasonable always to reject a request with this error with a
03575    400 Bad Request.  Elements attempting to be liberal with what they
03576    accept may choose to ignore the brackets.  If the element forwards
03577    the request, it must not include the brackets in the messages it
03578    sends.
03579 
03580 INVITE <sip:user@example.com> SIP/2.0
03581 To: sip:user@example.com
03582 From: sip:caller@example.net;tag=39291
03583 Max-Forwards: 23
03584 Call-ID: ltgtruri.1@192.0.2.5
03585 CSeq: 1 INVITE
03586 Via: SIP/2.0/UDP 192.0.2.5
03587 Contact: <sip:caller@host5.example.net>
03588 Content-Type: application/sdp
03589 Content-Length: 159
03590 
03591 v=0
03592 o=mhandley 29739 7272939 IN IP4 192.0.2.5
03593 s=-
03594 c=IN IP4 192.0.2.5
03595 t=3149328700 0
03596 m=audio 49217 RTP/AVP 0 12
03597 m=video 3227 RTP/AVP 31
03598 a=rtpmap:31 LPC
03599 
03600 */
03601    FILE* fid= fopen("ltgtruri.dat","r");
03602    tassert(fid);
03603    resip::Data txt;
03604    char mBuf[1024];
03605    int result;
03606    while(!feof(fid))
03607    {
03608       result = fread(&mBuf,1,1024,fid);
03609       txt += resip::Data(mBuf,result);
03610    }
03611    fclose(fid);
03612    resip::SipMessage* msg = resip::SipMessage::make(txt);
03613    tassert_reset();
03614    if(!msg)
03615    {
03616       return;
03617    }
03618 
03619    std::auto_ptr<resip::SipMessage> message(msg);
03620    msg->parseAllHeaders();
03621 
03622    resip::SipMessage copy(*msg);
03623 
03624    resip::Data encoded;
03625    {
03626       resip::oDataStream str(encoded);
03627       msg->encode(str);
03628    }
03629    resip::Data copyEncoded;
03630    {
03631       resip::oDataStream str(copyEncoded);
03632       copy.encode(str);
03633    }
03634 
03635    InfoLog(<< "In case ltgtruri:" );
03636    InfoLog(<< "Original text:" << std::endl << txt );
03637    InfoLog(<< "Encoded form:" << std::endl << encoded );
03638    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
03639 
03640 
03641 
03642 
03643 }
03644 
03645 
03646 void
03647 lwsruri()
03648 {
03649 /*
03650    This INVITE has illegal LWS within the Request-URI.
03651 
03652    An element receiving this request should respond with a 400 Bad
03653    Request.
03654 
03655    An element could attempt to ignore the embedded LWS for those schemes
03656    (like SIP) where doing so would not introduce ambiguity.
03657 
03658 INVITE sip:user@example.com; lr SIP/2.0
03659 To: sip:user@example.com;tag=3xfe-9921883-z9f
03660 From: sip:caller@example.net;tag=231413434
03661 Max-Forwards: 5
03662 Call-ID: lwsruri.asdfasdoeoi2323-asdfwrn23-asd834rk423
03663 CSeq: 2130706432 INVITE
03664 Via: SIP/2.0/UDP 192.0.2.1:5060;branch=z9hG4bKkdjuw2395
03665 Contact: <sip:caller@host1.example.net>
03666 Content-Type: application/sdp
03667 Content-Length: 159
03668 
03669 v=0
03670 o=mhandley 29739 7272939 IN IP4 192.0.2.1
03671 s=-
03672 c=IN IP4 192.0.2.1
03673 t=3149328700 0
03674 m=audio 49217 RTP/AVP 0 12
03675 m=video 3227 RTP/AVP 31
03676 a=rtpmap:31 LPC
03677 
03678 */
03679    FILE* fid= fopen("lwsruri.dat","r");
03680    tassert(fid);
03681    resip::Data txt;
03682    char mBuf[1024];
03683    int result;
03684    while(!feof(fid))
03685    {
03686       result = fread(&mBuf,1,1024,fid);
03687       txt += resip::Data(mBuf,result);
03688    }
03689    fclose(fid);
03690    resip::SipMessage* msg = resip::SipMessage::make(txt);
03691    tassert_reset();
03692    if(!msg)
03693    {
03694       return;
03695    }
03696 
03697    std::auto_ptr<resip::SipMessage> message(msg);
03698    msg->parseAllHeaders();
03699 
03700    resip::SipMessage copy(*msg);
03701 
03702    resip::Data encoded;
03703    {
03704       resip::oDataStream str(encoded);
03705       msg->encode(str);
03706    }
03707    resip::Data copyEncoded;
03708    {
03709       resip::oDataStream str(copyEncoded);
03710       copy.encode(str);
03711    }
03712 
03713    InfoLog(<< "In case lwsruri:" );
03714    InfoLog(<< "Original text:" << std::endl << txt );
03715    InfoLog(<< "Encoded form:" << std::endl << encoded );
03716    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
03717 
03718 
03719 
03720 
03721 }
03722 
03723 
03724 void
03725 lwsstart()
03726 {
03727 /*
03728 
03729    This INVITE has illegal multiple SP characters between elements of
03730    the start line.
03731 
03732    It is acceptable to reject this request as malformed.  An element
03733    that is liberal in what it accepts may ignore these extra SP
03734    characters when processing the request.  If the element forwards the
03735    request, it must not include these extra SP characters in the
03736    messages it sends.
03737 
03738 INVITE  sip:user@example.com  SIP/2.0
03739 Max-Forwards: 8
03740 To: sip:user@example.com
03741 From: sip:caller@example.net;tag=8814
03742 Call-ID: lwsstart.dfknq234oi243099adsdfnawe3@example.com
03743 CSeq: 1893884 INVITE
03744 Via: SIP/2.0/UDP host1.example.com;branch=z9hG4bKkdjuw3923
03745 Contact: <sip:caller@host1.example.net>
03746 Content-Type: application/sdp
03747 Content-Length: 150
03748 
03749 v=0
03750 o=mhandley 29739 7272939 IN IP4 192.0.2.1
03751 s=-
03752 c=IN IP4 192.0.2.1
03753 t=0 0
03754 m=audio 49217 RTP/AVP 0 12
03755 m=video 3227 RTP/AVP 31
03756 a=rtpmap:31 LPC
03757 
03758 */
03759    FILE* fid= fopen("lwsstart.dat","r");
03760    tassert(fid);
03761    resip::Data txt;
03762    char mBuf[1024];
03763    int result;
03764    while(!feof(fid))
03765    {
03766       result = fread(&mBuf,1,1024,fid);
03767       txt += resip::Data(mBuf,result);
03768    }
03769    fclose(fid);
03770    resip::SipMessage* msg = resip::SipMessage::make(txt);
03771    tassert_reset();
03772    if(!msg)
03773    {
03774       return;
03775    }
03776 
03777    std::auto_ptr<resip::SipMessage> message(msg);
03778    msg->parseAllHeaders();
03779 
03780    resip::SipMessage copy(*msg);
03781 
03782    resip::Data encoded;
03783    {
03784       resip::oDataStream str(encoded);
03785       msg->encode(str);
03786    }
03787    resip::Data copyEncoded;
03788    {
03789       resip::oDataStream str(copyEncoded);
03790       copy.encode(str);
03791    }
03792 
03793    InfoLog(<< "In case lwsstart:" );
03794    InfoLog(<< "Original text:" << std::endl << txt );
03795    InfoLog(<< "Encoded form:" << std::endl << encoded );
03796    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
03797 
03798 
03799 
03800 
03801 }
03802 
03803 
03804 void
03805 trws()
03806 {
03807 /*
03808 
03809    This OPTIONS request contains SP characters between the SIP-Version
03810    field and the CRLF terminating the Request-Line.
03811 
03812    It is acceptable to reject this request as malformed.  An element
03813    that is liberal in what it accepts may ignore these extra SP
03814    characters when processing the request.  If the element forwards the
03815    request, it must not include these extra SP characters in the
03816    messages it sends.
03817 
03818 OPTIONS sip:remote-target@example.com SIP/2.0  
03819 Via: SIP/2.0/TCP host1.examle.com;branch=z9hG4bK299342093
03820 To: <sip:remote-target@example.com>
03821 From: <sip:local-resource@example.com>;tag=329429089
03822 Call-ID: trws.oicu34958239neffasdhr2345r
03823 Accept: application/sdp
03824 CSeq: 238923 OPTIONS
03825 Max-Forwards: 70
03826 Content-Length: 0
03827 
03828 
03829 */
03830    FILE* fid= fopen("trws.dat","r");
03831    tassert(fid);
03832    resip::Data txt;
03833    char mBuf[1024];
03834    int result;
03835    while(!feof(fid))
03836    {
03837       result = fread(&mBuf,1,1024,fid);
03838       txt += resip::Data(mBuf,result);
03839    }
03840    fclose(fid);
03841    resip::SipMessage* msg = resip::SipMessage::make(txt);
03842    tassert_reset();
03843    if(!msg)
03844    {
03845       return;
03846    }
03847 
03848    std::auto_ptr<resip::SipMessage> message(msg);
03849    msg->parseAllHeaders();
03850 
03851    resip::SipMessage copy(*msg);
03852 
03853    resip::Data encoded;
03854    {
03855       resip::oDataStream str(encoded);
03856       msg->encode(str);
03857    }
03858    resip::Data copyEncoded;
03859    {
03860       resip::oDataStream str(copyEncoded);
03861       copy.encode(str);
03862    }
03863 
03864    InfoLog(<< "In case trws:" );
03865    InfoLog(<< "Original text:" << std::endl << txt );
03866    InfoLog(<< "Encoded form:" << std::endl << encoded );
03867    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
03868 
03869 
03870 
03871 
03872 }
03873 
03874 
03875 void
03876 escruri()
03877 {
03878 /*
03879 
03880    This INVITE is malformed, as the SIP Request-URI contains escaped
03881    headers.
03882 
03883    It is acceptable for an element to reject this request with a 400 Bad
03884    Request.  An element could choose to be liberal in what it accepts
03885    and ignore the escaped headers.  If the element is a proxy, the
03886    escaped headers must not appear in the Request-URI of the forwarded
03887    request (and most certainly must not be translated into the actual
03888    header of the forwarded request).
03889 
03890 INVITE sip:user@example.com?Route=%3Csip:example.com%3E SIP/2.0
03891 To: sip:user@example.com
03892 From: sip:caller@example.net;tag=341518
03893 Max-Forwards: 7
03894 Contact: <sip:caller@host39923.example.net>
03895 Call-ID: escruri.23940-asdfhj-aje3br-234q098w-fawerh2q-h4n5
03896 CSeq: 149209342 INVITE
03897 Via: SIP/2.0/UDP host-of-the-hour.example.com;branch=z9hG4bKkdjuw
03898 Content-Type: application/sdp
03899 Content-Length: 150
03900 
03901 v=0
03902 o=mhandley 29739 7272939 IN IP4 192.0.2.1
03903 s=-
03904 c=IN IP4 192.0.2.1
03905 t=0 0
03906 m=audio 49217 RTP/AVP 0 12
03907 m=video 3227 RTP/AVP 31
03908 a=rtpmap:31 LPC
03909 
03910 */
03911    FILE* fid= fopen("escruri.dat","r");
03912    tassert(fid);
03913    resip::Data txt;
03914    char mBuf[1024];
03915    int result;
03916    while(!feof(fid))
03917    {
03918       result = fread(&mBuf,1,1024,fid);
03919       txt += resip::Data(mBuf,result);
03920    }
03921    fclose(fid);
03922    resip::SipMessage* msg = resip::SipMessage::make(txt);
03923    tassert_reset();
03924    if(!msg)
03925    {
03926       return;
03927    }
03928 
03929    std::auto_ptr<resip::SipMessage> message(msg);
03930    msg->parseAllHeaders();
03931 
03932    resip::SipMessage copy(*msg);
03933 
03934    resip::Data encoded;
03935    {
03936       resip::oDataStream str(encoded);
03937       msg->encode(str);
03938    }
03939    resip::Data copyEncoded;
03940    {
03941       resip::oDataStream str(copyEncoded);
03942       copy.encode(str);
03943    }
03944 
03945    InfoLog(<< "In case escruri:" );
03946    InfoLog(<< "Original text:" << std::endl << txt );
03947    InfoLog(<< "Encoded form:" << std::endl << encoded );
03948    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
03949 
03950 
03951 
03952 
03953 }
03954 
03955 
03956 void
03957 baddate()
03958 {
03959 /*
03960 
03961    This INVITE is invalid, as it contains a non-GMT time zone in the SIP
03962    Date header field.
03963 
03964    It is acceptable to reject this request as malformed (though an
03965    element shouldn't do that unless the contents of the Date header
03966    field were actually important to its processing).  An element wishing
03967    to be liberal in what it accepts could ignore this value altogether
03968    if it wasn't going to use the Date header field anyway.  Otherwise,
03969    it could attempt to interpret this date and adjust it to GMT.
03970 
03971    RFC 3261 explicitly defines the only acceptable time zone designation
03972    as "GMT".  "UT", while synonymous with GMT per [RFC2822], is not
03973    valid.  "UTC" and "UCT" are also invalid.
03974 
03975 INVITE sip:user@example.com SIP/2.0
03976 To: sip:user@example.com
03977 From: sip:caller@example.net;tag=2234923
03978 Max-Forwards: 70
03979 Call-ID: baddate.239423mnsadf3j23lj42--sedfnm234
03980 CSeq: 1392934 INVITE
03981 Via: SIP/2.0/UDP host.example.com;branch=z9hG4bKkdjuw
03982 Date: Fri, 01 Jan 2010 16:00:00 EST
03983 Contact: <sip:caller@host5.example.net>
03984 Content-Type: application/sdp
03985 Content-Length: 150
03986 
03987 v=0
03988 o=mhandley 29739 7272939 IN IP4 192.0.2.5
03989 s=-
03990 c=IN IP4 192.0.2.5
03991 t=0 0
03992 m=audio 49217 RTP/AVP 0 12
03993 m=video 3227 RTP/AVP 31
03994 a=rtpmap:31 LPC
03995 
03996 */
03997    FILE* fid= fopen("baddate.dat","r");
03998    tassert(fid);
03999    resip::Data txt;
04000    char mBuf[1024];
04001    int result;
04002    while(!feof(fid))
04003    {
04004       result = fread(&mBuf,1,1024,fid);
04005       txt += resip::Data(mBuf,result);
04006    }
04007    fclose(fid);
04008    resip::SipMessage* msg = resip::SipMessage::make(txt);
04009    tassert_reset();
04010    if(!msg)
04011    {
04012       return;
04013    }
04014 
04015    std::auto_ptr<resip::SipMessage> message(msg);
04016    msg->parseAllHeaders();
04017 
04018    resip::SipMessage copy(*msg);
04019 
04020    resip::Data encoded;
04021    {
04022       resip::oDataStream str(encoded);
04023       msg->encode(str);
04024    }
04025    resip::Data copyEncoded;
04026    {
04027       resip::oDataStream str(copyEncoded);
04028       copy.encode(str);
04029    }
04030 
04031    InfoLog(<< "In case baddate:" );
04032    InfoLog(<< "Original text:" << std::endl << txt );
04033    InfoLog(<< "Encoded form:" << std::endl << encoded );
04034    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
04035 
04036 
04037 
04038 
04039 }
04040 
04041 
04042 void
04043 regbadct()
04044 {
04045 /*
04046 
04047    This REGISTER request is malformed.  The SIP URI contained in the
04048    Contact Header field has an escaped header, so the field must be in
04049    name-addr form (which implies that the URI must be enclosed in <>).
04050 
04051    It is reasonable for an element receiving this request to respond
04052    with a 400 Bad Request.  An element choosing to be liberal in what it
04053    accepts could infer the angle brackets since there is no ambiguity in
04054    this example.  In general, that won't be possible.
04055 
04056 REGISTER sip:example.com SIP/2.0
04057 To: sip:user@example.com
04058 From: sip:user@example.com;tag=998332
04059 Max-Forwards: 70
04060 Call-ID: regbadct.k345asrl3fdbv@10.0.0.1
04061 CSeq: 1 REGISTER
04062 Via: SIP/2.0/UDP 135.180.130.133:5060;branch=z9hG4bKkdjuw
04063 Contact: sip:user@example.com?Route=%3Csip:sip.example.com%3E
04064 l: 0
04065 
04066 
04067 */
04068    FILE* fid= fopen("regbadct.dat","r");
04069    tassert(fid);
04070    resip::Data txt;
04071    char mBuf[1024];
04072    int result;
04073    while(!feof(fid))
04074    {
04075       result = fread(&mBuf,1,1024,fid);
04076       txt += resip::Data(mBuf,result);
04077    }
04078    fclose(fid);
04079    resip::SipMessage* msg = resip::SipMessage::make(txt);
04080    tassert_reset();
04081    if(!msg)
04082    {
04083       return;
04084    }
04085 
04086    std::auto_ptr<resip::SipMessage> message(msg);
04087    msg->parseAllHeaders();
04088 
04089    resip::SipMessage copy(*msg);
04090 
04091    resip::Data encoded;
04092    {
04093       resip::oDataStream str(encoded);
04094       msg->encode(str);
04095    }
04096    resip::Data copyEncoded;
04097    {
04098       resip::oDataStream str(copyEncoded);
04099       copy.encode(str);
04100    }
04101 
04102    InfoLog(<< "In case regbadct:" );
04103    InfoLog(<< "Original text:" << std::endl << txt );
04104    InfoLog(<< "Encoded form:" << std::endl << encoded );
04105    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
04106 
04107 
04108 
04109 
04110 }
04111 
04112 
04113 void
04114 badaspec()
04115 {
04116 /*
04117 
04118    This request is malformed, since the addr-spec in the To header field
04119    contains spaces.  Parsers receiving this request must not break.  It
04120    is reasonable to reject this request with a 400 Bad Request response.
04121    Elements attempting to be liberal may ignore the spaces.
04122 
04123 OPTIONS sip:user@example.org SIP/2.0
04124 Via: SIP/2.0/UDP host4.example.com:5060;branch=z9hG4bKkdju43234
04125 Max-Forwards: 70
04126 From: "Bell, Alexander" <sip:a.g.bell@example.com>;tag=433423
04127 To: "Watson, Thomas" < sip:t.watson@example.org >
04128 Call-ID: badaspec.sdf0234n2nds0a099u23h3hnnw009cdkne3
04129 Accept: application/sdp
04130 CSeq: 3923239 OPTIONS
04131 l: 0
04132 
04133 
04134 */
04135    FILE* fid= fopen("badaspec.dat","r");
04136    tassert(fid);
04137    resip::Data txt;
04138    char mBuf[1024];
04139    int result;
04140    while(!feof(fid))
04141    {
04142       result = fread(&mBuf,1,1024,fid);
04143       txt += resip::Data(mBuf,result);
04144    }
04145    fclose(fid);
04146    resip::SipMessage* msg = resip::SipMessage::make(txt);
04147    tassert_reset();
04148    if(!msg)
04149    {
04150       return;
04151    }
04152 
04153    std::auto_ptr<resip::SipMessage> message(msg);
04154    msg->parseAllHeaders();
04155 
04156    resip::SipMessage copy(*msg);
04157 
04158    resip::Data encoded;
04159    {
04160       resip::oDataStream str(encoded);
04161       msg->encode(str);
04162    }
04163    resip::Data copyEncoded;
04164    {
04165       resip::oDataStream str(copyEncoded);
04166       copy.encode(str);
04167    }
04168    
04169    
04170 
04171    InfoLog(<< "In case badaspec:" );
04172    InfoLog(<< "Original text:" << std::endl << txt );
04173    InfoLog(<< "Encoded form:" << std::endl << encoded );
04174    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
04175 
04176 
04177 
04178 
04179 }
04180 
04181 
04182 void
04183 baddn()
04184 {
04185 /*
04186 
04187    This OPTIONS request is malformed, since the display names in the To
04188    and From header fields contain non-token characters but are unquoted.
04189 
04190    It is reasonable always to reject this kind of error with a 400 Bad
04191    Request response.
04192 
04193    An element may attempt to be liberal in what it receives and infer
04194    the missing quotes.  If this element were a proxy, it must not
04195    propagate the error into the request it forwards.  As a consequence,
04196    if the fields are covered by a signature, there's not much point in
04197    trying to be liberal - the message should simply be rejected.
04198 
04199 OPTIONS sip:t.watson@example.org SIP/2.0
04200 Via:     SIP/2.0/UDP c.example.com:5060;branch=z9hG4bKkdjuw
04201 Max-Forwards:      70
04202 From:    Bell, Alexander <sip:a.g.bell@example.com>;tag=43
04203 To:      Watson, Thomas <sip:t.watson@example.org>
04204 Call-ID: baddn.31415@c.example.com
04205 Accept: application/sdp
04206 CSeq:    3923239 OPTIONS
04207 l: 0
04208 
04209 */
04210    FILE* fid= fopen("baddn.dat","r");
04211    tassert(fid);
04212    resip::Data txt;
04213    char mBuf[1024];
04214    int result;
04215    while(!feof(fid))
04216    {
04217       result = fread(&mBuf,1,1024,fid);
04218       txt += resip::Data(mBuf,result);
04219    }
04220    fclose(fid);
04221    resip::SipMessage* msg = resip::SipMessage::make(txt);
04222    tassert_reset();
04223    if(!msg)
04224    {
04225       return;
04226    }
04227 
04228    std::auto_ptr<resip::SipMessage> message(msg);
04229    msg->parseAllHeaders();
04230 
04231    resip::SipMessage copy(*msg);
04232 
04233    resip::Data encoded;
04234    {
04235       resip::oDataStream str(encoded);
04236       msg->encode(str);
04237    }
04238    resip::Data copyEncoded;
04239    {
04240       resip::oDataStream str(copyEncoded);
04241       copy.encode(str);
04242    }
04243 
04244    InfoLog(<< "In case baddn:" );
04245    InfoLog(<< "Original text:" << std::endl << txt );
04246    InfoLog(<< "Encoded form:" << std::endl << encoded );
04247    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
04248 
04249 
04250 
04251 
04252 }
04253 
04254 
04255 void
04256 badvers()
04257 {
04258 /*
04259 
04260    To an element implementing [RFC3261], this request is malformed due
04261    to its high version number.
04262 
04263    The element should respond to the request with a 505 Version Not
04264    Supported error.
04265 
04266 OPTIONS sip:t.watson@example.org SIP/7.0
04267 Via:     SIP/7.0/UDP c.example.com;branch=z9hG4bKkdjuw
04268 Max-Forwards:     70
04269 From:    A. Bell <sip:a.g.bell@example.com>;tag=qweoiqpe
04270 To:      T. Watson <sip:t.watson@example.org>
04271 Call-ID: badvers.31417@c.example.com
04272 CSeq:    1 OPTIONS
04273 l: 0
04274 
04275 
04276 */
04277    FILE* fid= fopen("badvers.dat","r");
04278    tassert(fid);
04279    resip::Data txt;
04280    char mBuf[1024];
04281    int result;
04282    while(!feof(fid))
04283    {
04284       result = fread(&mBuf,1,1024,fid);
04285       txt += resip::Data(mBuf,result);
04286    }
04287    fclose(fid);
04288    resip::SipMessage* msg = resip::SipMessage::make(txt);
04289    tassert_reset();
04290    if(!msg)
04291    {
04292       return;
04293    }
04294 
04295    std::auto_ptr<resip::SipMessage> message(msg);
04296    msg->parseAllHeaders();
04297 
04298    resip::SipMessage copy(*msg);
04299 
04300    resip::Data encoded;
04301    {
04302       resip::oDataStream str(encoded);
04303       msg->encode(str);
04304    }
04305    resip::Data copyEncoded;
04306    {
04307       resip::oDataStream str(copyEncoded);
04308       copy.encode(str);
04309    }
04310 
04311    InfoLog(<< "In case badvers:" );
04312    InfoLog(<< "Original text:" << std::endl << txt );
04313    InfoLog(<< "Encoded form:" << std::endl << encoded );
04314    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
04315 
04316 
04317 
04318 
04319 }
04320 
04321 
04322 void
04323 mismatch01()
04324 {
04325 /*
04326 
04327    This request has mismatching values for the method in the start line
04328    and the CSeq header field.  Any element receiving this request will
04329    respond with a 400 Bad Request.
04330 
04331 OPTIONS sip:user@example.com SIP/2.0
04332 To: sip:j.user@example.com
04333 From: sip:caller@example.net;tag=34525
04334 Max-Forwards: 6
04335 Call-ID: mismatch01.dj0234sxdfl3
04336 CSeq: 8 INVITE
04337 Via: SIP/2.0/UDP host.example.com;branch=z9hG4bKkdjuw
04338 l: 0
04339 
04340 
04341 */
04342    FILE* fid= fopen("mismatch01.dat","r");
04343    tassert(fid);
04344    resip::Data txt;
04345    char mBuf[1024];
04346    int result;
04347    while(!feof(fid))
04348    {
04349       result = fread(&mBuf,1,1024,fid);
04350       txt += resip::Data(mBuf,result);
04351    }
04352    fclose(fid);
04353    resip::SipMessage* msg = resip::SipMessage::make(txt);
04354    tassert_reset();
04355    if(!msg)
04356    {
04357       return;
04358    }
04359 
04360    std::auto_ptr<resip::SipMessage> message(msg);
04361    msg->parseAllHeaders();
04362 
04363    resip::SipMessage copy(*msg);
04364 
04365    resip::Data encoded;
04366    {
04367       resip::oDataStream str(encoded);
04368       msg->encode(str);
04369    }
04370    resip::Data copyEncoded;
04371    {
04372       resip::oDataStream str(copyEncoded);
04373       copy.encode(str);
04374    }
04375 
04376    InfoLog(<< "In case mismatch01:" );
04377    InfoLog(<< "Original text:" << std::endl << txt );
04378    InfoLog(<< "Encoded form:" << std::endl << encoded );
04379    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
04380 
04381 
04382 
04383 
04384 }
04385 
04386 
04387 void
04388 mismatch02()
04389 {
04390 /*
04391 
04392    This message has an unknown method in the start line, and a CSeq
04393    method tag that does not match.
04394 
04395    Any element receiving this response should respond with a 501 Not
04396    Implemented.  A 400 Bad Request is also acceptable, but choosing a
04397    501 (particularly at proxies) has better future-proof
04398    characteristics.
04399 
04400 NEWMETHOD sip:user@example.com SIP/2.0
04401 To: sip:j.user@example.com
04402 From: sip:caller@example.net;tag=34525
04403 Max-Forwards: 6
04404 Call-ID: mismatch02.dj0234sxdfl3
04405 CSeq: 8 INVITE
04406 Contact: <sip:caller@host.example.net>
04407 Via: SIP/2.0/UDP host.example.net;branch=z9hG4bKkdjuw
04408 Content-Type: application/sdp
04409 l: 138
04410 
04411 v=0
04412 o=mhandley 29739 7272939 IN IP4 192.0.2.1
04413 c=IN IP4 192.0.2.1
04414 m=audio 49217 RTP/AVP 0 12
04415 m=video 3227 RTP/AVP 31
04416 a=rtpmap:31 LPC
04417 
04418 */
04419    FILE* fid= fopen("mismatch02.dat","r");
04420    tassert(fid);
04421    resip::Data txt;
04422    char mBuf[1024];
04423    int result;
04424    while(!feof(fid))
04425    {
04426       result = fread(&mBuf,1,1024,fid);
04427       txt += resip::Data(mBuf,result);
04428    }
04429    fclose(fid);
04430    resip::SipMessage* msg = resip::SipMessage::make(txt);
04431    tassert_reset();
04432    if(!msg)
04433    {
04434       return;
04435    }
04436 
04437    std::auto_ptr<resip::SipMessage> message(msg);
04438    msg->parseAllHeaders();
04439 
04440    resip::SipMessage copy(*msg);
04441 
04442    resip::Data encoded;
04443    {
04444       resip::oDataStream str(encoded);
04445       msg->encode(str);
04446    }
04447    resip::Data copyEncoded;
04448    {
04449       resip::oDataStream str(copyEncoded);
04450       copy.encode(str);
04451    }
04452 
04453    InfoLog(<< "In case mismatch02:" );
04454    InfoLog(<< "Original text:" << std::endl << txt );
04455    InfoLog(<< "Encoded form:" << std::endl << encoded );
04456    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
04457 
04458 
04459 
04460 
04461 }
04462 
04463 
04464 void
04465 bigcode()
04466 {
04467 /*
04468 
04469    This response has a response code larger than 699.  An element
04470    receiving this response should simply drop it.
04471 
04472 SIP/2.0 4294967301 better not break the receiver
04473 Via: SIP/2.0/UDP 192.0.2.105;branch=z9hG4bK2398ndaoe
04474 Call-ID: bigcode.asdof3uj203asdnf3429uasdhfas3ehjasdfas9i
04475 CSeq: 353494 INVITE
04476 From: <sip:user@example.com>;tag=39ansfi3
04477 To: <sip:user@example.edu>;tag=902jndnke3
04478 Content-Length: 0
04479 Contact: <sip:user@host105.example.com>
04480 
04481 
04482 */
04483    FILE* fid= fopen("bigcode.dat","r");
04484    tassert(fid);
04485    resip::Data txt;
04486    char mBuf[1024];
04487    int result;
04488    while(!feof(fid))
04489    {
04490       result = fread(&mBuf,1,1024,fid);
04491       txt += resip::Data(mBuf,result);
04492    }
04493    fclose(fid);
04494    resip::SipMessage* msg = resip::SipMessage::make(txt);
04495    tassert_reset();
04496    if(!msg)
04497    {
04498       return;
04499    }
04500 
04501    std::auto_ptr<resip::SipMessage> message(msg);
04502    msg->parseAllHeaders();
04503 
04504    resip::SipMessage copy(*msg);
04505 
04506    resip::Data encoded;
04507    {
04508       resip::oDataStream str(encoded);
04509       msg->encode(str);
04510    }
04511    resip::Data copyEncoded;
04512    {
04513       resip::oDataStream str(copyEncoded);
04514       copy.encode(str);
04515    }
04516 
04517    InfoLog(<< "In case bigcode:" );
04518    InfoLog(<< "Original text:" << std::endl << txt );
04519    InfoLog(<< "Encoded form:" << std::endl << encoded );
04520    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
04521 
04522 
04523 
04524 
04525 }
04526 
04527 
04528 void
04529 badbranch()
04530 {
04531 /*
04532 
04533    This request indicates support for RFC 3261-style transaction
04534    identifiers by providing the z9hG4bK prefix to the branch parameter,
04535    but it provides no identifier.  A parser must not break when
04536    receiving this message.  An element receiving this request could
04537    reject the request with a 400 Response (preferably statelessly, as
04538    other requests from the source are likely also to have a malformed
04539    branch parameter), or it could fall back to the RFC 2543-style
04540    transaction identifier.
04541 
04542 OPTIONS sip:user@example.com SIP/2.0
04543 To: sip:user@example.com
04544 From: sip:caller@example.org;tag=33242
04545 Max-Forwards: 3
04546 Via: SIP/2.0/UDP 192.0.2.1;branch=z9hG4bK
04547 Accept: application/sdp
04548 Call-ID: badbranch.sadonfo23i420jv0as0derf3j3n
04549 CSeq: 8 OPTIONS
04550 l: 0
04551 
04552 
04553 */
04554    FILE* fid= fopen("badbranch.dat","r");
04555    tassert(fid);
04556    resip::Data txt;
04557    char mBuf[1024];
04558    int result;
04559    while(!feof(fid))
04560    {
04561       result = fread(&mBuf,1,1024,fid);
04562       txt += resip::Data(mBuf,result);
04563    }
04564    fclose(fid);
04565    resip::SipMessage* msg = resip::SipMessage::make(txt);
04566    tassert_reset();
04567    tassert(msg);
04568    tassert_reset();
04569    if(!msg)
04570    {
04571       return;
04572    }
04573 
04574    std::auto_ptr<resip::SipMessage> message(msg);
04575    msg->parseAllHeaders();
04576 
04577    resip::SipMessage copy(*msg);
04578 
04579    resip::Data encoded;
04580    {
04581       resip::oDataStream str(encoded);
04582       msg->encode(str);
04583    }
04584    resip::Data copyEncoded;
04585    {
04586       resip::oDataStream str(copyEncoded);
04587       copy.encode(str);
04588    }
04589 
04590    //Request Line
04591    //OPTIONS sip:user@example.com SIP/2.0
04592    tassert(msg->header(resip::h_RequestLine).method()==resip::OPTIONS);
04593    tassert(msg->header(resip::h_RequestLine).unknownMethodName()=="OPTIONS");
04594    tassert(msg->header(resip::h_RequestLine).uri().scheme()=="sip");
04595    tassert(msg->header(resip::h_RequestLine).uri().user()=="user");
04596    tassert(msg->header(resip::h_RequestLine).uri().password().empty());
04597    tassert(msg->header(resip::h_RequestLine).uri().host()=="example.com");
04598    tassert(msg->header(resip::h_RequestLine).uri().port()==0);
04599    tassert(!(msg->header(resip::h_RequestLine).uri().hasEmbedded()));
04600    tassert(msg->header(resip::h_RequestLine).uri().numKnownParams()==0);
04601    tassert(msg->header(resip::h_RequestLine).uri().numUnknownParams()==0);
04602    tassert(msg->header(resip::h_RequestLine).getSipVersion()=="SIP/2.0");
04603 
04604    //To: sip:user@example.com
04605    tassert(msg->exists(resip::h_To));
04606    tassert(msg->header(resip::h_To).displayName()=="");
04607    tassert(msg->header(resip::h_To).numKnownParams()==0);
04608    tassert(msg->header(resip::h_To).numUnknownParams()==0);
04609    tassert(!(msg->header(resip::h_To).isAllContacts()));
04610    tassert(msg->header(resip::h_To).uri().scheme()=="sip");
04611    tassert(msg->header(resip::h_To).uri().user()=="user");
04612    tassert(msg->header(resip::h_To).uri().password().empty());
04613    tassert(msg->header(resip::h_To).uri().host()=="example.com");
04614    tassert(msg->header(resip::h_To).uri().port()==0);
04615    tassert(!(msg->header(resip::h_To).uri().hasEmbedded()));
04616    tassert(msg->header(resip::h_To).uri().numKnownParams()==0);
04617    tassert(msg->header(resip::h_To).uri().numUnknownParams()==0);
04618 
04619    //From: sip:caller@example.org;tag=33242
04620    tassert(msg->exists(resip::h_From));
04621    tassert(msg->header(resip::h_From).displayName()=="");
04622    tassert(msg->header(resip::h_From).numKnownParams()==1);
04623    tassert(msg->header(resip::h_From).numUnknownParams()==0);
04624    tassert(msg->header(resip::h_From).exists(resip::p_tag));
04625    tassert(msg->header(resip::h_From).param(resip::p_tag)=="33242");
04626    tassert(!(msg->header(resip::h_From).isAllContacts()));
04627    tassert(msg->header(resip::h_From).uri().scheme()=="sip");
04628    tassert(msg->header(resip::h_From).uri().user()=="caller");
04629    tassert(msg->header(resip::h_From).uri().password().empty());
04630    tassert(msg->header(resip::h_From).uri().host()=="example.org");
04631    tassert(msg->header(resip::h_From).uri().port()==0);
04632    tassert(!(msg->header(resip::h_From).uri().hasEmbedded()));
04633    tassert(msg->header(resip::h_From).uri().numKnownParams()==0);
04634    tassert(msg->header(resip::h_From).uri().numUnknownParams()==0);
04635 
04636    //Max-Forwards: 3
04637    tassert(msg->exists(resip::h_MaxForwards));
04638    tassert(msg->header(resip::h_MaxForwards).value()==3);
04639    tassert(msg->header(resip::h_MaxForwards).numKnownParams()==0);
04640    tassert(msg->header(resip::h_MaxForwards).numUnknownParams()==0);
04641 
04642    //Vias
04643    tassert(msg->exists(resip::h_Vias));
04644    tassert(msg->header(resip::h_Vias).size()==1);
04645    resip::ParserContainer<resip::Via>::iterator v=msg->header(resip::h_Vias).begin();
04646 
04647    //Via: SIP/2.0/UDP 192.0.2.1;branch=z9hG4bK
04648    tassert(v->numKnownParams()==1);
04649    tassert(v->numUnknownParams()==0);
04650    tassert(v->protocolName()=="SIP");
04651    tassert(v->protocolVersion()=="2.0");
04652    tassert(v->transport()=="UDP");
04653    tassert(v->sentHost()=="192.0.2.1");
04654    tassert(v->sentPort()==0);
04655    
04656    tassert(v->exists(resip::p_branch));
04657    tassert(v->param(resip::p_branch).hasMagicCookie());
04658    tassert(v->param(resip::p_branch).getTransactionId()=="");
04659    tassert(v->param(resip::p_branch).clientData().empty());
04660 
04661    //Accept: application/sdp
04662    tassert(msg->exists(resip::h_Accepts));
04663    tassert(msg->header(resip::h_Accepts).size()==1);
04664    
04665    resip::Mimes::iterator a=msg->header(resip::h_Accepts).begin();
04666    
04667    tassert(a->type()=="application");
04668    tassert(a->subType()=="sdp");
04669    tassert(a->numKnownParams()==0);
04670    tassert(a->numUnknownParams()==0);
04671 
04672    //Call-ID: badbranch.sadonfo23i420jv0as0derf3j3n
04673    tassert(msg->exists(resip::h_CallID));
04674    tassert(msg->header(resip::h_CallID).value()=="badbranch.sadonfo23i420jv0as0derf3j3n");
04675    tassert(msg->header(resip::h_CallID).numKnownParams()==0);
04676    tassert(msg->header(resip::h_CallID).numUnknownParams()==0);
04677 
04678    //CSeq: 8 OPTIONS
04679    tassert(msg->exists(resip::h_CSeq));
04680    tassert(msg->header(resip::h_CSeq).method()==resip::OPTIONS);
04681    tassert(msg->header(resip::h_CSeq).unknownMethodName()=="OPTIONS");
04682    tassert(msg->header(resip::h_CSeq).sequence()==8);
04683    tassert(msg->header(resip::h_CSeq).numKnownParams()==0);
04684    tassert(msg->header(resip::h_CSeq).numUnknownParams()==0);
04685 
04686    //l: 0
04687    tassert(msg->exists(resip::h_ContentLength));
04688    tassert(msg->header(resip::h_ContentLength).value()==0);
04689    tassert(msg->header(resip::h_ContentLength).numKnownParams()==0);
04690    tassert(msg->header(resip::h_ContentLength).numUnknownParams()==0);
04691 
04692 
04693    InfoLog(<< "In case badbranch:" );
04694    InfoLog(<< "Original text:" << std::endl << txt );
04695    InfoLog(<< "Encoded form:" << std::endl << encoded );
04696    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
04697 
04698 
04699 
04700 
04701 }
04702 
04703 
04704 void
04705 bcast()
04706 {
04707 /*
04708 
04709 SIP/2.0 200 OK
04710 Via: SIP/2.0/UDP 192.0.2.198;branch=z9hG4bK1324923
04711 Via: SIP/2.0/UDP 255.255.255.255;branch=z9hG4bK1saber23
04712 Call-ID: bcast.0384840201234ksdfak3j2erwedfsASdf
04713 CSeq: 35 INVITE
04714 From: sip:user@example.com;tag=11141343
04715 To: sip:user@example.edu;tag=2229
04716 Content-Length: 154
04717 Content-Type: application/sdp
04718 Contact: <sip:user@host28.example.com>
04719 
04720 v=0
04721 o=mhandley 29739 7272939 IN IP4 192.0.2.198
04722 s=-
04723 c=IN IP4 192.0.2.198
04724 t=0 0
04725 m=audio 49217 RTP/AVP 0 12
04726 m=video 3227 RTP/AVP 31
04727 a=rtpmap:31 LPC
04728 
04729 */
04730    FILE* fid= fopen("bcast.dat","r");
04731    tassert(fid);
04732    resip::Data txt;
04733    char mBuf[1024];
04734    int result;
04735    while(!feof(fid))
04736    {
04737       result = fread(&mBuf,1,1024,fid);
04738       txt += resip::Data(mBuf,result);
04739    }
04740    fclose(fid);
04741    resip::SipMessage* msg = resip::SipMessage::make(txt);
04742    tassert_reset();
04743    tassert(msg);
04744    tassert_reset();
04745    if(!msg)
04746    {
04747       return;
04748    }
04749 
04750    std::auto_ptr<resip::SipMessage> message(msg);
04751    msg->parseAllHeaders();
04752 
04753    resip::SipMessage copy(*msg);
04754 
04755    resip::Data encoded;
04756    {
04757       resip::oDataStream str(encoded);
04758       msg->encode(str);
04759    }
04760    resip::Data copyEncoded;
04761    {
04762       resip::oDataStream str(copyEncoded);
04763       copy.encode(str);
04764    }
04765 
04766    InfoLog(<< "In case bcast:" );
04767    InfoLog(<< "Original text:" << std::endl << txt );
04768    InfoLog(<< "Encoded form:" << std::endl << encoded );
04769    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
04770 
04771 
04772 
04773 
04774 }
04775 
04776 
04777 void
04778 bext01()
04779 {
04780 /*
04781 
04782 OPTIONS sip:user@example.com SIP/2.0
04783 To: sip:j_user@example.com
04784 From: sip:caller@example.net;tag=242etr
04785 Max-Forwards: 6
04786 Call-ID: bext01.0ha0isndaksdj
04787 Require: nothingSupportsThis, nothingSupportsThisEither
04788 Proxy-Require: noProxiesSupportThis, norDoAnyProxiesSupportThis
04789 CSeq: 8 OPTIONS
04790 Via: SIP/2.0/TLS fold-and-staple.example.com;branch=z9hG4bKkdjuw
04791 Content-Length: 0
04792 
04793 
04794 */
04795    FILE* fid= fopen("bext01.dat","r");
04796    tassert(fid);
04797    resip::Data txt;
04798    char mBuf[1024];
04799    int result;
04800    while(!feof(fid))
04801    {
04802       result = fread(&mBuf,1,1024,fid);
04803       txt += resip::Data(mBuf,result);
04804    }
04805    fclose(fid);
04806    resip::SipMessage* msg = resip::SipMessage::make(txt);
04807    tassert_reset();
04808    tassert(msg);
04809    tassert_reset();
04810    if(!msg)
04811    {
04812       return;
04813    }
04814 
04815    std::auto_ptr<resip::SipMessage> message(msg);
04816    msg->parseAllHeaders();
04817 
04818    resip::SipMessage copy(*msg);
04819 
04820    resip::Data encoded;
04821    {
04822       resip::oDataStream str(encoded);
04823       msg->encode(str);
04824    }
04825    resip::Data copyEncoded;
04826    {
04827       resip::oDataStream str(copyEncoded);
04828       copy.encode(str);
04829    }
04830 
04831    InfoLog(<< "In case bext01:" );
04832    InfoLog(<< "Original text:" << std::endl << txt );
04833    InfoLog(<< "Encoded form:" << std::endl << encoded );
04834    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
04835 
04836 
04837 
04838 
04839 }
04840 
04841 
04842 void
04843 cparam01()
04844 {
04845 /*
04846 
04847 REGISTER sip:example.com SIP/2.0
04848 Via: SIP/2.0/UDP saturn.example.com:5060;branch=z9hG4bKkdjuw
04849 Max-Forwards: 70
04850 From: sip:watson@example.com;tag=DkfVgjkrtMwaerKKpe
04851 To: sip:watson@example.com
04852 Call-ID: cparam01.70710@saturn.example.com
04853 CSeq: 2 REGISTER
04854 Contact: sip:+19725552222@gw1.example.net;unknownparam
04855 l: 0
04856 
04857 
04858 */
04859    FILE* fid= fopen("cparam01.dat","r");
04860    tassert(fid);
04861    resip::Data txt;
04862    char mBuf[1024];
04863    int result;
04864    while(!feof(fid))
04865    {
04866       result = fread(&mBuf,1,1024,fid);
04867       txt += resip::Data(mBuf,result);
04868    }
04869    fclose(fid);
04870    resip::SipMessage* msg = resip::SipMessage::make(txt);
04871    tassert_reset();
04872    tassert(msg);
04873    tassert_reset();
04874    if(!msg)
04875    {
04876       return;
04877    }
04878 
04879    std::auto_ptr<resip::SipMessage> message(msg);
04880    msg->parseAllHeaders();
04881 
04882    resip::SipMessage copy(*msg);
04883 
04884    resip::Data encoded;
04885    {
04886       resip::oDataStream str(encoded);
04887       msg->encode(str);
04888    }
04889    resip::Data copyEncoded;
04890    {
04891       resip::oDataStream str(copyEncoded);
04892       copy.encode(str);
04893    }
04894 
04895    InfoLog(<< "In case cparam01:" );
04896    InfoLog(<< "Original text:" << std::endl << txt );
04897    InfoLog(<< "Encoded form:" << std::endl << encoded );
04898    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
04899 
04900 
04901 
04902 
04903 }
04904 
04905 
04906 void
04907 cparam02()
04908 {
04909 /*
04910 
04911 REGISTER sip:example.com SIP/2.0
04912 Via: SIP/2.0/UDP saturn.example.com:5060;branch=z9hG4bKkdjuw
04913 Max-Forwards: 70
04914 From: sip:watson@example.com;tag=838293
04915 To: sip:watson@example.com
04916 Call-ID: cparam02.70710@saturn.example.com
04917 CSeq: 3 REGISTER
04918 Contact: <sip:+19725552222@gw1.example.net;unknownparam>
04919 l: 0
04920 
04921 
04922 */
04923    FILE* fid= fopen("cparam02.dat","r");
04924    tassert(fid);
04925    resip::Data txt;
04926    char mBuf[1024];
04927    int result;
04928    while(!feof(fid))
04929    {
04930       result = fread(&mBuf,1,1024,fid);
04931       txt += resip::Data(mBuf,result);
04932    }
04933    fclose(fid);
04934    resip::SipMessage* msg = resip::SipMessage::make(txt);
04935    tassert_reset();
04936    tassert(msg);
04937    tassert_reset();
04938    if(!msg)
04939    {
04940       return;
04941    }
04942 
04943    std::auto_ptr<resip::SipMessage> message(msg);
04944    msg->parseAllHeaders();
04945 
04946    resip::SipMessage copy(*msg);
04947 
04948    resip::Data encoded;
04949    {
04950       resip::oDataStream str(encoded);
04951       msg->encode(str);
04952    }
04953    resip::Data copyEncoded;
04954    {
04955       resip::oDataStream str(copyEncoded);
04956       copy.encode(str);
04957    }
04958 
04959    InfoLog(<< "In case cparam02:" );
04960    InfoLog(<< "Original text:" << std::endl << txt );
04961    InfoLog(<< "Encoded form:" << std::endl << encoded );
04962    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
04963 
04964 
04965 
04966 
04967 }
04968 
04969 
04970 void
04971 insuf()
04972 {
04973 /*
04974 
04975 INVITE sip:user@example.com SIP/2.0
04976 CSeq: 193942 INVITE
04977 Via: SIP/2.0/UDP 192.0.2.95;branch=z9hG4bKkdj.insuf
04978 Content-Type: application/sdp
04979 l: 152
04980 
04981 v=0
04982 o=mhandley 29739 7272939 IN IP4 192.0.2.95
04983 s=-
04984 c=IN IP4 192.0.2.95
04985 t=0 0
04986 m=audio 49217 RTP/AVP 0 12
04987 m=video 3227 RTP/AVP 31
04988 a=rtpmap:31 LPC
04989 
04990 */
04991    FILE* fid= fopen("insuf.dat","r");
04992    tassert(fid);
04993    resip::Data txt;
04994    char mBuf[1024];
04995    int result;
04996    while(!feof(fid))
04997    {
04998       result = fread(&mBuf,1,1024,fid);
04999       txt += resip::Data(mBuf,result);
05000    }
05001    fclose(fid);
05002    resip::SipMessage* msg = resip::SipMessage::make(txt);
05003    tassert_reset();
05004    tassert(msg);
05005    tassert_reset();
05006    if(!msg)
05007    {
05008       return;
05009    }
05010 
05011    std::auto_ptr<resip::SipMessage> message(msg);
05012    msg->parseAllHeaders();
05013 
05014    resip::SipMessage copy(*msg);
05015 
05016    resip::Data encoded;
05017    {
05018       resip::oDataStream str(encoded);
05019       msg->encode(str);
05020    }
05021    resip::Data copyEncoded;
05022    {
05023       resip::oDataStream str(copyEncoded);
05024       copy.encode(str);
05025    }
05026 
05027    InfoLog(<< "In case insuf:" );
05028    InfoLog(<< "Original text:" << std::endl << txt );
05029    InfoLog(<< "Encoded form:" << std::endl << encoded );
05030    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
05031 
05032 
05033 
05034 
05035 }
05036 
05037 
05038 void
05039 inv2543()
05040 {
05041 /*
05042 
05043 INVITE sip:UserB@example.com SIP/2.0
05044 Via: SIP/2.0/UDP iftgw.example.com
05045 From: <sip:+13035551111@ift.client.example.net;user=phone>
05046 Record-Route: <sip:UserB@example.com;maddr=ss1.example.com>
05047 To: sip:+16505552222@ss1.example.net;user=phone
05048 Call-ID: inv2543.1717@ift.client.example.com
05049 CSeq: 56 INVITE
05050 Content-Type: application/sdp
05051 
05052 v=0
05053 o=mhandley 29739 7272939 IN IP4 192.0.2.5
05054 s=-
05055 c=IN IP4 192.0.2.5
05056 t=0 0
05057 m=audio 49217 RTP/AVP 0
05058 
05059 */
05060    FILE* fid= fopen("inv2543.dat","r");
05061    tassert(fid);
05062    resip::Data txt;
05063    char mBuf[1024];
05064    int result;
05065    while(!feof(fid))
05066    {
05067       result = fread(&mBuf,1,1024,fid);
05068       txt += resip::Data(mBuf,result);
05069    }
05070    fclose(fid);
05071    resip::SipMessage* msg = resip::SipMessage::make(txt);
05072    tassert_reset();
05073    tassert(msg);
05074    tassert_reset();
05075    if(!msg)
05076    {
05077       return;
05078    }
05079 
05080    std::auto_ptr<resip::SipMessage> message(msg);
05081    msg->parseAllHeaders();
05082 
05083    resip::SipMessage copy(*msg);
05084 
05085    resip::Data encoded;
05086    {
05087       resip::oDataStream str(encoded);
05088       msg->encode(str);
05089    }
05090    resip::Data copyEncoded;
05091    {
05092       resip::oDataStream str(copyEncoded);
05093       copy.encode(str);
05094    }
05095 
05096    InfoLog(<< "In case inv2543:" );
05097    InfoLog(<< "Original text:" << std::endl << txt );
05098    InfoLog(<< "Encoded form:" << std::endl << encoded );
05099    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
05100 
05101 
05102 
05103 
05104 }
05105 
05106 
05107 void
05108 invut()
05109 {
05110 /*
05111 
05112 INVITE sip:user@example.com SIP/2.0
05113 Contact: <sip:caller@host5.example.net>
05114 To: sip:j.user@example.com
05115 From: sip:caller@example.net;tag=8392034
05116 Max-Forwards: 70
05117 Call-ID: invut.0ha0isndaksdjadsfij34n23d
05118 CSeq: 235448 INVITE
05119 Via: SIP/2.0/UDP somehost.example.com;branch=z9hG4bKkdjuw
05120 Content-Type: application/unknownformat
05121 Content-Length: 40
05122 
05123 <audio>
05124  <pcmu port="443"/>
05125 </audio>
05126 
05127 */
05128    FILE* fid= fopen("invut.dat","r");
05129    tassert(fid);
05130    resip::Data txt;
05131    char mBuf[1024];
05132    int result;
05133    while(!feof(fid))
05134    {
05135       result = fread(&mBuf,1,1024,fid);
05136       txt += resip::Data(mBuf,result);
05137    }
05138    fclose(fid);
05139    resip::SipMessage* msg = resip::SipMessage::make(txt);
05140    tassert_reset();
05141    tassert(msg);
05142    tassert_reset();
05143    if(!msg)
05144    {
05145       return;
05146    }
05147 
05148    std::auto_ptr<resip::SipMessage> message(msg);
05149    msg->parseAllHeaders();
05150 
05151    resip::SipMessage copy(*msg);
05152 
05153    resip::Data encoded;
05154    {
05155       resip::oDataStream str(encoded);
05156       msg->encode(str);
05157    }
05158    resip::Data copyEncoded;
05159    {
05160       resip::oDataStream str(copyEncoded);
05161       copy.encode(str);
05162    }
05163 
05164    InfoLog(<< "In case invut:" );
05165    InfoLog(<< "Original text:" << std::endl << txt );
05166    InfoLog(<< "Encoded form:" << std::endl << encoded );
05167    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
05168 
05169 
05170 
05171 
05172 }
05173 
05174 
05175 void
05176 mcl01()
05177 {
05178 /*
05179 
05180 OPTIONS sip:user@example.com SIP/2.0
05181 Via: SIP/2.0/UDP host5.example.net;branch=z9hG4bK293423
05182 To: sip:user@example.com
05183 From: sip:other@example.net;tag=3923942
05184 Call-ID: mcl01.fhn2323orihawfdoa3o4r52o3irsdf
05185 CSeq: 15932 OPTIONS
05186 Content-Length: 13
05187 Max-Forwards: 60
05188 Content-Length: 5
05189 Content-Type: text/plain
05190 
05191 There's no way to know how many octets are supposed to be here.
05192 
05193 
05194 */
05195    FILE* fid= fopen("mcl01.dat","r");
05196    tassert(fid);
05197    resip::Data txt;
05198    char mBuf[1024];
05199    int result;
05200    while(!feof(fid))
05201    {
05202       result = fread(&mBuf,1,1024,fid);
05203       txt += resip::Data(mBuf,result);
05204    }
05205    fclose(fid);
05206    resip::SipMessage* msg = resip::SipMessage::make(txt);
05207    tassert_reset();
05208    tassert(msg);
05209    tassert_reset();
05210    if(!msg)
05211    {
05212       return;
05213    }
05214 
05215    std::auto_ptr<resip::SipMessage> message(msg);
05216    msg->parseAllHeaders();
05217 
05218    resip::SipMessage copy(*msg);
05219 
05220    resip::Data encoded;
05221    {
05222       resip::oDataStream str(encoded);
05223       msg->encode(str);
05224    }
05225    resip::Data copyEncoded;
05226    {
05227       resip::oDataStream str(copyEncoded);
05228       copy.encode(str);
05229    }
05230 
05231    InfoLog(<< "In case mcl01:" );
05232    InfoLog(<< "Original text:" << std::endl << txt );
05233    InfoLog(<< "Encoded form:" << std::endl << encoded );
05234    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
05235 
05236 
05237 
05238 
05239 }
05240 
05241 
05242 void
05243 multi01()
05244 {
05245 /*
05246 
05247 INVITE sip:user@company.com SIP/2.0
05248 Contact: <sip:caller@host25.example.net>
05249 Via: SIP/2.0/UDP 192.0.2.25;branch=z9hG4bKkdjuw
05250 Max-Forwards: 70
05251 CSeq: 5 INVITE
05252 Call-ID: multi01.98asdh@192.0.2.1
05253 CSeq: 59 INVITE
05254 Call-ID: multi01.98asdh@192.0.2.2
05255 From: sip:caller@example.com;tag=3413415
05256 To: sip:user@example.com
05257 To: sip:other@example.net
05258 From: sip:caller@example.net;tag=2923420123
05259 Content-Type: application/sdp
05260 l: 154
05261 Contact: <sip:caller@host36.example.net>
05262 Max-Forwards: 5
05263 
05264 v=0
05265 o=mhandley 29739 7272939 IN IP4 192.0.2.25
05266 s=-
05267 c=IN IP4 192.0.2.25
05268 t=0 0
05269 m=audio 49217 RTP/AVP 0 12
05270 m=video 3227 RTP/AVP 31
05271 a=rtpmap:31 LPC
05272 
05273 
05274 */
05275    FILE* fid= fopen("multi01.dat","r");
05276    tassert(fid);
05277    resip::Data txt;
05278    char mBuf[1024];
05279    int result;
05280    while(!feof(fid))
05281    {
05282       result = fread(&mBuf,1,1024,fid);
05283       txt += resip::Data(mBuf,result);
05284    }
05285    fclose(fid);
05286    resip::SipMessage* msg = resip::SipMessage::make(txt);
05287    tassert_reset();
05288    tassert(msg);
05289    tassert_reset();
05290    if(!msg)
05291    {
05292       return;
05293    }
05294 
05295    std::auto_ptr<resip::SipMessage> message(msg);
05296    msg->parseAllHeaders();
05297 
05298    resip::SipMessage copy(*msg);
05299 
05300    resip::Data encoded;
05301    {
05302       resip::oDataStream str(encoded);
05303       msg->encode(str);
05304    }
05305    resip::Data copyEncoded;
05306    {
05307       resip::oDataStream str(copyEncoded);
05308       copy.encode(str);
05309    }
05310 
05311    InfoLog(<< "In case multi01:" );
05312    InfoLog(<< "Original text:" << std::endl << txt );
05313    InfoLog(<< "Encoded form:" << std::endl << encoded );
05314    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
05315 
05316 
05317 
05318 
05319 }
05320 
05321 
05322 void
05323 novelsc()
05324 {
05325 /*
05326 
05327 OPTIONS soap.beep://192.0.2.103:3002 SIP/2.0
05328 To: sip:user@example.com
05329 From: sip:caller@example.net;tag=384
05330 Max-Forwards: 3
05331 Call-ID: novelsc.asdfasser0q239nwsdfasdkl34
05332 CSeq: 3923423 OPTIONS
05333 Via: SIP/2.0/TCP host9.example.com;branch=z9hG4bKkdjuw39234
05334 Content-Length: 0
05335 
05336 
05337 */
05338    FILE* fid= fopen("novelsc.dat","r");
05339    tassert(fid);
05340    resip::Data txt;
05341    char mBuf[1024];
05342    int result;
05343    while(!feof(fid))
05344    {
05345       result = fread(&mBuf,1,1024,fid);
05346       txt += resip::Data(mBuf,result);
05347    }
05348    fclose(fid);
05349    resip::SipMessage* msg = resip::SipMessage::make(txt);
05350    tassert_reset();
05351    tassert(msg);
05352    tassert_reset();
05353    if(!msg)
05354    {
05355       return;
05356    }
05357 
05358    std::auto_ptr<resip::SipMessage> message(msg);
05359    msg->parseAllHeaders();
05360 
05361    resip::SipMessage copy(*msg);
05362 
05363    resip::Data encoded;
05364    {
05365       resip::oDataStream str(encoded);
05366       msg->encode(str);
05367    }
05368    resip::Data copyEncoded;
05369    {
05370       resip::oDataStream str(copyEncoded);
05371       copy.encode(str);
05372    }
05373 
05374    InfoLog(<< "In case novelsc:" );
05375    InfoLog(<< "Original text:" << std::endl << txt );
05376    InfoLog(<< "Encoded form:" << std::endl << encoded );
05377    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
05378 
05379 
05380 
05381 
05382 }
05383 
05384 
05385 void
05386 regaut01()
05387 {
05388 /*
05389 
05390 REGISTER sip:example.com SIP/2.0
05391 To: sip:j.user@example.com
05392 From: sip:j.user@example.com;tag=87321hj23128
05393 Max-Forwards: 8
05394 Call-ID: regaut01.0ha0isndaksdj
05395 CSeq: 9338 REGISTER
05396 Via: SIP/2.0/TCP 192.0.2.253;branch=z9hG4bKkdjuw
05397 Authorization: NoOneKnowsThisScheme opaque-data=here
05398 Content-Length:0
05399 
05400 
05401 */
05402    FILE* fid= fopen("regaut01.dat","r");
05403    tassert(fid);
05404    resip::Data txt;
05405    char mBuf[1024];
05406    int result;
05407    while(!feof(fid))
05408    {
05409       result = fread(&mBuf,1,1024,fid);
05410       txt += resip::Data(mBuf,result);
05411    }
05412    fclose(fid);
05413    resip::SipMessage* msg = resip::SipMessage::make(txt);
05414    tassert_reset();
05415    tassert(msg);
05416    tassert_reset();
05417    if(!msg)
05418    {
05419       return;
05420    }
05421 
05422    std::auto_ptr<resip::SipMessage> message(msg);
05423    msg->parseAllHeaders();
05424 
05425    resip::SipMessage copy(*msg);
05426 
05427    resip::Data encoded;
05428    {
05429       resip::oDataStream str(encoded);
05430       msg->encode(str);
05431    }
05432    resip::Data copyEncoded;
05433    {
05434       resip::oDataStream str(copyEncoded);
05435       copy.encode(str);
05436    }
05437 
05438    InfoLog(<< "In case regaut01:" );
05439    InfoLog(<< "Original text:" << std::endl << txt );
05440    InfoLog(<< "Encoded form:" << std::endl << encoded );
05441    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
05442 
05443 
05444 
05445 
05446 }
05447 
05448 
05449 void
05450 regescrt()
05451 {
05452 /*
05453 
05454 REGISTER sip:example.com SIP/2.0
05455 To: sip:user@example.com
05456 From: sip:user@example.com;tag=8
05457 Max-Forwards: 70
05458 Call-ID: regescrt.k345asrl3fdbv@192.0.2.1
05459 CSeq: 14398234 REGISTER
05460 Via: SIP/2.0/UDP host5.example.com;branch=z9hG4bKkdjuw
05461 M: <sip:user@example.com?Route=%3Csip:sip.example.com%3E>
05462 L:0
05463 
05464 
05465 */
05466    FILE* fid= fopen("regescrt.dat","r");
05467    tassert(fid);
05468    resip::Data txt;
05469    char mBuf[1024];
05470    int result;
05471    while(!feof(fid))
05472    {
05473       result = fread(&mBuf,1,1024,fid);
05474       txt += resip::Data(mBuf,result);
05475    }
05476    fclose(fid);
05477    resip::SipMessage* msg = resip::SipMessage::make(txt);
05478    tassert_reset();
05479    tassert(msg);
05480    tassert_reset();
05481    if(!msg)
05482    {
05483       return;
05484    }
05485 
05486    std::auto_ptr<resip::SipMessage> message(msg);
05487    msg->parseAllHeaders();
05488 
05489    resip::SipMessage copy(*msg);
05490 
05491    resip::Data encoded;
05492    {
05493       resip::oDataStream str(encoded);
05494       msg->encode(str);
05495    }
05496    resip::Data copyEncoded;
05497    {
05498       resip::oDataStream str(copyEncoded);
05499       copy.encode(str);
05500    }
05501 
05502    InfoLog(<< "In case regescrt:" );
05503    InfoLog(<< "Original text:" << std::endl << txt );
05504    InfoLog(<< "Encoded form:" << std::endl << encoded );
05505    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
05506 
05507 
05508 
05509 
05510 }
05511 
05512 
05513 void
05514 sdp01()
05515 {
05516 /*
05517 
05518 INVITE sip:user@example.com SIP/2.0
05519 To: sip:j_user@example.com
05520 Contact: <sip:caller@host15.example.net>
05521 From: sip:caller@example.net;tag=234
05522 Max-Forwards: 5
05523 Call-ID: sdp01.ndaksdj9342dasdd
05524 Accept: text/nobodyKnowsThis
05525 CSeq: 8 INVITE
05526 Via: SIP/2.0/UDP 192.0.2.15;branch=z9hG4bKkdjuw
05527 Content-Length: 150
05528 Content-Type: application/sdp
05529 
05530 v=0
05531 o=mhandley 29739 7272939 IN IP4 192.0.2.5
05532 s=-
05533 c=IN IP4 192.0.2.5
05534 t=0 0
05535 m=audio 49217 RTP/AVP 0 12
05536 m=video 3227 RTP/AVP 31
05537 a=rtpmap:31 LPC
05538 
05539 */
05540    FILE* fid= fopen("sdp01.dat","r");
05541    tassert(fid);
05542    resip::Data txt;
05543    char mBuf[1024];
05544    int result;
05545    while(!feof(fid))
05546    {
05547       result = fread(&mBuf,1,1024,fid);
05548       txt += resip::Data(mBuf,result);
05549    }
05550    fclose(fid);
05551    resip::SipMessage* msg = resip::SipMessage::make(txt);
05552    tassert_reset();
05553    tassert(msg);
05554    tassert_reset();
05555    if(!msg)
05556    {
05557       return;
05558    }
05559 
05560    std::auto_ptr<resip::SipMessage> message(msg);
05561    msg->parseAllHeaders();
05562 
05563    resip::SipMessage copy(*msg);
05564 
05565    resip::Data encoded;
05566    {
05567       resip::oDataStream str(encoded);
05568       msg->encode(str);
05569    }
05570    resip::Data copyEncoded;
05571    {
05572       resip::oDataStream str(copyEncoded);
05573       copy.encode(str);
05574    }
05575 
05576    InfoLog(<< "In case sdp01:" );
05577    InfoLog(<< "Original text:" << std::endl << txt );
05578    InfoLog(<< "Encoded form:" << std::endl << encoded );
05579    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
05580 
05581 
05582 
05583 
05584 }
05585 
05586 
05587 void
05588 unkscm()
05589 {
05590 /*
05591 
05592 OPTIONS nobodyKnowsThisScheme:totallyopaquecontent SIP/2.0
05593 To: sip:user@example.com
05594 From: sip:caller@example.net;tag=384
05595 Max-Forwards: 3
05596 Call-ID: unkscm.nasdfasser0q239nwsdfasdkl34
05597 CSeq: 3923423 OPTIONS
05598 Via: SIP/2.0/TCP host9.example.com;branch=z9hG4bKkdjuw39234
05599 Content-Length: 0
05600 
05601 
05602 */
05603    FILE* fid= fopen("unkscm.dat","r");
05604    tassert(fid);
05605    resip::Data txt;
05606    char mBuf[1024];
05607    int result;
05608    while(!feof(fid))
05609    {
05610       result = fread(&mBuf,1,1024,fid);
05611       txt += resip::Data(mBuf,result);
05612    }
05613    fclose(fid);
05614    resip::SipMessage* msg = resip::SipMessage::make(txt);
05615    tassert_reset();
05616    tassert(msg);
05617    tassert_reset();
05618    if(!msg)
05619    {
05620       return;
05621    }
05622 
05623    std::auto_ptr<resip::SipMessage> message(msg);
05624    msg->parseAllHeaders();
05625 
05626    resip::SipMessage copy(*msg);
05627 
05628    resip::Data encoded;
05629    {
05630       resip::oDataStream str(encoded);
05631       msg->encode(str);
05632    }
05633    resip::Data copyEncoded;
05634    {
05635       resip::oDataStream str(copyEncoded);
05636       copy.encode(str);
05637    }
05638 
05639    InfoLog(<< "In case unkscm:" );
05640    InfoLog(<< "Original text:" << std::endl << txt );
05641    InfoLog(<< "Encoded form:" << std::endl << encoded );
05642    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
05643 
05644 
05645 
05646 
05647 }
05648 
05649 
05650 void
05651 unksm2()
05652 {
05653 /*
05654 
05655 REGISTER sip:example.com SIP/2.0
05656 To: isbn:2983792873
05657 From: <http://www.example.com>;tag=3234233
05658 Call-ID: unksm2.daksdj@hyphenated-host.example.com
05659 CSeq: 234902 REGISTER
05660 Max-Forwards: 70
05661 Via: SIP/2.0/UDP 192.0.2.21:5060;branch=z9hG4bKkdjuw
05662 Contact: <name:John_Smith>
05663 l: 0
05664 
05665 
05666 */
05667    FILE* fid= fopen("unksm2.dat","r");
05668    tassert(fid);
05669    resip::Data txt;
05670    char mBuf[1024];
05671    int result;
05672    while(!feof(fid))
05673    {
05674       result = fread(&mBuf,1,1024,fid);
05675       txt += resip::Data(mBuf,result);
05676    }
05677    fclose(fid);
05678    resip::SipMessage* msg = resip::SipMessage::make(txt);
05679    tassert_reset();
05680    tassert(msg);
05681    tassert_reset();
05682    if(!msg)
05683    {
05684       return;
05685    }
05686 
05687    std::auto_ptr<resip::SipMessage> message(msg);
05688    msg->parseAllHeaders();
05689 
05690    resip::SipMessage copy(*msg);
05691 
05692    resip::Data encoded;
05693    {
05694       resip::oDataStream str(encoded);
05695       msg->encode(str);
05696    }
05697    resip::Data copyEncoded;
05698    {
05699       resip::oDataStream str(copyEncoded);
05700       copy.encode(str);
05701    }
05702 
05703    InfoLog(<< "In case unksm2:" );
05704    InfoLog(<< "Original text:" << std::endl << txt );
05705    InfoLog(<< "Encoded form:" << std::endl << encoded );
05706    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
05707 
05708 
05709 
05710 
05711 }
05712 
05713 
05714 void
05715 zeromf()
05716 {
05717 /*
05718 
05719 OPTIONS sip:user@example.com SIP/2.0
05720 To: sip:user@example.com
05721 From: sip:caller@example.net;tag=3ghsd41
05722 Call-ID: zeromf.jfasdlfnm2o2l43r5u0asdfas
05723 CSeq: 39234321 OPTIONS
05724 Via: SIP/2.0/UDP host1.example.com;branch=z9hG4bKkdjuw2349i
05725 Max-Forwards: 0
05726 Content-Length: 0
05727 
05728 
05729 */
05730    FILE* fid= fopen("zeromf.dat","r");
05731    tassert(fid);
05732    resip::Data txt;
05733    char mBuf[1024];
05734    int result;
05735    while(!feof(fid))
05736    {
05737       result = fread(&mBuf,1,1024,fid);
05738       txt += resip::Data(mBuf,result);
05739    }
05740    fclose(fid);
05741    resip::SipMessage* msg = resip::SipMessage::make(txt);
05742    tassert_reset();
05743    tassert(msg);
05744    tassert_reset();
05745    if(!msg)
05746    {
05747       return;
05748    }
05749 
05750    std::auto_ptr<resip::SipMessage> message(msg);
05751    msg->parseAllHeaders();
05752 
05753    resip::SipMessage copy(*msg);
05754 
05755    resip::Data encoded;
05756    {
05757       resip::oDataStream str(encoded);
05758       msg->encode(str);
05759    }
05760    resip::Data copyEncoded;
05761    {
05762       resip::oDataStream str(copyEncoded);
05763       copy.encode(str);
05764    }
05765 
05766    InfoLog(<< "In case zeromf:" );
05767    InfoLog(<< "Original text:" << std::endl << txt );
05768    InfoLog(<< "Encoded form:" << std::endl << encoded );
05769    InfoLog(<< "Encoded form of copy:" << std::endl << copyEncoded );
05770 
05771 
05772 
05773 
05774 }
05775 
05776 
05777 int main()
05778 {
05779 
05780 resip::SipMessage::checkContentLength=true;
05781 
05782 resip::Log::initialize("cout", "DEBUG", "RFC4475TortureTests");
05783 try
05784 {
05785    wsinv();
05786 }
05787 catch(resip::BaseException& e)
05788 {
05789    tassert(0);
05790    tassert_reset();
05791    InfoLog(<< "Exception caught in test case wsinv : " << e );
05792    InfoLog(<< "This message was valid." );
05793 }
05794 
05795 
05796 try
05797 {
05798    intmeth();
05799 }
05800 catch(resip::BaseException& e)
05801 {
05802    tassert(0);
05803    tassert_reset();
05804    InfoLog(<< "Exception caught in test case intmeth : " << e );
05805    InfoLog(<< "This message was valid." );
05806 }
05807 
05808 
05809 try
05810 {
05811    esc01();
05812 }
05813 catch(resip::BaseException& e)
05814 {
05815    tassert(0);
05816    tassert_reset();
05817    InfoLog(<< "Exception caught in test case esc01 : " << e );
05818    InfoLog(<< "This message was valid." );
05819 }
05820 
05821 
05822 try
05823 {
05824    escnull();
05825 }
05826 catch(resip::BaseException& e)
05827 {
05828    tassert(0);
05829    tassert_reset();
05830    InfoLog(<< "Exception caught in test case escnull : " << e );
05831    InfoLog(<< "This message was valid." );
05832 }
05833 
05834 
05835 try
05836 {
05837    esc02();
05838 }
05839 catch(resip::BaseException& e)
05840 {
05841    tassert(0);
05842    tassert_reset();
05843    InfoLog(<< "Exception caught in test case esc02 : " << e );
05844    InfoLog(<< "This message was valid." );
05845 }
05846 
05847 
05848 try
05849 {
05850    lwsdisp();
05851 }
05852 catch(resip::BaseException& e)
05853 {
05854    tassert(0);
05855    tassert_reset();
05856    InfoLog(<< "Exception caught in test case lwsdisp : " << e );
05857    InfoLog(<< "This message was valid." );
05858 }
05859 
05860 
05861 try
05862 {
05863    longreq();
05864 }
05865 catch(resip::BaseException& e)
05866 {
05867    tassert(0);
05868    tassert_reset();
05869    InfoLog(<< "Exception caught in test case longreq : " << e );
05870    InfoLog(<< "This message was valid." );
05871 }
05872 
05873 
05874 try
05875 {
05876    dblreq();
05877 }
05878 catch(resip::BaseException& e)
05879 {
05880    tassert(0);
05881    tassert_reset();
05882    InfoLog(<< "Exception caught in test case dblreq : " << e );
05883    InfoLog(<< "This message was valid." );
05884 }
05885 
05886 
05887 try
05888 {
05889    semiuri();
05890 }
05891 catch(resip::BaseException& e)
05892 {
05893    tassert(0);
05894    tassert_reset();
05895    InfoLog(<< "Exception caught in test case semiuri : " << e );
05896    InfoLog(<< "This message was valid." );
05897 }
05898 
05899 
05900 try
05901 {
05902    transports();
05903 }
05904 catch(resip::BaseException& e)
05905 {
05906    tassert(0);
05907    tassert_reset();
05908    InfoLog(<< "Exception caught in test case transports : " << e );
05909    InfoLog(<< "This message was valid." );
05910 }
05911 
05912 
05913 try
05914 {
05915    mpart01();
05916 }
05917 catch(resip::BaseException& e)
05918 {
05919    tassert(0);
05920    tassert_reset();
05921    InfoLog(<< "Exception caught in test case mpart01 : " << e );
05922    InfoLog(<< "This message was valid." );
05923 }
05924 
05925 
05926 try
05927 {
05928    unreason();
05929 }
05930 catch(resip::BaseException& e)
05931 {
05932    tassert(0);
05933    tassert_reset();
05934    InfoLog(<< "Exception caught in test case unreason : " << e );
05935    InfoLog(<< "This message was valid." );
05936 }
05937 
05938 
05939 try
05940 {
05941    noreason();
05942 }
05943 catch(resip::BaseException& e)
05944 {
05945    tassert(0);
05946    tassert_reset();
05947    InfoLog(<< "Exception caught in test case noreason : " << e );
05948    InfoLog(<< "This message was valid." );
05949 }
05950 
05951 
05952 try
05953 {
05954    badinv01();
05955 }
05956 catch(resip::BaseException& e)
05957 {
05958    InfoLog(<< "Exception caught in test case badinv01 : " << e );
05959    InfoLog(<< "This message wasn't valid." );
05960 }
05961 
05962 
05963 try
05964 {
05965    clerr();
05966 }
05967 catch(resip::BaseException& e)
05968 {
05969    InfoLog(<< "Exception caught in test case clerr : " << e );
05970    InfoLog(<< "This message wasn't valid." );
05971 }
05972 
05973 
05974 try
05975 {
05976    scalar02();
05977 }
05978 catch(resip::BaseException& e)
05979 {
05980    InfoLog(<< "Exception caught in test case scalar02 : " << e );
05981    InfoLog(<< "This message wasn't valid." );
05982 }
05983 
05984 
05985 try
05986 {
05987    scalarlg();
05988 }
05989 catch(resip::BaseException& e)
05990 {
05991    InfoLog(<< "Exception caught in test case scalarlg : " << e );
05992    InfoLog(<< "This message wasn't valid." );
05993 }
05994 
05995 
05996 try
05997 {
05998    quotbal();
05999 }
06000 catch(resip::BaseException& e)
06001 {
06002    InfoLog(<< "Exception caught in test case quotbal : " << e );
06003    InfoLog(<< "This message wasn't valid." );
06004 }
06005 
06006 
06007 try
06008 {
06009    ltgtruri();
06010 }
06011 catch(resip::BaseException& e)
06012 {
06013    InfoLog(<< "Exception caught in test case ltgtruri : " << e );
06014    InfoLog(<< "This message wasn't valid." );
06015 }
06016 
06017 
06018 try
06019 {
06020    lwsruri();
06021 }
06022 catch(resip::BaseException& e)
06023 {
06024    InfoLog(<< "Exception caught in test case lwsruri : " << e );
06025    InfoLog(<< "This message wasn't valid." );
06026 }
06027 
06028 
06029 try
06030 {
06031    lwsstart();
06032 }
06033 catch(resip::BaseException& e)
06034 {
06035    InfoLog(<< "Exception caught in test case lwsstart : " << e );
06036    InfoLog(<< "This message wasn't valid." );
06037 }
06038 
06039 
06040 try
06041 {
06042    trws();
06043 }
06044 catch(resip::BaseException& e)
06045 {
06046    InfoLog(<< "Exception caught in test case trws : " << e );
06047    InfoLog(<< "This message wasn't valid." );
06048 }
06049 
06050 
06051 try
06052 {
06053    escruri();
06054 }
06055 catch(resip::BaseException& e)
06056 {
06057    InfoLog(<< "Exception caught in test case escruri : " << e );
06058    InfoLog(<< "This message wasn't valid." );
06059 }
06060 
06061 
06062 try
06063 {
06064    baddate();
06065 }
06066 catch(resip::BaseException& e)
06067 {
06068    InfoLog(<< "Exception caught in test case baddate : " << e );
06069    InfoLog(<< "This message wasn't valid." );
06070 }
06071 
06072 
06073 try
06074 {
06075    regbadct();
06076 }
06077 catch(resip::BaseException& e)
06078 {
06079    InfoLog(<< "Exception caught in test case regbadct : " << e );
06080    InfoLog(<< "This message wasn't valid." );
06081 }
06082 
06083 
06084 try
06085 {
06086    badaspec();
06087 }
06088 catch(resip::BaseException& e)
06089 {
06090    InfoLog(<< "Exception caught in test case badaspec : " << e );
06091    InfoLog(<< "This message wasn't valid." );
06092 }
06093 
06094 
06095 try
06096 {
06097    baddn();
06098 }
06099 catch(resip::BaseException& e)
06100 {
06101    InfoLog(<< "Exception caught in test case baddn : " << e );
06102    InfoLog(<< "This message wasn't valid." );
06103 }
06104 
06105 
06106 try
06107 {
06108    badvers();
06109 }
06110 catch(resip::BaseException& e)
06111 {
06112    InfoLog(<< "Exception caught in test case badvers : " << e );
06113    InfoLog(<< "This message wasn't valid." );
06114 }
06115 
06116 
06117 try
06118 {
06119    mismatch01();
06120 }
06121 catch(resip::BaseException& e)
06122 {
06123    InfoLog(<< "Exception caught in test case mismatch01 : " << e );
06124    InfoLog(<< "This message wasn't valid." );
06125 }
06126 
06127 
06128 try
06129 {
06130    mismatch02();
06131 }
06132 catch(resip::BaseException& e)
06133 {
06134    InfoLog(<< "Exception caught in test case mismatch02 : " << e );
06135    InfoLog(<< "This message wasn't valid." );
06136 }
06137 
06138 
06139 try
06140 {
06141    bigcode();
06142 }
06143 catch(resip::BaseException& e)
06144 {
06145    InfoLog(<< "Exception caught in test case bigcode : " << e );
06146    InfoLog(<< "This message wasn't valid." );
06147 }
06148 
06149 
06150 try
06151 {
06152    badbranch();
06153 }
06154 catch(resip::BaseException& e)
06155 {
06156    tassert(0);
06157    tassert_reset();
06158    InfoLog(<< "Exception caught in test case badbranch : " << e );
06159    InfoLog(<< "This message was (syntactically) valid." );
06160 }
06161 
06162 
06163 try
06164 {
06165    bcast();
06166 }
06167 catch(resip::BaseException& e)
06168 {
06169    InfoLog(<< "Exception caught in test case bcast : " << e );
06170    InfoLog(<< "This message was/wasn't valid." );
06171 }
06172 
06173 
06174 try
06175 {
06176    bext01();
06177 }
06178 catch(resip::BaseException& e)
06179 {
06180    InfoLog(<< "Exception caught in test case bext01 : " << e );
06181    InfoLog(<< "This message was/wasn't valid." );
06182 }
06183 
06184 
06185 try
06186 {
06187    cparam01();
06188 }
06189 catch(resip::BaseException& e)
06190 {
06191    InfoLog(<< "Exception caught in test case cparam01 : " << e );
06192    InfoLog(<< "This message was/wasn't valid." );
06193 }
06194 
06195 
06196 try
06197 {
06198    cparam02();
06199 }
06200 catch(resip::BaseException& e)
06201 {
06202    InfoLog(<< "Exception caught in test case cparam02 : " << e );
06203    InfoLog(<< "This message was/wasn't valid." );
06204 }
06205 
06206 
06207 try
06208 {
06209    insuf();
06210 }
06211 catch(resip::BaseException& e)
06212 {
06213    InfoLog(<< "Exception caught in test case insuf : " << e );
06214    InfoLog(<< "This message was/wasn't valid." );
06215 }
06216 
06217 
06218 try
06219 {
06220    inv2543();
06221 }
06222 catch(resip::BaseException& e)
06223 {
06224    InfoLog(<< "Exception caught in test case inv2543 : " << e );
06225    InfoLog(<< "This message was/wasn't valid." );
06226 }
06227 
06228 
06229 try
06230 {
06231    invut();
06232 }
06233 catch(resip::BaseException& e)
06234 {
06235    InfoLog(<< "Exception caught in test case invut : " << e );
06236    InfoLog(<< "This message was/wasn't valid." );
06237 }
06238 
06239 
06240 try
06241 {
06242    mcl01();
06243 }
06244 catch(resip::BaseException& e)
06245 {
06246    InfoLog(<< "Exception caught in test case mcl01 : " << e );
06247    InfoLog(<< "This message was/wasn't valid." );
06248 }
06249 
06250 
06251 try
06252 {
06253    multi01();
06254 }
06255 catch(resip::BaseException& e)
06256 {
06257    InfoLog(<< "Exception caught in test case multi01 : " << e );
06258    InfoLog(<< "This message was/wasn't valid." );
06259 }
06260 
06261 
06262 try
06263 {
06264    ncl();
06265 }
06266 catch(resip::BaseException& e)
06267 {
06268    InfoLog(<< "Exception caught in test case ncl : " << e );
06269    InfoLog(<< "This message wasn't valid." );
06270 }
06271 
06272 
06273 try
06274 {
06275    novelsc();
06276 }
06277 catch(resip::BaseException& e)
06278 {
06279    InfoLog(<< "Exception caught in test case novelsc : " << e );
06280    InfoLog(<< "This message was/wasn't valid." );
06281 }
06282 
06283 
06284 try
06285 {
06286    regaut01();
06287 }
06288 catch(resip::BaseException& e)
06289 {
06290    InfoLog(<< "Exception caught in test case regaut01 : " << e );
06291    InfoLog(<< "This message was/wasn't valid." );
06292 }
06293 
06294 
06295 try
06296 {
06297    regescrt();
06298 }
06299 catch(resip::BaseException& e)
06300 {
06301    InfoLog(<< "Exception caught in test case regescrt : " << e );
06302    InfoLog(<< "This message was/wasn't valid." );
06303 }
06304 
06305 
06306 try
06307 {
06308    sdp01();
06309 }
06310 catch(resip::BaseException& e)
06311 {
06312    InfoLog(<< "Exception caught in test case sdp01 : " << e );
06313    InfoLog(<< "This message was/wasn't valid." );
06314 }
06315 
06316 
06317 try
06318 {
06319    unkscm();
06320 }
06321 catch(resip::BaseException& e)
06322 {
06323    InfoLog(<< "Exception caught in test case unkscm : " << e );
06324    InfoLog(<< "This message was/wasn't valid." );
06325 }
06326 
06327 
06328 try
06329 {
06330    unksm2();
06331 }
06332 catch(resip::BaseException& e)
06333 {
06334    InfoLog(<< "Exception caught in test case unksm2 : " << e );
06335    InfoLog(<< "This message was/wasn't valid." );
06336 }
06337 
06338 
06339 try
06340 {
06341    zeromf();
06342 }
06343 catch(resip::BaseException& e)
06344 {
06345    InfoLog(<< "Exception caught in test case zeromf : " << e );
06346    InfoLog(<< "This message was/wasn't valid." );
06347 }
06348 
06349 
06350 }
06351 
06352 /* ====================================================================
06353  * The Vovida Software License, Version 1.0
06354  *
06355  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
06356  *
06357  * Redistribution and use in source and binary forms, with or without
06358  * modification, are permitted provided that the following conditions
06359  * are met:
06360  *
06361  * 1. Redistributions of source code must retain the above copyright
06362  *    notice, this list of conditions and the following disclaimer.
06363  *
06364  * 2. Redistributions in binary form must reproduce the above copyright
06365  *    notice, this list of conditions and the following disclaimer in
06366  *    the documentation and/or other materials provided with the
06367  *    distribution.
06368  *
06369  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
06370  *    and "Vovida Open Communication Application Library (VOCAL)" must
06371  *    not be used to endorse or promote products derived from this
06372  *    software without prior written permission. For written
06373  *    permission, please contact vocal@vovida.org.
06374  *
06375  * 4. Products derived from this software may not be called "VOCAL", nor
06376  *    may "VOCAL" appear in their name, without prior written
06377  *    permission of Vovida Networks, Inc.
06378  *
06379  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
06380  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
06381  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
06382  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
06383  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
06384  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
06385  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
06386  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
06387  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
06388  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
06389  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
06390  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
06391  * DAMAGE.
06392  *
06393  * ====================================================================
06394  *
06395  * This software consists of voluntary contributions made by Vovida
06396  * Networks, Inc. and many individuals on behalf of Vovida Networks,
06397  * Inc.  For more information on Vovida Networks, Inc., please see
06398  * <http://www.vovida.org/>.
06399  *
06400  */