HaikuDepot : additional debugging for json-rpc invocations
This commit is contained in:
committed by
Adrien Destugues
parent
823466613f
commit
b45e8b1ef9
@@ -21,6 +21,8 @@ class BJson {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static status_t Parse(const char* JSON, BMessage& message);
|
static status_t Parse(const char* JSON, BMessage& message);
|
||||||
|
static status_t Parse(const char* JSON, size_t length,
|
||||||
|
BMessage& message);
|
||||||
static status_t Parse(const BString& JSON, BMessage& message);
|
static status_t Parse(const BString& JSON, BMessage& message);
|
||||||
static void Parse(BDataIO* data,
|
static void Parse(BDataIO* data,
|
||||||
BJsonEventListener* listener);
|
BJsonEventListener* listener);
|
||||||
|
|||||||
@@ -559,21 +559,33 @@ WebAppInterface::AuthenticateUser(const BString& nickName,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
WebAppInterface::_SendJsonRequest(const char* domain, BString jsonString,
|
WebAppInterface::_SendJsonRequest(const char* domain, BDataIO* requestData,
|
||||||
uint32 flags, BMessage& reply) const
|
size_t requestDataSize, uint32 flags, BMessage& reply) const
|
||||||
{
|
{
|
||||||
if (!ServerHelper::IsNetworkAvailable())
|
if (!ServerHelper::IsNetworkAvailable()) {
|
||||||
|
if (Logger::IsDebugEnabled()) {
|
||||||
|
printf("dropping json-rpc request to ...[%s] as network is not "
|
||||||
|
"available\n", domain);
|
||||||
|
}
|
||||||
return HD_NETWORK_INACCESSIBLE;
|
return HD_NETWORK_INACCESSIBLE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ServerSettings::IsClientTooOld())
|
if (ServerSettings::IsClientTooOld()) {
|
||||||
|
if (Logger::IsDebugEnabled()) {
|
||||||
|
printf("dropping json-rpc request to ...[%s] as client is too "
|
||||||
|
"old\n", domain);
|
||||||
|
}
|
||||||
return HD_CLIENT_TOO_OLD;
|
return HD_CLIENT_TOO_OLD;
|
||||||
|
}
|
||||||
if (Logger::IsTraceEnabled())
|
|
||||||
printf("_SendJsonRequest(%s)\n", jsonString.String());
|
|
||||||
|
|
||||||
BUrl url = ServerSettings::CreateFullUrl(BString("/__api/v1/") << domain);
|
BUrl url = ServerSettings::CreateFullUrl(BString("/__api/v1/") << domain);
|
||||||
bool isSecure = url.Protocol() == "https";
|
bool isSecure = url.Protocol() == "https";
|
||||||
|
|
||||||
|
if (Logger::IsDebugEnabled()) {
|
||||||
|
printf("will make json-rpc request to [%s]\n",
|
||||||
|
url.UrlString().String());
|
||||||
|
}
|
||||||
|
|
||||||
ProtocolListener listener(Logger::IsTraceEnabled());
|
ProtocolListener listener(Logger::IsTraceEnabled());
|
||||||
BUrlContext context;
|
BUrlContext context;
|
||||||
|
|
||||||
@@ -595,10 +607,7 @@ WebAppInterface::_SendJsonRequest(const char* domain, BString jsonString,
|
|||||||
context.AddAuthentication(url, authentication);
|
context.AddAuthentication(url, authentication);
|
||||||
}
|
}
|
||||||
|
|
||||||
BMemoryIO* data = new BMemoryIO(
|
request.AdoptInputData(requestData, requestDataSize);
|
||||||
jsonString.String(), jsonString.Length() - 1);
|
|
||||||
|
|
||||||
request.AdoptInputData(data, jsonString.Length() - 1);
|
|
||||||
|
|
||||||
BMallocIO replyData;
|
BMallocIO replyData;
|
||||||
listener.SetDownloadIO(&replyData);
|
listener.SetDownloadIO(&replyData);
|
||||||
@@ -611,6 +620,11 @@ WebAppInterface::_SendJsonRequest(const char* domain, BString jsonString,
|
|||||||
|
|
||||||
int32 statusCode = result.StatusCode();
|
int32 statusCode = result.StatusCode();
|
||||||
|
|
||||||
|
if (Logger::IsDebugEnabled()) {
|
||||||
|
printf("did receive json-rpc response http status [%" B_PRId32 "] "
|
||||||
|
"from [%s]\n", statusCode, url.UrlString().String());
|
||||||
|
}
|
||||||
|
|
||||||
switch (statusCode) {
|
switch (statusCode) {
|
||||||
case B_HTTP_STATUS_OK:
|
case B_HTTP_STATUS_OK:
|
||||||
break;
|
break;
|
||||||
@@ -625,14 +639,29 @@ WebAppInterface::_SendJsonRequest(const char* domain, BString jsonString,
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonString.SetTo(static_cast<const char*>(replyData.Buffer()),
|
status_t status = BJson::Parse(
|
||||||
replyData.BufferLength());
|
static_cast<const char *>(replyData.Buffer()), replyData.BufferLength(),
|
||||||
if (jsonString.Length() == 0)
|
reply);
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
status_t status = BJson::Parse(jsonString, reply);
|
|
||||||
if (Logger::IsTraceEnabled() && status == B_BAD_DATA) {
|
if (Logger::IsTraceEnabled() && status == B_BAD_DATA) {
|
||||||
printf("Parser choked on JSON:\n%s\n", jsonString.String());
|
BString resultString(static_cast<const char *>(replyData.Buffer()),
|
||||||
|
replyData.BufferLength());
|
||||||
|
printf("Parser choked on JSON:\n%s\n", resultString.String());
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
WebAppInterface::_SendJsonRequest(const char* domain, BString jsonString,
|
||||||
|
uint32 flags, BMessage& reply) const
|
||||||
|
{
|
||||||
|
if (Logger::IsTraceEnabled())
|
||||||
|
printf("_SendJsonRequest(%s)\n", jsonString.String());
|
||||||
|
|
||||||
|
BMemoryIO* data = new BMemoryIO(
|
||||||
|
jsonString.String(), jsonString.Length() - 1);
|
||||||
|
|
||||||
|
return _SendJsonRequest(domain, data, jsonString.Length() - 1, flags,
|
||||||
|
reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,6 +96,10 @@ private:
|
|||||||
status_t _SendJsonRequest(const char* domain,
|
status_t _SendJsonRequest(const char* domain,
|
||||||
BString jsonString, uint32 flags,
|
BString jsonString, uint32 flags,
|
||||||
BMessage& reply) const;
|
BMessage& reply) const;
|
||||||
|
status_t _SendJsonRequest(const char* domain,
|
||||||
|
BDataIO* requestData,
|
||||||
|
size_t requestDataSize, uint32 flags,
|
||||||
|
BMessage& reply) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BString fUsername;
|
BString fUsername;
|
||||||
|
|||||||
@@ -126,9 +126,9 @@ BJson::Parse(const BString& JSON, BMessage& message)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BJson::Parse(const char* JSON, BMessage& message)
|
BJson::Parse(const char* JSON, size_t length, BMessage& message)
|
||||||
{
|
{
|
||||||
BMemoryIO* input = new BMemoryIO(JSON, strlen(JSON));
|
BMemoryIO* input = new BMemoryIO(JSON, length);
|
||||||
ObjectDeleter<BMemoryIO> inputDeleter(input);
|
ObjectDeleter<BMemoryIO> inputDeleter(input);
|
||||||
BJsonMessageWriter* writer = new BJsonMessageWriter(message);
|
BJsonMessageWriter* writer = new BJsonMessageWriter(message);
|
||||||
ObjectDeleter<BJsonMessageWriter> writerDeleter(writer);
|
ObjectDeleter<BJsonMessageWriter> writerDeleter(writer);
|
||||||
@@ -140,6 +140,13 @@ BJson::Parse(const char* JSON, BMessage& message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BJson::Parse(const char* JSON, BMessage& message)
|
||||||
|
{
|
||||||
|
return Parse(JSON, strlen(JSON), message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! The data is read as a stream of JSON data. As the JSON is read, events are
|
/*! The data is read as a stream of JSON data. As the JSON is read, events are
|
||||||
raised such as;
|
raised such as;
|
||||||
- string
|
- string
|
||||||
|
|||||||
Reference in New Issue
Block a user