1583
static const ne_propname getetag[] = {
1584
{ "DAV:", "getetag" },
1585
{ "DAV:", "resourcetype" },
1589
static int FoundItem(bool &isEmpty,
1590
const std::string &href,
1591
const std::string &etag,
1592
const std::string &status)
1595
Neon::Status parsed;
1596
// Err on the side of caution: if unsure about status, include item.
1597
if (parsed.parse(status.c_str()) ||
1598
parsed.klass == 2) {
1602
return isEmpty ? 0 : 100;
1582
1605
bool WebDAVSource::isEmpty()
1584
1607
contactServer();
1586
// listing all items is relatively efficient, let's use that
1587
// TODO: use truncated result search
1588
RevisionMap_t revisions;
1589
listAllItems(revisions);
1590
return revisions.empty();
1610
if (!getContentMixed()) {
1611
// Can use simple PROPFIND because we do not have to
1612
// double-check that each item really contains the right data.
1613
bool failed = false;
1614
RevisionMap_t revisions;
1615
Timespec deadline = createDeadline();
1616
m_session->propfindURI(m_calendar.m_path, 1, getetag,
1617
boost::bind(&WebDAVSource::listAllItemsCallback,
1618
this, _1, _2, boost::ref(revisions),
1619
boost::ref(failed)),
1622
SE_THROW("incomplete listing of all items");
1624
isEmpty = revisions.empty();
1626
// Have to filter items on the server and set result to false
1627
// when we get items back.
1629
const std::string query =
1630
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
1631
"<C:calendar-query xmlns:D=\"DAV:\"\n"
1632
"xmlns:C=\"urn:ietf:params:xml:ns:caldav\">\n"
1636
// Only get items of the right kind. In listAllItems() we
1637
// don't trust the server to implement this correctly and
1638
// double-check by downloading the data and looking into
1639
// it, but here we are less concerned. It is less important
1640
// to have reliable "is empty" information as long as we
1641
// err on the side of returning "not empty" too often.
1643
"<C:comp-filter name=\"VCALENDAR\">\n"
1644
"<C:comp-filter name=\"" + getContent() + "\">\n"
1645
"</C:comp-filter>\n"
1646
"</C:comp-filter>\n"
1648
"</C:calendar-query>\n";
1649
Timespec deadline = createDeadline();
1650
getSession()->startOperation("REPORT 'check for items'", deadline);
1652
Neon::XMLParser parser;
1653
parser.initAbortingReportParser(boost::bind(FoundItem,
1654
boost::ref(isEmpty),
1656
Neon::Request report(*getSession(), "REPORT", getCalendar().m_path, query, parser);
1657
report.addHeader("Depth", "1");
1658
report.addHeader("Content-Type", "application/xml; charset=\"utf-8\"");
1659
if (getSession()->run(report, NULL, !boost::lambda::var(isEmpty))) {
1665
SE_LOG_DEBUG(getDisplayName(), "is %s", isEmpty ? "empty" : "not empty");
1593
1669
bool WebDAVSource::isUsable()