📄 db_parse.txt
字号:
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "XML_STRUCT.H"
#define TS
#define _DEBUG_HR_
#define SAFE_DELETE(p) do{delete p; p=NULL;}while(false)
void ParseMsgID(char *p, char *pMsgId)
{//---解析messageId 参数 p(in) 流指针 pMsgId(out) messageId
#ifdef TS
char *pch_temp = p + 13 + 2; //有TS头
#else
char *pch_temp = p + 2; //无TS头
#endif
memcpy(pMsgId, pch_temp, 2);
}
void ParseDSI(char *p, s_sdi *sdi)
{//---解析DSI消息 参数 p(in) 流指针 sdi(out) 存放SDI消息的结构体
char *pch_temp = p;
//---type_id_length(4 byte)
pch_temp = pch_temp + 44;
unsigned __int32 i_type_id_length = 0;
memcpy( (char*)&i_type_id_length, pch_temp + 3, 1 );
memcpy( (char*)&i_type_id_length + 1, pch_temp + 2, 1 );
memcpy( (char*)&i_type_id_length + 2, pch_temp + 1, 1 );
memcpy( (char*)&i_type_id_length + 3, pch_temp, 1 );
//---carouselId(4 byte)
pch_temp = pch_temp + 31 + i_type_id_length;
sdi->ch_carouselId = (char*)malloc(4);
memcpy(sdi->ch_carouselId, pch_temp, 4);
//---moduleId(4 byte)
pch_temp = pch_temp + 4;
sdi->ch_moduleId = (char*)malloc(2);
memcpy(sdi->ch_moduleId, pch_temp, 2);
//---version.major, version.minor(2 byte 0x0100)
pch_temp = pch_temp + 4;
//---objectKey_length(1 byte)
unsigned __int32 i_obj_length = 0;
memcpy( (char*)&i_obj_length, pch_temp, 1 );
//---objectKey_data_byte(i_obj_length byte)
pch_temp = pch_temp +1;
sdi->ch_objectKey_data_byte = (char*)malloc(i_obj_length);
memcpy(sdi->ch_objectKey_data_byte, pch_temp, i_obj_length);
}
void ParseDDBDir(char *p, s_sdi *sdi, s_ddbdir *ddbdir)
{//---解析DDB 参数 p(in) 数据流 sdi(in) 查找/判断条件 ddbdir 存放DDBDIR信息的结构体 blockSize(in) 块大小
char *pch_temp = p;
//---section_syntax_indicator, private_indicator, reserved, dsmcc_section_length(2 byte)
pch_temp = pch_temp + 1;
unsigned __int32 i_dsmcc_section_length = 0;
memcpy( (char*)&i_dsmcc_section_length, pch_temp + 1, 1 );
memcpy( (char*)&i_dsmcc_section_length + 1, pch_temp, 1 );
//---dsmcc_section_length
i_dsmcc_section_length = i_dsmcc_section_length & 0xfff; //后12位为长度
//---last_section_number(1 byte)
pch_temp = pch_temp + 6;
unsigned __int32 i_section_sum = 0;
memcpy( (char*)&i_section_sum, pch_temp, 1 );
++i_section_sum; //从0开始的
//---moduleId(2 byte)
pch_temp = pch_temp + 13;
if ( 0 != memcmp(sdi->ch_moduleId, pch_temp, 2) )
{//---判断模块ID 不等就返回
return;
}
//message_size(4 byte)
pch_temp = pch_temp + 14;
unsigned __int32 i_message_size = 0;
memcpy( (char*)&i_message_size, pch_temp + 3, 1 );
memcpy( (char*)&i_message_size + 1, pch_temp + 2, 1 );
memcpy( (char*)&i_message_size + 2, pch_temp + 1, 1 );
memcpy( (char*)&i_message_size + 3, pch_temp, 1 );
//---objectKey_length(1 byte)
//*---必须得计算出具体值
pch_temp = pch_temp + 4;
unsigned __int32 i_obj_length = 0;
memcpy( (char*)&i_obj_length, pch_temp, 1 );
//---objectKey_data_byte(i_obj_length byte)
pch_temp = pch_temp + 1;
if ( 0 != memcmp(sdi->ch_objectKey_data_byte, pch_temp, i_obj_length) )
{//---判断objectKey_data_byte 不等就返回
return;
}
//---bindings_count(2 byte)
pch_temp = pch_temp + 15 + i_obj_length;
unsigned __int32 i_bindings_count = 0;
memcpy( (char*)&i_bindings_count, pch_temp + 1, 1 );
memcpy( (char*)&i_bindings_count + 1, pch_temp, 1 );
//---将DIRMESSAGE的数据复制出来
pch_temp = pch_temp + 2;
char *ch_message = (char*)malloc(i_message_size);
char *ch_message_temp = ch_message;
unsigned __int32 i_pack_sum = 0; //一共有多少包
__int32 i_fill = 0; //最后一个包的数据
for (unsigned __int32 i = 0 ; i < i_section_sum; ++i)
{
if ( i > 0 )
{//---取段长度
pch_temp = pch_temp + i_fill + 4;
pch_temp = pch_temp + 1;
i_dsmcc_section_length = 0;
memcpy( (char*)&i_dsmcc_section_length, pch_temp + 1, 1 );
memcpy( (char*)&i_dsmcc_section_length + 1, pch_temp, 1 );
//---dsmcc_section_length
i_dsmcc_section_length = i_dsmcc_section_length & 0xfff; //后12位为长度
}
//---计算当前段有多少块和最后块有多少数据
if ( i_dsmcc_section_length > 180 )
{
i_fill = (i_dsmcc_section_length + 3 - 183) % 184 - 4; //减去4字节CRC
if ( 0 < i_fill )
{
i_pack_sum = (i_dsmcc_section_length + 3 - 183) / 184 + 2;
}
else
{
i_pack_sum = (i_dsmcc_section_length + 3 - 183) / 184 + 1;
i_fill = 184 - (4 + i_fill); //i_fill 是负数
}
}
else
{//---一个段只有一个包
i_pack_sum = 1;
i_fill = i_dsmcc_section_length - 23 - 4;
}
//---取数据
if (i_pack_sum > 2)
{
if ( i > 0 )
{//---非第一段
pch_temp = pch_temp + 5 + 26 - 6;
memcpy(ch_message_temp, pch_temp, 157); //第一块
ch_message_temp = ch_message_temp + 157;
pch_temp = pch_temp + 157;
for (unsigned __int32 j = 0; j < i_pack_sum - 2; ++j)
{
memcpy(ch_message_temp, pch_temp, 184);
pch_temp = pch_temp + 184;
ch_message_temp = ch_message_temp + 184;
}
memcpy(ch_message_temp, pch_temp, i_fill); //最后一块
ch_message_temp = ch_message_temp + i_fill;
}
else
{
memcpy(ch_message_temp, pch_temp, 119 + i_obj_length); //第一个包
ch_message_temp = ch_message_temp + 119 + i_obj_length;
pch_temp = pch_temp + 119 + i_obj_length;
for (unsigned __int32 j = 0; j < i_pack_sum - 2; ++j)
{
memcpy(ch_message_temp, pch_temp, 184);
pch_temp = pch_temp + 184;
ch_message_temp = ch_message_temp + 184;
}
memcpy(ch_message_temp, pch_temp, i_fill); //最后一个包
ch_message_temp = ch_message_temp + i_fill;
}
}
else
{
if ( i > 0 )
{//---非第一段
pch_temp = pch_temp + 5 + 26 - 6;
memcpy(ch_message_temp, pch_temp, 157); //第一个包
ch_message_temp = ch_message_temp + 157;
pch_temp = pch_temp + 157;
memcpy(ch_message_temp, pch_temp, i_fill); //最后一个包
ch_message_temp = ch_message_temp + i_fill;
}
else
{
memcpy(ch_message_temp, pch_temp, 119 + i_obj_length); //第一个包
ch_message_temp = ch_message_temp + 119 + i_obj_length;
pch_temp = pch_temp + 119 + i_obj_length;
memcpy(ch_message_temp, pch_temp, i_fill); //最后一个包
ch_message_temp = ch_message_temp + i_fill;
}
}
}
pch_temp = ch_message;
s_ddbdir *ddbdir_temp = ddbdir;
for ( i = 0; i < i_bindings_count; ++i )
{
if (0 != i)
{
ddbdir_temp->linkNext = (s_ddbdir*)malloc( sizeof(s_ddbdir) );
ddbdir_temp = ddbdir_temp->linkNext;
ddbdir_temp->linkNext= NULL;
}
//---id_length(1 byte)
//*---需要计算
pch_temp = pch_temp + 1;
unsigned __int32 i_id_length = 0;
memcpy( (char*)&i_id_length, pch_temp, 1 );
//---id_data_byte(i_id_length byte)
pch_temp = pch_temp + 1;
ddbdir_temp->ch_id_data_byte = (char*)malloc(i_id_length + 1);
memset(ddbdir_temp->ch_id_data_byte, 0, i_id_length + 1);
memcpy(ddbdir_temp->ch_id_data_byte, pch_temp, i_id_length);
//---kind_length(1 byte)
//*---长度得计算
pch_temp = pch_temp + i_id_length;
unsigned __int32 i_kind_length = 0;
memcpy( (char*)&i_kind_length, pch_temp, 1 );
//---type_id_length(4 byte)
//*---需计算
pch_temp = pch_temp + 2 + i_kind_length;
unsigned __int32 i_type_id_length = 0;
memcpy( (char*)&i_type_id_length, pch_temp + 3, 1 );
memcpy( (char*)&i_type_id_length + 1, pch_temp + 2, 1 );
memcpy( (char*)&i_type_id_length + 2, pch_temp + 1, 1 );
memcpy( (char*)&i_type_id_length + 3, pch_temp, 1 );
//---carouselId(4 byte)
pch_temp = pch_temp + 31 + i_type_id_length;
ddbdir_temp->ch_carouselId = (char*)malloc(4);
memcpy(ddbdir_temp->ch_carouselId, pch_temp, 4);
//---moduleId(2 byte)
pch_temp = pch_temp + 4;
ddbdir_temp->ch_moduleId = (char*)malloc(2);
memcpy(ddbdir_temp->ch_moduleId, pch_temp, 2);
//---objectKey_length(1 byte)
//*---需计算
pch_temp = pch_temp + 4;
i_obj_length = 0;
memcpy( (char*)&i_obj_length, pch_temp, 1 );
//---objectKey_data_byte(i_obj_length byte)
pch_temp = pch_temp + 1;
ddbdir_temp->ch_objectKey_data_byte = (char*)malloc(i_obj_length);
memcpy(ddbdir_temp->ch_objectKey_data_byte, pch_temp, i_obj_length);
//---objectInfo_length(2 byte)
pch_temp = pch_temp + 23 + i_obj_length;
unsigned __int32 i_objectInfo_length = 0;
memcpy( (char*)&i_objectInfo_length, pch_temp + 1, 1 );
memcpy( (char*)&i_objectInfo_length + 1, pch_temp, 1 );
pch_temp = pch_temp + 2 + i_objectInfo_length;
} // end of for
}
char *ParseDDBFil(char *p, s_ddbdir *ddbdir)
{//---解析DDB 参数 p(in) 数据流 ddbdir(in) 查找/判断条件 blockSize 块大小 返回:数据buffer
// /*static*/ int i_section_sum = 0;
char *pch_temp = p;
//---section_syntax_indicator, private_indicator, reserved, dsmcc_section_length(2 byte)
pch_temp = pch_temp + 1;
unsigned __int32 i_dsmcc_section_length = 0;
memcpy( (char*)&i_dsmcc_section_length, pch_temp + 1, 1 );
memcpy( (char*)&i_dsmcc_section_length + 1, pch_temp, 1 );
//---dsmcc_section_length
i_dsmcc_section_length = i_dsmcc_section_length & 0xfff; //后12位为长度
//---last_section_number(1 byte)
pch_temp = pch_temp + 6;
unsigned __int32 i_section_sum = 0;
memcpy( (char*)&i_section_sum, pch_temp, 1 );
++i_section_sum; //从0开始的
//---moduleId(2 byte)
pch_temp = pch_temp + 13;
if ( 0 != memcmp(ddbdir->ch_moduleId, pch_temp, 2) )
{//---判断模块ID 不等就返回
return NULL;
}
//message_size(4 byte)
pch_temp = pch_temp + 14;
unsigned __int32 i_message_size = 0;
memcpy( (char*)&i_message_size, pch_temp + 3, 1 );
memcpy( (char*)&i_message_size + 1, pch_temp + 2, 1 );
memcpy( (char*)&i_message_size + 2, pch_temp + 1, 1 );
memcpy( (char*)&i_message_size + 3, pch_temp, 1 );
//---objectKey_length(1 byte)
//*---必须得计算出具体值
pch_temp = pch_temp + 4;
unsigned __int32 i_obj_length = 0;
memcpy( (char*)&i_obj_length, pch_temp, 1 );
//---objectKey_data_byte(i_obj_length byte)
pch_temp = pch_temp + 1;
if ( 0 != memcmp(ddbdir->ch_objectKey_data_byte, pch_temp, i_obj_length) )
{//---判断objectKey_data_byte 不等就返回
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -