判断一条onvif消息是否完整:仅供参考
int is_onvif_msg(const char *psz_data, const int data_len)
{
if (NULL == psz_data ||data_len <= 0)
{
return 0;
}
const char *psz_mesg = psz_data;
const char *psz_head_pos = strstr(psz_mesg, "\r\n\r\n");
if (NULL == psz_head_pos)
{
return -1;
}
const char *psz_sub_pos = strstr(psz_mesg, "/onvif/"); //如果在http头中带/onvif/,是Onvif请求
if (NULL != psz_sub_pos)
{
if (psz_sub_pos < psz_head_pos)
{
//Onvif完整消息末尾
psz_sub_pos = strstr(psz_mesg, "Envelope>");
if (NULL == psz_sub_pos)
{
return -1;
}
return 0;
}
}
//http头中存在soap+xml则说明是soap消息
psz_sub_pos = strstr(psz_mesg, "/soap+xml");
if (NULL != psz_sub_pos)
{
if (psz_sub_pos < psz_head_pos)
{
psz_sub_pos = strstr(psz_mesg, "Envelope>");
if (NULL == psz_sub_pos)
{
return -1;
}
return 0;
}
}
//取http体中的前100字节
size_t nlen = psz_mesg - psz_head_pos + data_len;
if (nlen <= 0)
{
return -1;
}
if (nlen > 100)
{
nlen = 100;
}
char *p_env_flag = strstr(psz_head_pos, ":Envelope");
if (p_env_flag)
{
psz_sub_pos = strstr(psz_mesg, "Envelope>");
if (NULL == psz_sub_pos)
{
return -1;
}
return 0;
}
return -1;
}