/*! Copyright(c) 2008-2013 Shenzhen TP-LINK Technologies Co.Ltd.
*
*\file http_poeOut.c
*\brief
*\details
*
*\author Hu Haiming
*\version
*\date 2Sep21
*
*\warning
*
*\history \arg
*/
/**************************************************************************************************/
/* CONFIGURATIONS */
/**************************************************************************************************/
/**************************************************************************************************/
/* INCLUDE_FILES */
/**************************************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/sysinfo.h>
#include <net/if.h>
#include <netinet/if_ether.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include "http_file.h"
#include "http_io.h"
#include "http_data.h"
#include "http_auth.h"
#include "cJSON.h"
#include "wrp_com_op.h"
#include "dev_config.h"
#include "http_poeOut.h"
/**************************************************************************************************/
/* DEFINES */
/**************************************************************************************************/
/**************************************************************************************************/
/* TYPES */
/**************************************************************************************************/
/**************************************************************************************************/
/* EXTERN_PROTOTYPES */
/**************************************************************************************************/
/**************************************************************************************************/
/* LOCAL_PROTOTYPES */
/**************************************************************************************************/
/**************************************************************************************************/
/* VARIABLES */
/**************************************************************************************************/
/**************************************************************************************************/
/* LOCAL_FUNCTIONS */
/**************************************************************************************************/
static void
_poeOutJsonWrite(HTTP_DATATEMP *pData, LAN_PORT_ENTRY *poeOutCfgData, int status, int err)
{
cJSON *root = NULL;
cJSON *poeOutInfo = NULL;
char *out = NULL;
if (NULL == poeOutCfgData)
{
return;
}
root = cJSON_CreateObject();
if (NULL == root)
{
return;
}
poeOutInfo = cJSON_CreateObject();
if (NULL == poeOutInfo)
{
cJSON_Delete(root);
return;
}
cJSON_AddItemToObject(root, "success", cJSON_CreateBool(OK == status));
cJSON_AddNumberToObject(root, "error", err);
cJSON_AddItemToObject(root, "data", poeOutInfo);
if (poeOutCfgData->poe_out_bitmap)
{
cJSON_AddStringToObject(poeOutInfo, "enable", "on");
}
else
{
cJSON_AddStringToObject(poeOutInfo, "enable", "off");
}
out = cJSON_Print(root);
if (NULL != out)
{
pData->contentLength = strlen(out);
http_parser_makeHeader(pData, HTTP_OK);
http_io_fwrite(pData->pDataPersist, out, strlen(out));
pData->outputState = HTTP_NONEED_RETURN;
}
cJSON_Delete(root);
if (NULL != out)
{
free(out);
}
return;
}
HTTP_STATUS getPoeOutJson(HTTP_CONTEXT *pContext)
{
STATUS status = OK;
WRP_RET wrpRet = WRP_OK;
LAN_PORT_ENTRY info;
HTTP_DATATEMP *pData = NULL;
if (pContext == NULL)
return RPM_ERROR;
pData = pContext->pHttp_datatemp;
pData->outputState = HTTP_NEED_RETURN200;
memset(&info, 0, sizeof(info));
wrpRet = wrpOpDo(UCL_OPID_LAN_PORT_GET_INFO, NULL, 0, &info, sizeof(LAN_PORT_ENTRY), WRP_TRAN_TYPE_READ);
if (WRP_OK != wrpRet)
{
status = ERROR;
}
_poeOutJsonWrite(pData, &info, status, OK);
return RPM_DONE;
}
static STATUS
_parsePoeCfgSet(HTTP_DATATEMP *pData, POE_GLOBAL_CFG_STRUCT_UC *poeOutCfgData)
{
char *pStr = NULL;
cJSON *pRoot = NULL;
cJSON *pValue = NULL;
if (NULL == poeOutCfgData)
{
return ERROR;
}
pStr = httpGetEnv(pData, "new");
if (NULL == pStr)
{
// printf("failed to get param str:%s", "data");
printf("####&&&& in [%s] failed to get param str:%s\n", __FUNCTION__, "data");
return ERROR;
}
printf("_parsePoeCfgSet data str:%s \n ", pStr);
pRoot = cJSON_Parse(pStr);
if (NULL == pRoot)
{
printf("failed to parse json str:%s", pStr);
return ERROR;
}
/*limit*/
pValue = cJSON_GetObjectItem(pRoot, "limit");
if (NULL == pValue || (pValue->type != cJSON_String) || 0 == strlen(pValue->valuestring))
{
printf("module(%s) not present,use default \n", "0");
poeOutCfgData->sys_power_limit = 0;
}
else
{
poeOutCfgData->sys_power_limit = atof(pValue->valuestring) * 10;
}
return OK;
}
//ok
static void
_poeCfgJsonWrite(HTTP_DATATEMP *pData, POE_GLOBAL_CFG_STRUCT_UC *poeOutCfgData, int status, int err)
{
cJSON *root = NULL;
cJSON *poeOutInfo = NULL;
cJSON *poeOutInfo_Array = NULL;
char *out = NULL;
if (NULL == poeOutCfgData)
{
return;
}
root = cJSON_CreateObject();
if (NULL == root)
{
return;
}
poeOutInfo = cJSON_CreateObject();
poeOutInfo_Array = cJSON_CreateArray();
if (NULL == poeOutInfo)
{
cJSON_Delete(root);
return;
}
cJSON_AddItemToObject(root, "success", cJSON_CreateBool(OK == status));
cJSON_AddNumberToObject(root, "error", err);
cJSON_AddItemToObject(root, "data", poeOutInfo_Array);
cJSON_AddNumberToObject(poeOutInfo, "id", 0); //UCL_OPID_MONITORAP_GET_DEVINFO
cJSON_AddStringToObject(poeOutInfo, "device_name", "EAP650GP-Desktop"); //UCL_OPID_MONITORAP_GET_DEVINFO
cJSON_AddNumberToObject(poeOutInfo, "min", 4);
cJSON_AddNumberToObject(poeOutInfo, "max", (float)poeOutCfgData->sys_power_max/10.0);
cJSON_AddNumberToObject(poeOutInfo, "limit", (float)poeOutCfgData->sys_power_limit/10.0);
cJSON_AddNumberToObject(poeOutInfo, "consumption", (float)poeOutCfgData->sys_actual_cons/10.0);
if(poeOutCfgData->sys_power_limit < poeOutCfgData->sys_actual_cons)
{
cJSON_AddNumberToObject(poeOutInfo, "remain", 0);
}
else
{
cJSON_AddNumberToObject(poeOutInfo, "remain", (float)(poeOutCfgData->sys_power_limit - poeOutCfgData->sys_actual_cons)/10.0);
}
cJSON_AddBoolToObject(poeOutInfo, "total_overload", poeOutCfgData->sys_overload == 1);
cJSON_AddItemToArray(poeOutInfo_Array, poeOutInfo);
out = cJSON_Print(root);
if (NULL != out)
{
pData->contentLength = strlen(out);
http_parser_makeHeader(pData, HTTP_OK);
http_io_fwrite(pData->pDataPersist, out, strlen(out));
pData->outputState = HTTP_NONEED_RETURN;
}
cJSON_Delete(root);
if (NULL != out)
{
free(out);
}
return;
}
HTTP_STATUS poe_cfg_get(HTTP_CONTEXT *pContext)
{
STATUS status = OK;
WRP_RET wrpRet = WRP_OK;
POE_GLOBAL_CFG_STRUCT_UC info_new;
HTTP_DATATEMP *pData = NULL;
if (pContext == NULL)
return RPM_ERROR;
pData = pContext->pHttp_datatemp;
pData->outputState = HTTP_NEED_RETURN200;
memset(&info_new, 0, sizeof(info_new));
wrpRet = wrpOpDo(UCL_OPID_POE_GET_ENABLE, NULL, 0, &info_new, sizeof(POE_GLOBAL_CFG_STRUCT_UC), WRP_TRAN_TYPE_READ);
if (WRP_OK != wrpRet)
{
status = ERROR;
}
_poeCfgJsonWrite(pData, &info_new, status, OK); //ok
return RPM_DONE;
}
HTTP_STATUS poe_cfg_set(HTTP_CONTEXT *pContext)
{
// STATUS status = OK;
// WRP_RET wrpRet = WRP_OK;
// LAN_PORT_ENTRY info;
POE_GLOBAL_CFG_STRUCT_UC info_new;
UINT32 err = 0;
HTTP_DATATEMP *pData = NULL;
if (pContext == NULL)
return RPM_ERROR;
pData = pContext->pHttp_datatemp;
pData->outputState = HTTP_NEED_RETURN200;
RPM_POST_2_OTHER_OP(pContext, "load", NULL, poe_cfg_get); //ok
_parsePoeCfgSet(pData, &info_new); //half ok. only set limit now.need prd check
wrpOpDo(UCL_OPID_POE_SET_ENABLE, &info_new, sizeof(POE_GLOBAL_CFG_STRUCT_UC),
&err, sizeof(UINT32), WRP_TRAN_TYPE_WRITE);
return poe_cfg_get(pContext);
}
//ok
static STATUS
_parsePortCfgSet(HTTP_DATATEMP *pData, POE_PORT_CFG_STRUCT_UC *portCfgData, POE_PROFILE_STRUCT_UC *profileData)
{
char *pStr = NULL;
cJSON *pRoot = NULL;
cJSON *pValue = NULL;
if (NULL == portCfgData)
{
return ERROR;
}
pStr = httpGetEnv(pData, "id");
if (NULL == pStr)
{
printf("failed to get param str:%s", "new");
return ERROR;
}
printf("_parsePortCfgSet data str:%s \n", pStr);
portCfgData->port_no = atoi(pStr);
pStr = httpGetEnv(pData, "new");
if (NULL == pStr)
{
printf("failed to get param str:%s", "new");
return ERROR;
}
printf("_parsePortCfgSet data str:%s \n", pStr);
pRoot = cJSON_Parse(pStr);
if (NULL == pRoot)
{
printf("failed to parse json str:%s", pStr);
return ERROR;
}
/*poe_profile_no*/
pValue = cJSON_GetObjectItem(pRoot, "poe_profile");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "status");
}
else if(pValue->valuestring[0] == '\0' || (0 == strcmp(pValue->valuestring, "default-none")))
{
portCfgData->poe_profile_no = 0;
}
else
{
int index = 0;
for(index = 0; index < MAX_POE_PROFILE_NUM; index++)
{
if( profileData[index].profile_id == atoi(pValue->valuestring))
{
break;
}
if( index == MAX_POE_PROFILE_NUM -1)
{
printf("match profile failed \n");
return RPM_ERROR;
}
}
portCfgData->poe_profile_no = atoi(pValue->valuestring);
portCfgData->poe_enable = profileData[index].poe_enable;
portCfgData->priority = profileData[index].priority;
portCfgData->power_limit = profileData[index].power_limit;
portCfgData->power_limit_class = profileData[index].power_limit_class;
return OK;
}
/*status*/
pValue = cJSON_GetObjectItem(pRoot, "status");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "status");
portCfgData->poe_enable = POE_DISABLE;
}
else
{
if (0 == strcmp(pValue->valuestring, "on"))
{
portCfgData->poe_enable = POE_ENABLE;
}
else if(0 == strcmp(pValue->valuestring, "off"))
{
portCfgData->poe_enable = POE_DISABLE;
}
}
/*priority*/
pValue = cJSON_GetObjectItem(pRoot, "priority");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "priority");
portCfgData->priority = POE_PRI_LOW_AD;
}
else
{
if (0 == strcmp(pValue->valuestring, "low"))
{
portCfgData->priority = POE_PRI_LOW_AD;
}
else if (0 == strcmp(pValue->valuestring, "middle"))
{
portCfgData->priority = POE_PRI_MIDDLE_AD;
}
else if (0 == strcmp(pValue->valuestring, "high"))
{
portCfgData->priority = POE_PRI_HIGH_AD;
}
else
{
printf("module(%s)2 not present ,use default", "priority");
portCfgData->priority = POE_PRI_LOW_AD;
}
}
/*power_limit*/
pValue = cJSON_GetObjectItem(pRoot, "power_limit");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "power_limit");
portCfgData->power_limit = 0;
}
else
{
if (0 == strcmp(pValue->valuestring, "auto"))
{
portCfgData->power_limit = POE_CLASS_CLASS3_AD;
portCfgData->power_limit_class = POE_CLASS_AUTO_AD;
}
else if(0 == strcmp(pValue->valuestring, "class1"))
{
portCfgData->power_limit = POE_CLASS_CLASS1_AD;
portCfgData->power_limit_class = POE_CLASS1_AD;
}
else if(0 == strcmp(pValue->valuestring, "class2"))
{
portCfgData->power_limit = POE_CLASS_CLASS2_AD;
portCfgData->power_limit_class = POE_CLASS2_AD;
}
else if(0 == strcmp(pValue->valuestring, "class3"))
{
portCfgData->power_limit = POE_CLASS_CLASS3_AD;
portCfgData->power_limit_class = POE_CLASS3_AD;
}
// we cant set class4?
// else if(0 == strcmp(pValue->valuestring, "class4"))
// {
// portCfgData->power_limit = POE_CLASS_CLASS4_AD;
// }
else if(0 == strcmp(pValue->valuestring, "manual"))
{
/*power_limit_value*/
pValue = cJSON_GetObjectItem(pRoot, "power_limit_value");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "power_limit_value");
portCfgData->power_limit = POE_CLASS_CLASS3_AD;
portCfgData->power_limit_class = POE_CLASS_MANUAL_AD;
}
else
{
portCfgData->power_limit = (int)(atof(pValue->valuestring)*10);
portCfgData->power_limit_class = POE_CLASS_MANUAL_AD;
}
}
}
return OK;
}
static int
_composePortcfg(const POE_PORT_CFG_STRUCT_UC *portCfgData,cJSON *pEntry,int idx)
{
/*index*/
cJSON_AddNumberToObject(pEntry, "id", portCfgData->port_no);
/* port */
cJSON_AddNumberToObject(pEntry, "port", portCfgData->port_no);
/* poe_profile */
if(portCfgData->poe_profile_no == 0)
{
cJSON_AddStringToObject(pEntry, "poe_profile", "default-none"); //todo
}
else
{
cJSON_AddNumberToObject(pEntry, "poe_profile", portCfgData->poe_profile_no); //todo
}
/*power_limit*/
cJSON_AddNumberToObject(pEntry, "power_limit_value", (float)(portCfgData->power_limit)/10.0);
//@wxh 待修复 power limit 不能正常显示的问题, portCfgData->power_limit_class
// if(portCfgData->power_limit == POE_CLASS_CLASS1_AD)
// cJSON_AddStringToObject(pEntry, "power_limit", "class1");
// else if(portCfgData->power_limit == POE_CLASS_CLASS2_AD)
// cJSON_AddStringToObject(pEntry, "power_limit", "class2");
// else if(portCfgData->power_limit == POE_CLASS_CLASS3_AD)
// cJSON_AddStringToObject(pEntry, "power_limit", "class3");
// else if(portCfgData->power_limit == POE_CLASS_CLASS4_AD)
// cJSON_AddStringToObject(pEntry, "power_limit", "class4");
// else
// cJSON_AddStringToObject(pEntry, "power_limit", "manual");
//应该用
if(portCfgData->power_limit_class == POE_CLASS0_AD)
cJSON_AddStringToObject(pEntry, "power_limit", "class0");
else if(portCfgData->power_limit_class == POE_CLASS1_AD)
cJSON_AddStringToObject(pEntry, "power_limit", "class1");
else if(portCfgData->power_limit_class == POE_CLASS2_AD)
cJSON_AddStringToObject(pEntry, "power_limit", "class2");
else if(portCfgData->power_limit_class == POE_CLASS3_AD)
cJSON_AddStringToObject(pEntry, "power_limit", "class3");
else if(portCfgData->power_limit_class == POE_CLASS4_AD)
cJSON_AddStringToObject(pEntry, "power_limit", "class4");
// else if(portCfgData->power_limit_class == POE_CLASS_AUTO_AD)
// cJSON_AddStringToObject(pEntry, "power_limit", "class3");
else if(portCfgData->power_limit_class == POE_CLASS_AUTO_AD)
cJSON_AddStringToObject(pEntry, "power_limit", "auto");
else if(portCfgData->power_limit_class == POE_CLASS_MANUAL_AD)
cJSON_AddStringToObject(pEntry, "power_limit", "manual");
else
return ERROR;
//
/*poe_enable*/ /*status*/
if(portCfgData->poe_enable == POE_ENABLE)
cJSON_AddStringToObject(pEntry, "status", "on");
else
cJSON_AddStringToObject(pEntry, "status", "off");
/*priority*/
if(portCfgData->priority == POE_PRI_LOW_AD)
cJSON_AddStringToObject(pEntry, "priority", "low");
else if(portCfgData->priority == POE_PRI_MIDDLE_AD)
cJSON_AddStringToObject(pEntry, "priority", "middle");
else if(portCfgData->priority == POE_PRI_HIGH_AD)
cJSON_AddStringToObject(pEntry, "priority", "high");
else
cJSON_AddStringToObject(pEntry, "priority", "error"); //dbg
//not support
cJSON_AddStringToObject(pEntry, "time_range", "any");
cJSON_AddNumberToObject(pEntry, "current", (float)(portCfgData->actual_cur));
cJSON_AddNumberToObject(pEntry, "voltage", (float)(portCfgData->actual_vol)/10.0);
cJSON_AddNumberToObject(pEntry, "power", (float)(portCfgData->actual_cons)/10.0);
if(portCfgData->pd_class == POE_CLASS_CLASS1_AD)
cJSON_AddNumberToObject(pEntry, "pd_class", 1);
else if(portCfgData->pd_class == POE_CLASS_CLASS2_AD)
cJSON_AddNumberToObject(pEntry, "pd_class", 2);
else if(portCfgData->pd_class == POE_CLASS_CLASS3_AD)
cJSON_AddNumberToObject(pEntry, "pd_class", 3);
else if(portCfgData->pd_class == POE_CLASS_CLASS4_AD)
cJSON_AddNumberToObject(pEntry, "pd_class", 4);
else
cJSON_AddNumberToObject(pEntry, "pd_class", 0);
if(portCfgData->actual_cons > 0)
{
cJSON_AddStringToObject(pEntry, "power_status", "on");
}
else
{
cJSON_AddStringToObject(pEntry, "power_status", "off");
}
cJSON_AddBoolToObject(pEntry, "port_overload", portCfgData->port_overload == 1);
return OK;
}
static void
_portCfgJsonWrite(HTTP_DATATEMP *pData, POE_PORT_CFG_STRUCT_UC *portCfgData, POE_PROFILE_STRUCT_UC *profileData,int status, int err)
{
cJSON *root = NULL;
cJSON *poeOutInfo = NULL;
cJSON *othersInfo = NULL;
unsigned int l_poeBitMap = poeBitMap;
char *out = NULL;
int idx = 0;
if (NULL == portCfgData)
{
return;
}
root = cJSON_CreateObject();
if (NULL == root)
{
return;
}
poeOutInfo = cJSON_CreateArray();
if (NULL == poeOutInfo)
{
cJSON_Delete(root);
return;
}
othersInfo = cJSON_CreateObject();
if (NULL == othersInfo)
{
cJSON_Delete(root);
return;
}
cJSON_AddItemToObject(root, "success", cJSON_CreateBool(OK == status));
cJSON_AddNumberToObject(root, "error", err);
cJSON_AddItemToObject(root, "data", poeOutInfo);
cJSON_AddItemToObject(root, "others", othersInfo);
// for (idx = 0; portCfgData != NULL && idx < MAX_POE_PORT_NUM; idx ++)
/* @wxh 解耦端口数量 */
// for (idx = 0; portCfgData != NULL && idx < configuredPortNum; idx ++)
// {
// cJSON *entry = cJSON_CreateObject();
// status = _composePortcfg(portCfgData,entry,idx);
// if(status != OK)
// {
// return;
// }
// cJSON_AddItemToArray(poeOutInfo, entry);
// portCfgData++;
// }
/* @wxh 解耦端口数量 */
while (l_poeBitMap) // poeBitMap 二进制中1所在位置的端口设置为开启(从右往左看,最低位的1表示端口1开启,依次类推)
{
idx++;
if (l_poeBitMap & 1)
{
cJSON *entry = cJSON_CreateObject();
status = _composePortcfg(portCfgData,entry,idx);
if(status != OK)
{
return;
}
cJSON_AddItemToArray(poeOutInfo, entry);
}
l_poeBitMap >>= 1;
portCfgData++;
}
cJSON *profileOptions = cJSON_CreateArray();
for (idx = 0; profileData != NULL && profileData->profileName[0] != '\0' && idx < MAX_POE_PROFILE_NUM; idx ++)
{
cJSON *entry = cJSON_CreateObject();
cJSON_AddNumberToObject(entry, "profile_id", profileData->profile_id);
cJSON_AddStringToObject(entry, "profile_name", (void*)profileData->profileName);
cJSON_AddItemToArray(profileOptions, entry);
profileData++;
}
cJSON_AddItemToObject(othersInfo, "profile_option", profileOptions);
out = cJSON_Print(root);
if (NULL != out)
{
pData->contentLength = strlen(out);
http_parser_makeHeader(pData, HTTP_OK);
http_io_fwrite(pData->pDataPersist, out, strlen(out));
pData->outputState = HTTP_NONEED_RETURN;
}
cJSON_Delete(root);
if (NULL != out)
{
free(out);
}
return;
}
HTTP_STATUS port_cfg_get(HTTP_CONTEXT *pContext)
{
STATUS status = OK;
WRP_RET wrpRet = WRP_OK;
POE_PORT_CFG_STRUCT_UC info_new[MAX_POE_PORT_NUM];
POE_PROFILE_STRUCT_UC profile_info[MAX_POE_PROFILE_NUM];
HTTP_DATATEMP *pData = NULL;
if (pContext == NULL)
return RPM_ERROR;
pData = pContext->pHttp_datatemp;
pData->outputState = HTTP_NEED_RETURN200;
memset(&info_new, 0, sizeof(info_new));
wrpRet = wrpOpDo(UCL_OPID_POE_GET_PORT_CONFIG, NULL, 0, info_new, sizeof(POE_PORT_CFG_STRUCT_UC) * MAX_POE_PORT_NUM, WRP_TRAN_TYPE_READ);
if (WRP_OK != wrpRet)
{
status = ERROR;
}
memset(profile_info, 0, sizeof(profile_info));
wrpRet = wrpOpDo(UCL_OPID_POE_PROFILE_GET, NULL, 0, profile_info, sizeof(POE_PROFILE_STRUCT_UC) * MAX_POE_PROFILE_NUM, WRP_TRAN_TYPE_READ);
if (WRP_OK != wrpRet)
{
status = ERROR;
}
_portCfgJsonWrite(pData, info_new, profile_info, status, OK); //ok
return RPM_DONE;
}
HTTP_STATUS port_cfg_set(HTTP_CONTEXT *pContext)
{
WRP_RET wrpRet = WRP_OK;
POE_PORT_CFG_STRUCT_UC info_new;
POE_PROFILE_STRUCT_UC info_profile[MAX_POE_PROFILE_NUM];
UINT32 err = 0;
HTTP_DATATEMP *pData = NULL;
if (pContext == NULL)
return RPM_ERROR;
pData = pContext->pHttp_datatemp;
pData->outputState = HTTP_NEED_RETURN200;
RPM_POST_2_OTHER_OP(pContext, "load", NULL, port_cfg_get); //todo
memset(info_profile, 0, sizeof(info_profile));
wrpRet = wrpOpDo(UCL_OPID_POE_PROFILE_GET, NULL, 0, info_profile, sizeof(POE_PROFILE_STRUCT_UC) * MAX_POE_PROFILE_NUM, WRP_TRAN_TYPE_READ);
if (WRP_OK != wrpRet)
{
printf("UCL_OPID_POE_PROFILE_GET ERROR\n");
return RPM_ERROR;
}
_parsePortCfgSet(pData, &info_new, info_profile); //ok
wrpRet = wrpOpDo(UCL_OPID_POE_SET_PORT_CONFIG, &info_new, sizeof(POE_PORT_CFG_STRUCT_UC),
&err, sizeof(UINT32), WRP_TRAN_TYPE_WRITE);
if (WRP_OK != wrpRet)
{
printf("UCL_OPID_POE_SET_PORT_CONFIG ERROR\n");
return RPM_ERROR;
}
return port_cfg_get(pContext);
}
//ok
static void
_recoveryGlobalJsonWrite(HTTP_DATATEMP *pData, POE_RECOVERY_STATUS_UC *poeOutCfgData, int status, int err)
{
printf("####&&&& goto [%s]\n",__FUNCTION__);
cJSON *root = NULL;
cJSON *poeOutInfo = NULL;
char *out = NULL;
if (NULL == poeOutCfgData)
{
return;
}
root = cJSON_CreateObject();
if (NULL == root)
{
return;
}
poeOutInfo = cJSON_CreateObject();
if (NULL == poeOutInfo)
{
cJSON_Delete(root);
return;
}
cJSON_AddItemToObject(root, "success", cJSON_CreateBool(OK == status));
cJSON_AddNumberToObject(root, "error", err);
cJSON_AddItemToObject(root, "data", poeOutInfo);
/*
typedef enum
{
POE_RECOVERY_DISABLE_UC = 0,
POE_RECOVERY_ENABLE_UC
}POE_RECOVERY_STATUS_UC;
*/
if( *poeOutCfgData == POE_RECOVERY_ENABLE_UC)
{
cJSON_AddStringToObject(poeOutInfo, "global", "on");
printf("####&&&& in [%s] cJSON_AddStringToObject(poeOutInfo, global, on); \n",__FUNCTION__);
}
else if( *poeOutCfgData == POE_RECOVERY_DISABLE_UC)
{
cJSON_AddStringToObject(poeOutInfo, "global", "off");
printf("####&&&& in [%s] cJSON_AddStringToObject(poeOutInfo, global, off); \n",__FUNCTION__);
}
else
{
printf("####&&&& http_poeOut (%s) read wrong param,use default\n", "_recoveryGlobalJsonWrite");
cJSON_AddStringToObject(poeOutInfo, "global", "off");
}
out = cJSON_Print(root);
if (NULL != out)
{
pData->contentLength = strlen(out);
http_parser_makeHeader(pData, HTTP_OK);
http_io_fwrite(pData->pDataPersist, out, strlen(out));
pData->outputState = HTTP_NONEED_RETURN;
}
cJSON_Delete(root);
if (NULL != out)
{
free(out);
}
return;
}
HTTP_STATUS recovery_global_get(HTTP_CONTEXT *pContext)
{
printf("####&&&& goto [%s] &&&&####\n",__FUNCTION__);
STATUS status = OK;
WRP_RET wrpRet = WRP_OK;
POE_RECOVERY_STATUS_UC info;
HTTP_DATATEMP *pData = NULL;
if (pContext == NULL)
return RPM_ERROR;
pData = pContext->pHttp_datatemp;
pData->outputState = HTTP_NEED_RETURN200;
memset(&info, 0, sizeof(info));
wrpRet = wrpOpDo(UCL_OPID_POE_RECOVRY_GET_ENABLE, NULL, 0, &info, sizeof(POE_RECOVERY_STATUS_UC), WRP_TRAN_TYPE_READ);
if (WRP_OK != wrpRet)
{
status = ERROR;
}
_recoveryGlobalJsonWrite(pData, &info, status, OK); //ok
return RPM_DONE;
}
static STATUS
_recoveryGlobalCfgSet(HTTP_DATATEMP *pData, POE_RECOVERY_STATUS_UC *poeOutCfgData)
{
printf("####&&&& goto [%s]\n",__FUNCTION__);
char *pStr = NULL;
// cJSON *pRoot = NULL;
// cJSON *pValue = NULL;
if (NULL == poeOutCfgData)
{
return ERROR;
}
// pStr = httpGetEnv(pData, "data");
// if (NULL == pStr)
// {
// // printf("failed to get param str:%s", "data");
// printf("####&&&& in [%s] failed to get param str:%s\n", __FUNCTION__, "data");
// return ERROR;
// }
// printf("_recoveryGlobalCfgSet data str:%s", pStr);
// pRoot = cJSON_Parse(pStr);
// if (NULL == pRoot)
// {
// printf("failed to parse json str:%s\n", pStr);
// return ERROR;
// }
// /*global*/
// pValue = cJSON_GetObjectItem(pRoot, "global");
// if (NULL == pValue || (pValue->type != cJSON_String))
// {
// printf("module(%s) not present,use default \n", "global");
// printf("####&&&& module(%s) not present,use default \n", "global");
// *poeOutCfgData = POE_RECOVERY_DISABLE_UC;
// }
// else
// {
// if (0 == strcmp(pValue->valuestring, "on"))
// {
// printf("####&&&& in [%s] pData: pValue->valuestring : on\n",__FUNCTION__);
// *poeOutCfgData = POE_RECOVERY_ENABLE_UC;
// }
// else if(0 == strcmp(pValue->valuestring, "off"))
// {
// printf("####&&&& in [%s] pData: pValue->valuestring : off\n",__FUNCTION__);
// *poeOutCfgData = POE_RECOVERY_DISABLE_UC;
// }
// else
// {
// printf("####&&&& module(%s)2 not present,use default", "global");
// printf("module(%s)2 not present,use default", "global");
// *poeOutCfgData = POE_RECOVERY_DISABLE_UC;
// }
// }
/*global*/
pStr = httpGetEnv(pData, "global");
if (NULL == pStr)
{
printf("####&&&& in [%s] failed to get param str: %s\n", __FUNCTION__, "global");
return ERROR;
}
printf("####&&&& in [%s] global str:%s\n", __FUNCTION__, pStr);
if (NULL == pStr)
{
printf("####&&&& module(%s) not present,use default \n", "global");
*poeOutCfgData = POE_RECOVERY_DISABLE_UC;
}
else
{
if (0 == strcmp(pStr, "on"))
{
printf("####&&&& in [%s] pData: pValue->valuestring : on\n",__FUNCTION__);
*poeOutCfgData = POE_RECOVERY_ENABLE_UC;
}
else if(0 == strcmp(pStr, "off"))
{
printf("####&&&& in [%s] pData: pValue->valuestring : off\n",__FUNCTION__);
*poeOutCfgData = POE_RECOVERY_DISABLE_UC;
}
else
{
printf("####&&&& module(%s)2 not present,use default", "global");
printf("module(%s)2 not present,use default", "global");
*poeOutCfgData = POE_RECOVERY_DISABLE_UC;
}
}
return OK;
}
HTTP_STATUS recovery_global_set(HTTP_CONTEXT *pContext)
{
printf("####&&&& goto [%s] &&&&####\n",__FUNCTION__);
STATUS status = OK;
WRP_RET wrpRet = WRP_OK;
POE_RECOVERY_STATUS_UC info;
UINT32 err = 0;
HTTP_DATATEMP *pData = NULL;
if (pContext == NULL)
return RPM_ERROR;
pData = pContext->pHttp_datatemp;
pData->outputState = HTTP_NEED_RETURN200;
printf("####&&&& in [%s]\n",__FUNCTION__);
// RPM_POST_2_OTHER_OP(pContext, "load", NULL, recovery_global_get); //ok
RPM_POST_2_OTHER_OP(pContext, "read", NULL, recovery_global_get); //ok
printf("####&&&& in [%s] have done functionRPM_POST_2_OTHER_OP \n",__FUNCTION__);
_recoveryGlobalCfgSet(pData, &info); //ok
wrpRet = wrpOpDo(UCL_OPID_POE_RECOVRY_SET_ENABLE, &info, sizeof(POE_RECOVERY_STATUS_UC),
&err, sizeof(UINT32), WRP_TRAN_TYPE_WRITE);
if (WRP_OK != wrpRet)
{
status = ERROR;
}
else
{
status = OK;
}
wrpRet = wrpOpDo(UCL_OPID_POE_RECOVRY_GET_ENABLE, NULL, 0, &info, sizeof(POE_RECOVERY_STATUS_UC), WRP_TRAN_TYPE_READ);
if (WRP_OK != wrpRet)
{
status = ERROR;
}
_recoveryGlobalJsonWrite(pData, &info, status, err); //ok
return RPM_DONE;
}
static int
_composeRecoveryPortcfg(const POE_PORTRECOVERYCFG_STRUCT *recoveryPortCfgData,cJSON *pEntry, int idx)
{
// /* index */
// cJSON_AddNumberToObject(pEntry, "id", idx);
// /*port_no*/
// cJSON_AddNumberToObject(pEntry, "port", recoveryPortCfgData->port_no);
// /*status */
// if(POE_RECOVERY_ENABLE_UC == recoveryPortCfgData->status)
// cJSON_AddStringToObject(pEntry, "status", "on");
// else
// cJSON_AddStringToObject(pEntry, "status", "off");
// /*ip*/
// cJSON_AddStringToObject(pEntry, "ip", recoveryPortCfgData->ip);
// /*startup*/
// cJSON_AddNumberToObject(pEntry, "startup", recoveryPortCfgData->startup);
// /*interval*/
// cJSON_AddNumberToObject(pEntry, "interval", recoveryPortCfgData->interval);
// /*failure_threshold*/
// cJSON_AddNumberToObject(pEntry, "failure_threshold", recoveryPortCfgData->retry);
// /*break_time*/
// cJSON_AddNumberToObject(pEntry, "break_time", recoveryPortCfgData->reboot);
// /*failures*/
// cJSON_AddNumberToObject(pEntry, "failures", recoveryPortCfgData->failure);
// /*reboots*/
// cJSON_AddNumberToObject(pEntry, "reboots", recoveryPortCfgData->restart);
// /*total*/
// cJSON_AddNumberToObject(pEntry, "total", recoveryPortCfgData->total);
/* 转换成string 类型的响应*/
char buf_port[16], buf_startup[16], buf_interval[16], buf_retry[16];
char buf_reboot[16], buf_failure[16], buf_restart[16], buf_total[16];
/* index */
cJSON_AddNumberToObject(pEntry, "id", idx);
/*port_no*/
snprintf(buf_port, sizeof(buf_port), "%d", recoveryPortCfgData->port_no);
cJSON_AddStringToObject(pEntry, "port", buf_port);
/*status */
if(POE_RECOVERY_ENABLE_UC == recoveryPortCfgData->status)
cJSON_AddStringToObject(pEntry, "status", "on");
else
cJSON_AddStringToObject(pEntry, "status", "off");
/*ip*/
cJSON_AddStringToObject(pEntry, "ip", recoveryPortCfgData->ip);
/*startup*/
snprintf(buf_startup, sizeof(buf_startup), "%d", recoveryPortCfgData->startup);
cJSON_AddStringToObject(pEntry, "startup", buf_startup);
/*interval*/
snprintf(buf_interval, sizeof(buf_interval), "%d", recoveryPortCfgData->interval);
cJSON_AddStringToObject(pEntry, "interval", buf_interval);
/*failure_threshold*/
snprintf(buf_retry, sizeof(buf_retry), "%d", recoveryPortCfgData->retry);
cJSON_AddStringToObject(pEntry, "failure_threshold", buf_retry);
/*break_time*/
snprintf(buf_reboot, sizeof(buf_reboot), "%d", recoveryPortCfgData->reboot);
cJSON_AddStringToObject(pEntry, "break_time", buf_reboot);
/*failures*/
snprintf(buf_failure, sizeof(buf_failure), "%d", recoveryPortCfgData->failure);
cJSON_AddStringToObject(pEntry, "failures", buf_failure);
/*reboots*/
snprintf(buf_restart, sizeof(buf_restart), "%d", recoveryPortCfgData->restart);
cJSON_AddStringToObject(pEntry, "reboots", buf_restart);
/*total*/
snprintf(buf_total, sizeof(buf_total), "%d", recoveryPortCfgData->total);
cJSON_AddStringToObject(pEntry, "total", buf_total);
return OK;
}
static void
_recoveryPortCfgJsonWrite(HTTP_DATATEMP *pData, POE_PORTRECOVERYCFG_STRUCT *recoveryPortCfgData, int status, int err)
{
cJSON *root = NULL;
cJSON *poeOutInfo = NULL;
char *out = NULL;
int idx = 0;
unsigned int l_poeBitMap = poeBitMap;
if (NULL == recoveryPortCfgData)
{
return;
}
root = cJSON_CreateObject();
if (NULL == root)
{
return;
}
poeOutInfo = cJSON_CreateArray();
if (NULL == poeOutInfo)
{
cJSON_Delete(root);
return;
}
/* @wxh 解耦端口数量 */
if(0 == l_poeBitMap)
{
printf("####&&&& [%s] error: l_poeBitMap = 0\n",__FUNCTION__);
}
cJSON_AddItemToObject(root, "success", cJSON_CreateBool(OK == status));
cJSON_AddNumberToObject(root, "error", err);
cJSON_AddItemToObject(root, "data", poeOutInfo);
// for (idx = 0; recoveryPortCfgData != NULL && idx < MAX_POE_PORT_NUM; idx ++) // idx: port 1 对应 idx 0, port 2 对应idx 1
// for (idx = 0; recoveryPortCfgData != NULL && idx < configuredPortNum; idx ++)
// {
// if(0 == recoveryPortCfgData->port_no || 0 == recoveryPortCfgData->startup || 0 == recoveryPortCfgData->interval) // 跳过端口号等于 0 的无数据的端口
// {
// recoveryPortCfgData++;
// continue;
// }
// cJSON *entry = cJSON_CreateObject();
// status = _composeRecoveryPortcfg(recoveryPortCfgData,entry,idx); //ok
// if(status != OK)
// {
// return;
// }
// cJSON_AddItemToArray(poeOutInfo, entry);
// recoveryPortCfgData++;
// }
/* @wxh 解耦端口数量 */
while (l_poeBitMap) // poeBitMap 二进制中1所在位置的端口设置为开启(从右往左看,最低位的1表示端口1开启,依次类推)
{
idx++;
if (l_poeBitMap & 1)
{
if(0 == recoveryPortCfgData->port_no || 0 == recoveryPortCfgData->startup || 0 == recoveryPortCfgData->interval) // 跳过端口号等于 0 的无数据的端口
{
// printf("[%s] 0 == recoveryPortCfgData->port_no || 0 == recoveryPortCfgData->startup || 0 == recoveryPortCfgData->interval \n",__FUNCTION__);
}
else
{
cJSON *entry = cJSON_CreateObject();
status = _composeRecoveryPortcfg(recoveryPortCfgData,entry,idx); //ok
if(status != OK)
{
return;
}
cJSON_AddItemToArray(poeOutInfo, entry);
}
}
l_poeBitMap >>= 1;
recoveryPortCfgData++;
}
out = cJSON_Print(root);
if (NULL != out)
{
pData->contentLength = strlen(out);
http_parser_makeHeader(pData, HTTP_OK);
http_io_fwrite(pData->pDataPersist, out, strlen(out));
pData->outputState = HTTP_NONEED_RETURN;
}
cJSON_Delete(root);
if (NULL != out)
{
free(out);
}
return;
}
HTTP_STATUS recovery_port_cfg_get(HTTP_CONTEXT *pContext)
{
// printf("####&&&& goto [%s] &&&&####\n",__FUNCTION__);
STATUS status = OK;
WRP_RET wrpRet = WRP_OK;
POE_PORTRECOVERYCFG_STRUCT info[MAX_POE_PORT_NUM];
HTTP_DATATEMP *pData = NULL;
if (pContext == NULL)
return RPM_ERROR;
pData = pContext->pHttp_datatemp;
pData->outputState = HTTP_NEED_RETURN200;
memset(&info, 0, sizeof(info));
wrpRet = wrpOpDo(UCL_OPID_POE_RECOVRY_GET_PORT_CONFIG, NULL, 0, info, sizeof(POE_PORTRECOVERYCFG_STRUCT) * MAX_POE_PORT_NUM, WRP_TRAN_TYPE_READ);
if (WRP_OK != wrpRet)
{
status = ERROR;
}
_recoveryPortCfgJsonWrite(pData, info, status, OK); //ok
/* @wxh 解耦端口数量 */
// POE_PORTRECOVERYCFG_STRUCT *info_used = malloc(configuredPortNum * sizeof(POE_PORTRECOVERYCFG_STRUCT));
// memcpy(info_used, info, configuredPortNum * sizeof(POE_PORTRECOVERYCFG_STRUCT));
// if (!info_used)
// {
// // 错误处理
// printf("Memory allocation failed for configuredPortNum = %d\n", configuredPortNum);
// return RPM_ERROR;
// }
// else
// {
// printf(" _recoveryPortCfgJsonWrite(pData, info_used, status, OK); \n");
// _recoveryPortCfgJsonWrite(pData, info_used, status, OK);
// }
// free(info_used); // 释放避免泄漏
return RPM_DONE;
}
static STATUS
_parseRecoveryPortCfgAdd(HTTP_DATATEMP *pData, POE_PORTRECOVERYCFG_STRUCT *recoveryPortCfgData)
{
char *pStr = NULL;
cJSON *pRoot = NULL;
cJSON *pValue = NULL;
if (NULL == recoveryPortCfgData)
{
return ERROR;
}
pStr = httpGetEnv(pData, "new");
if (NULL == pStr)
{
printf("failed to get param str:%s\n", "new");
return ERROR;
}
printf("_parseRecoveryPortCfgAdd data str:%s\n", pStr);
pRoot = cJSON_Parse(pStr);
if (NULL == pRoot)
{
printf("failed to parse json str:%s\n", pStr);
return ERROR;
}
/*port*/
pValue = cJSON_GetObjectItem(pRoot, "port");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("input(%s) is ERROR \n", "port");
return ERROR;
}
else
{
recoveryPortCfgData->port_no = atoi(pValue->valuestring);
}
/*status*/
pValue = cJSON_GetObjectItem(pRoot, "status");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "status");
recoveryPortCfgData->status = POE_RECOVERY_DISABLE_UC;
}
else
{
if (0 == strcmp(pValue->valuestring, "on"))
{
recoveryPortCfgData->status = POE_RECOVERY_ENABLE_UC;
}
else if(0 == strcmp(pValue->valuestring, "off"))
{
recoveryPortCfgData->status = POE_RECOVERY_DISABLE_UC;
}
}
/*ip*/
pValue = cJSON_GetObjectItem(pRoot, "ip");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("input(%s) is ERROR \n", "ip");
return ERROR;
}
else
{
snprintf(recoveryPortCfgData->ip,IP_STR_LEN,pValue->valuestring);
}
/*startup*/
pValue = cJSON_GetObjectItem(pRoot, "startup");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("input(%s) is ERROR\n", "startup");
return ERROR;
}
else
{
recoveryPortCfgData->startup = atoi(pValue->valuestring);
}
/*interval*/
pValue = cJSON_GetObjectItem(pRoot, "interval");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("input(%s) is ERROR\n", "interval");
return ERROR;
}
else
{
recoveryPortCfgData->interval = atoi(pValue->valuestring);
}
/*failure_threshold*/
pValue = cJSON_GetObjectItem(pRoot, "failure_threshold");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("input(%s) is ERROR\n", "failure_threshold");
return ERROR;
}
else
{
recoveryPortCfgData->retry = atoi(pValue->valuestring);
}
/*break_time*/
pValue = cJSON_GetObjectItem(pRoot, "break_time");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("input(%s) is ERROR\n", "break_time");
return ERROR;
}
else
{
recoveryPortCfgData->reboot = atoi(pValue->valuestring);
}
recoveryPortCfgData->failure = 0;
recoveryPortCfgData->restart = 0;
recoveryPortCfgData->total = 0;
return OK;
}
static STATUS
_parseRecoveryPortCfgSet(HTTP_DATATEMP *pData, POE_PORTRECOVERYCFG_STRUCT *new_recoveryPortCfgData, POE_PORTRECOVERYCFG_STRUCT *old_recoveryPortCfgData)
{
char *pStr = NULL;
cJSON *pRoot = NULL;
cJSON *pValue = NULL;
char *pStr2 = NULL;
cJSON *pRoot2 = NULL;
cJSON *pValue2 = NULL;
if (NULL == new_recoveryPortCfgData)
{
return ERROR;
}
pStr = httpGetEnv(pData, "new");
if (NULL == pStr)
{
printf("failed to get param str:%s\n", "new");
return ERROR;
}
printf("_parseRecoveryPortCfgSet data str:%s\n", pStr);
pRoot = cJSON_Parse(pStr);
if (NULL == pRoot)
{
printf("failed to parse json str:%s\n", pStr);
return ERROR;
}
/*port*/
pValue = cJSON_GetObjectItem(pRoot, "port");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("input(%s) is ERROR \n", "port");
return ERROR;
}
else
{
new_recoveryPortCfgData->port_no = atoi(pValue->valuestring);
}
/*status*/
pValue = cJSON_GetObjectItem(pRoot, "status");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "status");
new_recoveryPortCfgData->status = POE_RECOVERY_DISABLE_UC;
}
else
{
if (0 == strcmp(pValue->valuestring, "on"))
{
new_recoveryPortCfgData->status = POE_RECOVERY_ENABLE_UC;
}
else if(0 == strcmp(pValue->valuestring, "off"))
{
new_recoveryPortCfgData->status = POE_RECOVERY_DISABLE_UC;
}
}
/*ip*/
pValue = cJSON_GetObjectItem(pRoot, "ip");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("input(%s) is ERROR \n", "ip");
return ERROR;
}
else
{
snprintf(new_recoveryPortCfgData->ip,IP_STR_LEN,pValue->valuestring);
}
/*startup*/
pValue = cJSON_GetObjectItem(pRoot, "startup");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("input(%s) is ERROR\n", "startup");
return ERROR;
}
else
{
new_recoveryPortCfgData->startup = atoi(pValue->valuestring);
}
/*interval*/
pValue = cJSON_GetObjectItem(pRoot, "interval");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("input(%s) is ERROR\n", "interval");
return ERROR;
}
else
{
new_recoveryPortCfgData->interval = atoi(pValue->valuestring);
}
/*failure_threshold*/
pValue = cJSON_GetObjectItem(pRoot, "failure_threshold");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("input(%s) is ERROR\n", "failure_threshold");
return ERROR;
}
else
{
new_recoveryPortCfgData->retry = atoi(pValue->valuestring);
}
/*break_time*/
pValue = cJSON_GetObjectItem(pRoot, "break_time");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("input(%s) is ERROR\n", "break_time");
return ERROR;
}
else
{
new_recoveryPortCfgData->reboot = atoi(pValue->valuestring);
}
new_recoveryPortCfgData->failure = 0;
new_recoveryPortCfgData->restart = 0;
new_recoveryPortCfgData->total = 0;
/* get old port Data */
printf("[%s] execute get old port Data\n", __FUNCTION__);
if (NULL == old_recoveryPortCfgData)
{
return ERROR;
}
pStr2 = httpGetEnv(pData, "old");
if (NULL == pStr2)
{
printf("failed to get param str:%s\n", "old");
return ERROR;
}
printf("_parseRecoveryPortCfgSet data str:%s\n", pStr2);
pRoot2 = cJSON_Parse(pStr2);
if (NULL == pRoot2)
{
printf("failed to parse json str:%s\n", pStr2);
return ERROR;
}
else
{
printf("sucessed to parse json str:%s\n", pStr2);
}
/*port*/
pValue2 = cJSON_GetObjectItem(pRoot2, "port");
if (NULL == pValue2 || (pValue2->type != cJSON_String))
{
printf("input(%s) is ERROR \n", "port");
return ERROR;
}
else
{
// old_recoveryPortCfgData->port_no = atoi(pValue->valuestring);
old_recoveryPortCfgData->port_no = atoi(pValue2->valuestring);
printf("sucessed to cJSON_GetObjectItem:%s\n", "port");
printf("[%s] old_recoveryPortCfgData->port_no = %d\n", __FUNCTION__, old_recoveryPortCfgData->port_no);
}
return OK;
}
static STATUS
_parseRecoveryPortCfgDel(HTTP_DATATEMP *pData, int *index)
{
// char *pStr = NULL;
char *port = NULL;
// cJSON *pRoot = NULL;
// cJSON *pValue = NULL;
if (NULL == index)
{
return ERROR;
}
/*index*/
// pIndex = httpGetEnv(pData, "index");
// pIndex = httpGetEnv(pData, "key");
port = httpGetEnv(pData, "port");
if (NULL == port)
{
printf("####&&&& in [%s] failed to get NULL param str: %s\n", __FUNCTION__, "port");
return ERROR;
}
*index = atoi(port);
if (*index < 1 || *index > MAX_POE_PORT_NUM)
{
printf("####&&&& in [%s] the param str: %s\n is out of range", __FUNCTION__, "port");
return ERROR;
}
printf("####&&&& in [%s] *port = %d\n", __FUNCTION__, *index);
return OK;
}
HTTP_STATUS recovery_port_cfg_set(HTTP_CONTEXT *pContext)
{
// printf("####&&&& goto [%s] &&&&####\n",__FUNCTION__);
STATUS status = OK;
WRP_RET wrpRet = WRP_OK;
WRP_RET wrpRet1 = WRP_OK;
WRP_RET wrpRet2 = WRP_OK;
POE_PORTRECOVERYCFG_STRUCT info;
POE_PORTRECOVERYCFG_STRUCT old_info;
int info_delIndex = 0;
UINT32 err = 0;
HTTP_DATATEMP *pData = NULL;
if (pContext == NULL)
return RPM_ERROR;
pData = pContext->pHttp_datatemp;
pData->outputState = HTTP_NEED_RETURN200;
RPM_POST_2_OTHER_OP(pContext, "load", NULL, recovery_port_cfg_get);
char* pStr = httpGetEnv(pContext->pHttp_datatemp,"operation");
// if( 0 == strcmp(pStr, "add"))
if( 0 == strcmp(pStr, "insert"))
{
_parseRecoveryPortCfgAdd(pData, &info);
wrpRet = wrpOpDo(UCL_OPID_POE_RECOVRY_ADD_PORT_CONFIG, &info, sizeof(POE_PORTRECOVERYCFG_STRUCT),
&err, sizeof(UINT32), WRP_TRAN_TYPE_WRITE);
if (WRP_OK != wrpRet)
status = ERROR;
else
status = OK;
}
// else if( 0 == strcmp(pStr, "set"))
else if (0 == strcmp(pStr, "update"))
{
_parseRecoveryPortCfgSet(pData, &info, &old_info);
if (info.port_no != old_info.port_no) // port changed
{
printf("移除 old_info.port_no, 新增 info->port_no\n");
info_delIndex = old_info.port_no;
printf("[%s] update: execute UCL_OPID_POE_RECOVRY_DEL_PORT_CONFIG wrpRet\n", __FUNCTION__);
wrpRet1 = wrpOpDo(UCL_OPID_POE_RECOVRY_DEL_PORT_CONFIG, (void *)&info_delIndex, sizeof(int),
&err, sizeof(UINT32), WRP_TRAN_TYPE_WRITE);
printf("[%s] update: UCL_OPID_POE_RECOVRY_DEL_PORT_CONFIG wrpRet1 = %d\n", __FUNCTION__, wrpRet1);
printf("[%s] update: execute UCL_OPID_POE_RECOVRY_ADD_PORT_CONFIG wrpRet\n", __FUNCTION__);
wrpRet2 = wrpOpDo(UCL_OPID_POE_RECOVRY_ADD_PORT_CONFIG, &info, sizeof(POE_PORTRECOVERYCFG_STRUCT),
&err, sizeof(UINT32), WRP_TRAN_TYPE_WRITE);
printf("[%s] update: UCL_OPID_POE_RECOVRY_ADD_PORT_CONFIG wrpRet2 = %d\n", __FUNCTION__, wrpRet2);
}
else // ohter param changed
{
wrpRet = wrpOpDo(UCL_OPID_POE_RECOVRY_SET_PORT_CONFIG, &info, sizeof(POE_PORTRECOVERYCFG_STRUCT),
&err, sizeof(UINT32), WRP_TRAN_TYPE_WRITE);
}
if (WRP_OK != wrpRet)
status = ERROR;
else
status = OK;
}
// else if( 0 == strcmp(pStr, "delete"))
else if( 0 == strcmp(pStr, "remove"))
{
if(OK == _parseRecoveryPortCfgDel(pData, (void*)&info_delIndex))
{
wrpRet = wrpOpDo(UCL_OPID_POE_RECOVRY_DEL_PORT_CONFIG, (void*)&info_delIndex, sizeof(int),
&err, sizeof(UINT32), WRP_TRAN_TYPE_WRITE);
}
else
{
printf("####&&&& in [%s] return error.\n", __FUNCTION__);
}
if (WRP_OK != wrpRet)
status = ERROR;
else
status = OK;
}
else
{
printf("recovery_port_cfg_set operation (%s) is ERROR", pStr);
return ERROR;
}
wrpRet = status;
return recovery_port_cfg_get(pContext);
}
static int
_composeProfilecfg(const POE_PROFILE_STRUCT_UC *profileData,cJSON *pEntry,int idx)
{
/* index */
cJSON_AddNumberToObject(pEntry, "id", profileData->profile_id);
/*profile_name*/
cJSON_AddStringToObject(pEntry, "profile_name", (void*)profileData->profileName);
/*poe_enable*/ /*status*/
if(profileData->poe_enable == POE_ENABLE)
cJSON_AddStringToObject(pEntry, "status", "on");
else
cJSON_AddStringToObject(pEntry, "status", "off");
/*priority*/
if(profileData->priority == POE_PRI_LOW_AD)
cJSON_AddStringToObject(pEntry, "priority", "low");
else if(profileData->priority == POE_PRI_MIDDLE_AD)
cJSON_AddStringToObject(pEntry, "priority", "middle");
else if(profileData->priority == POE_PRI_HIGH_AD)
cJSON_AddStringToObject(pEntry, "priority", "high");
else
cJSON_AddStringToObject(pEntry, "priority", "error");
/*power_limit*/
cJSON_AddNumberToObject(pEntry, "power_limit_value", (float)profileData->power_limit/10.0);
if(profileData->power_limit_class == POE_CLASS0_AD)
cJSON_AddStringToObject(pEntry, "power_limit", "class0");
else if(profileData->power_limit_class == POE_CLASS1_AD)
cJSON_AddStringToObject(pEntry, "power_limit", "class1");
else if(profileData->power_limit_class == POE_CLASS2_AD)
cJSON_AddStringToObject(pEntry, "power_limit", "class2");
else if(profileData->power_limit_class == POE_CLASS3_AD)
cJSON_AddStringToObject(pEntry, "power_limit", "class3");
else if(profileData->power_limit_class == POE_CLASS4_AD)
cJSON_AddStringToObject(pEntry, "power_limit", "class4");
else if(profileData->power_limit_class == POE_CLASS_AUTO_AD)
cJSON_AddStringToObject(pEntry, "power_limit", "auto");
else if(profileData->power_limit_class == POE_CLASS_MANUAL_AD)
cJSON_AddStringToObject(pEntry, "power_limit", "manual");
cJSON_AddBoolToObject(pEntry, "in_use", profileData->profile_in_use);
return OK;
}
static void
_profileJsonWrite(HTTP_DATATEMP *pData, POE_PROFILE_STRUCT_UC *profileData, int status, int err)
{
cJSON *root = NULL;
cJSON *poeOutInfo = NULL;
char *out = NULL;
int idx = 0;
if (NULL == profileData)
{
return;
}
root = cJSON_CreateObject();
if (NULL == root)
{
return;
}
poeOutInfo = cJSON_CreateArray();
if (NULL == poeOutInfo)
{
cJSON_Delete(root);
return;
}
cJSON_AddItemToObject(root, "success", cJSON_CreateBool(OK == status));
cJSON_AddNumberToObject(root, "error", err);
cJSON_AddItemToObject(root, "data", poeOutInfo);
for (idx = 0; profileData != NULL && idx < MAX_POE_PROFILE_NUM; idx ++)
{
if(profileData->profileName[0] == '\0')
{
profileData++;
continue;
}
cJSON *entry = cJSON_CreateObject();
status = _composeProfilecfg(profileData,entry,idx); //ok
if(status != OK)
{
return;
}
cJSON_AddItemToArray(poeOutInfo, entry);
profileData++;
}
out = cJSON_Print(root);
if (NULL != out)
{
pData->contentLength = strlen(out);
http_parser_makeHeader(pData, HTTP_OK);
http_io_fwrite(pData->pDataPersist, out, strlen(out));
pData->outputState = HTTP_NONEED_RETURN;
}
cJSON_Delete(root);
if (NULL != out)
{
free(out);
}
return;
}
HTTP_STATUS profile_get(HTTP_CONTEXT *pContext)
{
STATUS status = OK;
WRP_RET wrpRet = WRP_OK;
POE_PROFILE_STRUCT_UC info_new[MAX_POE_PROFILE_NUM];
HTTP_DATATEMP *pData = NULL;
if (pContext == NULL)
return RPM_ERROR;
pData = pContext->pHttp_datatemp;
pData->outputState = HTTP_NEED_RETURN200;
memset(info_new, 0, sizeof(info_new));
wrpRet = wrpOpDo(UCL_OPID_POE_PROFILE_GET, NULL, 0, info_new, sizeof(POE_PROFILE_STRUCT_UC) * MAX_POE_PROFILE_NUM, WRP_TRAN_TYPE_READ);
if (WRP_OK != wrpRet)
{
status = ERROR;
}
_profileJsonWrite(pData, info_new, status, OK); //ok
return RPM_DONE;
}
HTTP_STATUS profile_get_afterDelFailed(HTTP_CONTEXT *pContext)
{
STATUS status = ERROR;
WRP_RET wrpRet = WRP_OK;
POE_PROFILE_STRUCT_UC info_new[MAX_POE_PROFILE_NUM];
HTTP_DATATEMP *pData = NULL;
if (pContext == NULL)
return RPM_ERROR;
pData = pContext->pHttp_datatemp;
pData->outputState = HTTP_NEED_RETURN200;
memset(info_new, 0, sizeof(info_new));
wrpRet = wrpOpDo(UCL_OPID_POE_PROFILE_GET, NULL, 0, info_new, sizeof(POE_PROFILE_STRUCT_UC) * MAX_POE_PROFILE_NUM, WRP_TRAN_TYPE_READ);
if (WRP_OK != wrpRet)
{
status = ERROR;
}
_profileJsonWrite(pData, info_new, status, 4001); //ok
return RPM_DONE;
}
static STATUS
_parseProfileAdd(HTTP_DATATEMP *pData, POE_PROFILE_STRUCT_UC *profileData)
{
char *pStr = NULL;
cJSON *pRoot = NULL;
cJSON *pValue = NULL;
if (NULL == profileData)
{
return ERROR;
}
pStr = httpGetEnv(pData, "new");
if (NULL == pStr)
{
printf("failed to get param str:%s", "new");
return ERROR;
}
printf("data str:%s \n", pStr);
pRoot = cJSON_Parse(pStr);
if (NULL == pRoot)
{
printf("failed to parse json str:%s", pStr);
return ERROR;
}
// doesnt have profile id when add new profile_id
// /* profile_id */
// if (NULL == pValue || (pValue->type != cJSON_Number))
// {
// printf("module(%s) not present,use default \n", "profile_id");
// // return ERROR;
// }
// else
// {
// profileData->profile_id = pValue->valueint;
// }
/*profile_name*/
pValue = cJSON_GetObjectItem(pRoot, "profile_name");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "profile_name");
return ERROR;
}
else
{
snprintf((char *)profileData->profileName,strlen(pValue->valuestring)+1,pValue->valuestring);
}
/*status*/
pValue = cJSON_GetObjectItem(pRoot, "status");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "status");
profileData->poe_enable = POE_RECOVERY_DISABLE_UC;
}
else
{
if (0 == strcmp(pValue->valuestring, "on"))
{
profileData->poe_enable = POE_RECOVERY_ENABLE_UC;
}
else if(0 == strcmp(pValue->valuestring, "off"))
{
profileData->poe_enable = POE_RECOVERY_DISABLE_UC;
}
}
/*priority*/
pValue = cJSON_GetObjectItem(pRoot, "priority");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "priority");
profileData->priority = POE_PRI_LOW_AD;
}
else
{
if (0 == strcmp(pValue->valuestring, "low"))
{
profileData->priority = POE_PRI_LOW_AD;
}
else if (0 == strcmp(pValue->valuestring, "middle"))
{
profileData->priority = POE_PRI_MIDDLE_AD;
}
else if (0 == strcmp(pValue->valuestring, "high"))
{
profileData->priority = POE_PRI_HIGH_AD;
}
else
{
printf("module(%s)2 not present ,use default", "priority");
profileData->priority = POE_PRI_LOW_AD;
}
}
/*power_limit*/
pValue = cJSON_GetObjectItem(pRoot, "power_limit");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "power_limit");
profileData->power_limit = 0;
}
else
{
if (0 == strcmp(pValue->valuestring, "auto"))
{
profileData->power_limit = POE_CLASS_CLASS3_AD;
profileData->power_limit_class = POE_CLASS_AUTO_AD;
}
else if(0 == strcmp(pValue->valuestring, "class1"))
{
profileData->power_limit = POE_CLASS_CLASS1_AD;
profileData->power_limit_class = POE_CLASS1_AD;
}
else if(0 == strcmp(pValue->valuestring, "class2"))
{
profileData->power_limit = POE_CLASS_CLASS2_AD;
profileData->power_limit_class = POE_CLASS2_AD;
}
else if(0 == strcmp(pValue->valuestring, "class3"))
{
profileData->power_limit = POE_CLASS_CLASS3_AD;
profileData->power_limit_class = POE_CLASS3_AD;
}
//need check:can we set class4?
// else if(0 == strcmp(pValue->valuestring, "class4"))
// {
// profileData->power_limit = POE_CLASS_CLASS4_AD;
// profileData->power_limit_class = POE_CLASS4_AD;
// }
else if(0 == strcmp(pValue->valuestring, "manual"))
{
/*power_limit_value*/
pValue = cJSON_GetObjectItem(pRoot, "power_limit_value");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "power_limit_value");
profileData->power_limit = 0;
profileData->power_limit_class = POE_CLASS_MANUAL_AD;
}
else
{
profileData->power_limit = (int)(atof(pValue->valuestring)*10);
profileData->power_limit_class = POE_CLASS_MANUAL_AD;
}
}
}
return OK;
}
static STATUS
_parseProfileMod(HTTP_DATATEMP *pData, POE_PROFILE_STRUCT_UC *profileData)
{
char *pStr = NULL;
cJSON *pRoot = NULL;
cJSON *pValue = NULL;
if (NULL == profileData)
{
return ERROR;
}
pStr = httpGetEnv(pData, "old");
if (NULL == pStr)
{
printf("failed to get param str:%s", "old");
return ERROR;
}
printf("data str:%s \n", pStr);
pRoot = cJSON_Parse(pStr);
if (NULL == pRoot)
{
printf("failed to parse json str:%s", pStr);
return ERROR;
}
/* profile_id */
pValue = cJSON_GetObjectItem(pRoot, "id");
if (NULL == pValue || (pValue->type != cJSON_Number))
{
printf("module(%s) not present,use default \n", "profile_id");
// return ERROR;
}
else
{
profileData->profile_id = pValue->valueint;
}
/*profile_name*/
pValue = cJSON_GetObjectItem(pRoot, "profile_name");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "profile_name");
return ERROR;
}
else
{
snprintf((char *)profileData->profileName,strlen(pValue->valuestring)+1,pValue->valuestring);
}
pStr = httpGetEnv(pData, "new");
if (NULL == pStr)
{
printf("failed to get param str:%s", "new");
return ERROR;
}
printf("data str:%s \n", pStr);
pRoot = cJSON_Parse(pStr);
if (NULL == pRoot)
{
printf("failed to parse json str:%s", pStr);
return ERROR;
}
/*status*/
pValue = cJSON_GetObjectItem(pRoot, "status");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "status");
profileData->poe_enable = POE_RECOVERY_DISABLE_UC;
}
else
{
if (0 == strcmp(pValue->valuestring, "on"))
{
profileData->poe_enable = POE_RECOVERY_ENABLE_UC;
}
else if(0 == strcmp(pValue->valuestring, "off"))
{
profileData->poe_enable = POE_RECOVERY_DISABLE_UC;
}
}
/*priority*/
pValue = cJSON_GetObjectItem(pRoot, "priority");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "priority");
profileData->priority = POE_PRI_LOW_AD;
}
else
{
if (0 == strcmp(pValue->valuestring, "low"))
{
profileData->priority = POE_PRI_LOW_AD;
}
else if (0 == strcmp(pValue->valuestring, "middle"))
{
profileData->priority = POE_PRI_MIDDLE_AD;
}
else if (0 == strcmp(pValue->valuestring, "high"))
{
profileData->priority = POE_PRI_HIGH_AD;
}
else
{
printf("module(%s)2 not present ,use default", "priority");
profileData->priority = POE_PRI_LOW_AD;
}
}
/*power_limit*/
pValue = cJSON_GetObjectItem(pRoot, "power_limit");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "power_limit");
profileData->power_limit = 0;
}
else
{
if (0 == strcmp(pValue->valuestring, "auto"))
{
profileData->power_limit = POE_CLASS_CLASS3_AD;
profileData->power_limit_class = POE_CLASS_AUTO_AD;
}
else if(0 == strcmp(pValue->valuestring, "class1"))
{
profileData->power_limit = POE_CLASS_CLASS1_AD;
profileData->power_limit_class = POE_CLASS1_AD;
}
else if(0 == strcmp(pValue->valuestring, "class2"))
{
profileData->power_limit = POE_CLASS_CLASS2_AD;
profileData->power_limit_class = POE_CLASS2_AD;
}
else if(0 == strcmp(pValue->valuestring, "class3"))
{
profileData->power_limit = POE_CLASS_CLASS3_AD;
profileData->power_limit_class = POE_CLASS3_AD;
}
//need check:can we set class4?
// else if(0 == strcmp(pValue->valuestring, "class4"))
// {
// profileData->power_limit = POE_CLASS_CLASS4_AD;
// profileData->power_limit_class = POE_CLASS4_AD;
// }
else if(0 == strcmp(pValue->valuestring, "manual"))
{
/*power_limit_value*/
pValue = cJSON_GetObjectItem(pRoot, "power_limit_value");
if (NULL == pValue || (pValue->type != cJSON_String))
{
printf("module(%s) not present,use default \n", "power_limit_value");
profileData->power_limit = 0;
profileData->power_limit_class = POE_CLASS_MANUAL_AD;
}
else
{
profileData->power_limit = (int)(atof(pValue->valuestring)*10);
profileData->power_limit_class = POE_CLASS_MANUAL_AD;
}
}
}
return OK;
}
static STATUS
_parseProfileDel(HTTP_DATATEMP *pData, POE_PROFILE_STRUCT_UC *profileData)
{
char *pStr = NULL;
if (NULL == profileData)
{
return ERROR;
}
/* profile_name */
pStr = httpGetEnv(pData, "profile_name");
if (NULL == pStr)
{
printf("failed to get param str:%s\n", "profile_name");
return ERROR;
}
printf("_parseProfileDel data str:%s \n", pStr);
snprintf((char *)profileData->profileName,strlen(pStr)+1,pStr);
/* profile_id */
pStr = httpGetEnv(pData, "id");
if (NULL == pStr)
{
printf("failed to get param str:%s \n", "profile_id");
return ERROR;
}
printf("_parseProfileDel data str:%s \n", pStr);
profileData->profile_id = atoi(pStr);
return OK;
}
// profile_set
HTTP_STATUS profile_set(HTTP_CONTEXT *pContext)
{
STATUS status = OK;
WRP_RET wrpRet = WRP_OK;
POE_PROFILE_STRUCT_UC info[MAX_POE_PORT_NUM];
// int info_delIndex = 0;
UINT32 err = 0;
HTTP_DATATEMP *pData = NULL;
if (pContext == NULL)
return RPM_ERROR;
pData = pContext->pHttp_datatemp;
pData->outputState = HTTP_NEED_RETURN200;
RPM_POST_2_OTHER_OP(pContext, "load", NULL, profile_get);
char* pStr = httpGetEnv(pContext->pHttp_datatemp,"operation");
if( 0 == strcmp(pStr, "insert"))
{
_parseProfileAdd(pData, info); //ok
wrpRet = wrpOpDo(UCL_OPID_POE_PROFILE_ADD, info, sizeof(POE_PROFILE_STRUCT_UC),
&err, sizeof(int), WRP_TRAN_TYPE_WRITE);
if (WRP_OK != wrpRet)
status = ERROR;
else
status = OK;
}
else if( 0 == strcmp(pStr, "update"))
{
_parseProfileMod(pData, info); //ok
wrpRet = wrpOpDo(UCL_OPID_POE_PROFILE_MOD, info, sizeof(POE_PROFILE_STRUCT_UC),
&err, sizeof(int), WRP_TRAN_TYPE_WRITE);
if (WRP_OK != wrpRet)
status = ERROR;
else
status = OK;
}
else if( 0 == strcmp(pStr, "remove"))
{
// _parseProfileDel(pData, (void*)&info_delIndex);
_parseProfileDel(pData, info); //doing
// wrpRet = wrpOpDo(UCL_OPID_POE_PROFILE_DEL, (void*)&info_delIndex, sizeof(int),
// &err, sizeof(int), WRP_TRAN_TYPE_WRITE);
wrpRet = wrpOpDo(UCL_OPID_POE_PROFILE_DEL, info, sizeof(POE_PROFILE_STRUCT_UC),
&err, sizeof(int), WRP_TRAN_TYPE_WRITE);
if (WRP_OK != wrpRet)
status = ERROR;
else
status = OK;
if(err!=UCL_OK){
return profile_get_afterDelFailed(pContext);
}
}
else
{
printf("profile_set operation (%s) is ERROR \n", pStr);
return ERROR;
}
wrpRet = status;
return profile_get(pContext);
}
// todo
// @wxh poe_port_status.json poe_port_status_get
static void
_recoveryPortStatusJsonWrite(HTTP_DATATEMP *pData, POE_PORTRECOVERYCFG_STRUCT *recoveryPortCfgData, int status, int err)
{
printf("####&&&& goto [%s]\n",__FUNCTION__);
cJSON *root = NULL;
cJSON *poeOutInfo = NULL;
char *out = NULL;
int i = 0;
unsigned int l_poeBitMap = poeBitMap;
if (NULL == recoveryPortCfgData)
{
printf("####&&&& [%s] goto NULL == recoveryPortCfgData then return\n",__FUNCTION__);
// return;
}
root = cJSON_CreateObject();
if (NULL == root)
{
return;
}
poeOutInfo = cJSON_CreateArray();
if (NULL == poeOutInfo)
{
cJSON_Delete(root);
return;
}
cJSON_AddItemToObject(root, "success", cJSON_CreateBool(OK == status));
cJSON_AddNumberToObject(root, "error", err);
cJSON_AddItemToObject(root, "data", poeOutInfo);
/* @wxh 解耦端口数量 */
// printf("####&&&& in [%s] configuredPortNum = %d &&&&####\n",__FUNCTION__, configuredPortNum);
// for (i = 0; i < configuredPortNum; i++)
// {
// cJSON *entry = cJSON_CreateObject();
// cJSON_AddStringToObject(entry, "state", "connected");
// cJSON_AddNumberToObject(entry, "port", i + 1);
// cJSON_AddItemToArray(poeOutInfo, entry);
// }
/* @wxh 解耦端口数量 */
while (l_poeBitMap) // poeBitMap 二进制中1所在位置的端口设置为开启(从右往左看,最低位的1表示端口1开启,依次类推)
{
i++;
if (l_poeBitMap & 1)
{
cJSON *entry = cJSON_CreateObject();
cJSON_AddStringToObject(entry, "state", "connected");
cJSON_AddNumberToObject(entry, "port", i);
cJSON_AddItemToArray(poeOutInfo, entry);
}
l_poeBitMap >>= 1;
recoveryPortCfgData++;
}
out = cJSON_Print(root);
if (NULL != out)
{
pData->contentLength = strlen(out);
http_parser_makeHeader(pData, HTTP_OK);
http_io_fwrite(pData->pDataPersist, out, strlen(out));
pData->outputState = HTTP_NONEED_RETURN;
}
cJSON_Delete(root);
if (NULL != out)
{
free(out);
}
return;
}
HTTP_STATUS poe_port_status_get(HTTP_CONTEXT *pContext)
{
printf("####&&&& goto [%s] &&&&####\n",__FUNCTION__);
STATUS status = OK;
// WRP_RET wrpRet = WRP_OK;
POE_PORTRECOVERYCFG_STRUCT info[MAX_POE_PORT_NUM];
HTTP_DATATEMP *pData = NULL;
if (pContext == NULL)
return RPM_ERROR;
pData = pContext->pHttp_datatemp;
pData->outputState = HTTP_NEED_RETURN200;
memset(&info, 0, sizeof(info));
// wrpRet = wrpOpDo(UCL_OPID_POE_RECOVRY_GET_PORT_CONFIG, NULL, 0, info, sizeof(POE_PORTRECOVERYCFG_STRUCT) * MAX_POE_PORT_NUM, WRP_TRAN_TYPE_READ);
// if (WRP_OK != wrpRet)
// {
// status = ERROR;
// }
_recoveryPortStatusJsonWrite(pData, info, status, OK); //ok
return RPM_DONE;
}
/**************************************************************************************************/
/* PUBLIC_FUNCTIONS */
/**************************************************************************************************/
void http_managementPoeOutHandlerInit()
{
if(!poeBitMap || !configuredPortNum)
{
poeBitMap = devcfg_downLinkPort_getPoeOutBitMap();
configuredPortNum = devcfg_calculate_poeBitMap(poeBitMap);
printf(" [%s] ####&&&& poeBitMap = devcfg_downLinkPort_getPoeOutBitMap(); configuredPortNum = devcfg_calculate_poeBitMap(poeBitMap); &&&&#### \n", __FUNCTION__);
printf(" ####&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& poeBitMap = %d, configuredPortNum = %d &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&#### \n",poeBitMap, configuredPortNum);
}
if(!poeBitMap)
{
printf(" [%s] ####&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& poeBitMap init ERROR, poeBitMap = 0 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&#### \n", __FUNCTION__);
}
http_midware_getReg("/data/poe_cfg.json", poe_cfg_get, http_auth_check, NULL);
http_midware_postReg("/data/poe_cfg.json", poe_cfg_set, http_auth_check, NULL);
http_midware_getReg("/data/port_cfg.json", port_cfg_get, http_auth_check, NULL);
http_midware_postReg("/data/port_cfg.json", port_cfg_set, http_auth_check, NULL);
http_midware_getReg("/data/poe_profile.json", profile_get, http_auth_check, NULL);
http_midware_postReg("/data/poe_profile.json", profile_set, http_auth_check, NULL);
//not support recovery //@wxh testing
http_midware_getReg("/data/poe_auto_recovery_global.json", recovery_global_get, http_auth_check, NULL);
http_midware_postReg("/data/poe_auto_recovery_global.json", recovery_global_set, http_auth_check, NULL);
//not support recovery //@wxh testing
http_midware_getReg("/data/poe_auto_recovery_cfg.json", recovery_port_cfg_get, http_auth_check, NULL);
http_midware_postReg("/data/poe_auto_recovery_cfg.json", recovery_port_cfg_set, http_auth_check, NULL);
//@wxh not support now
// http_midware_getReg("/data/poe_port_status.json", poe_port_status_get, http_auth_check, NULL); //只需要响应?
http_midware_postReg("/data/poe_port_status.json", poe_port_status_get, http_auth_check, NULL);
}
/**************************************************************************************************/
/* GLOBAL_FUNCTIONS */
/**************************************************************************************************/
列出所有与 recovery 相关的函数的名字和入参 和他们的作用(简略)