#include <stdlib.h>
#include <string.h>
#include <signal.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
#include <iostream>
#include <sstream>
+#include <getopt.h>
#include "ocstack.h"
#include "logger.h"
#include "occlient.h"
#include "ocpayload.h"
#include "payload_logging.h"
+#include "common.h"
+#include "platform_features.h"
#ifdef ROUTING_GATEWAY
/**
static char discoveryAddr[100];
static std::string coapServerResource = "/a/light";
-void StripNewLineChar(char* str);
+// Following resource is used to verify coap-http proxy
+static std::string coapProxyResource = OC_RSRVD_PROXY_URI;
+static std::string httpResource; // Will be taken as user input
#ifdef WITH_PRESENCE
// The handle for observe registration
static void PrintUsage()
{
- OIC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1..17> -c <0|1>");
+ OIC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1..21> -c <0|1>");
OIC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources");
OIC_LOG(INFO, TAG, "-c 0 : Use Default connectivity(IP)");
OIC_LOG(INFO, TAG, "-c 1 : IP Connectivity Type");
"add vendor specific header options");
OIC_LOG(INFO, TAG, "-t 19 : Discover Platform");
OIC_LOG(INFO, TAG, "-t 20 : Discover Devices");
+ OIC_LOG(INFO, TAG, "-t 21 -p \"http_uri\": Discover Proxy and Initiate Nonconfirmable Get Request");
}
OCStackResult InvokeOCDoResource(std::ostringstream &query,
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- ret = OCDoResource(&handle, method, query.str().c_str(), remoteAddr,
+ const char *uri = query.str().length() ? query.str().c_str() : NULL;
+ ret = OCDoResource(&handle, method, uri, remoteAddr,
(method == OC_REST_PUT) ? putPayload() : NULL,
(ConnType), qos, &cbData, options, numOptions);
OCResourcePayload *resource = (OCResourcePayload*) payload->resources;
int found = 0;
+
+ std::string resourceToFind = (TestCase == TEST_PROXY_GET_REQ_NON) ?
+ coapProxyResource : coapServerResource;
while (resource)
{
- if(resource->uri && strcmp(resource->uri, coapServerResource.c_str()) == 0)
+ if(resource->uri && strcmp(resource->uri, resourceToFind.c_str()) == 0)
{
found = 1;
break;
if(!found)
{
- OIC_LOG_V (INFO, TAG, "No /a/light in payload");
+ OIC_LOG_V (INFO, TAG, "No %s in payload", resourceToFind.c_str());
return OC_STACK_KEEP_TRANSACTION;
}
case TEST_OBS_REQ_CON:
InitObserveRequest(OC_HIGH_QOS);
break;
+ case TEST_PROXY_GET_REQ_NON:
+ InitProxyGetRequest(OC_LOW_QOS);
+ break;
#ifdef WITH_PRESENCE
case TEST_OBS_PRESENCE:
case TEST_OBS_PRESENCE_WITH_FILTER:
return result;
}
-int InitGetRequest(OCQualityOfService qos, uint8_t withVendorSpecificHeaderOptions, bool getWithQuery)
+int InitProxyGetRequest(OCQualityOfService qos)
+{
+ OIC_LOG(INFO, TAG, "InitProxyGetRequest");
+ OCHeaderOption option;
+ memset(&option, 0, sizeof(option));
+
+ option.protocolID = OC_COAP_ID;
+ option.optionID = OC_RSRVD_PROXY_OPTION_ID;
+ memcpy(option.optionData, (uint8_t *)httpResource.c_str(), httpResource.length());
+ option.optionLength = httpResource.length();
+
+ std::ostringstream query;
+ // A request with proxy uri shall not have resource uri
+ // query << coapProxyResource;
+
+ return (InvokeOCDoResource(query, &serverAddr, OC_REST_GET,
+ (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, getReqCB, &option, 1));
+}
+
+int InitGetRequest(OCQualityOfService qos, uint8_t withVendorSpecificHeaderOptions,
+ bool getWithQuery)
{
OCHeaderOption options[MAX_HEADER_OPTIONS];
OCStackResult ret;
OCCallbackData cbData;
- char szQueryUri[64] = { 0 };
+ char szQueryUri[MAX_QUERY_LENGTH] = { 0 };
snprintf(szQueryUri, sizeof (szQueryUri) - 1, PLATFORM_DISCOVERY_QUERY, discoveryAddr);
OCStackResult ret;
OCCallbackData cbData;
- char szQueryUri[100] = { 0 };
+ char szQueryUri[MAX_QUERY_LENGTH] = { 0 };
snprintf(szQueryUri, sizeof (szQueryUri) - 1, DEVICE_DISCOVERY_QUERY, discoveryAddr);
{
OCStackResult ret;
OCCallbackData cbData;
- char szQueryUri[100] = { 0 };
+ char szQueryUri[MAX_QUERY_LENGTH] = { 0 };
snprintf(szQueryUri, sizeof (szQueryUri) - 1, RESOURCE_DISCOVERY_QUERY, discoveryAddr);
{
int opt;
- while ((opt = getopt(argc, argv, "u:t:c:")) != -1)
+ while ((opt = getopt(argc, argv, "u:t:c:p:")) != -1)
{
switch(opt)
{
case 'c':
Connectivity = atoi(optarg);
break;
+ case 'p':
+ if(optarg)
+ {
+ httpResource = optarg;
+ }
+ break;
default:
PrintUsage();
return -1;
if ((UnicastDiscovery != 0 && UnicastDiscovery != 1) ||
(TestCase < TEST_DISCOVER_REQ || TestCase >= MAX_TESTS) ||
- (Connectivity < CT_ADAPTER_DEFAULT || Connectivity >= MAX_CT))
+ (Connectivity < CT_ADAPTER_DEFAULT || Connectivity >= MAX_CT) ||
+ (TestCase == TEST_PROXY_GET_REQ_NON && httpResource.length() == 0) )
{
PrintUsage();
return -1;