| | 47 | void 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 | |
| | 57 | void 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 | } |