#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 System Web Mode: %s 1 <mode>\n", name);
printf("Test 2: Gets admin mode of System Web: %s 2\n", name);
printf("Test 3: Sets the port-number for HTTP Access: %s 3 <port><flag>\n", name);
printf("Test 4: Gets HTTP access port number: %s 4 \n", name);
printf("Test 5: Sets maximum number of HTTP web sessions: %s 5 <maxSession>\n", name);
printf("Test 6: Gets maximum number of HTTP web sessions: %s 6\n", name);
printf("Test 7: Sets HTTP session soft timeout (in minutes): %s 7 <timeout>\n", name);
printf("Test 8: Gets HTTP session soft timeout information: %s 8\n", name);
printf("Test 9: Sets HTTP session hard timeout (in hours): %s 9 <timeout>\n", name);
printf("Test 10: Gets HTTP session hard timeout information (in hours): %s 10\n", name);
printf("Test 11: Run API sanity checks: %s 11 \n", name);
return;
}
{
uint32_t pSession;
uint32_t pPort;
uint32_t pTimeout;
printf("Testing WebMgmt OpEN APIs sanity:\n");
printf("Testing openapiSwDevCtrlWebMgmtModeGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiSwDevCtrlWebMgmtPortNumGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiCliWebHttpNumSessionsGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiCliWebHttpSessionSoftTimeOutGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
printf("Testing openapiCliWebHttpSessionHardTimeOutGet():\n");
printf("NULL client handle:(result = %d)\n", result);
printf("NULL argument 2:(result = %d)\n", result);
return;
}
{
{
printf("Bad return code trying to sets System Web Mode. (result = %d)\n", result);
}
else
{
printf(
"System Web Mode is successfully %s\n", (
OPEN_ENABLE == mode) ?
"enabled" :
"disabled");
}
return;
}
{
{
printf("Bad return code trying to gets admin mode of System Web. (result = %d)\n", result);
}
else
{
printf(
"Admin mode of System Web is in %s state\n", (
OPEN_ENABLE == *pMode) ?
"enabled" :
"disabled");
}
return;
}
{
{
printf("Bad return code trying to sets the port-number for HTTP Access. (result = %d)\n", result);
}
else
{
printf("port-number for HTTP Access is succesfully set\n");
}
return;
}
{
{
printf("Bad return code trying to gets HTTP access port number. (result = %d)\n", result);
}
else
{
printf("HTTP access port number is %d\n", *pPort);
}
return;
}
{
{
printf("Bad return code trying to sets maximum number of HTTP web sessions. (result = %d)\n", result);
}
else
{
printf("maximum number of HTTP web sessions is succesfully set to %d\n", maxSession);
}
return;
}
{
{
printf("Bad return code trying to gets maximum number of HTTP web sessions. (result = %d)\n", result);
}
else
{
printf("maximum number of HTTP web sessions is %d\n", *pSession);
}
return;
}
{
{
printf("Bad return code trying to sets HTTP session soft timeout (in minutes). (result = %d)\n", result);
}
else
{
printf("HTTP session soft timeout is succesfully set to %d\n", timeout);
}
return;
}
{
{
printf("Bad return code trying to gets HTTP session soft timeout information. (result = %d)\n", result);
}
else
{
printf("HTTP session soft timeout is %d\n", *pTimeout);
}
return;
}
{
{
printf("Bad return code trying to sets HTTP session hard timeout (in hours). (result = %d)\n", result);
}
else
{
printf("HTTP session hard timeout is succesfully set to %d\n", timeout);
}
return;
}
{
{
printf("Bad return code trying to gets HTTP session hard timeout information (in hours). (result = %d)\n", result);
}
else
{
printf("HTTP session hard timeout is %d\n", *pTimeout);
}
return;
}
int main(int argc, char **argv)
{
uint32_t testNum;
char switch_os_revision_string[100];
int show_help = 1;
uint32_t session;
uint32_t port;
uint32_t timeout;
uint32_t recvMode;
uint32_t recvFlag;
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 WebMgmt 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))
{
swDevCtrlWebMgmtModeSet(&clientHandle, mode);
}
show_help = 0;
}
break;
case 2:
if (argc == 2)
{
swDevCtrlWebMgmtModeGet(&clientHandle, &mode);
show_help = 0;
}
break;
case 3:
if (argc == 4)
{
port = atoi(argv[2]);
recvFlag = atoi(argv[3]);
if ((0 == recvFlag) || (1 == recvFlag))
{
swDevCtrlWebMgmtPortNumSet(&clientHandle, port, flag);
}
show_help = 0;
}
break;
case 4:
if (argc == 2)
{
swDevCtrlWebMgmtPortNumGet(&clientHandle, &port);
show_help = 0;
}
break;
case 5:
if (argc == 3)
{
session = atoi(argv[2]);
cliWebHttpNumSessionsSet(&clientHandle, session);
show_help = 0;
}
break;
case 6:
if (argc == 2)
{
cliWebHttpNumSessionsGet(&clientHandle, &session);
show_help = 0;
}
break;
case 7:
if (argc == 3)
{
timeout = atoi(argv[2]);
cliWebHttpSessionSoftTimeOutSet(&clientHandle, timeout);
show_help = 0;
}
break;
case 8:
if (argc == 2)
{
cliWebHttpSessionSoftTimeOutGet(&clientHandle, &timeout);
show_help = 0;
}
break;
case 9:
if (argc == 3)
{
timeout = atoi(argv[2]);
cliWebHttpSessionHardTimeOutSet(&clientHandle, timeout);
show_help = 0;
}
break;
case 10:
if (argc == 2)
{
cliWebHttpSessionHardTimeOutGet(&clientHandle, &timeout);
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 WebMgmt API example application");
return 0;
}