From f28e6dd02943c4e77585a998f745482ebc20b6ab Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Tue, 4 Apr 2017 11:15:26 +0200 Subject: [PATCH] CPaster: Fix fetching list of pastebin.ca Page now uses websockets internally that updates respective content asynchronously. Initial GET of the page only fetches an empty list - work around by using a pre-constructed json array that is contained within the initial content. Change-Id: Id8619450ecc758057fce23079e7eed6de8abe5dc Reviewed-by: Friedemann Kleint --- src/plugins/cpaster/pastebindotcaprotocol.cpp | 73 +++++++------------ 1 file changed, 28 insertions(+), 45 deletions(-) diff --git a/src/plugins/cpaster/pastebindotcaprotocol.cpp b/src/plugins/cpaster/pastebindotcaprotocol.cpp index 6d413a37b7f..aeb83d20d4e 100644 --- a/src/plugins/cpaster/pastebindotcaprotocol.cpp +++ b/src/plugins/cpaster/pastebindotcaprotocol.cpp @@ -28,9 +28,11 @@ #include #include -#include -#include #include +#include +#include +#include +#include static const char urlC[] = "http://pastebin.ca/"; static const char internalUrlC[] = "http://pbin.ca/"; @@ -180,58 +182,39 @@ bool PasteBinDotCaProtocol::checkConfiguration(QString *errorMessage) return ok; } -/* Quick & dirty: Parse the
-elements with the "Recent Posts" listing - * out of the page. +/* Quick & dirty: Parse page does no more work due to internal javascript/websocket magic - so, + * search for _initial_ json array containing the last added pastes. \code - -
- - ...

Create a New Pastebin Post

+"); + if (pos == -1) + return rc; + data.truncate(pos); + QJsonParseError error; + const QJsonDocument doc = QJsonDocument::fromJson(data, &error); + if (error.error != QJsonParseError::NoError) + return rc; + QJsonArray array = doc.array(); + for (const QJsonValue &val : array) { + const QJsonObject obj = val.toObject(); + const QJsonValue id = obj.value("id"); + const QJsonValue name = obj.value("name"); + if (!id.isUndefined()) + rc.append(QString::number(id.toInt()) + ' ' + name.toString()); + } return rc; }