+ OIC_LOG(ERROR, TAG, "OCStack resource error");
+ }
+ return ret;
+}
+
+void queryResource()
+{
+ switch(TestCase)
+ {
+ case TEST_DISCOVER_REQ:
+ break;
+ case TEST_NON_CON_OP:
+ InitGetRequest(OC_LOW_QOS);
+ InitPutRequest(OC_LOW_QOS);
+ InitPostRequest(OC_LOW_QOS);
+ break;
+ case TEST_CON_OP:
+ InitGetRequest(OC_HIGH_QOS);
+ InitPutRequest(OC_HIGH_QOS);
+ InitPostRequest(OC_HIGH_QOS);
+ break;
+ default:
+ PrintUsage();
+ break;
+ }
+}
+
+
+void collectUniqueResource(const OCClientResponse * clientResponse)
+{
+ OCDiscoveryPayload* pay = (OCDiscoveryPayload*) clientResponse->payload;
+ OCResourcePayload* res = pay->resources;
+
+ // Including the NUL terminator, length of UUID string of the form:
+ // "a62389f7-afde-00b6-cd3e-12b97d2fcf09"
+# define UUID_LENGTH 37
+
+ char sidStr[UUID_LENGTH];
+
+ while(res) {
+
+ int ret = snprintf(sidStr, UUID_LENGTH,
+ "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+ pay->sid[0], pay->sid[1], pay->sid[2], pay->sid[3],
+ pay->sid[4], pay->sid[5], pay->sid[6], pay->sid[7],
+ pay->sid[8], pay->sid[9], pay->sid[10], pay->sid[11],
+ pay->sid[12], pay->sid[13], pay->sid[14], pay->sid[15]
+ );
+
+ if (ret == UUID_LENGTH - 1)
+ {
+ if(insertResource(sidStr, res->uri, clientResponse) == 1)
+ {
+ OIC_LOG_V(INFO,TAG,"%s%s%s%s\n",sidStr, ":", res->uri, " is new");
+ printResourceList();
+ queryResource();
+ }
+ else {
+ OIC_LOG_V(INFO,TAG,"%s%s%s%s\n",sidStr, ":", res->uri, " is old");
+ }
+ }
+ else
+ {
+ OIC_LOG(ERROR, TAG, "Could Not Retrieve the Server ID");
+ }
+
+ res = res->next;
+ }
+}
+
+/* This function searches for the resource(sid:uri) in the ResourceList.
+ * If the Resource is found in the list then it returns 0 else insert
+ * the resource to front of the list and returns 1.
+ */
+int insertResource(const char * sid, char const * uri,
+ const OCClientResponse * clientResponse)
+{
+ ResourceNode * iter = resourceList;
+ char * sid_cpy = OICStrdup(sid);
+ char * uri_cpy = OICStrdup(uri);
+
+ //Checking if the resource(sid:uri) is new
+ while(iter)
+ {
+ if((strcmp(iter->sid, sid) == 0) && (strcmp(iter->uri, uri) == 0))
+ {
+ OICFree(sid_cpy);
+ OICFree(uri_cpy);
+ return 0;
+ }
+ else
+ {
+ iter = iter->next;
+ }
+ }
+
+ //Creating new ResourceNode
+ if((iter = (ResourceNode *) OICMalloc(sizeof(ResourceNode))))
+ {
+ iter->sid = sid_cpy;
+ iter->uri = uri_cpy;
+ iter->endpoint = clientResponse->devAddr;
+ iter->next = NULL;