1 /*
2 * GPAC - Multimedia Framework C SDK
3 *
4 * Authors: Jean Le Feuvre
5 * Copyright (c) Telecom ParisTech 2000-2012
6 * All rights reserved
7 *
8 * This file is part of GPAC / MPEG-4 ObjectDescriptor sub-project
9 *
10 * GPAC is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * GPAC is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25
26
27 #include <gpac/internal/odf_dev.h>
28
29 #ifndef GPAC_MINIMAL_ODF
30
31 void GF_IPMPX_AUTH_Delete(GF_IPMPX_Authentication *auth);
32
33
gf_ipmpx_get_tag(char * dataName)34 u8 gf_ipmpx_get_tag(char *dataName)
35 {
36 if (!stricmp(dataName, "IPMP_KeyData")) return GF_IPMPX_KEY_DATA_TAG;
37 else if (!stricmp(dataName, "IPMP_RightsData")) return GF_IPMPX_RIGHTS_DATA_TAG;
38 else if (!stricmp(dataName, "IPMP_OpaqueData")) return GF_IPMPX_OPAQUE_DATA_TAG;
39 else if (!stricmp(dataName, "IPMP_SecureContainer")) return GF_IPMPX_SECURE_CONTAINER_TAG;
40 else if (!stricmp(dataName, "IPMP_InitAuthentication")) return GF_IPMPX_INIT_AUTHENTICATION_TAG;
41 else if (!stricmp(dataName, "IPMP_TrustSecurityMetadata")) return GF_IPMPX_TRUST_SECURITY_METADATA_TAG;
42 else if (!stricmp(dataName, "IPMP_TrustedTool")) return GF_IPMPX_TRUSTED_TOOL_TAG;
43 else if (!stricmp(dataName, "IPMP_TrustSpecification")) return GF_IPMPX_TRUST_SPECIFICATION_TAG;
44 else if (!stricmp(dataName, "IPMP_MutualAuthentication")) return GF_IPMPX_MUTUAL_AUTHENTICATION_TAG;
45 else if (!stricmp(dataName, "IPMP_AlgorithmDescriptor")) return GF_IPMPX_ALGORITHM_DESCRIPTOR_TAG;
46 else if (!stricmp(dataName, "IPMP_KeyDescriptor")) return GF_IPMPX_KEY_DESCRIPTOR_TAG;
47 else if (!stricmp(dataName, "IPMP_GetToolsResponse")) return GF_IPMPX_GET_TOOLS_RESPONSE_TAG;
48 else if (!stricmp(dataName, "IPMP_ParametricDescription")) return GF_IPMPX_PARAMETRIC_DESCRIPTION_TAG;
49 else if (!stricmp(dataName, "IPMP_ParametricDescriptionItem")) return GF_IPMPX_PARAM_DESCRIPTOR_ITEM_TAG;
50 else if (!stricmp(dataName, "IPMP_ToolParamCapabilitiesQuery")) return GF_IPMPX_PARAMETRIC_CAPS_QUERY_TAG;
51 else if (!stricmp(dataName, "IPMP_ToolParamCapabilitiesResponse")) return GF_IPMPX_PARAMETRIC_CAPS_RESPONSE_TAG;
52 else if (!stricmp(dataName, "IPMP_ConnectTool")) return GF_IPMPX_CONNECT_TOOL_TAG;
53 else if (!stricmp(dataName, "IPMP_DisconnectTool")) return GF_IPMPX_DISCONNECT_TOOL_TAG;
54 else if (!stricmp(dataName, "IPMP_GetToolContext")) return GF_IPMPX_GET_TOOL_CONTEXT_TAG;
55 else if (!stricmp(dataName, "IPMP_GetToolContextResponse")) return GF_IPMPX_GET_TOOL_CONTEXT_RESPONSE_TAG;
56 else if (!stricmp(dataName, "IPMP_AddToolNotificationListener")) return GF_IPMPX_ADD_TOOL_LISTENER_TAG;
57 else if (!stricmp(dataName, "IPMP_RemoveToolNotificationListener")) return GF_IPMPX_REMOVE_TOOL_LISTENER_TAG;
58 else if (!stricmp(dataName, "IPMP_NotifyToolEvent")) return GF_IPMPX_NOTIFY_TOOL_EVENT_TAG;
59 else if (!stricmp(dataName, "IPMP_CanProcess")) return GF_IPMPX_CAN_PROCESS_TAG;
60 else if (!stricmp(dataName, "IPMP_ToolAPI_Config")) return GF_IPMPX_TOOL_API_CONFIG_TAG;
61 else if (!stricmp(dataName, "IPMP_AudioWatermarkingInit")) return GF_IPMPX_AUDIO_WM_INIT_TAG;
62 else if (!stricmp(dataName, "IPMP_VideoWatermarkingInit")) return GF_IPMPX_VIDEO_WM_INIT_TAG;
63 else if (!stricmp(dataName, "IPMP_SendAudioWatermark")) return GF_IPMPX_AUDIO_WM_SEND_TAG;
64 else if (!stricmp(dataName, "IPMP_SendVideoWatermark")) return GF_IPMPX_VIDEO_WM_SEND_TAG;
65 else if (!stricmp(dataName, "IPMP_SelectiveDecryptionInit")) return GF_IPMPX_SEL_DEC_INIT_TAG;
66 else if (!stricmp(dataName, "IPMP_SelectiveBuffer")) return GF_IPMPX_SEL_ENC_BUFFER_TAG;
67 else if (!stricmp(dataName, "IPMP_SelectiveField")) return GF_IPMPX_SEL_ENC_FIELD_TAG;
68 else if (!stricmp(dataName, "ISMACryp_Data")) return GF_IPMPX_ISMACRYP_TAG;
69 return 0;
70 }
71
gf_ipmpx_get_field_type(GF_IPMPX_Data * p,char * fieldName)72 u32 gf_ipmpx_get_field_type(GF_IPMPX_Data *p, char *fieldName)
73 {
74 switch (p->tag) {
75 case GF_IPMPX_KEY_DATA_TAG:
76 if (!stricmp(fieldName, "keyBody") || !stricmp(fieldName, "opaqueData")) return GF_ODF_FT_IPMPX_BA;
77 break;
78 case GF_IPMPX_RIGHTS_DATA_TAG:
79 if (!stricmp(fieldName, "rightsInfo")) return GF_ODF_FT_IPMPX_BA;
80 break;
81 case GF_IPMPX_OPAQUE_DATA_TAG:
82 if (!stricmp(fieldName, "OpaqueData")) return GF_ODF_FT_IPMPX_BA;
83 break;
84 case GF_IPMPX_SECURE_CONTAINER_TAG:
85 if (!stricmp(fieldName, "encryptedData") || !stricmp(fieldName, "MAC")) return GF_ODF_FT_IPMPX_BA;
86 else if (!stricmp(fieldName, "protectedMsg")) return GF_ODF_FT_IPMPX;
87 break;
88 case GF_IPMPX_TRUST_SECURITY_METADATA_TAG:
89 if (!stricmp(fieldName, "trustedTools")) return GF_ODF_FT_IPMPX_LIST;
90 break;
91 case GF_IPMPX_TRUSTED_TOOL_TAG:
92 if (!stricmp(fieldName, "trustSpecifications")) return GF_ODF_FT_IPMPX_LIST;
93 break;
94 case GF_IPMPX_TRUST_SPECIFICATION_TAG:
95 if (!stricmp(fieldName, "CCTrustMetadata")) return GF_ODF_FT_IPMPX_BA;
96 break;
97 case GF_IPMPX_MUTUAL_AUTHENTICATION_TAG:
98 if (!stricmp(fieldName, "candidateAlgorithms") || !stricmp(fieldName, "agreedAlgorithms")) return GF_ODF_FT_IPMPX_LIST;
99 else if (!stricmp(fieldName, "certificates")) return GF_ODF_FT_IPMPX_BA_LIST;
100 else if (!stricmp(fieldName, "publicKey") || !stricmp(fieldName, "trustData")) return GF_ODF_FT_IPMPX;
101 else if (!stricmp(fieldName, "authCodes") || !stricmp(fieldName, "opaque") || !stricmp(fieldName, "AuthenticationData"))
102 return GF_ODF_FT_IPMPX_BA;
103 break;
104 case GF_IPMPX_ALGORITHM_DESCRIPTOR_TAG:
105 if (!stricmp(fieldName, "specAlgoID") || !stricmp(fieldName, "OpaqueData")) return GF_ODF_FT_IPMPX_BA;
106 break;
107 case GF_IPMPX_GET_TOOLS_RESPONSE_TAG:
108 if (!stricmp(fieldName, "ipmp_tools")) return GF_ODF_FT_OD_LIST;
109 break;
110 case GF_IPMPX_PARAMETRIC_DESCRIPTION_TAG:
111 if (!stricmp(fieldName, "descriptionComment")) return GF_ODF_FT_IPMPX_BA;
112 else if (!stricmp(fieldName, "descriptions")) return GF_ODF_FT_IPMPX_LIST;
113 break;
114 case GF_IPMPX_PARAM_DESCRIPTOR_ITEM_TAG:
115 /*all is IPMPX data*/
116 return GF_ODF_FT_IPMPX_BA;
117 case GF_IPMPX_PARAMETRIC_CAPS_QUERY_TAG:
118 if (!stricmp(fieldName, "description")) return GF_ODF_FT_IPMPX;
119 break;
120 case GF_IPMPX_CONNECT_TOOL_TAG:
121 if (!stricmp(fieldName, "toolDescriptor")) return GF_ODF_FT_OD;
122 break;
123 case GF_IPMPX_TOOL_API_CONFIG_TAG:
124 if (!stricmp(fieldName, "opaqueData")) return GF_ODF_FT_IPMPX_BA;
125 break;
126 case GF_IPMPX_AUDIO_WM_SEND_TAG:
127 case GF_IPMPX_VIDEO_WM_SEND_TAG:
128 if (!stricmp(fieldName, "payload") || !stricmp(fieldName, "opaqueData")) return GF_ODF_FT_IPMPX_BA;
129 break;
130 case GF_IPMPX_SEL_DEC_INIT_TAG:
131 if (!stricmp(fieldName, "SelectiveBuffers") || !stricmp(fieldName, "SelectiveFields")) return GF_ODF_FT_IPMPX_LIST;
132 break;
133 case GF_IPMPX_SEL_ENC_BUFFER_TAG:
134 if (!stricmp(fieldName, "StreamCipher")) return GF_ODF_FT_IPMPX_BA;
135 break;
136 case GF_IPMPX_SEL_ENC_FIELD_TAG:
137 if (!stricmp(fieldName, "shuffleSpecificInfo")) return GF_ODF_FT_IPMPX_BA;
138 break;
139 default:
140 break;
141 }
142 return 0;
143 }
144
145 #include <gpac/internal/odf_parse_common.h>
146
GF_IPMPX_ParseBinData(char * val,char ** out_data,u32 * out_data_size)147 void GF_IPMPX_ParseBinData(char *val, char **out_data, u32 *out_data_size)
148 {
149 u32 i, c, len;
150 char s[3];
151
152 if (val[0] != '%') {
153 len = *out_data_size = (u32)strlen(val);
154 *out_data = (char*)gf_malloc(sizeof(char) * len);
155 memcpy(*out_data, val, sizeof(char) * len);
156 return;
157 }
158
159 len = (u32)strlen(val) / 3;
160 if (*out_data) gf_free(*out_data);
161 *out_data_size = len;
162 *out_data = (char*)gf_malloc(sizeof(char) * len);
163 s[2] = 0;
164 for (i = 0; i<len; i++) {
165 s[0] = val[3 * i + 1];
166 s[1] = val[3 * i + 2];
167 sscanf(s, "%02X", &c);
168 (*out_data)[i] = (unsigned char)c;
169 }
170 }
171
GF_IPMPX_ParseFileData(char * fileName,char ** out_data,u32 * out_data_size)172 void GF_IPMPX_ParseFileData(char *fileName, char **out_data, u32 *out_data_size)
173 {
174 FILE *f;
175 u32 size;
176 if (*out_data) gf_free(*out_data);
177 *out_data = NULL;
178 *out_data_size = 0;
179 f = gf_fopen(fileName, "rb");
180 if (!f) {
181 GF_LOG(GF_LOG_WARNING, GF_LOG_PARSER, ("[IPMPX Parse] cannot open data file %s - skipping\n", fileName));
182 return;
183 }
184 gf_fseek(f, 0, SEEK_END);
185 assert(gf_ftell(f) < 1 << 31);
186 size = (u32)gf_ftell(f);
187 gf_fseek(f, 0, SEEK_SET);
188 *out_data = (char*)gf_malloc(sizeof(char) * size);
189 size = (s32)fread(*out_data, sizeof(char), size, f);
190 if ((s32)size >= 0)
191 *out_data_size = size;
192 gf_fclose(f);
193 }
194
GF_IPMPX_ParseBin128(char * val,bin128 * data)195 void GF_IPMPX_ParseBin128(char *val, bin128 *data)
196 {
197 if (!strnicmp(val, "0x", 2)) val += 2;
198
199 if (strlen(val)<16) {
200 GF_BitStream *bs;
201 u32 int_val = atoi(val);
202 bs = gf_bs_new((char*)(*data), 16, GF_BITSTREAM_WRITE);
203 gf_bs_write_int(bs, 0, 32);
204 gf_bs_write_int(bs, 0, 32);
205 gf_bs_write_int(bs, 0, 32);
206 gf_bs_write_int(bs, int_val, 32);
207 gf_bs_del(bs);
208 }
209 else {
210 u32 i, b;
211 char szB[3];
212 szB[2] = 0;
213 for (i = 0; i<16; i++) {
214 szB[0] = val[2 * i];
215 szB[1] = val[2 * i + 1];
216 sscanf(szB, "%x", &b);
217 ((char *)data)[i] = (u8)b;
218 }
219 }
220 }
221
GF_IPMPX_ParseDate(char * val,GF_IPMPX_Date * date)222 void GF_IPMPX_ParseDate(char *val, GF_IPMPX_Date *date)
223 {
224 if ((strlen(val)<7) || strnicmp(val, "0x", 2)) {
225 GF_BitStream *bs;
226 u32 int_val = atoi(val);
227 bs = gf_bs_new((*date), 5, GF_BITSTREAM_WRITE);
228 gf_bs_write_int(bs, 0, 8);
229 gf_bs_write_int(bs, int_val, 32);
230 gf_bs_del(bs);
231 }
232 else {
233 val += 2;
234 memcpy((char *)(*date), val, sizeof(char) * 5);
235 }
236 }
237
GF_IPMPX_ParseEventType(char * val,GF_IPMPX_ListenType * eventType,u8 * eventTypeCount)238 GF_Err GF_IPMPX_ParseEventType(char *val, GF_IPMPX_ListenType *eventType, u8 *eventTypeCount)
239 {
240 char szVal[50];
241 u32 i, j, len, v;
242 *eventTypeCount = 0;
243 len = (u32)strlen(val);
244 j = 0;
245 for (i = 0; i<len; i++) {
246 switch (val[i]) {
247 case '\'':
248 case '\"':
249 case ',':
250 case ' ':
251 break;
252 default:
253 szVal[j] = val[i];
254 j++;
255 if (i + 1 == len) break;
256 continue;
257 }
258 if (j) {
259 szVal[j] = 0;
260 if (!strnicmp(szVal, "0x", 2)) {
261 sscanf(szVal, "%x", &v);
262 eventType[*eventTypeCount] = v;
263 }
264 else {
265 sscanf(szVal, "%u", &v);
266 eventType[*eventTypeCount] = v;
267 }
268 j = 0;
269 (*eventTypeCount) += 1;
270 if (*eventTypeCount == 9) return GF_OK;
271 }
272 }
273 return GF_OK;
274 }
275
gf_ipmpx_data_parse_16(char * val,u16 ** outData,u16 * outDataSize)276 GF_Err gf_ipmpx_data_parse_16(char *val, u16 **outData, u16 *outDataSize)
277 {
278 char szVal[50];
279 u32 i, j, len, v, alloc, count;
280 u16 *data = (u16*)gf_malloc(sizeof(u16) * 100);
281 alloc = 100;
282
283 len = (u32)strlen(val);
284 count = j = 0;
285 for (i = 0; i<len; i++) {
286 switch (val[i]) {
287 case '\'':
288 case '\"':
289 case ',':
290 case ' ':
291 break;
292 default:
293 szVal[j] = val[i];
294 j++;
295 if (i + 1 == len) break;
296 continue;
297 }
298 if (j) {
299 szVal[j] = 0;
300 if (!strnicmp(szVal, "0x", 2)) {
301 sscanf(szVal, "%x", &v);
302 data[count] = v;
303 }
304 else {
305 sscanf(szVal, "%u", &v);
306 data[count] = v;
307 }
308 j = 0;
309 count += 1;
310 if (count == alloc) {
311 alloc += 100;
312 data = (u16*)gf_realloc(data, sizeof(u16)*alloc);
313 }
314 }
315 }
316 (*outData) = (u16*)gf_realloc(data, sizeof(u16)*count);
317 *outDataSize = count;
318 return GF_OK;
319 }
320
gf_ipmpx_set_field(GF_IPMPX_Data * _p,char * fieldName,char * val)321 GF_Err gf_ipmpx_set_field(GF_IPMPX_Data *_p, char *fieldName, char *val)
322 {
323 u32 ret = 0;
324
325 if (!stricmp(val, "auto")) return GF_OK;
326 else if (!stricmp(val, "unspecified")) return GF_OK;
327
328 switch (_p->tag) {
329 case GF_IPMPX_KEY_DATA_TAG:
330 {
331 GF_IPMPX_KeyData *p = (GF_IPMPX_KeyData*)_p;
332 if (!stricmp(fieldName, "hasStartDTS")) {
333 if (!stricmp(val, "false") || !stricmp(val, "0")) p->flags &= ~1;
334 else p->flags |= 1;
335 ret = 1;
336 }
337 else if (!stricmp(fieldName, "hasStartPacketID")) {
338 if (!stricmp(val, "false") || !stricmp(val, "0")) p->flags &= ~2;
339 else p->flags |= 2;
340 ret = 1;
341 }
342 else if (!stricmp(fieldName, "hasExpireDTS")) {
343 if (!stricmp(val, "false") || !stricmp(val, "0")) p->flags &= ~4;
344 else p->flags |= 4;
345 ret = 1;
346 }
347 else if (!stricmp(fieldName, "hasExpirePacketID")) {
348 if (!stricmp(val, "false") || !stricmp(val, "0")) p->flags &= ~8;
349 else p->flags |= 8;
350 ret = 1;
351 }
352 else if (!stricmp(fieldName, "startDTS")) GET_U64(p->startDTS)
353 else if (!stricmp(fieldName, "startPacketID")) GET_U32(p->startPacketID)
354 else if (!stricmp(fieldName, "expireDTS")) GET_U32(p->expireDTS)
355 else if (!stricmp(fieldName, "expirePacketID")) GET_U32(p->expirePacketID)
356 }
357 break;
358 case GF_IPMPX_SECURE_CONTAINER_TAG:
359 {
360 GF_IPMPX_SecureContainer*p = (GF_IPMPX_SecureContainer*)_p;
361 if (!stricmp(fieldName, "isMACEncrypted")) GET_BOOL(p->isMACEncrypted)
362 }
363 break;
364 case GF_IPMPX_INIT_AUTHENTICATION_TAG:
365 {
366 GF_IPMPX_InitAuthentication *p = (GF_IPMPX_InitAuthentication*)_p;
367 if (!stricmp(fieldName, "Context")) GET_U32(p->Context)
368 else if (!stricmp(fieldName, "AuthType")) GET_U8(p->AuthType)
369 }
370 break;
371 case GF_IPMPX_TRUSTED_TOOL_TAG:
372 {
373 GF_IPMPX_TrustedTool *p = (GF_IPMPX_TrustedTool*)_p;
374 if (!stricmp(fieldName, "toolID")) {
375 GF_IPMPX_ParseBin128(val, &p->toolID);
376 ret = 1;
377 }
378 else if (!stricmp(fieldName, "AuditDate")) {
379 GF_IPMPX_ParseDate(val, &p->AuditDate);
380 ret = 1;
381 }
382 }
383 break;
384 case GF_IPMPX_TRUST_SPECIFICATION_TAG:
385 {
386 GF_IPMPX_TrustSpecification *p = (GF_IPMPX_TrustSpecification*)_p;
387 if (!stricmp(fieldName, "startDate")) {
388 GF_IPMPX_ParseDate(val, &p->startDate);
389 ret = 1;
390 }
391 else if (!stricmp(fieldName, "attackerProfile")) GET_U8(p->attackerProfile)
392 else if (!stricmp(fieldName, "trustedDuration")) GET_U32(p->trustedDuration)
393 }
394 break;
395 case GF_IPMPX_ALGORITHM_DESCRIPTOR_TAG:
396 {
397 GF_IPMPX_AUTH_AlgorithmDescriptor *p = (GF_IPMPX_AUTH_AlgorithmDescriptor *)_p;
398 if (!stricmp(fieldName, "regAlgoID")) GET_U16(p->regAlgoID)
399 }
400 break;
401 case GF_IPMPX_KEY_DESCRIPTOR_TAG:
402 {
403 GF_IPMPX_AUTH_KeyDescriptor *p = (GF_IPMPX_AUTH_KeyDescriptor *)_p;
404 if (!stricmp(fieldName, "keyBody")) {
405 u32 s;
406 GF_IPMPX_ParseBinData(val, &p->keyBody, &s);
407 p->keyBodyLength = s;
408 ret = 1;
409 }
410 }
411 break;
412 case GF_IPMPX_PARAMETRIC_DESCRIPTION_TAG:
413 {
414 GF_IPMPX_ParametricDescription*p = (GF_IPMPX_ParametricDescription*)_p;
415 if (!stricmp(fieldName, "majorVersion")) GET_U8(p->majorVersion)
416 else if (!stricmp(fieldName, "minorVersion")) GET_U8(p->minorVersion)
417 }
418 break;
419 case GF_IPMPX_PARAMETRIC_CAPS_RESPONSE_TAG:
420 {
421 GF_IPMPX_ToolParamCapabilitiesResponse*p = (GF_IPMPX_ToolParamCapabilitiesResponse*)_p;
422 if (!stricmp(fieldName, "capabilitiesSupported")) GET_BOOL(p->capabilitiesSupported)
423 }
424 break;
425 case GF_IPMPX_DISCONNECT_TOOL_TAG:
426 {
427 GF_IPMPX_DisconnectTool*p = (GF_IPMPX_DisconnectTool*)_p;
428 if (!stricmp(fieldName, "IPMP_ToolContextID")) GET_U16(p->IPMP_ToolContextID)
429 }
430 break;
431 case GF_IPMPX_GET_TOOL_CONTEXT_TAG:
432 {
433 GF_IPMPX_GetToolContext*p = (GF_IPMPX_GetToolContext*)_p;
434 if (!stricmp(fieldName, "scope")) GET_U8(p->scope)
435 else if (!stricmp(fieldName, "IPMP_DescriptorIDEx")) GET_U16(p->IPMP_DescriptorIDEx)
436 }
437 break;
438 case GF_IPMPX_GET_TOOL_CONTEXT_RESPONSE_TAG:
439 {
440 GF_IPMPX_GetToolContextResponse*p = (GF_IPMPX_GetToolContextResponse*)_p;
441 if (!stricmp(fieldName, "OD_ID")) GET_U16(p->OD_ID)
442 else if (!stricmp(fieldName, "ESD_ID")) GET_U16(p->ESD_ID)
443 else if (!stricmp(fieldName, "IPMP_ToolContextID")) GET_U16(p->IPMP_ToolContextID)
444 }
445 break;
446 case GF_IPMPX_ADD_TOOL_LISTENER_TAG:
447 {
448 GF_IPMPX_AddToolNotificationListener*p = (GF_IPMPX_AddToolNotificationListener*)_p;
449 if (!stricmp(fieldName, "eventType")) return GF_IPMPX_ParseEventType(val, p->eventType, &p->eventTypeCount);
450 else if (!stricmp(fieldName, "scope")) GET_U8(p->scope)
451 }
452 break;
453 case GF_IPMPX_REMOVE_TOOL_LISTENER_TAG:
454 {
455 GF_IPMPX_RemoveToolNotificationListener*p = (GF_IPMPX_RemoveToolNotificationListener*)_p;
456 if (!stricmp(fieldName, "eventType")) return GF_IPMPX_ParseEventType(val, p->eventType, &p->eventTypeCount);
457 }
458 break;
459 case GF_IPMPX_NOTIFY_TOOL_EVENT_TAG:
460 {
461 GF_IPMPX_NotifyToolEvent*p = (GF_IPMPX_NotifyToolEvent*)_p;
462 if (!stricmp(fieldName, "OD_ID")) GET_U16(p->OD_ID)
463 else if (!stricmp(fieldName, "ESD_ID")) GET_U16(p->ESD_ID)
464 else if (!stricmp(fieldName, "IPMP_ToolContextID")) GET_U16(p->IPMP_ToolContextID)
465 else if (!stricmp(fieldName, "eventType")) GET_U8(p->eventType)
466 }
467 break;
468 case GF_IPMPX_CAN_PROCESS_TAG:
469 {
470 GF_IPMPX_CanProcess*p = (GF_IPMPX_CanProcess*)_p;
471 if (!stricmp(fieldName, "canProcess")) GET_BOOL(p->canProcess)
472 }
473 break;
474 case GF_IPMPX_TOOL_API_CONFIG_TAG:
475 {
476 GF_IPMPX_ToolAPI_Config*p = (GF_IPMPX_ToolAPI_Config*)_p;
477 if (!stricmp(fieldName, "Instantiation_API_ID")) GET_U32(p->Instantiation_API_ID)
478 else if (!stricmp(fieldName, "Messaging_API_ID")) GET_U32(p->Messaging_API_ID)
479 }
480 break;
481 case GF_IPMPX_AUDIO_WM_INIT_TAG:
482 case GF_IPMPX_VIDEO_WM_INIT_TAG:
483 {
484 GF_IPMPX_WatermarkingInit *p = (GF_IPMPX_WatermarkingInit*)_p;
485 if (!stricmp(fieldName, "inputFormat")) GET_U8(p->inputFormat)
486 else if (!stricmp(fieldName, "requiredOp")) GET_U8(p->requiredOp)
487 else if (!stricmp(fieldName, "nChannels")) GET_U8(p->nChannels)
488 else if (!stricmp(fieldName, "bitPerSample")) GET_U8(p->bitPerSample)
489 else if (!stricmp(fieldName, "frequency")) GET_U32(p->frequency)
490 else if (!stricmp(fieldName, "frame_horizontal_size")) GET_U16(p->frame_horizontal_size)
491 else if (!stricmp(fieldName, "frame_vertical_size")) GET_U16(p->frame_vertical_size)
492 else if (!stricmp(fieldName, "chroma_format")) GET_U8(p->chroma_format)
493 else if (!stricmp(fieldName, "wmPayload")) {
494 ret = 1;
495 GF_IPMPX_ParseBinData(val, &p->wmPayload, &p->wmPayloadLen);
496 }
497 else if (!stricmp(fieldName, "opaqueData")) {
498 ret = 1;
499 GF_IPMPX_ParseBinData(val, &p->opaqueData, &p->opaqueDataSize);
500 }
501 else if (!stricmp(fieldName, "wmRecipientId")) GET_U16(p->wmRecipientId)
502 }
503 break;
504 case GF_IPMPX_AUDIO_WM_SEND_TAG:
505 case GF_IPMPX_VIDEO_WM_SEND_TAG:
506 {
507 GF_IPMPX_SendWatermark *p = (GF_IPMPX_SendWatermark*)_p;
508 if (!stricmp(fieldName, "wm_status")) GET_U8(p->wm_status)
509 else if (!stricmp(fieldName, "compression_status")) GET_U8(p->compression_status)
510 }
511 break;
512 case GF_IPMPX_SEL_DEC_INIT_TAG:
513 {
514 GF_IPMPX_SelectiveDecryptionInit*p = (GF_IPMPX_SelectiveDecryptionInit*)_p;
515 if (!stricmp(fieldName, "mediaTypeExtension")) GET_U8(p->mediaTypeExtension)
516 else if (!stricmp(fieldName, "mediaTypeExtension")) GET_U8(p->mediaTypeExtension)
517 else if (!stricmp(fieldName, "mediaTypeIndication")) GET_U8(p->mediaTypeIndication)
518 else if (!stricmp(fieldName, "profileLevelIndication")) GET_U8(p->profileLevelIndication)
519 else if (!stricmp(fieldName, "compliance")) GET_U8(p->compliance)
520 else if (!stricmp(fieldName, "RLE_Data")) {
521 ret = 1;
522 gf_ipmpx_data_parse_16(val, &p->RLE_Data, &p->RLE_DataLength);
523 }
524 }
525 break;
526 case GF_IPMPX_SEL_ENC_BUFFER_TAG:
527 {
528 GF_IPMPX_SelEncBuffer*p = (GF_IPMPX_SelEncBuffer*)_p;
529 if (!stricmp(fieldName, "cipher_Id")) {
530 GF_IPMPX_ParseBin128(val, &p->cipher_Id);
531 ret = 1;
532 }
533 else if (!stricmp(fieldName, "syncBoundary")) GET_U8(p->syncBoundary)
534 else if (!stricmp(fieldName, "mode")) GET_U8(p->mode)
535 else if (!stricmp(fieldName, "blockSize")) GET_U16(p->blockSize)
536 else if (!stricmp(fieldName, "keySize")) GET_U16(p->keySize)
537 }
538 break;
539 case GF_IPMPX_SEL_ENC_FIELD_TAG:
540 {
541 GF_IPMPX_SelEncField*p = (GF_IPMPX_SelEncField*)_p;
542 if (!stricmp(fieldName, "field_Id")) GET_U8(p->field_Id)
543 else if (!stricmp(fieldName, "field_Scope")) GET_U8(p->field_Scope)
544 else if (!stricmp(fieldName, "buf")) GET_U8(p->buf)
545 else if (!stricmp(fieldName, "mappingTable")) {
546 ret = 1;
547 gf_ipmpx_data_parse_16(val, &p->mappingTable, &p->mappingTableSize);
548 }
549 }
550 break;
551 case GF_IPMPX_ISMACRYP_TAG:
552 {
553 GF_IPMPX_ISMACryp*p = (GF_IPMPX_ISMACryp*)_p;
554 if (!stricmp(fieldName, "crypto_suite")) GET_U8(p->cryptoSuite)
555 else if (!stricmp(fieldName, "IV_length")) GET_U8(p->IV_length)
556 else if (!stricmp(fieldName, "selective_encryption")) GET_BOOL(p->use_selective_encryption)
557 else if (!stricmp(fieldName, "key_indicator_length")) GET_U8(p->key_indicator_length)
558 }
559 break;
560 }
561 return ret ? GF_OK : GF_BAD_PARAM;
562 }
563
gf_ipmpx_set_sub_data(GF_IPMPX_Data * _p,char * fieldName,GF_IPMPX_Data * sp)564 GF_Err gf_ipmpx_set_sub_data(GF_IPMPX_Data *_p, char *fieldName, GF_IPMPX_Data *sp)
565 {
566 switch (_p->tag) {
567 case GF_IPMPX_SECURE_CONTAINER_TAG:
568 {
569 GF_IPMPX_SecureContainer*p = (GF_IPMPX_SecureContainer*)_p;
570 if (p->protectedMsg) gf_ipmpx_data_del(p->protectedMsg);
571 p->protectedMsg = sp;
572 return GF_OK;
573 }
574 break;
575 case GF_IPMPX_TRUST_SECURITY_METADATA_TAG:
576 {
577 GF_IPMPX_TrustSecurityMetadata *p = (GF_IPMPX_TrustSecurityMetadata*)_p;
578 if (!sp || (sp->tag != GF_IPMPX_TRUSTED_TOOL_TAG)) return GF_BAD_PARAM;
579 gf_list_add(p->TrustedTools, sp);
580 return GF_OK;
581 }
582 break;
583 case GF_IPMPX_TRUSTED_TOOL_TAG:
584 {
585 GF_IPMPX_TrustedTool *p = (GF_IPMPX_TrustedTool *)_p;
586 if (!sp || (sp->tag != GF_IPMPX_TRUST_SPECIFICATION_TAG)) return GF_BAD_PARAM;
587 gf_list_add(p->trustSpecifications, sp);
588 return GF_OK;
589 }
590 break;
591 case GF_IPMPX_MUTUAL_AUTHENTICATION_TAG:
592 {
593 GF_IPMPX_MutualAuthentication *p = (GF_IPMPX_MutualAuthentication *)_p;
594 if (!sp) return GF_BAD_PARAM;
595 switch (sp->tag) {
596 case GF_IPMPX_ALGORITHM_DESCRIPTOR_TAG:
597 sp->tag = GF_IPMPX_AUTH_AlgorithmDescr_Tag;
598 if (!stricmp(fieldName, "candidateAlgorithms")) return gf_list_add(p->agreedAlgorithms, sp);
599 else if (!stricmp(fieldName, "agreedAlgorithms")) return gf_list_add(p->agreedAlgorithms, sp);
600 else return GF_BAD_PARAM;
601 case GF_IPMPX_KEY_DESCRIPTOR_TAG:
602 sp->tag = GF_IPMPX_AUTH_KeyDescr_Tag;
603 if (!stricmp(fieldName, "candidateAlgorithms")) return gf_list_add(p->agreedAlgorithms, sp);
604 else if (!stricmp(fieldName, "agreedAlgorithms")) return gf_list_add(p->agreedAlgorithms, sp);
605 else if (!stricmp(fieldName, "publicKey")) {
606 if (p->publicKey) GF_IPMPX_AUTH_Delete((GF_IPMPX_Authentication *)p->publicKey);
607 p->publicKey = (GF_IPMPX_AUTH_KeyDescriptor *)sp;
608 return GF_OK;
609 }
610 else return GF_BAD_PARAM;
611 case GF_IPMPX_TRUST_SECURITY_METADATA_TAG:
612 if (p->trustData) gf_ipmpx_data_del((GF_IPMPX_Data *)p->trustData);
613 p->trustData = (GF_IPMPX_TrustSecurityMetadata*)sp;
614 return GF_OK;
615 default:
616 return GF_BAD_PARAM;
617 }
618 }
619 break;
620 case GF_IPMPX_PARAMETRIC_DESCRIPTION_TAG:
621 {
622 GF_IPMPX_ParametricDescription*p = (GF_IPMPX_ParametricDescription*)_p;
623 if (!sp || (sp->tag != GF_IPMPX_PARAM_DESCRIPTOR_ITEM_TAG)) return GF_BAD_PARAM;
624 if (!stricmp(fieldName, "descriptions")) return gf_list_add(p->descriptions, sp);
625 else return GF_BAD_PARAM;
626 }
627 break;
628 case GF_IPMPX_PARAMETRIC_CAPS_QUERY_TAG:
629 {
630 GF_IPMPX_ToolParamCapabilitiesQuery*p = (GF_IPMPX_ToolParamCapabilitiesQuery*)_p;
631 if (!sp || (sp->tag != GF_IPMPX_PARAMETRIC_DESCRIPTION_TAG)) return GF_BAD_PARAM;
632 if (stricmp(fieldName, "description")) return GF_BAD_PARAM;
633 if (p->description) gf_ipmpx_data_del((GF_IPMPX_Data *)p->description);
634 p->description = (GF_IPMPX_ParametricDescription*)sp;
635 return GF_OK;
636 }
637 break;
638 case GF_IPMPX_SEL_DEC_INIT_TAG:
639 {
640 GF_IPMPX_SelectiveDecryptionInit*p = (GF_IPMPX_SelectiveDecryptionInit*)_p;
641 if (!sp) return GF_BAD_PARAM;
642 if (sp->tag == GF_IPMPX_SEL_ENC_BUFFER_TAG) return gf_list_add(p->SelEncBuffer, sp);
643 else if (sp->tag == GF_IPMPX_SEL_ENC_FIELD_TAG) return gf_list_add(p->SelEncFields, sp);
644 else return GF_BAD_PARAM;
645 }
646 break;
647 }
648 return GF_BAD_PARAM;
649 }
650
gf_ipmpx_set_byte_array(GF_IPMPX_Data * p,char * field,char * str)651 GF_Err gf_ipmpx_set_byte_array(GF_IPMPX_Data *p, char *field, char *str)
652 {
653 GF_IPMPX_ByteArray *d;
654 GF_IPMPX_ByteArray **dest;
655 d = (GF_IPMPX_ByteArray*)gf_malloc(sizeof(GF_IPMPX_ByteArray));
656 d->length = (u32)strlen(str);
657 d->data = (char*)gf_malloc(sizeof(char)*d->length);
658 memcpy(d->data, str, d->length);
659
660 dest = NULL;
661 switch (p->tag) {
662 case GF_IPMPX_KEY_DATA_TAG:
663 if (!stricmp(field, "keyBody")) dest = &((GF_IPMPX_KeyData*)p)->keyBody;
664 else if (!stricmp(field, "opaqueData")) dest = &((GF_IPMPX_KeyData*)p)->OpaqueData;
665 break;
666 case GF_IPMPX_RIGHTS_DATA_TAG:
667 if (!stricmp(field, "rightsInfo")) dest = &((GF_IPMPX_RightsData*)p)->rightsInfo;
668 break;
669 case GF_IPMPX_OPAQUE_DATA_TAG:
670 if (!stricmp(field, "opaqueData")) dest = &((GF_IPMPX_OpaqueData*)p)->opaqueData;
671 break;
672 case GF_IPMPX_SECURE_CONTAINER_TAG:
673 if (!stricmp(field, "encryptedData")) dest = &((GF_IPMPX_SecureContainer*)p)->encryptedData;
674 else if (!stricmp(field, "MAC")) dest = &((GF_IPMPX_SecureContainer*)p)->MAC;
675 break;
676 case GF_IPMPX_TRUST_SPECIFICATION_TAG:
677 if (!stricmp(field, "CCTrustMetadata")) dest = &((GF_IPMPX_TrustSpecification*)p)->CCTrustMetadata;
678 break;
679 case GF_IPMPX_MUTUAL_AUTHENTICATION_TAG:
680 if (!stricmp(field, "AuthenticationData")) dest = &((GF_IPMPX_MutualAuthentication*)p)->AuthenticationData;
681 else if (!stricmp(field, "opaque")) dest = &((GF_IPMPX_MutualAuthentication*)p)->opaque;
682 else if (!stricmp(field, "authCodes")) dest = &((GF_IPMPX_MutualAuthentication*)p)->authCodes;
683 else if (!stricmp(field, "certificates")) {
684 gf_list_add(((GF_IPMPX_MutualAuthentication*)p)->certificates, d);
685 return GF_OK;
686 }
687 break;
688 case GF_IPMPX_PARAMETRIC_DESCRIPTION_TAG:
689 if (!stricmp(field, "descriptionComment")) dest = &((GF_IPMPX_ParametricDescription*)p)->descriptionComment;
690 break;
691 case GF_IPMPX_PARAM_DESCRIPTOR_ITEM_TAG:
692 if (!stricmp(field, "class")) dest = &((GF_IPMPX_ParametricDescriptionItem*)p)->main_class;
693 else if (!stricmp(field, "subClass")) dest = &((GF_IPMPX_ParametricDescriptionItem*)p)->subClass;
694 else if (!stricmp(field, "typeData")) dest = &((GF_IPMPX_ParametricDescriptionItem*)p)->typeData;
695 else if (!stricmp(field, "type")) dest = &((GF_IPMPX_ParametricDescriptionItem*)p)->type;
696 else if (!stricmp(field, "addedData")) dest = &((GF_IPMPX_ParametricDescriptionItem*)p)->addedData;
697 break;
698 case GF_IPMPX_TOOL_API_CONFIG_TAG:
699 if (!stricmp(field, "opaqueData")) dest = &((GF_IPMPX_ToolAPI_Config*)p)->opaqueData;
700 break;
701 case GF_IPMPX_AUDIO_WM_SEND_TAG:
702 case GF_IPMPX_VIDEO_WM_SEND_TAG:
703 if (!stricmp(field, "payload")) dest = &((GF_IPMPX_SendWatermark *)p)->payload;
704 else if (!stricmp(field, "opaqueData")) dest = &((GF_IPMPX_SendWatermark*)p)->opaqueData;
705 break;
706 case GF_IPMPX_SEL_ENC_BUFFER_TAG:
707 if (!stricmp(field, "StreamCipher")) dest = &((GF_IPMPX_SelEncBuffer*)p)->Stream_Cipher_Specific_Init_Info;
708 break;
709 case GF_IPMPX_SEL_ENC_FIELD_TAG:
710 if (!stricmp(field, "shuffleSpecificInfo")) dest = &((GF_IPMPX_SelEncField*)p)->shuffleSpecificInfo;
711 break;
712 }
713 if (!dest) {
714 gf_free(d->data);
715 gf_free(d);
716 return GF_BAD_PARAM;
717 }
718 if ((*dest)) {
719 if ((*dest)->data) gf_free((*dest)->data);
720 gf_free((*dest));
721 }
722 (*dest) = d;
723 return GF_OK;
724 }
725
726 #endif /*GPAC_MINIMAL_ODF*/
727
728