#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#include <stdlib.h>
-int g_quitFlag = 0;
+static int g_quitFlag = 0;
+static int g_secureFlag = 0;
void handleSigInt(int signum);
+static void PrintUsage()
+{
+ printf("Usage : proxy_main -s <0|1>\n");
+ printf("-s 0 : Launch proxy in unsecure mode.\n");
+ printf("-s 1 : Launch proxy in secure mode.\n");
+}
+
/*
* This method is an entry point of CoAP-HTTP Proxy.
*/
-
-int main()
+int main(int argc, char* argv[])
{
- printf("CoAP-HTTP proxy is starting..\n");
+ int opt = 0;
+ while ((opt = getopt(argc, argv, "s:")) != -1)
+ {
+ switch (opt)
+ {
+ case 's':
+ g_secureFlag = atoi(optarg);
+ break;
+ default:
+ PrintUsage();
+ return -1;
+ }
+ }
+
+ if (g_secureFlag != 0 && g_secureFlag != 1)
+ {
+ PrintUsage();
+ return -1;
+ }
+
+ printf("CoAP-HTTP proxy is starting. Mode [%d].\n", g_secureFlag);
OCStackResult result = OCInit(NULL, 0, OC_SERVER);
if (result != OC_STACK_OK)
{
return 0;
}
- if (CHPInitialize() != OC_STACK_OK)
+ if (CHPInitialize(g_secureFlag) != OC_STACK_OK)
{
printf("Failed to start proxy.\n");
OCStop();
return g_isCHProxyInitialized;
}
-OCStackResult CHPInitialize()
+OCStackResult CHPInitialize(bool secure)
{
- OIC_LOG(DEBUG, TAG, "CHPInitialize IN");
+ OIC_LOG_V(DEBUG, TAG, "%s IN", __func__);
if (g_isCHProxyInitialized)
{
OIC_LOG(DEBUG, TAG, "CH Proxy already initialized");
return result;
}
+ uint8_t prop = OC_ACTIVE | OC_DISCOVERABLE | OC_SLOW;
+ if(secure)
+ {
+ prop |= OC_SECURE;
+ }
result = OCCreateResource(&g_proxyHandle,
CHP_RESOURCE_TYPE_NAME,
CHP_RESOURCE_INTF_NAME,
OC_RSRVD_PROXY_URI,
CHPEntityHandler,
NULL,
- OC_ACTIVE | OC_DISCOVERABLE | OC_SLOW);
+ prop);
if (OC_STACK_OK != result)
{
}
g_isCHProxyInitialized = true;
- OIC_LOG(DEBUG, TAG, "CHPInitialize OUT");
+ OIC_LOG_V(DEBUG, TAG, "%s OUT", __func__);
return OC_STACK_OK;
}
OCStackResult CHPTerminate()
{
- OIC_LOG(DEBUG, TAG, "CHPTerminate IN");
+ OIC_LOG_V(DEBUG, TAG, "%s IN", __func__);
OCStackResult result = CHPParserTerminate();
if (OC_STACK_OK != result)
{
g_proxyHandle = NULL;
g_isCHProxyInitialized = false;
return result;
- OIC_LOG(DEBUG, TAG, "CHPTerminate OUT");
+ OIC_LOG_V(DEBUG, TAG, "%s OUT", __func__);
}
static void CHPGetProxyURI(OCHeaderOption* options, uint8_t *numOptions, char* uri,
size_t uriLength)
{
- OIC_LOG(DEBUG, TAG, "CHPGetProxyURI IN");
+ OIC_LOG_V(DEBUG, TAG, "%s IN", __func__);
if (!uri || uriLength <= 0)
{
OIC_LOG (INFO, TAG, "Invalid uri buffer");
}
}
- OIC_LOG(DEBUG, TAG, "CHPGetProxyURI OUT");
+ OIC_LOG_V(DEBUG, TAG, "%s OUT", __func__);
return;
}
OCEntityHandlerRequest* entityHandlerRequest,
void* callbackParam)
{
- OIC_LOG_V(INFO, TAG, "Proxy request received");
+ OIC_LOG(INFO, TAG, "Proxy request received");
UNUSED(callbackParam);
if (!g_isCHProxyInitialized)
void CHPHandleHttpResponse(const HttpResponse_t *httpResponse, void *context)
{
- OIC_LOG(DEBUG, TAG, "CHPHandleHttpResponse IN");
+ OIC_LOG_V(DEBUG, TAG, "%s IN", __func__);
if (!httpResponse || !context)
{
OIC_LOG(ERROR, TAG, "Invalid arguements");
}
//OICFree(coapResponseInfo.info.payload);
- OIC_LOG(DEBUG, TAG, "CHPHandleHttpResponse OUT");
+ OIC_LOG_V(DEBUG, TAG, "%s OUT", __func__);
}
OCStackResult CHPHandleOCFRequest(const OCEntityHandlerRequest* requestInfo,