#include <stdlib.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
static void printAppMenu(char *name)
{
printf("Usage: %s <test#> <arg1> <arg2> ... \n", name);
printf("Test 1: Sets admin mode of Bonjour responder: %s 1 <mode>\n", name);
printf("Test 2: Gets admin mode of Bonjour responder: %s 2\n", name);
printf("Test 3: Sets the level-1 tracing mode of Bonjour responder: %s 3 <mode>\n", name);
printf("Test 4: Gets the level-1 tracing mode of Bonjour responder: %s 4\n", name);
printf("Test 5: Sets the level-2 tracing mode of Bonjour responder: %s 5 <mode>\n", name);
printf("Test 6: Gets the level-2 tracing mode of Bonjour responder: %s 6\n", name);
printf("Test 7: Gets information about the next published service: %s 7 <serviceNo{0-Generic,1-HTTP,2-HTTPS,3-TELNET,4-SSH}>\n", name);
printf("Test 8: Gets information about the published service: %s 8 <serviceNo{0-Generic,1-HTTP,2-HTTPS,3-TELNET,4-SSH}>\n", name);
printf("Test 9: Gets information about the next published service index: %s 9 <index>\n", name);
printf("Test 10: Gets information about the published service corresponding to index: %s 10 <index>\n", name);
printf("Test 11: Run API sanity checks: %s 11 \n", name);
return;
}
{
uint32_t index=0;
uint32_t nextIndex;
printf("Testing Bonjour OpEN APIs sanity:\n");
printf("Testing openapiBonjourAdminModeGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL mode argument :(result = %d)\n", result);
printf("Testing openapiBonjourDebugLevel1Get():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL mode argument :(result = %d)\n", result);
printf("Testing openapiBonjourDebugLevel2Get():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL mode argument :(result = %d)\n", result);
printf("Testing openapiBonjourPublishedServiceGetNext():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL serviceEntry argument :(result = %d)\n", result);
printf("Testing openapiBonjourPublishedServiceGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL serviceEntry argument :(result = %d)\n", result);
printf("Testing openapiBonjourServiceIndexGetNext():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL nextIndex argument :(result = %d)\n", result);
printf("Testing openapiBonjourServiceGetByIndex():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL serviceEntry argument :(result = %d)\n", result);
return;
}
{
{
printf("Bad return code trying to sets admin mode of Bonjour responder. (result = %d)\n", result);
}
else
{
printf(
"Bonjour admin mode is successfully %s\n", (
OPEN_ENABLE == mode) ?
"enabled" :
"disabled");
}
return;
}
{
{
printf("Bad return code trying to gets admin mode of Bonjour responder. (result = %d)\n", result);
}
else
{
printf(
"Bonjour admin mode is in %s state\n", (
OPEN_ENABLE == *pMode) ?
"enabled" :
"disabled");
}
return;
}
{
{
printf("Bad return code trying to sets the level-1 tracing mode of Bonjour responder. (result = %d)\n", result);
}
else
{
printf(
"Bonjour responder level-1 tracing mode is successfully %s\n", (
OPEN_ENABLE == mode) ?
"enabled" :
"disabled");
}
return;
}
{
{
printf("Bad return code trying to gets the level-1 tracing mode of Bonjour responder. (result = %d)\n", result);
}
else
{
printf(
"Bonjour responder level-1 tracing mode is in %s state\n", (
OPEN_ENABLE == *pMode) ?
"enabled" :
"disabled");
}
return;
}
{
{
printf("Bad return code trying to sets the level-2 tracing mode of Bonjour responder. (result = %d)\n", result);
}
else
{
printf(
"Bonjour responder level-2 tracing mode is successfully %s\n", (
OPEN_ENABLE == mode) ?
"enabled" :
"disabled");
}
return;
}
{
{
printf("Bad return code trying to gets the level-2 tracing mode of Bonjour responder. (result = %d)\n", result);
}
else
{
printf(
"Bonjour responder level-2 tracing mode is in %s state\n", (
OPEN_ENABLE == *pMode) ?
"enabled" :
"disabled");
}
return;
}
{
{
printf("Bad return code trying to gets information about the next published service. (result = %d)\n", result);
}
else
{
printf("Bonjour next published service information \nservice:%d \npublished:%s \nserviceName:%s"
"serviceType:%s \nserviceDomain:%s \nservicePort:%d \nserviceText:%s \n",
pServiceEntry->
service, (pServiceEntry->
published)?
"enabled" :
"disabled",
pServiceEntry->
serviceName, pServiceEntry->
serviceType,
pServiceEntry->
serviceDomain, pServiceEntry->
servicePort,
pServiceEntry->
serviceText);
}
return;
}
{
{
printf("Bad return code trying to gets information about the published service. (result = %d)\n", result);
}
else
{
printf("Bonjour published service information \nservice:%d \npublished:%s \nserviceName:%s"
"serviceType:%s \nserviceDomain:%s \nservicePort:%d \nserviceText:%s \n",
pServiceEntry->service, (pServiceEntry->published)?"enabled" : "disabled",
pServiceEntry->serviceName, pServiceEntry->serviceType,
pServiceEntry->serviceDomain, pServiceEntry->servicePort,
pServiceEntry->serviceText);
}
return;
}
void bonjourServiceIndexGetNext(
openapiClientHandle_t *client_handle, uint32_t index, uint32_t *pNextIndex)
{
{
printf("Bad return code trying to gets information about the next published service index. (result = %d)\n", result);
}
else
{
printf("Next published service index for the given index[%d] is %d\n", index, *pNextIndex);
}
return;
}
{
{
printf("Bad return code trying to gets information about the published service corresponding to index. (result = %d)\n", result);
}
else
{
printf("Bonjour published service information corresponding to the index:%d\n"
"service:%d \npublished:%s \nserviceName:%s \n"
"serviceType:%s \nserviceDomain:%s \nservicePort:%d \nserviceText:%s \n",index,
pServiceEntry->service, (pServiceEntry->published)?"enabled" : "disabled",
pServiceEntry->serviceName, pServiceEntry->serviceType,
pServiceEntry->serviceDomain, pServiceEntry->servicePort,
pServiceEntry->serviceText);
}
return;
}
int main(int argc, char **argv)
{
uint32_t testNum;
char switch_os_revision_string[100];
int show_help = 1;
uint32_t recvMode;
uint32_t index;
uint32_t nextIndex;
if (argc < 2)
{
printAppMenu(argv[0]);
return -1;
}
testNum = atoi(argv[1]);
l7proc_crashlog_register();
{
printf("\nFailed to initialize RPC to OpEN. Exiting (result = %d)\n", result);
return -1;
}
{
sleep(1);
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Starting Bonjour API example application");
printf("\n");
switch_os_revision.
pstart = switch_os_revision_string;
switch_os_revision.
size =
sizeof(switch_os_revision_string);
printf("Network OS version = %s\n", switch_os_revision_string);
else
printf("Network OS version retrieve error\n");
printf("\n");
switch (testNum)
{
case 1:
if (argc == 3)
{
recvMode = atoi(argv[2]);
if ((0 == recvMode) || (1 == recvMode))
{
bonjourAdminModeSet(&clientHandle, mode);
}
show_help = 0;
}
break;
case 2:
if (argc == 2)
{
bonjourAdminModeGet(&clientHandle, &mode);
show_help = 0;
}
break;
case 3:
if (argc == 3)
{
recvMode = atoi(argv[2]);
if ((0 == recvMode) || (1 == recvMode))
{
bonjourDebugLevel1Set(&clientHandle, mode);
}
show_help = 0;
}
break;
case 4:
if (argc == 2)
{
bonjourDebugLevel1Get(&clientHandle, &mode);
show_help = 0;
}
break;
case 5:
if (argc == 3)
{
recvMode = atoi(argv[2]);
if ((0 == recvMode) || (1 == recvMode))
{
bonjourDebugLevel2Set(&clientHandle, mode);
}
show_help = 0;
}
break;
case 6:
if (argc == 2)
{
bonjourDebugLevel2Get(&clientHandle, &mode);
show_help = 0;
}
break;
case 7:
if (argc == 3)
{
memset(&serviceEntry, 0, sizeof(serviceEntry));
serviceEntry.service = atoi(argv[2]);
bonjourPublishedServiceGetNext(&clientHandle, &serviceEntry);
show_help = 0;
}
break;
case 8:
if (argc == 3)
{
memset(&serviceEntry, 0, sizeof(serviceEntry));
serviceEntry.service = atoi(argv[2]);
bonjourPublishedServiceGet(&clientHandle, &serviceEntry);
show_help = 0;
}
break;
case 9:
if (argc == 3)
{
index = atoi(argv[2]);
bonjourServiceIndexGetNext(&clientHandle, index, &nextIndex);
show_help = 0;
}
break;
case 10:
if (argc == 3)
{
memset(&serviceEntry, 0, sizeof(serviceEntry));
index = atoi(argv[2]);
bonjourServiceGetByIndex(&clientHandle, index, &serviceEntry);
show_help = 0;
}
break;
case 11:
if (argc == 2)
{
runSanity(&clientHandle);
show_help = 0;
}
break;
default:
break;
}
if (show_help == 1)
{
printAppMenu(argv[0]);
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Stopping Bonjour API example application");
return 0;
}