Show
Ignore:
Timestamp:
01/02/08 00:03:39 (1 year ago)
Author:
daboo
Message:

Lots of CardDAV stuff.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Mulberry/branches/v4.1d1/Sources_Common/HTTP/CardDAVClient/CCardDAVMakeAdbk.cpp

    r86 r148  
    2424#include "CCardDAVMakeAdbk.h" 
    2525 
     26#include "CHTTPDataString.h" 
     27#include "CWebDAVDefinitions.h" 
     28#include "XMLDocument.h" 
     29#include "XMLNode.h" 
     30 
     31#include <strstream> 
     32 
     33using namespace webdav;  
    2634using namespace carddav;  
    2735 
    2836CCardDAVMakeAdbk::CCardDAVMakeAdbk(CWebDAVSession* session, const cdstring& ruri) : 
    29         CWebDAVRequestResponse(session, eRequest_MKADBK, ruri) 
     37        CWebDAVMakeCollection(session, ruri) 
    3038{ 
     39        InitRequestData(); 
    3140} 
    3241 
     
    3645} 
    3746 
     47void CCardDAVMakeAdbk::InitRequestData() 
     48{ 
     49        // Write XML info to a string 
     50        std::ostrstream os; 
     51        GenerateXML(os); 
     52        os << ends; 
     53 
     54        mRequestData = new CHTTPInputDataString(os.str(), "text/xml; charset=utf-8"); 
     55} 
     56 
     57void CCardDAVMakeAdbk::GenerateXML(ostream& os) 
     58{ 
     59        using namespace xmllib; 
     60 
     61        // Structure of document is: 
     62        // 
     63        // <DAV:mkcol> 
     64        //   <DAV:set> 
     65        //     <DAV:prop> 
     66        //       <DAV:resource-type> 
     67        //         <DAV:collection/> 
     68        //         <CARDDAV:addressbook/> 
     69        //       </DAV:resource-type> 
     70        //     </DAV:prop> 
     71        //   </DAV:set> 
     72        // </DAV:mkcol> 
     73         
     74        // Create document and get the root 
     75        xmllib::XMLDocument xmldoc; 
     76         
     77        // <DAV:mkcol> element 
     78        xmllib::XMLNode* mkcol = xmldoc.GetRoot(); 
     79        xmllib::XMLNamespace dav_namespc(http::webdav::cNamespace, "D"); 
     80        xmllib::XMLNamespace carddav_namespc(carddav::cNamespace, "C"); 
     81        mkcol->SetName(http::webdav::cElement_mkcol.Name(), dav_namespc); 
     82        mkcol->AddNamespace(dav_namespc); 
     83         
     84        // <DAV:set> element 
     85        xmllib::XMLNode* set = new xmllib::XMLNode(&xmldoc, mkcol, cElement_set.Name(), dav_namespc); 
     86         
     87        // <DAV:prop> element 
     88        xmllib::XMLNode* prop = new xmllib::XMLNode(&xmldoc, set, cElement_prop.Name(), dav_namespc); 
     89         
     90        // <DAV:resourcetype> element 
     91        xmllib::XMLNode* resourcetype = new xmllib::XMLNode(&xmldoc, prop, cProperty_resourcetype.Name(), dav_namespc); 
     92         
     93        // <DAV:collection> element 
     94        new xmllib::XMLNode(&xmldoc, resourcetype, cProperty_collection.Name(), dav_namespc); 
     95         
     96        // <DAV:resourcetype> element 
     97        new xmllib::XMLNode(&xmldoc, resourcetype, cProperty_carddavadbk.Name(), carddav_namespc); 
     98         
     99        // Now we have the complete document, so write it out (no indentation) 
     100        xmldoc.Generate(os, false); 
     101}