📄 ipmpx_parse.c
字号:
/* * GPAC - Multimedia Framework C SDK * * Copyright (c) Jean Le Feuvre 2000-2005 * All rights reserved * * This file is part of GPAC / MPEG-4 ObjectDescriptor sub-project * * GPAC is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * GPAC is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * */#include <gpac/internal/odf_dev.h>void GF_IPMPX_AUTH_Delete(GF_IPMPX_Authentication *auth);u8 gf_ipmpx_get_tag(char *dataName){ if (!stricmp(dataName, "IPMP_KeyData")) return GF_IPMPX_KEY_DATA_TAG; else if (!stricmp(dataName, "IPMP_RightsData")) return GF_IPMPX_RIGHTS_DATA_TAG; else if (!stricmp(dataName, "IPMP_OpaqueData")) return GF_IPMPX_OPAQUE_DATA_TAG; else if (!stricmp(dataName, "IPMP_SecureContainer")) return GF_IPMPX_SECURE_CONTAINER_TAG; else if (!stricmp(dataName, "IPMP_InitAuthentication")) return GF_IPMPX_INIT_AUTHENTICATION_TAG; else if (!stricmp(dataName, "IPMP_TrustSecurityMetadata")) return GF_IPMPX_TRUST_SECURITY_METADATA_TAG; else if (!stricmp(dataName, "IPMP_TrustedTool")) return GF_IPMPX_TRUSTED_TOOL_TAG; else if (!stricmp(dataName, "IPMP_TrustSpecification")) return GF_IPMPX_TRUST_SPECIFICATION_TAG; else if (!stricmp(dataName, "IPMP_MutualAuthentication")) return GF_IPMPX_MUTUAL_AUTHENTICATION_TAG; else if (!stricmp(dataName, "IPMP_AlgorithmDescriptor")) return GF_IPMPX_ALGORITHM_DESCRIPTOR_TAG; else if (!stricmp(dataName, "IPMP_KeyDescriptor")) return GF_IPMPX_KEY_DESCRIPTOR_TAG; else if (!stricmp(dataName, "IPMP_GetToolsResponse")) return GF_IPMPX_GET_TOOLS_RESPONSE_TAG; else if (!stricmp(dataName, "IPMP_ParametricDescription")) return GF_IPMPX_PARAMETRIC_DESCRIPTION_TAG; else if (!stricmp(dataName, "IPMP_ParametricDescriptionItem")) return GF_IPMPX_PARAM_DESCRIPTOR_ITEM_TAG; else if (!stricmp(dataName, "IPMP_ToolParamCapabilitiesQuery")) return GF_IPMPX_PARAMETRIC_CAPS_QUERY_TAG; else if (!stricmp(dataName, "IPMP_ToolParamCapabilitiesResponse")) return GF_IPMPX_PARAMETRIC_CAPS_RESPONSE_TAG; else if (!stricmp(dataName, "IPMP_ConnectTool")) return GF_IPMPX_CONNECT_TOOL_TAG; else if (!stricmp(dataName, "IPMP_DisconnectTool")) return GF_IPMPX_DISCONNECT_TOOL_TAG; else if (!stricmp(dataName, "IPMP_GetToolContext")) return GF_IPMPX_GET_TOOL_CONTEXT_TAG; else if (!stricmp(dataName, "IPMP_GetToolContextResponse")) return GF_IPMPX_GET_TOOL_CONTEXT_RESPONSE_TAG; else if (!stricmp(dataName, "IPMP_AddToolNotificationListener")) return GF_IPMPX_ADD_TOOL_LISTENER_TAG; else if (!stricmp(dataName, "IPMP_RemoveToolNotificationListener")) return GF_IPMPX_REMOVE_TOOL_LISTENER_TAG; else if (!stricmp(dataName, "IPMP_NotifyToolEvent")) return GF_IPMPX_NOTIFY_TOOL_EVENT_TAG; else if (!stricmp(dataName, "IPMP_CanProcess")) return GF_IPMPX_CAN_PROCESS_TAG; else if (!stricmp(dataName, "IPMP_ToolAPI_Config")) return GF_IPMPX_TOOL_API_CONFIG_TAG; else if (!stricmp(dataName, "IPMP_AudioWatermarkingInit")) return GF_IPMPX_AUDIO_WM_INIT_TAG; else if (!stricmp(dataName, "IPMP_VideoWatermarkingInit")) return GF_IPMPX_VIDEO_WM_INIT_TAG; else if (!stricmp(dataName, "IPMP_SendAudioWatermark")) return GF_IPMPX_AUDIO_WM_SEND_TAG; else if (!stricmp(dataName, "IPMP_SendVideoWatermark")) return GF_IPMPX_VIDEO_WM_SEND_TAG; else if (!stricmp(dataName, "IPMP_SelectiveDecryptionInit")) return GF_IPMPX_SEL_DEC_INIT_TAG; else if (!stricmp(dataName, "IPMP_SelectiveBuffer")) return GF_IPMPX_SEL_ENC_BUFFER_TAG; else if (!stricmp(dataName, "IPMP_SelectiveField")) return GF_IPMPX_SEL_ENC_FIELD_TAG; else if (!stricmp(dataName, "ISMACryp_Data")) return GF_IPMPX_ISMACRYP_TAG; return 0;}u32 gf_ipmpx_get_field_type(GF_IPMPX_Data *p, char *fieldName){ switch (p->tag) { case GF_IPMPX_KEY_DATA_TAG: if (!stricmp(fieldName, "keyBody")|| !stricmp(fieldName, "opaqueData")) return GF_ODF_FT_IPMPX_BA; break; case GF_IPMPX_RIGHTS_DATA_TAG: if (!stricmp(fieldName, "rightsInfo")) return GF_ODF_FT_IPMPX_BA; break; case GF_IPMPX_OPAQUE_DATA_TAG: if (!stricmp(fieldName, "OpaqueData")) return GF_ODF_FT_IPMPX_BA; break; case GF_IPMPX_SECURE_CONTAINER_TAG: if (!stricmp(fieldName, "encryptedData") || !stricmp(fieldName, "MAC")) return GF_ODF_FT_IPMPX_BA; else if (!stricmp(fieldName, "protectedMsg")) return GF_ODF_FT_IPMPX; break; case GF_IPMPX_TRUST_SECURITY_METADATA_TAG: if (!stricmp(fieldName, "trustedTools")) return GF_ODF_FT_IPMPX_LIST; break; case GF_IPMPX_TRUSTED_TOOL_TAG: if (!stricmp(fieldName, "trustSpecifications")) return GF_ODF_FT_IPMPX_LIST; break; case GF_IPMPX_TRUST_SPECIFICATION_TAG: if (!stricmp(fieldName, "CCTrustMetadata")) return GF_ODF_FT_IPMPX_BA; break; case GF_IPMPX_MUTUAL_AUTHENTICATION_TAG: if (!stricmp(fieldName, "candidateAlgorithms") || !stricmp(fieldName, "agreedAlgorithms")) return GF_ODF_FT_IPMPX_LIST; else if (!stricmp(fieldName, "certificates")) return GF_ODF_FT_IPMPX_BA_LIST; else if (!stricmp(fieldName, "publicKey") || !stricmp(fieldName, "trustData")) return GF_ODF_FT_IPMPX; else if (!stricmp(fieldName, "authCodes") || !stricmp(fieldName, "opaque") || !stricmp(fieldName, "AuthenticationData")) return GF_ODF_FT_IPMPX_BA; break; case GF_IPMPX_ALGORITHM_DESCRIPTOR_TAG: if (!stricmp(fieldName, "specAlgoID") || !stricmp(fieldName, "OpaqueData")) return GF_ODF_FT_IPMPX_BA; break; case GF_IPMPX_GET_TOOLS_RESPONSE_TAG: if (!stricmp(fieldName, "ipmp_tools")) return GF_ODF_FT_OD_LIST; break; case GF_IPMPX_PARAMETRIC_DESCRIPTION_TAG: if (!stricmp(fieldName, "descriptionComment")) return GF_ODF_FT_IPMPX_BA; else if (!stricmp(fieldName, "descriptions")) return GF_ODF_FT_IPMPX_LIST; break; case GF_IPMPX_PARAM_DESCRIPTOR_ITEM_TAG: /*all is IPMPX data*/ return GF_ODF_FT_IPMPX_BA; case GF_IPMPX_PARAMETRIC_CAPS_QUERY_TAG: if (!stricmp(fieldName, "description")) return GF_ODF_FT_IPMPX; break; case GF_IPMPX_CONNECT_TOOL_TAG: if (!stricmp(fieldName, "toolDescriptor")) return GF_ODF_FT_OD; break; case GF_IPMPX_TOOL_API_CONFIG_TAG: if (!stricmp(fieldName, "opaqueData")) return GF_ODF_FT_IPMPX_BA; break; case GF_IPMPX_AUDIO_WM_SEND_TAG: case GF_IPMPX_VIDEO_WM_SEND_TAG: if (!stricmp(fieldName, "payload") || !stricmp(fieldName, "opaqueData")) return GF_ODF_FT_IPMPX_BA; break; case GF_IPMPX_SEL_DEC_INIT_TAG: if (!stricmp(fieldName, "SelectiveBuffers") || !stricmp(fieldName, "SelectiveFields")) return GF_ODF_FT_IPMPX_LIST; break; case GF_IPMPX_SEL_ENC_BUFFER_TAG: if (!stricmp(fieldName, "StreamCipher")) return GF_ODF_FT_IPMPX_BA; break; case GF_IPMPX_SEL_ENC_FIELD_TAG: if (!stricmp(fieldName, "shuffleSpecificInfo")) return GF_ODF_FT_IPMPX_BA; break; default: break; } return 0;}#define GET_U8(field) { if (strstr(val, "0x")) { ret += sscanf(val, "%x", &d); if (ret) field = (u8) d; } else { ret += sscanf(val, "%d", &d); if (ret) field = (u8) d; } } #define GET_U16(field) { if (strstr(val, "0x")) { ret += sscanf(val, "%x", &d); if (ret) field = (u16) d; } else { ret += sscanf(val, "%d", &d); if (ret) field = (u16) d; } } #define GET_U32(field) { if (strstr(val, "0x")) { ret += sscanf(val, "%x", &d); if (ret) field = (u32) d; } else { ret += sscanf(val, "%d", &d); if (ret) field = (u32) d; } } #define GET_S32(field) { if (strstr(val, "0x")) { ret += sscanf(val, "%x", &d); if (ret) field = (s32) d; } else { ret += sscanf(val, "%d", &d); if (ret) field = (s32) d; } } #define GET_BOOL(field) { ret = 1; field = (!stricmp(val, "true") || !stricmp(val, "1")) ? 1 : 0; }#define GET_DOUBLE(field) { Float v; ret = 1; sscanf(val, "%f", &v); field = (Double) v;}#define GET_STRING(field) { ret = 1; field = strdup(val); if (val[0] == '"') strcpy(field, val+1); if (field[strlen(field)-1] == '"') field[strlen(field)-1] = 0; }void GF_IPMPX_ParseBinData(char *val, char **out_data, u32 *out_data_size){ u32 i, c, len; char s[3]; if (val[0] != '%') { len = *out_data_size = strlen(val); *out_data = (char*)malloc(sizeof(char) * len); memcpy(*out_data, val, sizeof(char) * len); return; } len = strlen(val) / 3; if (*out_data) free(*out_data); *out_data_size = len; *out_data = (char*)malloc(sizeof(char) * len); s[2] = 0; for (i=0; i<len; i++) { s[0] = val[3*i+1]; s[1] = val[3*i+2]; sscanf(s, "%02X", &c); (*out_data)[i] = (unsigned char) c; }}void GF_IPMPX_ParseFileData(char *fileName, char **out_data, u32 *out_data_size){ FILE *f; u32 size; if (*out_data) free(*out_data); *out_data = NULL; *out_data_size = 0; f = fopen(fileName, "rb"); if (!f) { GF_LOG(GF_LOG_WARNING, GF_LOG_PARSER, ("[IPMPX Parse] cannot open data file %s - skipping\n", fileName)); return; } fseek(f, 0, SEEK_END); size = ftell(f); fseek(f, 0, SEEK_SET); *out_data_size = size; *out_data = (char*)malloc(sizeof(char) * size); fread(*out_data, sizeof(char) * size, 1, f); fclose(f);}void GF_IPMPX_ParseBin128(char *val, bin128 *data){ if (!strnicmp(val, "0x", 2)) val+=2; if (strlen(val)<16) { GF_BitStream *bs; u32 int_val = atoi(val); bs = gf_bs_new((char*) (*data), 16, GF_BITSTREAM_WRITE); gf_bs_write_int(bs, 0, 32); gf_bs_write_int(bs, 0, 32); gf_bs_write_int(bs, 0, 32); gf_bs_write_int(bs, int_val, 32); gf_bs_del(bs); } else { u32 i, b; char szB[3]; szB[2] = 0; for (i=0; i<16; i++) { szB[0] = val[2*i]; szB[1] = val[2*i+1]; sscanf(szB, "%x", &b); ((char *)data)[i] = (u8) b; } }}void GF_IPMPX_ParseDate(char *val, GF_IPMPX_Date *date){ if ((strlen(val)<7) || strnicmp(val, "0x", 2)) { GF_BitStream *bs; u32 int_val = atoi(val); bs = gf_bs_new((*date), 5, GF_BITSTREAM_WRITE); gf_bs_write_int(bs, 0, 8); gf_bs_write_int(bs, int_val, 32); gf_bs_del(bs); } else { val += 2; memcpy((char *) (*date), val, sizeof(char)*5); }}GF_Err GF_IPMPX_ParseEventType(char *val, u8 *eventType, u8 *eventTypeCount){ char szVal[50]; u32 i, j, len, v; *eventTypeCount = 0; len = strlen(val); j=0; for (i=0; i<len; i++) { switch (val[i]) { case '\'': case '\"': case ',': case ' ': break; default: szVal[j] = val[i]; j++; if (i+1==len) break; continue; } if (j) { szVal[j] = 0; if (!strnicmp(szVal, "0x", 2)) { sscanf(szVal, "%x", &v); eventType[*eventTypeCount] = v; } else { sscanf(szVal, "%d", &v); eventType[*eventTypeCount] = v; } j=0; (*eventTypeCount) += 1; if (*eventTypeCount == 9) return GF_OK; } } return GF_OK;}GF_Err gf_ipmpx_data_parse_16(char *val, u16 **outData, u16 *outDataSize){ char szVal[50]; u32 i, j, len, v, alloc, count; u16 *data = (u16*)malloc(sizeof(u16) * 100); alloc = 100; len = strlen(val); count = j = 0; for (i=0; i<len; i++) { switch (val[i]) { case '\'': case '\"': case ',': case ' ': break; default: szVal[j] = val[i]; j++; if (i+1==len) break; continue; } if (j) { szVal[j] = 0; if (!strnicmp(szVal, "0x", 2)) { sscanf(szVal, "%x", &v); data[count] = v; } else { sscanf(szVal, "%d", &v); data[count] = v; } j=0; count += 1; if (count == alloc) { alloc += 100; data = (u16*)realloc(data, sizeof(u16)*alloc); } } } (*outData) = (u16*)realloc(data, sizeof(u16)*count); *outDataSize = count; return GF_OK;}GF_Err gf_ipmpx_set_field(GF_IPMPX_Data *_p, char *fieldName, char *val){ u32 d, ret = 0; if (!stricmp(val, "auto")) return GF_OK; else if (!stricmp(val, "unspecified")) return GF_OK; switch (_p->tag) { case GF_IPMPX_KEY_DATA_TAG: { GF_IPMPX_KeyData *p = (GF_IPMPX_KeyData*)_p; if (!stricmp(fieldName, "hasStartDTS")) { if (!stricmp(val, "false") || !stricmp(val, "0") ) p->flags &= ~1; else p->flags |= 1; ret = 1; } else if (!stricmp(fieldName, "hasStartPacketID")) { if (!stricmp(val, "false") || !stricmp(val, "0") ) p->flags &= ~2; else p->flags |= 2; ret = 1; } else if (!stricmp(fieldName, "hasExpireDTS")) { if (!stricmp(val, "false") || !stricmp(val, "0") ) p->flags &= ~4; else p->flags |= 4; ret = 1; } else if (!stricmp(fieldName, "hasExpirePacketID")) { if (!stricmp(val, "false") || !stricmp(val, "0") ) p->flags &= ~8; else p->flags |= 8; ret = 1; } else if (!stricmp(fieldName, "startDTS")) GET_U32(p->startDTS) else if (!stricmp(fieldName, "startPacketID")) GET_U32(p->startPacketID) else if (!stricmp(fieldName, "expireDTS")) GET_U32(p->expireDTS) else if (!stricmp(fieldName, "expirePacketID")) GET_U32(p->expirePacketID) } break; case GF_IPMPX_SECURE_CONTAINER_TAG: { GF_IPMPX_SecureContainer*p = (GF_IPMPX_SecureContainer*)_p;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -