Logo Search packages:      
Sourcecode: akonadi-googledata version File versions  Download package

int GCalResource::getUpdated ( char *  timestamp ) [protected]

XXX: google server has a bug where a 2.0 protocol request is being met with a 2.1 protocol behaviour (if updated-min > 30 days, return a HTTP 410 error). Further details: http://code.google.com/p/gdata-issues/issues/detail?id=1036

The workaround is:

  • add a new dummy entry
  • save the dummy timestamp
  • delete the dummy
  • force a slow sync

Definition at line 269 of file gcalresource.cpp.

{
      int result = 0;
      gcal_event_t event;
      QString newerTimestamp;
      QString temp;
      KCal::Incidence::Status status = KCal::Incidence::StatusConfirmed;
      KDateTime start, end;
      QByteArray t_byte;
      KCal::Event *kevent;
      IncidencePtr ptrEvent;
      KUrl url;
      /* Just in case, I'm not sure when this member function is called */
      pending.clear();
      deleted.clear();

      kError() << "Timestamp of last updated event is: " << timestamp;
      gcal_cleanup_events(&all_events);
      gcal_deleted(gcal, SHOW);
      if ((result = gcal_get_updated_events(gcal, &all_events, timestamp))) {

        /** XXX: google server has a bug where a 2.0 protocol request
         * is being met with a 2.1 protocol behaviour
         * (if updated-min > 30 days, return a HTTP 410 error).
         * Further details:
         * http://code.google.com/p/gdata-issues/issues/detail?id=1036
         *
         * The workaround is:
         * - add a new dummy entry
         * - save the dummy timestamp
         * - delete the dummy
         * - force a slow sync
         */
            int gBug = gcal_status_httpcode(gcal);
            if (gBug != 410) {
                  qDebug() << "Failed querying by updated";
                  return result;
            } else {
                  qDebug() << "Workarounding bug: HTTP 410 Gone...";
                  gcal_event_t event;
                  if (!(event = gcal_event_new(NULL))) {
                        qDebug() << "Failed allocating HTTP 410 event";
                        return result;
                  }

                  gcal_event_set_title(event, "HTTP 410 workaround");
                  gcal_event_set_start(event, "2009-06-30T21:00:00Z");
                  gcal_event_set_end(event, "2009-06-30T22:00:00Z");
                  if ((result = gcal_add_event(gcal, event))) {
                        qDebug() << "Failed adding HTTP 410 event";
                        return result;
                  }

                  newerTimestamp = gcal_event_get_updated(event);
                  saveTimestamp(newerTimestamp);

                  if ((result = gcal_erase_event(gcal, event))) {
                        qDebug() << "Failed deleting HTTP 410 event";
                        return result;
                  }

                  gcal_event_delete(event);

                  if ((result = gcal_get_events(gcal, &all_events))) {
                        qDebug() << "Failed slowsync...";
                        return result;
                  }

                  qDebug() << "Forcing slow sync: HTTP 410";
            }

      }
      kError() << "Updated events are: " << all_events.length;


      /* Query is inclusive regarding timestamp */
      if (all_events.length == 1) {
            kError() << "no updates, done!";
            itemsRetrievedIncremental(pending, deleted);
            return result;
      }

      /* First element was already included in last retrieval, because
       * query-by-updated is inclusive.
       */
      for (size_t i = 0; i < all_events.length; ++i) {
            event = gcal_event_element(&all_events, i);
            Item item(QLatin1String("text/calendar"));
            if (!strcmp(timestamp, gcal_event_get_updated(event))) {
                  kError() << "This is an old event... continue.";
                  continue;
            }

            if (!gcal_event_is_deleted(event)) {

                  kevent = new KCal::Event;
                  kevent->setStatus(status);

                  temp = QString::fromUtf8(gcal_event_get_title(event));
                  kevent->setSummary(temp);

                  temp = QString::fromUtf8(gcal_event_get_where(event));
                  kevent->setLocation(temp);

                  temp = QString::fromUtf8(gcal_event_get_content(event));
                  kevent->setDescription(temp);

                  temp = gcal_event_get_start(event);
                  start = start.fromString(temp, KDateTime::ISODate);
                  temp = gcal_event_get_end(event);
                  end = end.fromString(temp, KDateTime::ISODate);
                  kevent->setDtStart(start);
                  kevent->setDtEnd(end);

                  url = gcal_event_get_url(event);
                  item.setRemoteId(url.url());
                  item.setPayload(IncidencePtr(kevent));

                  pending << item;

            } else {
                  url = gcal_event_get_url(event);
                  item.setRemoteId(url.url());
                  kError() << "index: " << i
                         << "deleted: " << url.url();
                  deleted << item;
            }
      }

      itemsRetrievedIncremental(pending, deleted);

      /* Only save timestamp if it was not initialized (i.e. normal
       * behavior).
       */
      if (newerTimestamp.isEmpty()) {
            /* Events return last updated entry as first element */
            event = gcal_event_element(&all_events, 0);
            if (!event) {
                  kError() << "Failed to retrieve last updated event.";
                  const QString message = i18nc("@info:status",
                                          "Failed getting last"
                                          " updated"
                                          " event.");
                  emit error(message);
                  //emit status(Broken, message);
                  result = -1;
                  return result;

            }

            newerTimestamp = gcal_event_get_updated(event);
            saveTimestamp(newerTimestamp);
      }

      return result;
}

Generated by  Doxygen 1.6.0   Back to index