diff options
author | George Hazan <george.hazan@gmail.com> | 2013-06-24 14:11:10 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-06-24 14:11:10 +0000 |
commit | ff3e2e1dc74ea1f983a3b95773800de2ac5d7ea2 (patch) | |
tree | 1c1c06d13c8af9b5d9c6db069b4bd8f3a5dc7fc0 /protocols/WhatsApp/src/proto.cpp | |
parent | 9d62e31863057f847b56e82e3880c4c588c9cb0a (diff) |
custom json parser removed
git-svn-id: http://svn.miranda-ng.org/main/trunk@5119 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/WhatsApp/src/proto.cpp')
-rw-r--r-- | protocols/WhatsApp/src/proto.cpp | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp index 657a15a18d..a1da570953 100644 --- a/protocols/WhatsApp/src/proto.cpp +++ b/protocols/WhatsApp/src/proto.cpp @@ -262,10 +262,7 @@ string WhatsAppProto::Register(int state, string cc, string number, string code) LOG("Server response: %s", pnlhr->pData);
MessageBoxA(NULL, pnlhr->pData, "Debug", MB_OK);
- cJSON* resp = cJSON_Parse(pnlhr->pData);
- cJSON* val;
-
- // Invalid
+ JSONNODE* resp = json_parse(pnlhr->pData);
if (resp == NULL)
{
this->NotifyEvent(title, this->TranslateStr("Registration failed. Invalid server response."), NULL, WHATSAPP_EVENT_CLIENT);
@@ -273,48 +270,38 @@ string WhatsAppProto::Register(int state, string cc, string number, string code) }
// Status = fail
- val = cJSON_GetObjectItem(resp, "status");
- if (strcmp(val->valuestring, "fail") == 0)
+ JSONNODE *val = json_get(resp, "status");
+ if (!lstrcmpA( json_as_string(val), "fail"))
{
- cJSON* tmpVal = cJSON_GetObjectItem(resp, "reason");
- if (strcmp(tmpVal->valuestring, "stale") == 0)
- {
+ JSONNODE *tmpVal = json_get(resp, "reason");
+ if (!lstrcmpA( json_as_string(tmpVal), "stale"))
this->NotifyEvent(title, this->TranslateStr("Registration failed due to stale code. Please request a new code"), NULL, WHATSAPP_EVENT_CLIENT);
- }
else
- {
this->NotifyEvent(title, this->TranslateStr("Registration failed."), NULL, WHATSAPP_EVENT_CLIENT);
- }
- tmpVal = cJSON_GetObjectItem(resp, "retry_after");
+ tmpVal = json_get(resp, "retry_after");
if (tmpVal != NULL)
- {
- this->NotifyEvent(title, this->TranslateStr("Please try again in %i seconds", tmpVal->valueint), NULL, WHATSAPP_EVENT_OTHER);
- }
+ this->NotifyEvent(title, this->TranslateStr("Please try again in %i seconds", json_as_int(tmpVal)), NULL, WHATSAPP_EVENT_OTHER);
}
// Request code
else if (state == REG_STATE_REQ_CODE)
{
- if (strcmp(val->valuestring, "sent") == 0)
- {
+ if (!lstrcmpA(json_as_string(val), "sent"))
this->NotifyEvent(title, this->TranslateStr("Registration code has been sent to your phone."), NULL, WHATSAPP_EVENT_OTHER);
- }
}
// Register
else if (state == REG_STATE_REG_CODE)
{
- val = cJSON_GetObjectItem(resp, "pw");
+ val = json_get(resp, "pw");
if (val == NULL)
- {
this->NotifyEvent(title, this->TranslateStr("Registration failed."), NULL, WHATSAPP_EVENT_CLIENT);
- } else
- ret = val->valuestring;
+ else
+ ret = json_as_string(val);
}
- cJSON_Delete(resp);
-
+ json_delete(resp);
return ret;
}
|