reSIProcate/stack  9694
testHack.cxx
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <memory>
00003 
00004 #include "resip/stack/MultipartMixedContents.hxx"
00005 #include "resip/stack/Rlmi.hxx"
00006 #include "resip/stack/Pidf.hxx"
00007 #include "resip/stack/Pkcs7Contents.hxx"
00008 #include "resip/stack/MultipartSignedContents.hxx"
00009 #include "resip/stack/SipMessage.hxx"
00010 #include "resip/stack/test/TestSupport.hxx"
00011 #include "rutil/ParseBuffer.hxx"
00012 
00013 #include "resip/stack/UnknownParameterType.hxx"
00014 #include "rutil/XMLCursor.hxx"
00015 
00016 using namespace resip;
00017 using namespace std;
00018 
00019 void indent(int indent)
00020 {
00021    for (int i = 0; i < 3*indent; ++i)
00022    {
00023       cerr << " ";
00024    }
00025 }
00026 
00027 static UnknownParameterType p_start("start");
00028 static UnknownParameterType p_type("type");
00029 
00030 Rlmi* findRlmi(const MultipartMixedContents* mp)
00031 {
00032   Mime type = mp->getType();
00033 
00034   if (type.exists(p_type))
00035   {
00036     if ( type.param(p_type)==Data("application/rlmi+xml") )
00037     {
00038        if (type.exists(p_start))
00039        {
00040          const Data& start = type.param(p_start);
00041          for (MultipartMixedContents::Parts::const_iterator i = mp->parts().begin();
00042               i != mp->parts().end(); ++i)
00043          {
00044             if ((*i)->exists(h_ContentID))
00045             {
00046               if ((*i)->header(h_ContentID).value()==start)
00047               {
00048                 Rlmi *rlmi;
00049                 if ( (rlmi=dynamic_cast<Rlmi*>(*i))) return rlmi;
00050               }
00051             } 
00052          }
00053        }
00054     }
00055   }    
00056   cerr << "Not dealing well with this document - can't find the top level rlmi\n";
00057   assert(0);
00058 }
00059 
00060 void interpretRlmi(Rlmi *rlmi)
00061 {
00062   cerr << "Attempting to build an XMLCursor " << endl;
00063   cerr << "Working over" << rlmi->get() << endl << "Length is : " << rlmi->get().size() << endl;
00064   
00065   ParseBuffer pb(rlmi->get().data(),rlmi->get().size());
00066   cerr << "Got a parsebuffer" << endl;
00067 
00068   XMLCursor xmlc(pb);
00069 
00070   cerr << "Attempting to use this XMLCursor " << endl;
00071 
00072   cerr << "getTag() returns" << xmlc.getTag() << endl;
00073   assert(xmlc.getTag()=="list");
00074   assert(xmlc.getAttributes().find("uri")!=xmlc.getAttributes().end());
00075   cout << "Found a list for " <<  (*(xmlc.getAttributes().find("uri"))).second << endl;
00076 
00077 }
00078 
00079 void
00080 traverseMulti(const MultipartMixedContents* mp,
00081               int level = 0)
00082 {
00083       for (MultipartRelatedContents::Parts::const_iterator i = mp->parts().begin();
00084            i != mp->parts().end(); ++i)
00085       {
00086          Pidf* pidf;
00087          Rlmi* rlmi;
00088 //         MultipartSignedContents* mps;
00089          MultipartMixedContents* mpm;
00090          Pkcs7Contents* pkcs7;
00091 
00092          if ((pidf = dynamic_cast<Pidf*>(*i)))
00093          {
00094             indent(level);
00095             cerr << "discovered a Pidf" << endl;
00096          } 
00097          else if ((rlmi = dynamic_cast<Rlmi*>(*i)))
00098          {
00099             indent(level);
00100             cerr << "discovered a Rlmi" << endl;
00101          }
00102          else if ((pkcs7 = dynamic_cast<Pkcs7Contents*>(*i)))
00103          {
00104             indent(level);
00105             cerr << "discovered a Pkcs7Contents" << endl;
00106          }
00107          else if ((mpm = dynamic_cast<MultipartMixedContents*>(*i)))
00108          {
00109             indent(level);
00110             cerr << "discovered a multipart with " << mpm->parts().size() << " parts " << endl;
00111             traverseMulti(mpm, level+1);
00112          }
00113          else 
00114          {
00115             indent(level);
00116             cerr << "Some other kind of content!" << endl;
00117          }
00118       }
00119 }
00120 
00121 // http://www.softarmor.com/simple/drafts/draft-ietf-simple-event-list-04.txt
00122 int
00123 main()
00124 {
00125    {
00126       const Data tx0("NOTIFY sip:terminal.example.com SIP/2.0\r\n"
00127                      "Via: SIP/2.0/TCP pres.example.com;branch=z9hG4bKMgRenTETmm\r\n"
00128                      "Max-Forwards: 70\r\n"
00129                      "From: <sip:adam-buddies@pres.example.com>;tag=zpNctbZq\r\n"
00130                      "To: <sip:adam@example.com>;tag=ie4hbb8t\r\n"
00131                      "Call-ID: cdB34qLToC@terminal.example.com\r\n"
00132                      "CSeq: 997935768 NOTIFY\r\n"
00133                      "Contact: <sip:pres.example.com>\r\n"
00134                      "Event: presence\r\n"
00135                      "Subscription-State: active;expires=7200\r\n"
00136                      "Require: eventlist\r\n"
00137                      "Content-Type: multipart/related;type=\"application/rlmi+xml\";\r\n"
00138                      "    start=\"<nXYxAE@pres.example.com>\";boundary=\"50UBfW7LSCVLtggUPe5z\"\r\n"
00139                      "Content-Length: 1560\r\n"
00140                      "\r\n"
00141                      "--50UBfW7LSCVLtggUPe5z\r\n"
00142                      "Content-Transfer-Encoding: binary\r\n"
00143                      "Content-ID: <nXYxAE@pres.example.com>\r\n"
00144                      "Content-Type: application/rlmi+xml;charset=\"UTF-8\"\r\n"
00145                      "\r\n"
00146                      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
00147                      "<list xmlns=\"urn:ietf:params:xml:ns:rmli\"\r\n"
00148                      "      uri=\"sip:adam-friends@pres.example.com\" version=\"1\"\r\n"
00149                      "      name=\"Buddy List at COM\" fullState=\"true\">\r\n"
00150                      "  <resource uri=\"sip:bob@example.com\" name=\"Bob Smith\">\r\n"
00151                      "    <instance id=\"juwigmtboe\" state=\"active\"\r\n"
00152                      "              cid=\"bUZBsM@pres.example.com\"/>\r\n"
00153                      "  </resource>\r\n"
00154                      "  <resource uri=\"sip:dave@example.com\" name=\"Dave Jones\">\r\n"
00155                      "    <instance id=\"hqzsuxtfyq\" state=\"active\"\r\n"
00156                      "              cid=\"ZvSvkz@pres.example.com\"/>\r\n"
00157                      "  </resource>\r\n"
00158                      "  <resource uri=\"sip:ed@example.net\" name=\"Ed at NET\" />\r\n"
00159                      "  <resource uri=\"sip:adam-friends@example.org\"\r\n"
00160                      "            name=\"My Friends at ORG\" />\r\n"
00161                      "</list>\r\n"
00162                      "\r\n"
00163                      "--50UBfW7LSCVLtggUPe5z\r\n"
00164                      "Content-Transfer-Encoding: binary\r\n"
00165                      "Content-ID: <bUZBsM@pres.example.com>\r\n"
00166                      "Content-Type: application/pidf+xml;charset=\"UTF-8\"\r\n"
00167                      "\r\n"
00168                      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
00169                      "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\r\n"
00170                      "    entity=\"sip:bob@example.com\">\r\n"
00171                      "  <tuple id=\"sg89ae\">\r\n"
00172                      "    <status>\r\n"
00173                      "      <basic>open</basic>\r\n"
00174                      "    </status>\r\n"
00175                      "    <contact priority=\"1.0\">sip:bob@example.com</contact>\r\n"
00176                      "  </tuple>\r\n"
00177                      "</presence>\r\n"
00178                      "\r\n"
00179                      "--50UBfW7LSCVLtggUPe5z\r\n"
00180                      "Content-Transfer-Encoding: binary\r\n"
00181                      "Content-ID: <ZvSvkz@pres.example.com>\r\n"
00182                      "Content-Type: application/pidf+xml;charset=\"UTF-8\"\r\n"
00183                      "\r\n"
00184                      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
00185                      "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\r\n"
00186                      "    entity=\"sip:dave@example.com\">\r\n"
00187                      "  <tuple id=\"slie74\">\r\n"
00188                      "    <status>\r\n"
00189                      "      <basic>closed</basic>\r\n"
00190                      "    </status>\r\n"
00191                      "  </tuple>\r\n"
00192                      "</presence>\r\n"
00193                      "\r\n"
00194                      "--50UBfW7LSCVLtggUPe5z--\r\n");
00195 
00196       const Data txt("NOTIFY sip:terminal.example.com SIP/2.0\r\n"
00197                      "Via: SIP/2.0/TCP pres.example.com;branch=z9hG4bK4EPlfSFQK1\r\n"
00198                      "Max-Forwards: 70\r\n"
00199                      "From: <sip:adam-buddies@pres.example.com>;tag=zpNctbZq\r\n"
00200                      "To: <sip:adam@example.com>;tag=ie4hbb8t\r\n"
00201                      "Call-ID: cdB34qLToC@terminal.example.com\r\n"
00202                      "CSeq: 997935769 NOTIFY\r\n"
00203                      "Contact: <sip:pres.example.com>\r\n"
00204                      "Event: presence\r\n"
00205                      "Subscription-State: active;expires=7200\r\n"
00206                      "Require: eventlist\r\n"
00207                      "Content-Type: multipart/related;type=\"application/rlmi+xml\";\r\n"
00208                      "    start=\"<2BEI83@pres.example.com>\";boundary=\"TfZxoxgAvLqgj4wRWPDL\"\r\n"
00209                      "Content-Length: 2862\r\n"
00210                      "\r\n"
00211                      "--TfZxoxgAvLqgj4wRWPDL\r\n"
00212                      "Content-Transfer-Encoding: binary\r\n"
00213                      "Content-ID: <2BEI83@pres.example.com>\r\n"
00214                      "Content-Type: application/rlmi+xml;charset=\"UTF-8\"\r\n"
00215                      "\r\n"
00216                      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
00217                      "<list xmlns=\"urn:ietf:params:xml:ns:rmli\"\r\n"
00218                      "      uri=\"sip:adam-friends@pres.example.com\" version=\"2\"\r\n"
00219                      "      name=\"Buddy List at COM\" fullState=\"false\">\r\n"
00220                      "  <resource uri=\"sip:ed@example.net\" name=\"Ed at NET\">\r\n"
00221                      "    <instance id=\"sdlkmeopdf\" state=\"pending\"/>\r\n"
00222                      "  </resource>\r\n"
00223                      "  <resource uri=\"sip:adam-friends@example.org\"\r\n"
00224                      "            name=\"My Friends at ORG\">\r\n"
00225                      "    <instance id=\"cmpqweitlp\" state=\"active\"\r\n"
00226                      "              cid=\"1KQhyE@pres.example.com\"/>\r\n"
00227                      "  </resource>\r\n"
00228                      "</list>\r\n"
00229                      "\r\n"
00230                      "--TfZxoxgAvLqgj4wRWPDL\r\n"
00231                      "Content-Transfer-Encoding: binary\r\n"
00232                      "Content-ID: <1KQhyE@pres.example.com>\r\n"
00233                      "Content-Type: multipart/signed;\r\n"
00234                      "    protocol=\"application/pkcs7-signature\";\r\n"
00235                      "    micalg=sha1;boundary=\"l3WMZaaL8NpQWGnQ4mlU\"\r\n"
00236                      "\r\n"
00237                      "--l3WMZaaL8NpQWGnQ4mlU\r\n"
00238                      "Content-Transfer-Encoding: binary\r\n"
00239                      "Content-ID: <ZPvJHL@example.org>\r\n"
00240                      "Content-Type: multipart/related;type=\"application/rlmi+xml\";\r\n"
00241                      "    start=\"<Cvjpeo@example.org>\";boundary=\"tuLLl3lDyPZX0GMr2YOo\"\r\n"
00242                      "\r\n"
00243                      "--tuLLl3lDyPZX0GMr2YOo\r\n"
00244                      "Content-Transfer-Encoding: binary\r\n"
00245                      "Content-ID: <Cvjpeo@example.org>\r\n"
00246                      "Content-Type: application/rlmi+xml;charset=\"UTF-8\"\r\n"
00247                      "\r\n"
00248                      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
00249                      "<list xmlns=\"urn:ietf:params:xml:ns:rmli\"\r\n"
00250                      "      uri=\"sip:adam-friends@example.org\" version=\"1\"\r\n"
00251                      "      name=\"Buddy List at ORG\" fullState=\"true\">\r\n"
00252                      "  <resource uri=\"sip:joe@example.org\" name=\"Joe Thomas\">\r\n"
00253                      "    <instance id=\"1\" state=\"active\" cid=\"mrEakg@example.org\"/>\r\n"
00254                      "  </resource>\r\n"
00255                      "  <resource uri=\"sip:mark@example.org\" name=\"Mark Edwards\">\r\n"
00256                      "    <instance id=\"1\" state=\"active\" cid=\"KKMDmv@example.org\"/>\r\n"
00257                      "  </resource>\r\n"
00258                      "</list>\r\n"
00259                      "\r\n"
00260                      "--tuLLl3lDyPZX0GMr2YOo\r\n"
00261                      "Content-Transfer-Encoding: binary\r\n"
00262                      "Content-ID: <mrEakg@example.org>\r\n"
00263                      "Content-Type: application/pidf+xml;charset=\"UTF-8\"\r\n"
00264                      "\r\n"
00265                      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
00266                      "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\r\n"
00267                      "    entity=\"sip:joe@example.org\">\r\n"
00268                      "  <tuple id=\"7823a4\">\r\n"
00269                      "    <status>\r\n"
00270                      "      <basic>open</basic>\r\n"
00271                      "    </status>\r\n"
00272                      "    <contact priority=\"1.0\">sip:joe@example.org</contact>\r\n"
00273                      "  </tuple>\r\n"
00274                      "</presence>\r\n"
00275                      "\r\n"
00276                      "--tuLLl3lDyPZX0GMr2YOo\r\n"
00277                      "Content-Transfer-Encoding: binary\r\n"
00278                      "Content-ID: <KKMDmv@example.org>\r\n"
00279                      "Content-Type: application/pidf+xml;charset=\"UTF-8\"\r\n"
00280                      "\r\n"
00281                      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
00282                      "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\r\n"
00283                      "    entity=\"sip:mark@example.org\">\r\n"
00284                      "  <tuple id=\"398075\">\r\n"
00285                      "    <status>\r\n"
00286                      "      <basic>closed</basic>\r\n"
00287                      "    </status>\r\n"
00288                      "  </tuple>\r\n"
00289                      "</presence>\r\n"
00290                      "\r\n"
00291                      "--tuLLl3lDyPZX0GMr2YOo--\r\n"
00292                      "\r\n"
00293                      "--l3WMZaaL8NpQWGnQ4mlU\r\n"
00294                      "Content-Transfer-Encoding: binary\r\n"
00295                      "Content-ID: <K9LB7k@example.org>\r\n"
00296                      "Content-Type: application/pkcs7-signature\r\n"
00297                      "\r\n"
00298                      "[PKCS #7 signature here]\r\n"
00299                      "\r\n"
00300                      "--l3WMZaaL8NpQWGnQ4mlU--\r\n"
00301                      "\r\n"
00302                      "--TfZxoxgAvLqgj4wRWPDL--\r\n");
00303 
00304       auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt.c_str()));
00305 
00306       MultipartRelatedContents* mpc = dynamic_cast<MultipartRelatedContents*>(msg->getContents());
00307       Rlmi* rlmi = NULL;
00308       if (mpc)
00309       {
00310         rlmi = findRlmi(mpc);
00311       } else
00312       {
00313         rlmi = dynamic_cast<Rlmi*>(msg->getContents());
00314       }
00315       assert(rlmi);
00316       interpretRlmi(rlmi);
00317    }
00318 
00319    return 0;
00320 }
00321 
00322 /* ====================================================================
00323  * The Vovida Software License, Version 1.0 
00324  * 
00325  * Copyright (c) 2000-2005 Vovida Networks, Inc.  All rights reserved.
00326  * 
00327  * Redistribution and use in source and binary forms, with or without
00328  * modification, are permitted provided that the following conditions
00329  * are met:
00330  * 
00331  * 1. Redistributions of source code must retain the above copyright
00332  *    notice, this list of conditions and the following disclaimer.
00333  * 
00334  * 2. Redistributions in binary form must reproduce the above copyright
00335  *    notice, this list of conditions and the following disclaimer in
00336  *    the documentation and/or other materials provided with the
00337  *    distribution.
00338  * 
00339  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00340  *    and "Vovida Open Communication Application Library (VOCAL)" must
00341  *    not be used to endorse or promote products derived from this
00342  *    software without prior written permission. For written
00343  *    permission, please contact vocal@vovida.org.
00344  *
00345  * 4. Products derived from this software may not be called "VOCAL", nor
00346  *    may "VOCAL" appear in their name, without prior written
00347  *    permission of Vovida Networks, Inc.
00348  * 
00349  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00350  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00351  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00352  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00353  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00354  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00355  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00356  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00357  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00358  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00359  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00360  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00361  * DAMAGE.
00362  * 
00363  * ====================================================================
00364  * 
00365  * This software consists of voluntary contributions made by Vovida
00366  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00367  * Inc.  For more information on Vovida Networks, Inc., please see
00368  * <http://www.vovida.org/>.
00369  *
00370  */