diff options
author | Robert Pösel <robyer@seznam.cz> | 2013-09-29 15:34:03 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2013-09-29 15:34:03 +0000 |
commit | e010af0624dd701a4e8c52c1a5bcea92f5482f0f (patch) | |
tree | c70029a98b778765bb317b825555ba2ff7690221 | |
parent | d09782a435ae4a9229b853e53e603d4c621df3a3 (diff) |
Facebook: validate_reseponse now notify all facebook errors
git-svn-id: http://svn.miranda-ng.org/main/trunk@6271 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/FacebookRM/src/client.h | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 88 | ||||
-rw-r--r-- | protocols/FacebookRM/src/http.h | 1 | ||||
-rw-r--r-- | protocols/FacebookRM/src/messages.cpp | 3 |
4 files changed, 48 insertions, 46 deletions
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h index 5009389098..a14a29b483 100644 --- a/protocols/FacebookRM/src/client.h +++ b/protocols/FacebookRM/src/client.h @@ -110,7 +110,7 @@ public: unsigned int error_count_;
- bool validate_response(http::response*);
+ bool validate_response(http::response *resp, bool notify = true);
bool handle_entry(std::string method);
bool handle_success(std::string method);
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 6cd98e11e7..6b4dbb509f 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -118,7 +118,7 @@ http::response facebook_client::flap(RequestType request_type, std::string* requ return resp;
}
-bool facebook_client::validate_response(http::response* resp)
+bool facebook_client::validate_response(http::response* resp, bool notify)
{
if (resp->code == HTTP_CODE_FAKE_DISCONNECTED)
{
@@ -142,35 +142,46 @@ bool facebook_client::validate_response(http::response* resp) }
*/
std::string::size_type pos = resp->data.find("\"error\":");
- if (pos != std::string::npos)
- try
- {
- pos += 8;
- int error_num = atoi(resp->data.substr(pos, resp->data.find(",", pos) - pos).c_str());
- if (error_num != 0)
- {
- std::string error = "";
- pos = resp->data.find("\"errorDescription\":\"", pos);
- if (pos != std::string::npos) {
- pos += 20;
- error = resp->data.substr(pos, resp->data.find("\"", pos) - pos);
- error = utils::text::trim(
- utils::text::special_expressions_decode(
- utils::text::slashu_to_utf8(error)));
-
+ if (pos != std::string::npos) {
+ try
+ {
+ pos += 8;
+ int error_num = atoi(resp->data.substr(pos, resp->data.find(",", pos) - pos).c_str());
+ if (error_num != 0) {
+ std::string error = "";
+ pos = resp->data.find("\"errorDescription\":\"", pos);
+ if (pos != std::string::npos) {
+ pos += 20;
+ error = resp->data.substr(pos, resp->data.find("\"", pos) - pos);
+ error = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(error)));
+ error = ptrA( mir_utf8decodeA(error.c_str()));
+ }
+
+ std::string title = "";
+ pos = resp->data.find("\"errorSummary\":\"", pos);
+ if (pos != std::string::npos) {
+ pos += 16;
+ title = resp->data.substr(pos, resp->data.find("\"", pos) - pos);
+ title = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(title)));
+ title = ptrA( mir_utf8decodeA(title.c_str()));
+ }
+
+ resp->error_number = error_num;
+ resp->error_text = error;
+ resp->error_title = title;
+ resp->code = HTTP_CODE_FAKE_ERROR;
+
+ parent->Log(" ! ! Received Facebook error: %d -- %s", error_num, error.c_str());
+ if (notify)
+ client_notify(_A2T(error.c_str()));
+
+ return false;
}
-
- resp->error_number = error_num;
- resp->error_text = error;
- parent->Log(" ! ! Received Facebook error: %d -- %s", error_num, error.c_str());
- // client_notify(...);
- resp->code = HTTP_CODE_FAKE_ERROR;
- return false;
- }
- } catch (const std::exception &e) {
- parent->Log(" @ @ validate_response: Exception: %s",e.what());
- return false;
- }
+ } catch (const std::exception &e) {
+ parent->Log(" @ @ validate_response: Exception: %s",e.what());
+ return false;
+ }
+ }
return true;
}
@@ -1249,7 +1260,7 @@ bool facebook_client::send_message(std::string message_recipient, std::string me }
}
- validate_response(&resp);
+ validate_response(&resp, false);
*error_text = resp.error_text;
switch (resp.error_number)
@@ -1366,21 +1377,12 @@ bool facebook_client::post_status(status_data *status) flap(REQUEST_IDENTITY_SWITCH, &data);
}
- validate_response(&resp);
-
- switch (resp.code)
- {
- case HTTP_CODE_OK:
- if (resp.error_number != 0 && !resp.error_text.empty())
- client_notify(ptrT(mir_utf8decodeT(resp.error_text.c_str())));
- else
- parent->NotifyEvent(parent->m_tszUserName, TranslateT("Status update was successful."), NULL, FACEBOOK_EVENT_OTHER);
+ if (validate_response(&resp) && resp.code == HTTP_CODE_OK) {
+ parent->NotifyEvent(parent->m_tszUserName, TranslateT("Status update was successful."), NULL, FACEBOOK_EVENT_OTHER);
return handle_success("post_status");
- case HTTP_CODE_FAKE_ERROR:
- case HTTP_CODE_FAKE_DISCONNECTED:
- default:
- return handle_error("post_status");
}
+
+ return handle_error("post_status");
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/FacebookRM/src/http.h b/protocols/FacebookRM/src/http.h index 23938cfb18..69dc4dc9c7 100644 --- a/protocols/FacebookRM/src/http.h +++ b/protocols/FacebookRM/src/http.h @@ -96,6 +96,7 @@ namespace http int code;
unsigned int error_number;
std::string error_text;
+ std::string error_title;
std::map< std::string, std::string > headers;
std::string data;
};
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index 604ca2d2ee..298413cec4 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -60,8 +60,7 @@ void FacebookProto::SendMsgWorker(void *p) ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, data->msgid, 0);
CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)data->hContact, NULL);
} else {
- ptrA err( mir_utf8decodeA(error_text.c_str()));
- ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, data->msgid, (LPARAM)err);
+ ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, data->msgid, (LPARAM)error_text.c_str());
}
db_free(&dbv);
}
|