/******************************************************************************
\* Copyright (c) 2018-2018 TP-Link Systems Inc.
*
\* Filename: tan_passthrough.c
\* Version: 1.0
\* Description: TAN请求中,与透传相关的指令处理接口
\* Author: Deng Peng<dengpeng@tp-link.com.cn>
\* Date: 2019-03-12
******************************************************************************/
\#include <stdio.h>
\#include <stdlib.h>
\#include <unistd.h>
\#include "onvif_passthrough.h"
\#include "soap_parse.h"
\#include "soap_pack.h"
\#include "soap_auth.h"
\#include "soap_tan.h"
\#include "md_active_cells.h"
\#define ACTIVE_CELLS_FORMAT "Value=\"%s\" Name=\"ActiveCells\""
/*********************************************************************************
\* tan:ModifyRules
*********************************************************************************/
/******************************************************************************
\* 函数名称: soap_out_tan_modify_rules_rsp()
\* 函数描述: 组装tan:ModifyRulesResponse element内容
\* 输 入: xml_buf -- 存放输出xml字串的内存地址
\* data -- 为空
\* 输 出: N/A
\* 返 回 值: ERROR/OK
******************************************************************************/
LOCAL S32 soap_out_tan_modify_rules_rsp(ONVIF_BUF *xml_buf, void *data)
{
if (xml_buf == NULL)
{
ONVIF_WARN("xml_buf == NULL.");
return ERROR;
}
/* 应答消息为空 */
SOAP_IF_FAIL_RET(soap_element(xml_buf, "tan:ModifyRulesResponse", NULL, NULL));
return OK;
}
/******************************************************************************
\* 函数名称: tan_modify_rules_json_to_xml()
\* 函数描述: tan:ModifyRules请求的应答报文构造函数
\* 输 入: soap -- soap结构体
\* json_rsp -- 应答的json数据
\* 输 出: N/A
\* 返 回 值: ERROR/OK
******************************************************************************/
LOCAL S32 tan_modify_rules_json_to_xml(SOAP_CONTEXT *soap, JSON_OBJ *json_rsp)
{
if (soap == NULL)
{
ONVIF_TRACE("soap == NULL.");
return ERROR;
}
ONVIF_TRACE("tan:ModifyRules rsp.");
return soap_generate_xml((p_out_fun)(soap_out_tan_modify_rules_rsp), soap, NULL);
}
/******************************************************************************
\* 函数名称: tan_modify_rules_xml_to_json()
\* 函数描述: 解析tan:ModifyRules请求的具体内容
\* 输 入: soap -- soap结构体
\* 输 出: json_req -- 根据请求构造的json object
\* 返 回 值: ERROR/OK
******************************************************************************/
LOCAL S32 tan_modify_rules_xml_to_json(SOAP_CONTEXT *soap, JSON_OBJ **json_req)
{
JSON_OBJ *jso_obj = NULL;
S32 request_len = 0;
S32 ch = 0;
char *xml_start = NULL;
char *xml_str = NULL;
char **p = NULL;
char charbuf[LEN_INFO] = {0};
char attr_in_name[2][10] = {{"Name"}, {"Value"}};
char attr_out_buf[2][(90 * 32)] = {{0}, {0}};/* 一个region_info的字符最大长度为90,region_info列表的成员个数不定,model_desc.xml中设置最大个数为32个 */
int name_str_len = sizeof(attr_in_name[0]);
int value_str_len = sizeof(attr_out_buf[0]);
int attr_num = sizeof(attr_in_name) / sizeof(attr_in_name[0]);
if (soap == NULL || json_req == NULL)
{
ONVIF_TRACE("soap == NULL.");
return ERROR;
}
ONVIF_TRACE("tan:ModifyRules parse.");
/* 需要鉴权 */
if (OK != soap_usernametoken_auth(soap, UM_OPERATOR))
{
ONVIF_TRACE("Auth failed\n");
soap_fault(soap, "SOAP-ENV:Sender", "ter:NotAuthorized", NULL, "Authority failure");
soap->error = 400;
return ERROR;
}
/* 分析ModifyRules请求的具体内容 */
if (soap->request_begin != NULL && soap->request_end != NULL)
{
request_len = soap->request_end - soap->request_begin;
if (request_len < 0)
{
ONVIF_TRACE("request_len < 0.");
goto error_parse;
}
xml_str = xml_start = soap->request_begin;
p = (char **)&xml_str;
}
else
{
ONVIF_ERROR("soap request content is NULL.");
return ERROR;
}
while (((*p) - xml_start) < request_len)
{
if ((ch = soap_get_tag(xml_start, request_len, p, charbuf, sizeof(charbuf))) == EOF)
{
goto error_parse;
}
if (charbuf[0] == '/')
{
continue;
}
if (TRUE == soap_match_tag(charbuf, "SimpleItem"))
{
if (IS_WHITE_SPACE(ch))
{
ch = soap_parse_element_attr_out_len(xml_start, request_len, p,
attr_num, (char *)attr_in_name, name_str_len, (char *)attr_out_buf, value_str_len);/* parse attribute */
ONVIF_TRACE("attr_out_buf_0[%s], attr_out_buf_1[%s]", attr_out_buf[0], attr_out_buf[1]);
if (ch == EOF)
{
ONVIF_TRACE("soap_parse_element_attr error.");
return ERROR;
}
if (0 == strcmp(attr_out_buf[0], "ActiveCells"))
{
ONVIF_TRACE("get value, break");
break;
}
else
{
memset(attr_out_buf, 0, sizeof(attr_out_buf));
}
}
continue;
}
}
/* 解析value值,生成json对象 */
jso_obj = parse_modify_rules_value(attr_out_buf[1]);
if (NULL == jso_obj)
{
ONVIF_TRACE("parse region_info error.");
return ERROR;
}
*json_req = jso_obj;
return OK;
error_parse:
return ERROR;
}
/*********************************************************************************
\* tan:ModifyAnalyticsModules
*********************************************************************************/
/******************************************************************************
\* 函数名称: soap_out_tan_modify_analytics_modules_rsp()
\* 函数描述: 组装tan:ModifyAnalyticsModulesResponse element内容
\* 输 入: xml_buf -- 存放输出xml字串的内存地址
\* data -- 为空
\* 输 出: N/A
\* 返 回 值: ERROR/OK
******************************************************************************/
LOCAL S32 soap_out_tan_modify_analytics_modules_rsp(ONVIF_BUF *xml_buf, void *data)
{
/* tan:ModifyAnalyticsModulesResponse */
if (xml_buf == NULL)
{
ONVIF_TRACE("xml_buf == NULL.");
return ERROR;
}
/* 应答消息为空 */
SOAP_IF_FAIL_RET(soap_element(xml_buf, "tan:ModifyAnalyticsModulesResponse", NULL, NULL));
return OK;
}
/******************************************************************************
\* 函数名称: tan_modify_analytics_modules_json_to_xml()
\* 函数描述: tan:ModifyAnalyticsModules请求的应答报文构造函数
\* 输 入: soap -- soap结构体
\* json_rsp -- 应答的json数据
\* 输 出: N/A
\* 返 回 值: ERROR/OK
******************************************************************************/
LOCAL S32 tan_modify_analytics_modules_json_to_xml(SOAP_CONTEXT *soap, JSON_OBJ *json_rsp)
{
if (soap == NULL)
{
ONVIF_TRACE("soap == NULL.");
return ERROR;
}
ONVIF_TRACE("tan:ModifyAnalyticsModules rsp.");
return soap_generate_xml((p_out_fun)(soap_out_tan_modify_analytics_modules_rsp), soap, NULL);
}
/******************************************************************************
\* 函数名称: tan_modify_analytics_modules_xml_to_json()
\* 函数描述: 解析tan:ModifyAnalyticsModules请求的具体内容
\* 输 入: soap -- soap结构体
\* 输 出: json_req -- 根据请求构造的json object
\* 返 回 值: ERROR/OK
******************************************************************************/
LOCAL S32 tan_modify_analytics_modules_xml_to_json(SOAP_CONTEXT *soap, JSON_OBJ **json_req)
{
JSON_OBJ *json_obj = NULL;
JSON_OBJ *json_son_obj = NULL;
JSON_OBJ *json_grandson_obj = NULL;
JSON_OBJ *json_son_obj2 = NULL;
JSON_OBJ *json_grandson_obj2 = NULL;
S32 request_len = 0;
S32 ch = 0;
char *xml_start = NULL;
char *xml_str = NULL;
char **p = NULL;
char charbuf[LEN_INFO] = {0};
char attr_name[1][5] = {{"Name"}};
int name_str_len = sizeof(attr_name[0]);
char attr_value_buf[1][20] = {{0}};
int value_str_len = sizeof(attr_value_buf[0]);
char attr_in_name[2][10] = {{"Name"}, {"Value"}};
char attr_out_buf[2][25] = {{0}, {0}};
if (soap == NULL || json_req == NULL)
{
ONVIF_TRACE("soap == NULL.");
return ERROR;
}
ONVIF_TRACE("tan:ModifyAnalyticsModules parse.");
/* 需要鉴权 */
if (OK != soap_usernametoken_auth(soap, UM_OPERATOR))
{
ONVIF_TRACE("Auth failed\n");
soap_fault(soap, "SOAP-ENV:Sender", "ter:NotAuthorized", NULL, "Authority failure");
soap->error = 400;
return ERROR;
}
/* 分析ModifyAnalyticsModules请求的具体内容 */
if (soap->request_begin != NULL && soap->request_end != NULL)
{
request_len = soap->request_end - soap->request_begin;
if (request_len < 0)
{
ONVIF_TRACE("request_len < 0.");
return ERROR;
}
xml_str = xml_start = soap->request_begin;
p = (char **)&xml_str;
}
else
{
ONVIF_ERROR("soap request content is NULL.");
return ERROR;
}
json_obj = jso_new_obj();
if (json_obj == NULL)
{
goto error_out;
}
while (((*p) - xml_start) < request_len)
{
if ((ch = soap_get_tag(xml_start, request_len, p, charbuf, sizeof(charbuf))) == EOF)
{
goto error_out;
}
if (charbuf[0] == '/')
{
continue;
}
/* 首先判断 tan:AnalyticsModule的 Name是 MyCellMotionModule 还是 MyTamperDetecModule */
if (TRUE == soap_match_tag(charbuf, "AnalyticsModule"))
{
if (IS_WHITE_SPACE(ch))
{
memset(attr_value_buf, 0, sizeof(attr_value_buf));
ch = soap_parse_element_attr_out_len(xml_start, request_len, p,
1, (char *)attr_name, name_str_len, (char *)attr_value_buf, value_str_len);/* parse attribute */
ONVIF_TRACE("attr_value_buf[%s]", attr_value_buf[0]);
if (ch == EOF)
{
ONVIF_TRACE("soap_parse_element_attr error.");
goto error_out;
}
if (0 == strcmp(attr_value_buf[0], "MyCellMotionModule"))
{
json_son_obj = jso_new_obj();
if (json_son_obj == NULL)
{
goto error_out;
}
jso_obj_add(json_obj, "motion_detection", json_son_obj);
json_grandson_obj = jso_new_obj();
if (json_grandson_obj == NULL)
{
goto error_out;
}
jso_obj_add(json_son_obj, "motion_det", json_grandson_obj);
ONVIF_TRACE("AnalyticsModule Name is MyCellMotionModule");
continue;
}
else if (0 == strcmp(attr_value_buf[0], "MyTamperDetecModule"))
{
json_son_obj2 = jso_new_obj();
if (json_son_obj2 == NULL)
{
goto error_out;
}
jso_obj_add(json_obj, "tamper_detection", json_son_obj2);
json_grandson_obj2 = jso_new_obj();
if (json_grandson_obj2 == NULL)
{
goto error_out;
}
jso_obj_add(json_son_obj2, "tamper_det", json_grandson_obj2);
ONVIF_TRACE("AnalyticsModule Name is MyTamperDetecModule");
continue;
}
}
continue;
}
if ((NULL == json_obj || NULL == json_son_obj || NULL == json_grandson_obj) && (NULL == json_obj || NULL == json_son_obj2 || NULL == json_grandson_obj2))
{
continue;
}
/* 然后读取两个Value
<tt:SimpleItem Name="Sensitivity" Value="high"/>
<tt:SimpleItem Name="Enabled" Value="on"/>
*/
if (TRUE == soap_match_tag(charbuf, "SimpleItem") && 0 == strcmp(attr_value_buf[0], "MyCellMotionModule"))
{
if (IS_WHITE_SPACE(ch))
{
memset(attr_out_buf, 0, sizeof(attr_out_buf));
ch = soap_parse_element_attr_out_len(xml_start, request_len, p,
//attr_in_name, attr_out_buf, 2);/* parse attribute */
2, (char *)attr_in_name, (sizeof(attr_in_name)[0]), (char *)attr_out_buf, (sizeof(attr_out_buf)[0]));
ONVIF_TRACE("attr_out_buf_1[%s], attr_out_buf_1[%s]", attr_out_buf[0], attr_out_buf[1]);
if (ch == EOF)
{
ONVIF_TRACE("soap_parse_element_attr error.");
goto error_out;
}
if (TRUE == soap_match_tag(attr_out_buf[0], "Sensitivity"))
{
ONVIF_TRACE("set Sensitivity %s", attr_out_buf[1]);
if((0 == strcmp("low", attr_out_buf[1])) ||
(0 == strcmp("medium", attr_out_buf[1])) ||
(0 == strcmp("high", attr_out_buf[1])))
{
jso_add_string(json_grandson_obj, "sensitivity", attr_out_buf[1]);
}
\#ifdef SENSITIVITY_INT
/* 使用数字灵敏度 */
else if (1 <= atoi(attr_out_buf[1]) && 100 >= atoi(attr_out_buf[1]))
{
jso_add_string(json_grandson_obj, "digital_sensitivity", attr_out_buf[1]);
jso_add_string(json_grandson_obj, "enabled", "on");
}
\#else
else if((1 <= atoi(attr_out_buf[1])) && (35 > atoi(attr_out_buf[1])))
{
jso_add_string(json_grandson_obj, "sensitivity", "low");
jso_add_string(json_grandson_obj, "enabled", "on");
}
else if((35 <= atoi(attr_out_buf[1])) && (65 >= atoi(attr_out_buf[1])))
{
jso_add_string(json_grandson_obj, "sensitivity", "medium");
jso_add_string(json_grandson_obj, "enabled", "on");
}
else if((65 < atoi(attr_out_buf[1])) && (100 >= atoi(attr_out_buf[1])))
{
jso_add_string(json_grandson_obj, "sensitivity", "high");
jso_add_string(json_grandson_obj, "enabled", "on");
}
\#endif
else if (0 == atoi(attr_out_buf[1]))
{
//jso_add_string(json_grandson_obj, "sensitivity", "medium");
jso_add_string(json_grandson_obj, "enabled", "off");
}
else
{
goto error_out;
}
}
else if (TRUE == soap_match_tag(attr_out_buf[0], "Enabled"))
{
jso_add_string(json_grandson_obj, "enabled", attr_out_buf[1]);
}
}
continue;
}
else if (TRUE == soap_match_tag(charbuf, "SimpleItem") && 0 == strcmp(attr_value_buf[0], "MyTamperDetecModule"))
{
if (IS_WHITE_SPACE(ch))
{
memset(attr_out_buf, 0, sizeof(attr_out_buf));
ch = soap_parse_element_attr_out_len(xml_start, request_len, p,
//attr_in_name, attr_out_buf, 2);/* parse attribute */
2, (char *)attr_in_name, (sizeof(attr_in_name)[0]), (char *)attr_out_buf, (sizeof(attr_out_buf)[0]));
ONVIF_TRACE("attr_out_buf_1[%s], attr_out_buf_1[%s]", attr_out_buf[0], attr_out_buf[1]);
if (ch == EOF)
{
ONVIF_TRACE("soap_parse_element_attr error.");
goto error_out;
}
if (TRUE == soap_match_tag(attr_out_buf[0], "Sensitivity"))
{
ONVIF_TRACE("set Sensitivity %s", attr_out_buf[1]);
if((0 == strcmp("low", attr_out_buf[1])) ||
(0 == strcmp("medium", attr_out_buf[1])) ||
(0 == strcmp("high", attr_out_buf[1])))
{
jso_add_string(json_grandson_obj2, "sensitivity", attr_out_buf[1]);
}
\#ifdef SENSITIVITY_INT
/* 使用数字灵敏度 */
else if (1 <= atoi(attr_out_buf[1]) && 100 >= atoi(attr_out_buf[1]))
{
jso_add_string(json_grandson_obj2, "digital_sensitivity", attr_out_buf[1]);
jso_add_string(json_grandson_obj2, "enabled", "on");
}
\#else
else if((1 <= atoi(attr_out_buf[1])) && (35 > atoi(attr_out_buf[1])))
{
jso_add_string(json_grandson_obj2, "sensitivity", "low");
jso_add_string(json_grandson_obj2, "enabled", "on");
}
else if((35 <= atoi(attr_out_buf[1])) && (65 >= atoi(attr_out_buf[1])))
{
jso_add_string(json_grandson_obj2, "sensitivity", "medium");
jso_add_string(json_grandson_obj2, "enabled", "on");
}
else if((65 < atoi(attr_out_buf[1])) && (100 >= atoi(attr_out_buf[1])))
{
jso_add_string(json_grandson_obj2, "sensitivity", "high");
jso_add_string(json_grandson_obj2, "enabled", "on");
}
\#endif
else if (0 == atoi(attr_out_buf[1]))
{
//jso_add_string(json_grandson_obj, "sensitivity", "medium");
jso_add_string(json_grandson_obj2, "enabled", "off");
}
else
{
goto error_out;
}
}
else if (TRUE == soap_match_tag(attr_out_buf[0], "Enabled"))
{
jso_add_string(json_grandson_obj2, "enabled", attr_out_buf[1]);
}
}
continue;
}
}
/* 当json_son_obj和json_grandson_obj为空时,说明未解析出tan:AnalyticsModule的Name */
if ((NULL == json_obj || NULL == json_son_obj || NULL == json_grandson_obj) && (NULL == json_obj || NULL == json_son_obj2 || NULL == json_grandson_obj2))
{
ONVIF_TRACE("parse error, soap %s", soap->request_begin);
goto error_out;
}
/* 组织json object */
jso_add_string(json_obj, "method", "set");
ONVIF_TRACE("json: %s", json_object_to_json_string(json_obj));
*json_req = json_obj;
return OK;
error_out:
jso_free_obj(json_obj);
return ERROR;
}
/*********************************************************************************
\* tan:GetRules
*********************************************************************************/
/******************************************************************************
\* 函数名称: soap_out_tan_get_rules_rsp()
\* 函数描述: 组装tan:GetRulesResponse element内容
\* 输 入: xml_buf -- 存放输出xml字串的内存地址
\* data -- 为空
\* 输 出: N/A
\* 返 回 值: ERROR/OK
******************************************************************************/
LOCAL S32 soap_out_tan_get_rules_rsp(ONVIF_BUF *xml_buf, char *data)
{
char *buf = NULL;
S32 len = 0;
S32 ret = 0;
S32 buf_len = 0;
/* tan:GetRulesResponse */
if (xml_buf == NULL || data == NULL)
{
ONVIF_TRACE("xml_buf == NULL.");
return ERROR;
}
/* tan:GetRulesResponse */
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tan:GetRulesResponse", NULL));
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tan:Rule", "Name=\"MyMotionDetectorRule\" Type=\"tt:CellMotionDetector\""));
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tt:Parameters", NULL));
ONVIF_TRACE("data: %s", data);
buf_len = strlen(data) + sizeof(ACTIVE_CELLS_FORMAT);
buf = SAFE_MALLOC(buf_len);
if (buf == NULL)
{
return ERROR;
}
memset(buf, 0, buf_len);
len = snprintf(buf, buf_len, ACTIVE_CELLS_FORMAT, data);
if (len > buf_len)
{
ONVIF_TRACE("buf is too small");
ret = ERROR;
goto out;
}
ONVIF_TRACE("buf: %s", (char *) buf);
ret = soap_element(xml_buf, "tt:SimpleItem", NULL, buf);
if (ret != OK)
{
goto out;
}
ret = soap_element(xml_buf, "tt:SimpleItem", NULL, "Value=\"5\" Name=\"MinCount\"");
if (ret != OK)
{
goto out;
}
ret = soap_element(xml_buf, "tt:SimpleItem", NULL, "Value=\"1000\" Name=\"AlarmOnDelay\"");
if (ret != OK)
{
goto out;
}
ret = soap_element(xml_buf, "tt:SimpleItem", NULL, "Value=\"1000\" Name=\"AlarmOffDelay\"");
if (ret != OK)
{
goto out;
}
ret = soap_element_end_out(xml_buf, "tt:Parameters");
if (ret != OK)
{
goto out;
}
ret = soap_element_end_out(xml_buf, "tan:Rule");
if (ret != OK)
{
goto out;
}
ret = soap_element_end_out(xml_buf, "tan:GetRulesResponse");
out:
SAFE_FREE(buf);
return ret;
}
/******************************************************************************
\* 函数名称: tan_get_rules_json_to_xml()
\* 函数描述: tan:GetRules请求的应答报文构造函数
\* 输 入: soap -- soap结构体
\* json_rsp -- 应答的json数据
\* 输 出: N/A
\* 返 回 值: ERROR/OK
******************************************************************************/
LOCAL S32 tan_get_rules_json_to_xml(SOAP_CONTEXT *soap, JSON_OBJ *json_rsp)
{
int ret = 0;
char *md_region_code = NULL;
json_object* json_data = NULL;
if (soap == NULL || json_rsp == NULL)
{
ONVIF_TRACE("soap == NULL.");
return ERROR;
}
ONVIF_TRACE("tan:GetRules rsp.");
/* 获取json_rsp中motion_detection/region_info的地址,不要单独释放json_data,否则会破坏json_rsp */
json_data = json_parse(json_rsp, "motion_detection", "region_info");
if (json_data == NULL)
{
ONVIF_TRACE("json_parse module get NULL");
return SOAP_FAULT;
}
ONVIF_TRACE("\n\n%s\n\n", json_object_to_json_string(json_data));
/* 读取移动侦测区域信息 */
md_region_code = md_get_active_cells_alloc(json_data);
if (md_region_code == NULL)
{
ONVIF_ERROR("get active cells failed");
return SOAP_FAULT;
}
ret = soap_generate_xml((p_out_fun)(soap_out_tan_get_rules_rsp), soap, md_region_code);
ONVIF_FREE(md_region_code);
return ret;
}
/******************************************************************************
\* 函数名称: tan_get_rules_xml_to_json()
\* 函数描述:解析onvif tan:GetRules请求报文的具体内容
\* 输 入: soap -- soap结构体
\* 输 出: N/A
\* 返 回 值: ERROR/OK
******************************************************************************/
LOCAL S32 tan_get_rules_xml_to_json(SOAP_CONTEXT *soap, JSON_OBJ **json_req)
{
JSON_OBJ *json_obj = NULL;
JSON_OBJ *json_sec = NULL;
if (soap == NULL || json_req == NULL)
{
ONVIF_TRACE("soap == NULL.");
return ERROR;
}
ONVIF_TRACE("tan:GetRules parse.");
/* 需要鉴权 */
if (OK != soap_usernametoken_auth(soap, UM_OPERATOR))
{
ONVIF_TRACE("Auth failed\n");
soap_fault(soap, "SOAP-ENV:Sender", "ter:NotAuthorized", NULL, "Authority failure");
soap->error = 400;
return ERROR;
}
/* 不需要分析tan:GetRules请求的具体内容 */
/* 组织json object */
json_obj = jso_new_obj();
json_sec = jso_new_obj();
if (json_obj == NULL || json_sec == NULL)
{
ONVIF_TRACE("jso_new_obj error.");
jso_free_obj(json_obj);
jso_free_obj(json_sec);
return ERROR;
}
jso_add_string(json_obj, "method", "get");
jso_obj_add(json_obj, "motion_detection", json_sec);
jso_add_string(json_sec, "name", "motion_det");
jso_add_string(json_sec, "table", "region_info");
*json_req = json_obj;
return OK;
}
/******************************************************************************
\* 函数名称: soap_out_tan_get_analytics_modules_rsp()
\* 函数描述: 组装tan:GetAnalyticsModulesResponse element内容
\* 输 入: xml_buf -- 存放输出xml字串的内存地址
\* data -- 实际为NULL
\* 输 出: N/A
\* 返 回 值: ERROR/OK
******************************************************************************/
LOCAL S32 soap_out_tan_get_analytics_modules_rsp(ONVIF_BUF *xml_buf, void *data)
{
/* tan:GetRulesResponse */
if (NULL== xml_buf)
{
ONVIF_TRACE("ptr is NULL.");
return ERROR;
}
MOTION_DETECT motion_detect;
char simpleItem[60] = {0};
/* 从ds中读取移动侦测enable情况 */
memset(&motion_detect, 0, sizeof(MOTION_DETECT));
if (0 == ds_read(MOTION_DETECT_PATH, &motion_detect, sizeof(MOTION_DETECT)))
{
ONVIF_TRACE("read motion_detect config fail.\n");
return ERROR;
}
OD_ALARM od_alarm;
char simple_item_od[60] = {0};
/* 从ds中读取遮挡侦测enable情况 */
memset(&od_alarm, 0, sizeof(OD_ALARM));
if (0 == ds_read(OD_ALARM_PATH, &od_alarm, sizeof(OD_ALARM)))
{
ONVIF_TRACE("read od_alarm config fail.\n");
return ERROR;
}
/* tan:GetRulesResponse */
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tan:GetAnalyticsModulesResponse", NULL));
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tan:AnalyticsModule", "Name=\"MyCellMotionModule\" Type=\"tt:CellMotionEngine\""));
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tt:Parameters", NULL));
/* IPC移动侦测关闭:0; IPC移动侦测打开:60 */
if (motion_detect.enabled)
{
snprintf(simpleItem, sizeof(simpleItem), "Value=\"%d\" Name=\"Sensitivity\"", motion_detect.digital_sensitivity);
SOAP_IF_FAIL_RET(soap_element(xml_buf, "tt:SimpleItem", NULL, simpleItem));
}
else
{
SOAP_IF_FAIL_RET(soap_element(xml_buf, "tt:SimpleItem", NULL, "Value=\"0\" Name=\"Sensitivity\""));
}
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tt:ElementItem", "Name=\"Layout\""));
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tt:CellLayout", "Rows=\"18\" Columns=\"22\""));
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tt:Transformation", NULL));
SOAP_IF_FAIL_RET(soap_element(xml_buf, "tt:Translate", NULL, "y=\"-1\" x=\"-1\""));
SOAP_IF_FAIL_RET(soap_element(xml_buf, "tt:Scale", NULL, "y=\"0.109999999\" x=\"0.0900000036\""));
SOAP_IF_FAIL_RET(soap_element_end_out(xml_buf, "tt:Transformation"));
SOAP_IF_FAIL_RET(soap_element_end_out(xml_buf, "tt:CellLayout"));
SOAP_IF_FAIL_RET(soap_element_end_out(xml_buf, "tt:ElementItem"));
SOAP_IF_FAIL_RET(soap_element_end_out(xml_buf, "tt:Parameters"));
SOAP_IF_FAIL_RET(soap_element_end_out(xml_buf, "tan:AnalyticsModule"));
/*MyTamperDetecModule*/
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tan:AnalyticsModule", "Name=\"MyTamperDetecModule\" Type=\"tt:TamperEngine\""));
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tt:Parameters", NULL));
if (od_alarm.enabled)
{
snprintf(simple_item_od, sizeof(simple_item_od), "Value=\"%d\" Name=\"Sensitivity\"", od_alarm.digital_sensitivity);
SOAP_IF_FAIL_RET(soap_element(xml_buf, "tt:SimpleItem", NULL, simple_item_od));
}
else
{
SOAP_IF_FAIL_RET(soap_element(xml_buf, "tt:SimpleItem", NULL, "Value=\"0\" Name=\"Sensitivity\""));
}
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tt:ElementItem", "Name=\"Transformation\""));
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tt:Transformation", NULL));
SOAP_IF_FAIL_RET(soap_element(xml_buf, "tt:Translate", NULL, "y=\"-1\" x=\"-1\""));
SOAP_IF_FAIL_RET(soap_element(xml_buf, "tt:Scale", NULL, "y=\"0.109999999\" x=\"0.0900000036\""));
SOAP_IF_FAIL_RET(soap_element_end_out(xml_buf, "tt:Transformation"));
SOAP_IF_FAIL_RET(soap_element_end_out(xml_buf, "tt:ElementItem"));
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tt:ElementItem", "Name=\"Field\""));
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tt:PolygonConfiguration", NULL));
SOAP_IF_FAIL_RET(soap_element_begin_out(xml_buf, "tt:Polygon", NULL));
SOAP_IF_FAIL_RET(soap_element(xml_buf, "tt:Point", NULL, "y=\"0\" x=\"0\""));
SOAP_IF_FAIL_RET(soap_element(xml_buf, "tt:Point", NULL, "y=\"10000\" x=\"0\""));
SOAP_IF_FAIL_RET(soap_element(xml_buf, "tt:Point", NULL, "y=\"0\" x=\"10000\""));
SOAP_IF_FAIL_RET(soap_element(xml_buf, "tt:Point", NULL, "y=\"10000\" x=\"10000\""));
SOAP_IF_FAIL_RET(soap_element_end_out(xml_buf, "tt:Polygon"));
SOAP_IF_FAIL_RET(soap_element_end_out(xml_buf, "tt:PolygonConfiguration"));
SOAP_IF_FAIL_RET(soap_element_end_out(xml_buf, "tt:ElementItem"));
SOAP_IF_FAIL_RET(soap_element_end_out(xml_buf, "tt:Parameters"));
SOAP_IF_FAIL_RET(soap_element_end_out(xml_buf, "tan:AnalyticsModule"));
SOAP_IF_FAIL_RET(soap_element_end_out(xml_buf, "tan:GetAnalyticsModulesResponse"));
return OK;
}
/******************************************************************************
\* 函数名称: tan_get_analytics_modules_json_to_xml()
\* 函数描述: tan:GetAnalyticsModules请求的应答报文构造函数
\* 输 入: soap -- soap结构体
\* json_rsp -- 应答的json数据
\* 输 出: N/A
\* 返 回 值: ERROR/OK
******************************************************************************/
LOCAL S32 tan_get_analytics_modules_json_to_xml(SOAP_CONTEXT *soap, JSON_OBJ *json_rsp)
{
MOTION_DETECT motion_detect;
if (soap == NULL)
{
ONVIF_TRACE("soap == NULL.");
return ERROR;
}
ONVIF_TRACE("tan:GetAnalyticsModules rsp.");
/* 从ds中读取移动侦测enable情况 */
memset(&motion_detect, 0, sizeof(MOTION_DETECT));
if (0 == ds_read(MOTION_DETECT_PATH, &motion_detect, sizeof(MOTION_DETECT)))
{
ONVIF_TRACE("read motion_detect config fail.\n");
soap->error = SOAP_FAULT;
return ERROR;
}
return soap_generate_xml((p_out_fun)(soap_out_tan_get_analytics_modules_rsp), soap, NULL);
}
/******************************************************************************
\* 函数名称: tan_get_analytics_modules_xml_to_json()
\* 函数描述: tan:GetAnalyticsModules请求的处理函数
\* 输 入: soap -- soap结构体
json_rsp-- 解析xml后得到的json数据
\* 输 出: N/A
\* 返 回 值: ERROR/OK
******************************************************************************/
LOCAL S32 tan_get_analytics_modules_xml_to_json(SOAP_CONTEXT *soap, JSON_OBJ **json_req)
{
JSON_OBJ *json_obj = NULL;
JSON_OBJ *json_sec = NULL;
if (soap == NULL || json_req == NULL)
{
ONVIF_TRACE("soap == NULL.");
return ERROR;
}
ONVIF_TRACE("tan:GetAnalyticsModules parse.");
/* 需要鉴权 */
if (OK != soap_usernametoken_auth(soap, UM_OPERATOR))
{
ONVIF_TRACE("Auth failed\n");
soap_fault(soap, "SOAP-ENV:Sender", "ter:NotAuthorized", NULL, "Authority failure");
soap->error = 400;
return ERROR;
}
/* 不需要分析SetSystemFactoryDefault请求的具体内容 */
/* 组织json object */
json_obj = jso_new_obj();
json_sec = jso_new_obj();
if (json_obj == NULL || json_sec == NULL)
{
ONVIF_WARN("jso_new_obj error.");
jso_free_obj(json_obj);
jso_free_obj(json_sec);
return ERROR;
}
jso_add_string(json_obj, "method", "get");
jso_obj_add(json_obj, "motion_detection", json_sec);
jso_add_string(json_sec, "name", "motion_det");
jso_add_string(json_sec, "table", "region_info");
*json_req = json_obj;
return OK;
}
/*********************************************************************************
\* Soap tan Handles init
*********************************************************************************/
void tan_passthrough_init()
{
onvif_passthrough_handle_add("tan:ModifyRules",
tan_modify_rules_xml_to_json,
tan_modify_rules_json_to_xml);
onvif_passthrough_handle_add("tan:ModifyAnalyticsModules",
tan_modify_analytics_modules_xml_to_json,
tan_modify_analytics_modules_json_to_xml);
onvif_passthrough_handle_add("tan:GetRules",
tan_get_rules_xml_to_json,
tan_get_rules_json_to_xml);
onvif_passthrough_handle_add("tan:GetAnalyticsModules",
tan_get_analytics_modules_xml_to_json,
tan_get_analytics_modules_json_to_xml);
}
——这个是关于透传层怎么调用soap_usernametoken_auth的例子,以下是目前的报文:只有digest凭据且验证通过情况下返回了200 OK但是SOAP消息体不对,发挥了SOAP FAULT,请问怎么解决?
HTTP/1.1 200 OK
Connection: close
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 1935
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV=“http://www.w3.org/2003/05/soap-envelope” xmlns:SOAP-ENC=“http://www.w3.org/2003/05/soap-encoding” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/2001/XMLSchema” xmlns:wsa=“http://schemas.xmlsoap.org/ws/2004/08/addressing” xmlns:wsdd=“http://schemas.xmlsoap.org/ws/2005/04/discovery” xmlns:chan=“http://schemas.microsoft.com/ws/2005/02/duplex” xmlns:wsse=“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd” xmlns:wsu=“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd” xmlns:wsa5=“http://www.w3.org/2005/08/addressing” xmlns:xmime=“http://tempuri.org/xmime.xsd” xmlns:xop=“http://www.w3.org/2004/08/xop/include” xmlns:wsrfbf=“http://docs.oasis-open.org/wsrf/bf-2” xmlns:wstop=“http://docs.oasis-open.org/wsn/t-1” xmlns:wsrfr=“http://docs.oasis-open.org/wsrf/r-2” xmlns:wsnt=“http://docs.oasis-open.org/wsn/b-2” xmlns:tt=“http://www.onvif.org/ver10/schema” xmlns:ter=“http://www.onvif.org/ver10/error” xmlns:tns1=“http://www.onvif.org/ver10/topics” xmlns:tds=“http://www.onvif.org/ver10/device/wsdl” xmlns:tmd=“http://www.onvif.org/ver10/deviceIO/wsdl” xmlns:trt=“http://www.onvif.org/ver10/media/wsdl” xmlns:tev=“http://www.onvif.org/ver10/events/wsdl” xmlns:tdn=“http://www.onvif.org/ver10/network/wsdl” xmlns:timg=“http://www.onvif.org/ver20/imaging/wsdl” xmlns:trp=“http://www.onvif.org/ver10/replay/wsdl” xmlns:tan=“http://www.onvif.org/ver20/analytics/wsdl” xmlns:tptz=“http://www.onvif.org/ver20/ptz/wsdl”>
SOAP-ENV:Body
SOAP-ENV:Fault
SOAP-ENV:Code
SOAP-ENV:ValueSOAP-ENV:Sender</SOAP-ENV:Value>
SOAP-ENV:Subcode
SOAP-ENV:Valueter:NotAuthorized</SOAP-ENV:Value>
</SOAP-ENV:Subcode>
</SOAP-ENV:Code>
SOAP-ENV:Reason
<SOAP-ENV:Text xml:lang=“en”>Authority failure</SOAP-ENV:Text>
</SOAP-ENV:Reason>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>