void parseClientResponse(OCClientResponse * clientResponse) { coapServerIP = getIPAddrTBServer(clientResponse); coapServerPort = getPortTBServer(clientResponse); coapServerResource = getQueryStrForGetPut(clientResponse); }
void parseClientResponse(OCClientResponse * clientResponse) { coapServerIP = getIPAddrTBServer(clientResponse); coapServerPort = getPortTBServer(clientResponse); coapServerResource = "/a/light"; }
int parseClientResponse(OCClientResponse * clientResponse) { int port = -1; cJSON * root = NULL; cJSON * oc = NULL; // Initialize all global variables coapServerResource.clear(); coapServerPort.clear(); coapServerIP.clear(); coapSecureResource = 0; root = cJSON_Parse((char *)(clientResponse->resJSONPayload)); if (!root) { return -1; } oc = cJSON_GetObjectItem(root,"oc"); if (!oc) { return -1; } if (oc->type == cJSON_Array) { if (cJSON_GetArraySize(oc) > 0) { cJSON * resource = cJSON_GetArrayItem(oc, 0); if (cJSON_GetObjectItem(resource, "href")) { coapServerResource.assign(cJSON_GetObjectItem(resource, "href")->valuestring); } else { coapServerResource = ""; } OC_LOG_V(INFO, TAG, "Uri -- %s", coapServerResource.c_str()); cJSON * prop = cJSON_GetObjectItem(resource,"prop"); if (prop) { // If this is a secure resource, the info about the port at which the // resource is hosted on server is embedded inside discovery JSON response if (cJSON_GetObjectItem(prop, "sec")) { if ((cJSON_GetObjectItem(prop, "sec")->valueint) == 1) { coapSecureResource = 1; } } OC_LOG_V(INFO, TAG, "Secure -- %s", coapSecureResource == 1 ? "YES" : "NO"); if (cJSON_GetObjectItem(prop, "port")) { port = cJSON_GetObjectItem(prop, "port")->valueint; OC_LOG_V(INFO, TAG, "Hosting Server Port (embedded inside JSON) -- %u", port); std::ostringstream ss; ss << port; coapServerPort = ss.str(); } } } } cJSON_Delete(root); coapServerIP = getIPAddrTBServer(clientResponse); if (port == -1) { coapServerPort = getPortTBServer(clientResponse); OC_LOG_V(INFO, TAG, "Hosting Server Port -- %s", coapServerPort.c_str()); } return 0; }