summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Ohly <patrick.ohly@intel.com>2012-07-02 14:06:08 +0200
committerPatrick Ohly <patrick.ohly@intel.com>2012-07-02 14:06:08 +0200
commit68ff18bba4bddefdab14d9b1f58f99e4117da483 (patch)
treebc943e0a67939782fce43eac65bc09e33a2102b6
parentbfdc3977e2a4c40449b72506eb2c3b1982537ba8 (diff)
WebDAV: added possibility to accept certain error codes
Some WebDAV requests might fail with a non-okay status code that the caller expects. This was reported via an exception. But SyncEvolution's design uses exceptions only for non-normal incidencences. Therefore better allow the caller to indicate which status codes are expected and return normally from run() and checkError() when those are encountered, without retrying and without throwing an exception.
-rw-r--r--src/backends/webdav/NeonCXX.cpp18
-rw-r--r--src/backends/webdav/NeonCXX.h10
2 files changed, 20 insertions, 8 deletions
diff --git a/src/backends/webdav/NeonCXX.cpp b/src/backends/webdav/NeonCXX.cpp
index 2f718777..5c564a9a 100644
--- a/src/backends/webdav/NeonCXX.cpp
+++ b/src/backends/webdav/NeonCXX.cpp
@@ -514,7 +514,8 @@ void Session::flush()
}
}
-bool Session::checkError(int error, int code, const ne_status *status, const string &location)
+bool Session::checkError(int error, int code, const ne_status *status, const string &location,
+ const std::set<int> *expectedCodes)
{
flush();
SuspendFlags &s = SuspendFlags::getSuspendFlags();
@@ -561,6 +562,12 @@ bool Session::checkError(int error, int code, const ne_status *status, const str
switch (error) {
case NE_OK:
// request itself completed, but might still have resulted in bad status
+ if (expectedCodes &&
+ expectedCodes->find(code) != expectedCodes->end()) {
+ // return to caller immediately as if we had succeeded,
+ // without throwing an exception and without retrying
+ return true;
+ }
if (code &&
(code < 200 || code >= 300)) {
if (status) {
@@ -868,7 +875,7 @@ static int ne_accept_2xx(void *userdata, ne_request *req, const ne_status *st)
}
#endif
-bool Request::run()
+bool Request::run(const std::set<int> *expectedCodes)
{
int error;
@@ -881,7 +888,7 @@ bool Request::run()
error = ne_xml_dispatch_request(m_req, m_parser->get());
}
- return checkError(error);
+ return checkError(error, expectedCodes);
}
int Request::addResultData(void *userdata, const char *buf, size_t len)
@@ -891,9 +898,10 @@ int Request::addResultData(void *userdata, const char *buf, size_t len)
return 0;
}
-bool Request::checkError(int error)
+bool Request::checkError(int error, const std::set<int> *expectedCodes)
{
- return m_session.checkError(error, getStatus()->code, getStatus(), getResponseHeader("Location"));
+ return m_session.checkError(error, getStatus()->code, getStatus(), getResponseHeader("Location"),
+ expectedCodes);
}
}
diff --git a/src/backends/webdav/NeonCXX.h b/src/backends/webdav/NeonCXX.h
index 39d21008..5ba0f11e 100644
--- a/src/backends/webdav/NeonCXX.h
+++ b/src/backends/webdav/NeonCXX.h
@@ -309,12 +309,16 @@ class Session {
* @param code HTTP status code
* @param status optional ne_status pointer, non-NULL for all requests
* @param location optional "Location" header value
+ * @param expectedCodes set of codes which are normal and must not result
+ * in retrying or an exception (returns true, as if the
+ * operation succeeded)
*
* @return true for success, false if retry needed (only if deadline not empty);
* errors reported via exceptions
*/
bool checkError(int error, int code = 0, const ne_status *status = NULL,
- const string &location = "");
+ const string &location = "",
+ const std::set<int> *expectedCodes = NULL);
ne_session *getSession() const { return m_session; }
@@ -528,7 +532,7 @@ class Request
*
* @return result of Session::checkError()
*/
- bool run();
+ bool run(const std::set<int> *expectedCodes = NULL);
std::string getResponseHeader(const std::string &name) {
const char *value = ne_get_response_header(m_req, name.c_str());
@@ -552,7 +556,7 @@ class Request
static int addResultData(void *userdata, const char *buf, size_t len);
/** throw error if error code *or* current status indicates failure */
- bool checkError(int error);
+ bool checkError(int error, const std::set<int> *expectedCodes = NULL);
};
/** thrown for 301 HTTP status */