aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libesg
diff options
context:
space:
mode:
authorMark Purcell <msp@debian.org>2008-06-22 11:00:40 +1000
committeretobi <git@e-tobi.net>2013-09-03 09:48:42 +0200
commit891c51ff368ed700dec6025eeb47ce4d96f76418 (patch)
tree3729664829e4faa691d403274f38eb10890b533c /lib/libesg
parent1c6e1f28f54ec2606c23936c1d8689f2be55a86c (diff)
parentab959d7b4194715870128e616b8e29d4a101e488 (diff)
downloadlinux-dvb-apps-891c51ff368ed700dec6025eeb47ce4d96f76418.tar.gz
Imported Debian patch 1.1.1+rev1207-1debian/1.1.1+rev1207-1
Diffstat (limited to 'lib/libesg')
-rw-r--r--lib/libesg/Makefile27
-rw-r--r--lib/libesg/TODO18
-rw-r--r--lib/libesg/bootstrap/Makefile24
-rw-r--r--lib/libesg/bootstrap/access_descriptor.c115
-rw-r--r--lib/libesg/bootstrap/access_descriptor.h86
-rw-r--r--lib/libesg/bootstrap/provider_discovery_descriptor.c50
-rw-r--r--lib/libesg/bootstrap/provider_discovery_descriptor.h59
-rw-r--r--lib/libesg/encapsulation/Makefile28
-rw-r--r--lib/libesg/encapsulation/auxiliary_data.h62
-rw-r--r--lib/libesg/encapsulation/container.c206
-rw-r--r--lib/libesg/encapsulation/container.h94
-rw-r--r--lib/libesg/encapsulation/data_repository.c53
-rw-r--r--lib/libesg/encapsulation/data_repository.h59
-rw-r--r--lib/libesg/encapsulation/fragment_management_information.c118
-rw-r--r--lib/libesg/encapsulation/fragment_management_information.h96
-rw-r--r--lib/libesg/encapsulation/string_repository.c54
-rw-r--r--lib/libesg/encapsulation/string_repository.h60
-rw-r--r--lib/libesg/representation/Makefile26
-rw-r--r--lib/libesg/representation/bim_decoder_init.h40
-rw-r--r--lib/libesg/representation/encapsulated_bim_esg_xml_fragment.h40
-rw-r--r--lib/libesg/representation/encapsulated_textual_esg_xml_fragment.c70
-rw-r--r--lib/libesg/representation/encapsulated_textual_esg_xml_fragment.h60
-rw-r--r--lib/libesg/representation/init_message.c112
-rw-r--r--lib/libesg/representation/init_message.h80
-rw-r--r--lib/libesg/representation/textual_decoder_init.c128
-rw-r--r--lib/libesg/representation/textual_decoder_init.h104
-rw-r--r--lib/libesg/transport/Makefile22
-rw-r--r--lib/libesg/transport/session_partition_declaration.c253
-rw-r--r--lib/libesg/transport/session_partition_declaration.h139
-rw-r--r--lib/libesg/types.c37
-rw-r--r--lib/libesg/types.h53
-rw-r--r--lib/libesg/xml/provider_discovery_descriptor.xsd22
32 files changed, 2395 insertions, 0 deletions
diff --git a/lib/libesg/Makefile b/lib/libesg/Makefile
new file mode 100644
index 0000000..abb9d4f
--- /dev/null
+++ b/lib/libesg/Makefile
@@ -0,0 +1,27 @@
+# Makefile for linuxtv.org dvb-apps/lib/libesg
+
+includes = types.h
+
+objects = types.o
+
+lib_name = libesg
+
+CPPFLAGS += -I../../lib
+
+.PHONY: all
+
+all: library
+
+include bootstrap/Makefile
+include encapsulation/Makefile
+include representation/Makefile
+include transport/Makefile
+
+.PHONY: $(sub-install)
+
+install:: $(sub-install)
+
+$(sub-install):
+ $(MAKE) -C $@ install
+
+include ../../Make.rules
diff --git a/lib/libesg/TODO b/lib/libesg/TODO
new file mode 100644
index 0000000..952215a
--- /dev/null
+++ b/lib/libesg/TODO
@@ -0,0 +1,18 @@
+*** General
+- Add enums for constants
+
+*** EncodingVersion
+- GZIP : use zlib
+- BiM : ???
+
+*** BOOTSTRAP
+- ESGProviderDiscoveryDescriptor : XML parsing with libexpat ?
+
+*** TRANSPORT
+- Indexation
+
+*** ENCAPSULATION
+- Auxiliary Data
+
+*** REPRESENTATION
+- BiM Decoder Init
diff --git a/lib/libesg/bootstrap/Makefile b/lib/libesg/bootstrap/Makefile
new file mode 100644
index 0000000..16a2457
--- /dev/null
+++ b/lib/libesg/bootstrap/Makefile
@@ -0,0 +1,24 @@
+# Makefile for linuxtv.org dvb-apps/lib/libesg/bootstrap
+
+.PHONY: sub-error-bootstrap
+
+sub-error-bootstrap:
+ $(error You can't use this makefile directly.)
+
+ifneq ($(lib_name),)
+
+objects += bootstrap/access_descriptor.o \
+ bootstrap/provider_discovery_descriptor.o
+
+sub-install += bootstrap
+
+else
+
+includes = access_descriptor.h \
+ provider_discovery_descriptor.h
+
+include ../../../Make.rules
+
+lib_name = libesg/bootstrap
+
+endif
diff --git a/lib/libesg/bootstrap/access_descriptor.c b/lib/libesg/bootstrap/access_descriptor.c
new file mode 100644
index 0000000..e8f89a3
--- /dev/null
+++ b/lib/libesg/bootstrap/access_descriptor.c
@@ -0,0 +1,115 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <libesg/bootstrap/access_descriptor.h>
+
+struct esg_access_descriptor *esg_access_descriptor_decode(uint8_t *buffer, uint32_t size) {
+ uint32_t pos;
+ struct esg_access_descriptor *access_descriptor;
+ struct esg_entry *entry;
+ struct esg_entry *last_entry;
+ uint32_t entry_length;
+ uint16_t entry_index;
+ uint8_t ip_index;
+
+ if ((buffer == NULL) || (size <= 2)) {
+ return NULL;
+ }
+
+ pos = 0;
+
+ access_descriptor = (struct esg_access_descriptor *) malloc(sizeof(struct esg_access_descriptor));
+ memset(access_descriptor, 0, sizeof(struct esg_access_descriptor));
+ access_descriptor->entry_list = NULL;
+
+ access_descriptor->n_o_entries = (buffer[pos] << 8) | buffer[pos+1];
+ pos += 2;
+
+ last_entry = NULL;
+ for (entry_index = 0; entry_index < access_descriptor->n_o_entries; entry_index++) {
+ entry = (struct esg_entry *) malloc(sizeof(struct esg_entry));
+ memset(entry, 0, sizeof(struct esg_entry));
+ entry->_next = NULL;
+
+ if (last_entry == NULL) {
+ access_descriptor->entry_list = entry;
+ } else {
+ last_entry->_next = entry;
+ }
+ last_entry = entry;
+
+ entry->version = buffer[pos];
+ pos += 1;
+
+ pos += vluimsbf8(buffer + pos, size - pos, &entry_length);
+
+ if (size < pos + entry_length) {
+ esg_access_descriptor_free(access_descriptor);
+ return NULL;
+ }
+
+ entry->multiple_stream_transport = (buffer[pos] & 0x80) ? 1 : 0;
+ entry->ip_version_6 = (buffer[pos] & 0x40) ? 1 : 0;
+ pos += 1;
+
+ entry->provider_id = (buffer[pos] << 8) | buffer[pos+1];
+ pos += 2;
+
+ if (entry->ip_version_6) {
+ for (ip_index = 0; ip_index < 16; ip_index++) {
+ entry->source_ip.ipv6[ip_index] = buffer[pos+ip_index];
+ entry->destination_ip.ipv6[ip_index] = buffer[pos+16+ip_index];
+ }
+ pos += 32;
+ } else {
+ for (ip_index = 0; ip_index < 4; ip_index++) {
+ entry->source_ip.ipv4[ip_index] = buffer[pos+ip_index];
+ entry->destination_ip.ipv4[ip_index] = buffer[pos+4+ip_index];
+ }
+ pos += 8;
+ }
+ entry->port = (buffer[pos] << 8) | buffer[pos+1];
+ pos += 2;
+
+ entry->tsi = (buffer[pos] << 8) | buffer[pos+1];
+ pos += 2;
+ }
+
+ return access_descriptor;
+}
+
+void esg_access_descriptor_free(struct esg_access_descriptor *access_descriptor) {
+ struct esg_entry *entry;
+ struct esg_entry *next_entry;
+
+ if (access_descriptor == NULL) {
+ return;
+ }
+
+ for(entry = access_descriptor->entry_list; entry; entry = next_entry) {
+ next_entry = entry->_next;
+ free(entry);
+ }
+
+ free(access_descriptor);
+}
diff --git a/lib/libesg/bootstrap/access_descriptor.h b/lib/libesg/bootstrap/access_descriptor.h
new file mode 100644
index 0000000..49aec46
--- /dev/null
+++ b/lib/libesg/bootstrap/access_descriptor.h
@@ -0,0 +1,86 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _ESG_BOOTSTRAP_ACCESS_DESCRIPTOR_H
+#define _ESG_BOOTSTRAP_ACCESS_DESCRIPTOR_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libesg/types.h>
+
+/**
+ * esg_entry structure.
+ */
+struct esg_entry {
+ uint8_t version;
+ uint8_t multiple_stream_transport;
+ uint8_t ip_version_6;
+ uint16_t provider_id;
+ union esg_ip_address source_ip;
+ union esg_ip_address destination_ip;
+ uint16_t port;
+ uint16_t tsi;
+
+ struct esg_entry *_next;
+};
+
+/**
+ * esg_access_descriptor structure.
+ */
+struct esg_access_descriptor {
+ uint16_t n_o_entries;
+ struct esg_entry *entry_list;
+};
+
+/**
+ * Process an esg_access_descriptor.
+ *
+ * @param buffer Binary buffer to decode.
+ * @param size Binary buffer size.
+ * @return Pointer to an esg_access_descriptor structure, or NULL on error.
+ */
+extern struct esg_access_descriptor *esg_access_descriptor_decode(uint8_t *buffer, uint32_t size);
+
+/**
+ * Free an esg_access_descriptor.
+ *
+ * @param esg Pointer to an esg_access_descriptor structure.
+ */
+extern void esg_access_descriptor_free(struct esg_access_descriptor *access_descriptor);
+
+/**
+ * Convenience iterator for esg_entry_list field of an esg_access_descriptor.
+ *
+ * @param access_descriptor The esg_access_descriptor pointer.
+ * @param entry Variable holding a pointer to the current esg_entry.
+ */
+#define esg_access_descriptor_entry_list_for_each(access_descriptor, entry) \
+ for ((entry) = (access_descriptor)->entry_list; \
+ (entry); \
+ (entry) = (entry)->_next)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libesg/bootstrap/provider_discovery_descriptor.c b/lib/libesg/bootstrap/provider_discovery_descriptor.c
new file mode 100644
index 0000000..833a038
--- /dev/null
+++ b/lib/libesg/bootstrap/provider_discovery_descriptor.c
@@ -0,0 +1,50 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <libesg/bootstrap/provider_discovery_descriptor.h>
+
+struct esg_provider_discovery_descriptor *esg_esg_provider_discovery_descriptor_decode(uint8_t *buffer, uint32_t size) {
+ struct esg_provider_discovery_descriptor *provider;
+
+ provider = (struct esg_provider_discovery_descriptor *) malloc(sizeof(struct esg_provider_discovery_descriptor));
+ memset(provider, 0, sizeof(struct esg_provider_discovery_descriptor));
+
+ provider->xml = (uint8_t *) malloc(size);
+ memcpy(provider->xml, buffer, size);
+
+ provider->size = size;
+
+ return provider;
+}
+
+void esg_provider_discovery_descriptor_free(struct esg_provider_discovery_descriptor *provider) {
+ if (provider == NULL) {
+ return;
+ }
+
+ if (provider->xml) {
+ free(provider->xml);
+ }
+
+ free(provider);
+}
diff --git a/lib/libesg/bootstrap/provider_discovery_descriptor.h b/lib/libesg/bootstrap/provider_discovery_descriptor.h
new file mode 100644
index 0000000..36065ec
--- /dev/null
+++ b/lib/libesg/bootstrap/provider_discovery_descriptor.h
@@ -0,0 +1,59 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _ESG_BOOTSTRAP_PROVIDER_DISCOVERY_DESCRIPTOR_H
+#define _ESG_BOOTSTRAP_PROVIDER_DISCOVERY_DESCRIPTOR_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+
+/**
+ * esg_provider_discovery_descriptor structure.
+ */
+struct esg_provider_discovery_descriptor {
+ uint8_t *xml;
+ uint32_t size;
+};
+
+/**
+ * Process an esg_provider_discovery_descriptor.
+ *
+ * @param buffer Binary buffer to decode.
+ * @param size Binary buffer size.
+ * @return Pointer to an esg_provider_discovery_descriptor structure, or NULL on error.
+ */
+extern struct esg_provider_discovery_descriptor *esg_esg_provider_discovery_descriptor_decode(uint8_t *buffer, uint32_t size);
+
+/**
+ * Free an esg_provider_discovery_descriptor.
+ *
+ * @param esg Pointer to an esg_provider_discovery_descriptor structure.
+ */
+extern void esg_provider_discovery_descriptor_free(struct esg_provider_discovery_descriptor *provider);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libesg/encapsulation/Makefile b/lib/libesg/encapsulation/Makefile
new file mode 100644
index 0000000..2f222ed
--- /dev/null
+++ b/lib/libesg/encapsulation/Makefile
@@ -0,0 +1,28 @@
+# Makefile for linuxtv.org dvb-apps/lib/libesg/encapsulation
+
+.PHONY: sub-error-encapsulation
+
+sub-error-encapsulation:
+ $(error You can't use this makefile directly.)
+
+ifneq ($(lib_name),)
+
+objects += encapsulation/container.o \
+ encapsulation/fragment_management_information.o \
+ encapsulation/data_repository.o \
+ encapsulation/string_repository.o
+
+sub-install += encapsulation
+
+else
+
+includes = container.h \
+ fragment_management_information.h \
+ data_repository.h \
+ string_repository.h
+
+include ../../../Make.rules
+
+lib_name = libesg/encapsulation
+
+endif
diff --git a/lib/libesg/encapsulation/auxiliary_data.h b/lib/libesg/encapsulation/auxiliary_data.h
new file mode 100644
index 0000000..e05b241
--- /dev/null
+++ b/lib/libesg/encapsulation/auxiliary_data.h
@@ -0,0 +1,62 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _ESG_ENCAPSULATION_AUXILIARY_DATA_H
+#define _ESG_ENCAPSULATION_AUXILIARY_DATA_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+
+/**
+ * esg_any_attribute structure.
+ */
+struct esg_any_attribute {
+ uint8_t version_id;
+ uint8_t *extension;
+
+ struct esg_any_attribure *_next;
+};
+
+/**
+ * esg_binary_header structure.
+ */
+struct esg_binary_header {
+ uint16_t encoding_metadatauri_mimetype;
+ struct esg_any_attribute *any_attribute_list;
+};
+
+/**
+ * esg_encapsulated_aux_data struct.
+ */
+struct esg_encapsulated_aux_data {
+ struct esg_binary_header *binary_header;
+ uint32_t aux_data_length;
+ uint8_t aux_data;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libesg/encapsulation/container.c b/lib/libesg/encapsulation/container.c
new file mode 100644
index 0000000..15b17bf
--- /dev/null
+++ b/lib/libesg/encapsulation/container.c
@@ -0,0 +1,206 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <libesg/encapsulation/container.h>
+#include <libesg/encapsulation/fragment_management_information.h>
+#include <libesg/encapsulation/data_repository.h>
+#include <libesg/encapsulation/string_repository.h>
+#include <libesg/representation/init_message.h>
+#include <libesg/transport/session_partition_declaration.h>
+
+struct esg_container *esg_container_decode(uint8_t *buffer, uint32_t size) {
+ uint32_t pos;
+ struct esg_container *container;
+ struct esg_container_structure *structure;
+ struct esg_container_structure *last_structure;
+ uint8_t structure_index;
+
+ if ((buffer == NULL) || (size <= 1)) {
+ return NULL;
+ }
+
+ pos = 0;
+
+ container = (struct esg_container *) malloc(sizeof(struct esg_container));
+ memset(container, 0, sizeof(struct esg_container));
+
+ // Container header
+ container->header = (struct esg_container_header *) malloc(sizeof(struct esg_container_header));
+ memset(container->header, 0, sizeof(struct esg_container_header));
+
+ container->header->num_structures = buffer[pos];
+ pos += 1;
+
+ if (size < pos + (container->header->num_structures * 8)) {
+ esg_container_free(container);
+ return NULL;
+ }
+
+ last_structure = NULL;
+ for (structure_index = 0; structure_index < container->header->num_structures; structure_index++) {
+ structure = (struct esg_container_structure *) malloc(sizeof(struct esg_container_structure));
+ memset(structure, 0, sizeof(struct esg_container_structure));
+ structure->_next = NULL;
+
+ if (last_structure == NULL) {
+ container->header->structure_list = structure;
+ } else {
+ last_structure->_next = structure;
+ }
+ last_structure = structure;
+
+ structure->type = buffer[pos];
+ pos += 1;
+
+ structure->id = buffer[pos];
+ pos += 1;
+
+ structure->ptr = (buffer[pos] << 16) | (buffer[pos+1] << 8) | buffer[pos+2];
+ pos += 3;
+
+ structure->length = (buffer[pos] << 16) | (buffer[pos+1] << 8) | buffer[pos+2];
+ pos += 3;
+
+ if (size < (structure->ptr + structure->length)) {
+ esg_container_free(container);
+ return NULL;
+ }
+
+ // Decode structure
+ switch (structure->type) {
+ case 0x01: {
+ switch (structure->id) {
+ case 0x00: {
+ structure->data = (void *) esg_encapsulation_structure_decode(buffer + structure->ptr, structure->length);
+ break;
+ }
+ default: {
+ esg_container_free(container);
+ return NULL;
+ }
+ }
+ break;
+ }
+ case 0x02: {
+ switch (structure->id) {
+ case 0x00: {
+ structure->data = (void *) esg_string_repository_decode(buffer + structure->ptr, structure->length);
+ break;
+ }
+ default: {
+ esg_container_free(container);
+ return NULL;
+ }
+ }
+ break;
+ }
+ case 0x03: {
+ //TODO
+ break;
+ }
+ case 0x04: {
+ //TODO
+ break;
+ }
+ case 0x05: {
+ //TODO
+ break;
+ }
+ case 0xE0: {
+ switch (structure->id) {
+ case 0x00: {
+ structure->data = (void *) esg_data_repository_decode(buffer + structure->ptr, structure->length);
+ break;
+ }
+ default: {
+ esg_container_free(container);
+ return NULL;
+ }
+ }
+ break;
+ }
+ case 0xE1: {
+ switch (structure->id) {
+ case 0xFF: {
+ structure->data = (void *) esg_session_partition_declaration_decode(buffer + structure->ptr, structure->length);
+ break;
+ }
+ default: {
+ esg_container_free(container);
+ return NULL;
+ }
+ }
+ break;
+ }
+ case 0xE2: {
+ switch (structure->id) {
+ case 0x00: {
+ structure->data = (void *) esg_init_message_decode(buffer + structure->ptr, structure->length);
+ break;
+ }
+ default: {
+ esg_container_free(container);
+ return NULL;
+ }
+ }
+ break;
+ }
+ default: {
+ esg_container_free(container);
+ return NULL;
+ }
+ }
+ }
+
+ // Container structure body
+ container->structure_body_ptr = pos;
+ container->structure_body_length = size - pos;
+ container->structure_body = (uint8_t *) malloc(size - pos);
+ memcpy(container->structure_body, buffer + pos, size - pos);
+
+ return container;
+}
+
+void esg_container_free(struct esg_container *container) {
+ struct esg_container_structure *structure;
+ struct esg_container_structure *next_structure;
+
+ if (container == NULL) {
+ return;
+ }
+
+ if (container->header) {
+ for(structure = container->header->structure_list; structure; structure = next_structure) {
+ next_structure = structure->_next;
+ free(structure);
+ }
+
+ free(container->header);
+ }
+
+ if (container->structure_body) {
+ free(container->structure_body);
+ }
+
+ free(container);
+}
diff --git a/lib/libesg/encapsulation/container.h b/lib/libesg/encapsulation/container.h
new file mode 100644
index 0000000..dc54ef2
--- /dev/null
+++ b/lib/libesg/encapsulation/container.h
@@ -0,0 +1,94 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _ESG_ENCAPSULATION_CONTAINER_H
+#define _ESG_ENCAPSULATION_CONTAINER_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+
+/**
+ * esg_container_structure structure.
+ */
+struct esg_container_structure {
+ uint8_t type;
+ uint8_t id;
+ uint32_t ptr;
+ uint32_t length;
+
+ void *data;
+
+ struct esg_container_structure *_next;
+};
+
+/**
+ * esg_container_header structure.
+ */
+struct esg_container_header {
+ uint8_t num_structures;
+ struct esg_container_structure *structure_list;
+};
+
+/**
+ * esg_container structure
+ */
+struct esg_container {
+ struct esg_container_header *header;
+ uint32_t structure_body_ptr;
+ uint32_t structure_body_length;
+ uint8_t *structure_body;
+};
+
+/**
+ * Process an esg_container.
+ *
+ * @param buffer Binary buffer to decode.
+ * @param size Binary buffer size.
+ * @return Pointer to an esg_container structure, or NULL on error.
+ */
+extern struct esg_container *esg_container_decode(uint8_t *buffer, uint32_t size);
+
+/**
+ * Free an esg_container.
+ *
+ * @param container Pointer to an esg_container structure.
+ */
+extern void esg_container_free(struct esg_container *container);
+
+/**
+ * Convenience iterator for structure_list field of an esg_container_header.
+ *
+ * @param container The esg_container_header pointer.
+ * @param structure Variable holding a pointer to the current esg_container_structure.
+ */
+#define esg_container_header_structure_list_for_each(header, structure) \
+ for ((structure) = (header)->structure_list; \
+ (structure); \
+ (structure) = (structure)->_next)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libesg/encapsulation/data_repository.c b/lib/libesg/encapsulation/data_repository.c
new file mode 100644
index 0000000..629e5ea
--- /dev/null
+++ b/lib/libesg/encapsulation/data_repository.c
@@ -0,0 +1,53 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <libesg/encapsulation/data_repository.h>
+
+struct esg_data_repository *esg_data_repository_decode(uint8_t *buffer, uint32_t size) {
+ struct esg_data_repository *data_repository;
+
+ if ((buffer == NULL) || (size <= 0)) {
+ return NULL;
+ }
+
+ data_repository = (struct esg_data_repository *) malloc(sizeof(struct esg_data_repository));
+ memset(data_repository, 0, sizeof(struct esg_data_repository));
+
+ data_repository->length = size;
+ data_repository->data = (uint8_t *) malloc(size);
+ memcpy(data_repository->data, buffer, size);
+
+ return data_repository;
+}
+
+void esg_data_repository_free(struct esg_data_repository *data_repository) {
+ if (data_repository == NULL) {
+ return;
+ }
+
+ if (data_repository->data) {
+ free(data_repository->data);
+ }
+
+ free(data_repository);
+}
diff --git a/lib/libesg/encapsulation/data_repository.h b/lib/libesg/encapsulation/data_repository.h
new file mode 100644
index 0000000..4c691cf
--- /dev/null
+++ b/lib/libesg/encapsulation/data_repository.h
@@ -0,0 +1,59 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _ESG_ENCAPSULATION_DATA_REPOSITORY_H
+#define _ESG_ENCAPSULATION_DATA_REPOSITORY_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+
+/**
+ * esg_data_repository structure.
+ */
+struct esg_data_repository {
+ uint32_t length;
+ uint8_t *data;
+};
+
+/**
+ * Process an esg_data_repository.
+ *
+ * @param buffer Binary buffer to decode.
+ * @param size Binary buffer size.
+ * @return Pointer to an esg_data_repository structure, or NULL on error.
+ */
+extern struct esg_data_repository *esg_data_repository_decode(uint8_t *buffer, uint32_t size);
+
+/**
+ * Free an esg_data_repository.
+ *
+ * @param data_repository Pointer to an esg_data_repository structure.
+ */
+extern void esg_data_repository_free(struct esg_data_repository *data_repository);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libesg/encapsulation/fragment_management_information.c b/lib/libesg/encapsulation/fragment_management_information.c
new file mode 100644
index 0000000..b08265d
--- /dev/null
+++ b/lib/libesg/encapsulation/fragment_management_information.c
@@ -0,0 +1,118 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <libesg/encapsulation/fragment_management_information.h>
+
+struct esg_encapsulation_structure *esg_encapsulation_structure_decode(uint8_t *buffer, uint32_t size) {
+ uint32_t pos;
+ struct esg_encapsulation_structure *structure;
+ struct esg_encapsulation_entry *entry;
+ struct esg_encapsulation_entry *last_entry;
+
+ if ((buffer == NULL) || (size <= 2)) {
+ return NULL;
+ }
+
+ pos = 0;
+
+ structure = (struct esg_encapsulation_structure *) malloc(sizeof(struct esg_encapsulation_structure));
+ memset(structure, 0, sizeof(struct esg_encapsulation_structure));
+ structure->entry_list = NULL;
+
+ // Encapsulation header
+ structure->header = (struct esg_encapsulation_header *) malloc(sizeof(struct esg_encapsulation_header));
+ // buffer[pos] reserved
+ structure->header->fragment_reference_format = buffer[pos+1];
+ pos += 2;
+
+ // Encapsulation entry list
+ last_entry = NULL;
+ while (size > pos) {
+ entry = (struct esg_encapsulation_entry *) malloc(sizeof(struct esg_encapsulation_entry));
+ memset(entry, 0, sizeof(struct esg_encapsulation_entry));
+ entry->_next = NULL;
+
+ if (last_entry == NULL) {
+ structure->entry_list = entry;
+ } else {
+ last_entry->_next = entry;
+ }
+ last_entry = entry;
+
+ // Fragment reference
+ switch (structure->header->fragment_reference_format) {
+ case 0x21: {
+ entry->fragment_reference = (struct esg_fragment_reference *) malloc(sizeof(struct esg_fragment_reference));
+ memset(entry->fragment_reference, 0, sizeof(struct esg_fragment_reference));
+
+ entry->fragment_reference->fragment_type = buffer[pos];
+ pos += 1;
+
+ entry->fragment_reference->data_repository_offset = (buffer[pos] << 16) | (buffer[pos+1] << 8) | buffer[pos+2];
+ pos += 3;
+
+ break;
+ }
+ default: {
+ esg_encapsulation_structure_free(structure);
+ return NULL;
+ }
+ }
+
+ // Fragment version & id
+ entry->fragment_version = buffer[pos];
+ pos += 1;
+
+ entry->fragment_id = (buffer[pos] << 16) | (buffer[pos+1] << 8) | buffer[pos+2];
+ pos += 3;
+ }
+
+ return structure;
+}
+
+void esg_encapsulation_structure_free(struct esg_encapsulation_structure *structure) {
+ struct esg_encapsulation_entry *entry;
+ struct esg_encapsulation_entry *next_entry;
+
+ if (structure == NULL) {
+ return;
+ }
+
+ if (structure->header) {
+ free(structure->header);
+ }
+
+ if (structure->entry_list) {
+ for(entry = structure->entry_list; entry; entry = next_entry) {
+ next_entry = entry->_next;
+ if (entry->fragment_reference) {
+ free(entry->fragment_reference);
+ }
+ free(entry);
+ }
+
+ free(structure->entry_list);
+ }
+
+ free(structure);
+}
diff --git a/lib/libesg/encapsulation/fragment_management_information.h b/lib/libesg/encapsulation/fragment_management_information.h
new file mode 100644
index 0000000..04050b5
--- /dev/null
+++ b/lib/libesg/encapsulation/fragment_management_information.h
@@ -0,0 +1,96 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _ESG_ENCAPSULATION_FRAGMENT_MANAGEMENT_INFORMATION_H
+#define _ESG_ENCAPSULATION_FRAGMENT_MANAGEMENT_INFORMATION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+
+/**
+ * esg_encapsulation_header structure.
+ */
+struct esg_encapsulation_header {
+ uint8_t fragment_reference_format;
+};
+
+/**
+ * esg_fragment_reference structure.
+ */
+struct esg_fragment_reference {
+ uint8_t fragment_type;
+ uint32_t data_repository_offset;
+};
+
+/**
+ * esg_encapsulation_entry structure.
+ */
+struct esg_encapsulation_entry {
+ struct esg_fragment_reference *fragment_reference;
+ uint8_t fragment_version;
+ uint32_t fragment_id;
+
+ struct esg_encapsulation_entry *_next;
+};
+
+/**
+ * esg_encapsulation_structure structure.
+ */
+struct esg_encapsulation_structure {
+ struct esg_encapsulation_header *header;
+ struct esg_encapsulation_entry *entry_list;
+};
+
+/**
+ * Process an esg_encapsulation_structure.
+ *
+ * @param buffer Binary buffer to decode.
+ * @param size Binary buffer size.
+ * @return Pointer to an esg_encapsulation_structure structure, or NULL on error.
+ */
+extern struct esg_encapsulation_structure *esg_encapsulation_structure_decode(uint8_t *buffer, uint32_t size);
+
+/**
+ * Free an esg_encapsulation_structure.
+ *
+ * @param container Pointer to an esg_container structure.
+ */
+extern void esg_encapsulation_structure_free(struct esg_encapsulation_structure *structure);
+
+/**
+ * Convenience iterator for entry_list field of an esg_encapsulation_structure.
+ *
+ * @param structure The esg_encapsulation_structure pointer.
+ * @param entry Variable holding a pointer to the current esg_encapsulation_entry.
+ */
+#define esg_encapsulation_structure_entry_list_for_each(structure, entry) \
+ for ((entry) = (structure)->entry_list; \
+ (entry); \
+ (entry) = (entry)->_next)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libesg/encapsulation/string_repository.c b/lib/libesg/encapsulation/string_repository.c
new file mode 100644
index 0000000..3b88742
--- /dev/null
+++ b/lib/libesg/encapsulation/string_repository.c
@@ -0,0 +1,54 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <libesg/encapsulation/string_repository.h>
+
+struct esg_string_repository *esg_string_repository_decode(uint8_t *buffer, uint32_t size) {
+ struct esg_string_repository *string_repository;
+
+ if ((buffer == NULL) || (size <= 1)) {
+ return NULL;
+ }
+
+ string_repository = (struct esg_string_repository *) malloc(sizeof(struct esg_string_repository));
+ memset(string_repository, 0, sizeof(struct esg_string_repository));
+
+ string_repository->encoding_type = buffer[0];
+ string_repository->length = size-1;
+ string_repository->data = (uint8_t *) malloc(size-1);
+ memcpy(string_repository->data, buffer+1, size-1);
+
+ return string_repository;
+}
+
+void esg_string_repository_free(struct esg_string_repository *string_repository) {
+ if (string_repository == NULL) {
+ return;
+ }
+
+ if (string_repository->data) {
+ free(string_repository->data);
+ }
+
+ free(string_repository);
+}
diff --git a/lib/libesg/encapsulation/string_repository.h b/lib/libesg/encapsulation/string_repository.h
new file mode 100644
index 0000000..0cf64c2
--- /dev/null
+++ b/lib/libesg/encapsulation/string_repository.h
@@ -0,0 +1,60 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _ESG_ENCAPSULATION_STRING_REPOSITORY_H
+#define _ESG_ENCAPSULATION_STRING_REPOSITORY_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+
+/**
+ * esg_string_repository structure.
+ */
+struct esg_string_repository {
+ uint8_t encoding_type;
+ uint32_t length;
+ uint8_t *data;
+};
+
+/**
+ * Process an esg_string_repository.
+ *
+ * @param buffer Binary buffer to decode.
+ * @param size Binary buffer size.
+ * @return Pointer to an esg_string_repository structure, or NULL on error.
+ */
+extern struct esg_string_repository *esg_string_repository_decode(uint8_t *buffer, uint32_t size);
+
+/**
+ * Free an esg_string_repository.
+ *
+ * @param data_repository Pointer to an esg_string_repository structure.
+ */
+extern void esg_string_repository_free(struct esg_string_repository *string_repository);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libesg/representation/Makefile b/lib/libesg/representation/Makefile
new file mode 100644
index 0000000..059f8bd
--- /dev/null
+++ b/lib/libesg/representation/Makefile
@@ -0,0 +1,26 @@
+# Makefile for linuxtv.org dvb-apps/lib/libesg/representation
+
+.PHONY: sub-error-representation
+
+sub-error-representation:
+ $(error You can't use this makefile directly.)
+
+ifneq ($(lib_name),)
+
+objects += representation/encapsulated_textual_esg_xml_fragment.o \
+ representation/init_message.o \
+ representation/textual_decoder_init.o
+
+sub-install += representation
+
+else
+
+includes = encapsulated_textual_esg_xml_fragment.h \
+ init_message.h \
+ textual_decoder_init.h
+
+include ../../../Make.rules
+
+lib_name = libesg/representation
+
+endif
diff --git a/lib/libesg/representation/bim_decoder_init.h b/lib/libesg/representation/bim_decoder_init.h
new file mode 100644
index 0000000..4860da9
--- /dev/null
+++ b/lib/libesg/representation/bim_decoder_init.h
@@ -0,0 +1,40 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _ESG_REPRESENTATION_BIM_DECODER_INIT_H
+#define _ESG_REPRESENTATION_BIM_DECODER_INIT_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * esg_bim_decoder_init structure.
+ */
+struct esg_bim_decoder_init {
+// TODO
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libesg/representation/encapsulated_bim_esg_xml_fragment.h b/lib/libesg/representation/encapsulated_bim_esg_xml_fragment.h
new file mode 100644
index 0000000..8ab39dd
--- /dev/null
+++ b/lib/libesg/representation/encapsulated_bim_esg_xml_fragment.h
@@ -0,0 +1,40 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _ESG_REPRESENTATION_ENCAPSULATED_BIM_ESG_XML_FRAGMENT_H
+#define _ESG_REPRESENTATION_ENCAPSULATED_BIM_ESG_XML_FRAGMENT_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * esg_encapsulated_bim_esg_xml_fragment structure.
+ */
+struct esg_encapsulated_bim_esg_xml_fragment {
+ //TODO
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libesg/representation/encapsulated_textual_esg_xml_fragment.c b/lib/libesg/representation/encapsulated_textual_esg_xml_fragment.c
new file mode 100644
index 0000000..199c857
--- /dev/null
+++ b/lib/libesg/representation/encapsulated_textual_esg_xml_fragment.c
@@ -0,0 +1,70 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <libesg/types.h>
+#include <libesg/representation/encapsulated_textual_esg_xml_fragment.h>
+
+struct esg_encapsulated_textual_esg_xml_fragment *esg_encapsulated_textual_esg_xml_fragment_decode(uint8_t *buffer, uint32_t size) {
+ struct esg_encapsulated_textual_esg_xml_fragment *esg_xml_fragment;
+ uint32_t pos;
+ uint32_t length;
+ uint8_t offset_pos;
+
+ if ((buffer == NULL) || (size <= 0)) {
+ return NULL;
+ }
+
+ pos = 0;
+
+ esg_xml_fragment = (struct esg_encapsulated_textual_esg_xml_fragment *) malloc(sizeof(struct esg_encapsulated_textual_esg_xml_fragment));
+ memset(esg_xml_fragment, 0, sizeof(struct esg_encapsulated_textual_esg_xml_fragment));
+
+ offset_pos = vluimsbf8(buffer+pos+2, size-pos-2, &length);
+
+ if (size-pos-2 < offset_pos+length) {
+ esg_encapsulated_textual_esg_xml_fragment_free(esg_xml_fragment);
+ return NULL;
+ }
+
+ esg_xml_fragment->esg_xml_fragment_type = (buffer[pos] << 8) | buffer[pos+1];
+ pos += 2+offset_pos;
+
+ esg_xml_fragment->data_length = length;
+ esg_xml_fragment->data = (uint8_t *) malloc(length);
+ memcpy(esg_xml_fragment->data, buffer+pos, length);
+ pos += length;
+
+ return esg_xml_fragment;
+}
+
+void esg_encapsulated_textual_esg_xml_fragment_free(struct esg_encapsulated_textual_esg_xml_fragment *esg_xml_fragment) {
+ if (esg_xml_fragment == NULL) {
+ return;
+ }
+
+ if (esg_xml_fragment->data) {
+ free(esg_xml_fragment->data);
+ }
+
+ free(esg_xml_fragment);
+}
diff --git a/lib/libesg/representation/encapsulated_textual_esg_xml_fragment.h b/lib/libesg/representation/encapsulated_textual_esg_xml_fragment.h
new file mode 100644
index 0000000..ee8aba1
--- /dev/null
+++ b/lib/libesg/representation/encapsulated_textual_esg_xml_fragment.h
@@ -0,0 +1,60 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _ESG_REPRESENTATION_ENCAPSULATED_TEXTUAL_ESG_XML_FRAGMENT_H
+#define _ESG_REPRESENTATION_ENCAPSULATED_TEXTUAL_ESG_XML_FRAGMENT_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+
+/**
+ * esg_encapsulated_textual_esg_xml_fragment structure.
+ */
+struct esg_encapsulated_textual_esg_xml_fragment {
+ uint16_t esg_xml_fragment_type;
+ uint32_t data_length;
+ uint8_t *data;
+};
+
+/**
+ * Process an esg_encapsulated_textual_esg_xml_fragment.
+ *
+ * @param buffer Binary buffer to decode.
+ * @param size Binary buffer size.
+ * @return Pointer to an esg_encapsulated_textual_esg_xml_fragment structure, or NULL on error.
+ */
+extern struct esg_encapsulated_textual_esg_xml_fragment *esg_encapsulated_textual_esg_xml_fragment_decode(uint8_t *buffer, uint32_t size);
+
+/**
+ * Free an esg_encapsulated_textual_esg_xml_fragment.
+ *
+ * @param data_repository Pointer to an esg_encapsulated_textual_esg_xml_fragment structure.
+ */
+extern void esg_encapsulated_textual_esg_xml_fragment_free(struct esg_encapsulated_textual_esg_xml_fragment *esg_xml_fragment);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libesg/representation/init_message.c b/lib/libesg/representation/init_message.c
new file mode 100644
index 0000000..0038607
--- /dev/null
+++ b/lib/libesg/representation/init_message.c
@@ -0,0 +1,112 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <libesg/representation/init_message.h>
+#include <libesg/representation/textual_decoder_init.h>
+#include <libesg/representation/bim_decoder_init.h>
+
+struct esg_init_message *esg_init_message_decode(uint8_t *buffer, uint32_t size) {
+ uint32_t pos;
+ struct esg_init_message *init_message;
+
+ if ((buffer == NULL) || (size <= 3)) {
+ return NULL;
+ }
+
+ pos = 0;
+
+ init_message = (struct esg_init_message *) malloc(sizeof(struct esg_init_message));
+ memset(init_message, 0, sizeof(struct esg_init_message));
+
+ init_message->encoding_version = buffer[pos];
+ pos += 1;
+
+ init_message->indexing_flag = (buffer[pos] & 0x80) >> 7;
+ pos += 1;
+
+ init_message->decoder_init_ptr = buffer[pos];
+ pos += 1;
+
+ if (init_message->indexing_flag) {
+ init_message->indexing_version = buffer[pos];
+ pos += 1;
+ }
+
+ switch (init_message->encoding_version) {
+ case 0xF1: {
+ struct esg_bim_encoding_parameters *encoding_parameters = (struct esg_bim_encoding_parameters *) malloc(sizeof(struct esg_bim_encoding_parameters));
+ memset(encoding_parameters, 0, sizeof(struct esg_bim_encoding_parameters));
+ init_message->encoding_parameters = (void *) encoding_parameters;
+
+ encoding_parameters->buffer_size_flag = (buffer[pos] & 0x80) >> 7;
+ encoding_parameters->position_code_flag = (buffer[pos] & 0x40) >> 6;
+ pos += 1;
+
+ encoding_parameters->character_encoding = buffer[pos];
+ pos += 1;
+
+ if (encoding_parameters->buffer_size_flag) {
+ encoding_parameters->buffer_size = (buffer[pos] << 16) | (buffer[pos+1] << 8) | buffer[pos+2];
+ pos += 3;
+ }
+
+// TODO
+// init_message->decoder_init = (void *) esg_bim_decoder_init_decode(buffer + init_message->decoder_init_ptr, size - init_message->decoder_init_ptr);
+ break;
+ }
+ case 0xF2:
+ case 0xF3: {
+ struct esg_textual_encoding_parameters *encoding_parameters = (struct esg_textual_encoding_parameters *) malloc(sizeof(struct esg_textual_encoding_parameters));
+ memset(encoding_parameters, 0, sizeof(struct esg_textual_encoding_parameters));
+ init_message->encoding_parameters = (void *) encoding_parameters;
+
+ encoding_parameters->character_encoding = buffer[pos];
+ pos += 1;
+
+ init_message->decoder_init = (void *) esg_textual_decoder_init_decode(buffer + init_message->decoder_init_ptr, size - init_message->decoder_init_ptr);
+ break;
+ }
+ default: {
+ esg_init_message_free(init_message);
+ return NULL;
+ }
+ }
+
+ return init_message;
+}
+
+void esg_init_message_free(struct esg_init_message *init_message) {
+ if (init_message == NULL) {
+ return;
+ }
+
+ if (init_message->encoding_parameters) {
+ free(init_message->encoding_parameters);
+ }
+
+ if (init_message->decoder_init) {
+ free(init_message->decoder_init);
+ }
+
+ free(init_message);
+}
diff --git a/lib/libesg/representation/init_message.h b/lib/libesg/representation/init_message.h
new file mode 100644
index 0000000..a525495
--- /dev/null
+++ b/lib/libesg/representation/init_message.h
@@ -0,0 +1,80 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _ESG_REPRESENTATION_INIT_MESSAGE_H
+#define _ESG_REPRESENTATION_INIT_MESSAGE_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+
+/**
+ * esg_textual_encoding_parameters structure.
+ */
+struct esg_textual_encoding_parameters {
+ uint8_t character_encoding;
+};
+
+/**
+ * esg_bim_encoding_parameters structure.
+ */
+struct esg_bim_encoding_parameters {
+ uint8_t buffer_size_flag;
+ uint8_t position_code_flag;
+ uint8_t character_encoding;
+ uint32_t buffer_size; // if buffer_size_flag
+};
+
+/**
+ * esg_init_message structure.
+ */
+struct esg_init_message {
+ uint8_t encoding_version;
+ uint8_t indexing_flag;
+ uint8_t decoder_init_ptr;
+ uint8_t indexing_version; // if indexing_flag
+ void *encoding_parameters;
+ void *decoder_init;
+};
+
+/**
+ * Process an esg_init_message.
+ *
+ * @param buffer Binary buffer to decode.
+ * @param size Binary buffer size.
+ * @return Pointer to an esg_string_repository structure, or NULL on error.
+ */
+extern struct esg_init_message *esg_init_message_decode(uint8_t *buffer, uint32_t size);
+
+/**
+ * Free an esg_init_message.
+ *
+ * @param init_message Pointer to an esg_init_message structure.
+ */
+extern void esg_init_message_free(struct esg_init_message *init_message);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libesg/representation/textual_decoder_init.c b/lib/libesg/representation/textual_decoder_init.c
new file mode 100644
index 0000000..c797d0e
--- /dev/null
+++ b/lib/libesg/representation/textual_decoder_init.c
@@ -0,0 +1,128 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <libesg/types.h>
+#include <libesg/representation/textual_decoder_init.h>
+
+struct esg_textual_decoder_init *esg_textual_decoder_init_decode(uint8_t *buffer, uint32_t size) {
+ uint32_t pos;
+ struct esg_textual_decoder_init *decoder_init;
+ struct esg_namespace_prefix *namespace_prefix;
+ struct esg_namespace_prefix *last_namespace_prefix;
+ struct esg_xml_fragment_type *xml_fragment_type;
+ struct esg_xml_fragment_type *last_xml_fragment_type;
+ uint32_t decoder_init_length;
+ uint8_t num_index;
+
+ if ((buffer == NULL) || (size <= 1)) {
+ return NULL;
+ }
+
+ pos = 0;
+
+ decoder_init = (struct esg_textual_decoder_init *) malloc(sizeof(struct esg_textual_decoder_init));
+ memset(decoder_init, 0, sizeof(struct esg_textual_decoder_init));
+ decoder_init->namespace_prefix_list = NULL;
+ decoder_init->xml_fragment_type_list = NULL;
+
+ decoder_init->version = buffer[pos];
+ pos += 1;
+
+ pos += vluimsbf8(buffer+pos, size-pos, &decoder_init_length);
+
+ if (size < pos + decoder_init_length) {
+ esg_textual_decoder_init_free(decoder_init);
+ return NULL;
+ }
+
+ decoder_init->num_namespace_prefixes = buffer[pos];
+ pos += 1;
+
+ last_namespace_prefix = NULL;
+ for (num_index = 0; num_index < decoder_init->num_namespace_prefixes; num_index++) {
+ namespace_prefix = (struct esg_namespace_prefix *) malloc(sizeof(struct esg_namespace_prefix));
+ memset(namespace_prefix, 0, sizeof(struct esg_namespace_prefix));
+ namespace_prefix->_next = NULL;
+
+ if (last_namespace_prefix == NULL) {
+ decoder_init->namespace_prefix_list = namespace_prefix;
+ } else {
+ last_namespace_prefix->_next = namespace_prefix;
+ }
+ last_namespace_prefix = namespace_prefix;
+
+ namespace_prefix->prefix_string_ptr = (buffer[pos] << 8) | buffer[pos+1];
+ pos += 2;
+
+ namespace_prefix->namespace_uri_ptr = (buffer[pos] << 8) | buffer[pos+1];
+ pos += 2;
+ }
+
+ decoder_init->num_fragment_types = buffer[pos];
+ pos += 1;
+
+ last_xml_fragment_type = NULL;
+ for (num_index = 0; num_index < decoder_init->num_fragment_types; num_index++) {
+ xml_fragment_type = (struct esg_xml_fragment_type *) malloc(sizeof(struct esg_xml_fragment_type));
+ memset(xml_fragment_type, 0, sizeof(struct esg_xml_fragment_type));
+ xml_fragment_type->_next = NULL;
+
+ if (last_xml_fragment_type == NULL) {
+ decoder_init->xml_fragment_type_list = xml_fragment_type;
+ } else {
+ last_xml_fragment_type->_next = xml_fragment_type;
+ }
+ last_xml_fragment_type = xml_fragment_type;
+
+ xml_fragment_type->xpath_ptr = (buffer[pos] << 8) | buffer[pos+1];
+ pos += 2;
+
+ xml_fragment_type->xml_fragment_type = (buffer[pos] << 8) | buffer[pos+1];
+ pos += 2;
+ }
+
+ return decoder_init;
+}
+
+void esg_textual_decoder_init_free(struct esg_textual_decoder_init *decoder_init) {
+ struct esg_namespace_prefix *namespace_prefix;
+ struct esg_namespace_prefix *next_namespace_prefix;
+ struct esg_xml_fragment_type *xml_fragment_type;
+ struct esg_xml_fragment_type *next_xml_fragment_type;
+
+ if (decoder_init == NULL) {
+ return;
+ }
+
+ for(namespace_prefix = decoder_init->namespace_prefix_list; namespace_prefix; namespace_prefix = next_namespace_prefix) {
+ next_namespace_prefix = namespace_prefix->_next;
+ free(namespace_prefix);
+ }
+
+ for(xml_fragment_type = decoder_init->xml_fragment_type_list; xml_fragment_type; xml_fragment_type = next_xml_fragment_type) {
+ next_xml_fragment_type = xml_fragment_type->_next;
+ free(xml_fragment_type);
+ }
+
+ free(decoder_init);
+}
diff --git a/lib/libesg/representation/textual_decoder_init.h b/lib/libesg/representation/textual_decoder_init.h
new file mode 100644
index 0000000..c1352cc
--- /dev/null
+++ b/lib/libesg/representation/textual_decoder_init.h
@@ -0,0 +1,104 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _ESG_REPRESENTATION_TEXTUAL_DECODER_INIT_H
+#define _ESG_REPRESENTATION_TEXTUAL_DECODER_INIT_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+
+/**
+ * esg_namespace_prefix structure.
+ */
+struct esg_namespace_prefix {
+ uint16_t prefix_string_ptr;
+ uint16_t namespace_uri_ptr;
+
+ struct esg_namespace_prefix *_next;
+};
+
+/**
+ * esg_fragment_type structure.
+ */
+struct esg_xml_fragment_type {
+ uint16_t xpath_ptr;
+ uint16_t xml_fragment_type;
+
+ struct esg_xml_fragment_type *_next;
+};
+
+/**
+ * esg_textual_decoder_init structure.
+ */
+struct esg_textual_decoder_init {
+ uint8_t version;
+ uint8_t num_namespace_prefixes;
+ struct esg_namespace_prefix *namespace_prefix_list;
+ uint8_t num_fragment_types;
+ struct esg_xml_fragment_type *xml_fragment_type_list;
+};
+
+/**
+ * Process an esg_textual_decoder_init.
+ *
+ * @param buffer Binary buffer to decode.
+ * @param size Binary buffer size.
+ * @return Pointer to an esg_textual_decoder_init structure, or NULL on error.
+ */
+extern struct esg_textual_decoder_init *esg_textual_decoder_init_decode(uint8_t *buffer, uint32_t size);
+
+/**
+ * Free an esg_textual_decoder_init.
+ *
+ * @param decoder_init Pointer to an esg_textual_decoder_init structure.
+ */
+extern void esg_textual_decoder_init_free(struct esg_textual_decoder_init *decoder_init);
+
+/**
+ * Convenience iterator for namespace_prefix_list field of an esg_textual_decoder_init.
+ *
+ * @param decoder_init The esg_textual_decoder_init pointer.
+ * @param namespace_prefix Variable holding a pointer to the current esg_namespace_prefix.
+ */
+#define esg_textual_decoder_namespace_prefix_list_for_each(decoder_init, namespace_prefix) \
+ for ((namespace_prefix) = (decoder_init)->namespace_prefix_list; \
+ (namespace_prefix); \
+ (namespace_prefix) = (namespace_prefix)->_next)
+
+/**
+ * Convenience iterator for xml_fragment_type_list field of an esg_textual_decoder_init.
+ *
+ * @param decoder_init The esg_textual_decoder_init pointer.
+ * @param xml_fragment_type Variable holding a pointer to the current esg_xml_fragment_type.
+ */
+#define esg_textual_decoder_xml_fragment_type_list_for_each(decoder_init, xml_fragment_type) \
+ for ((xml_fragment_type) = (decoder_init)->xml_fragment_type_list; \
+ (xml_fragment_type); \
+ (xml_fragment_type) = (xml_fragment_type)->_next)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libesg/transport/Makefile b/lib/libesg/transport/Makefile
new file mode 100644
index 0000000..7900770
--- /dev/null
+++ b/lib/libesg/transport/Makefile
@@ -0,0 +1,22 @@
+# Makefile for linuxtv.org dvb-apps/lib/libesg/transport
+
+.PHONY: sub-error-transport
+
+sub-error-transport:
+ $(error You can't use this makefile directly.)
+
+ifneq ($(lib_name),)
+
+objects += transport/session_partition_declaration.o
+
+sub-install += transport
+
+else
+
+includes = session_partition_declaration.h
+
+include ../../../Make.rules
+
+lib_name = libesg/transport
+
+endif
diff --git a/lib/libesg/transport/session_partition_declaration.c b/lib/libesg/transport/session_partition_declaration.c
new file mode 100644
index 0000000..d590bd3
--- /dev/null
+++ b/lib/libesg/transport/session_partition_declaration.c
@@ -0,0 +1,253 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <libesg/transport/session_partition_declaration.h>
+
+struct esg_session_partition_declaration *esg_session_partition_declaration_decode(uint8_t *buffer, uint32_t size) {
+ uint32_t pos;
+ struct esg_session_partition_declaration *partition;
+ struct esg_session_field *field;
+ struct esg_session_field *last_field;
+ uint8_t field_index;
+ struct esg_session_ip_stream *ip_stream;
+ struct esg_session_ip_stream *last_ip_stream;
+ uint8_t ip_stream_index;
+ uint8_t ip_index;
+ struct esg_session_ip_stream_field *ip_stream_field;
+ struct esg_session_ip_stream_field *last_ip_stream_field;
+ uint8_t *field_buffer;
+ uint32_t field_length;
+ union esg_session_ip_stream_field_value *field_value;
+
+ if ((buffer == NULL) || (size <= 2)) {
+ return NULL;
+ }
+
+ pos = 0;
+
+ partition = (struct esg_session_partition_declaration *) malloc(sizeof(struct esg_session_partition_declaration));
+ memset(partition, 0, sizeof(struct esg_session_partition_declaration));
+ partition->field_list = NULL;
+ partition->ip_stream_list = NULL;
+
+ partition->num_fields = buffer[pos];
+ pos += 1;
+
+ partition->overlapping = (buffer[pos] & 0x80) ? 1 : 0;
+ pos += 1;
+
+ if (size < (pos + 5*(partition->num_fields))) {
+ esg_session_partition_declaration_free(partition);
+ return NULL;
+ }
+
+ last_field = NULL;
+ for (field_index = 0; field_index < partition->num_fields; field_index++) {
+ field = (struct esg_session_field *) malloc(sizeof(struct esg_session_field));
+ memset(field, 0, sizeof(struct esg_session_field));
+ field->_next = NULL;
+
+ if (last_field == NULL) {
+ partition->field_list = field;
+ } else {
+ last_field->_next = field;
+ }
+ last_field = field;
+
+ field->identifier = (buffer[pos] << 8) | buffer[pos+1];
+ pos += 2;
+
+ field->encoding = (buffer[pos] << 8) | buffer[pos+1];
+ pos += 2;
+
+ field->length = buffer[pos];
+ pos += 1;
+ }
+
+ partition->n_o_ip_streams = buffer[pos];
+ pos += 1;
+
+ partition->ip_version_6 = (buffer[pos] & 0x80) ? 1 : 0;
+ pos += 1;
+
+ last_ip_stream = NULL;
+ for (ip_stream_index = 0; ip_stream_index < partition->n_o_ip_streams; ip_stream_index++) {
+ ip_stream = (struct esg_session_ip_stream *) malloc(sizeof(struct esg_session_ip_stream));
+ memset(ip_stream, 0, sizeof(struct esg_session_ip_stream));
+ ip_stream->_next = NULL;
+
+ if (last_ip_stream == NULL) {
+ partition->ip_stream_list = ip_stream;
+ } else {
+ last_ip_stream->_next = ip_stream;
+ }
+ last_ip_stream = ip_stream;
+
+ ip_stream->id = buffer[pos];
+ pos += 1;
+
+ if (partition->ip_version_6) {
+ for (ip_index = 0; ip_index < 16; ip_index++) {
+ ip_stream->source_ip.ipv6[ip_index] = buffer[pos+ip_index];
+ ip_stream->destination_ip.ipv6[ip_index] = buffer[pos+16+ip_index];
+ }
+ pos += 32;
+ } else {
+ for (ip_index = 0; ip_index < 4; ip_index++) {
+ ip_stream->source_ip.ipv4[ip_index] = buffer[pos+ip_index];
+ ip_stream->destination_ip.ipv4[ip_index] = buffer[pos+4+ip_index];
+ }
+ pos += 8;
+ }
+ ip_stream->port = (buffer[pos] << 8) | buffer[pos+1];
+ pos += 2;
+
+ ip_stream->session_id = (buffer[pos] << 8) | buffer[pos+1];
+ pos += 2;
+
+ last_ip_stream_field = NULL;
+ esg_session_partition_declaration_field_list_for_each(partition, field) {
+ ip_stream_field = (struct esg_session_ip_stream_field *) malloc(sizeof(struct esg_session_ip_stream_field));
+ memset(ip_stream_field, 0, sizeof(struct esg_session_ip_stream_field));
+ ip_stream_field->_next = NULL;
+ ip_stream_field->start_field_value = NULL;
+ ip_stream_field->end_field_value = NULL;
+
+ if (last_ip_stream_field == NULL) {
+ ip_stream->field_list = ip_stream_field;
+ } else {
+ last_ip_stream_field->_next = ip_stream_field;
+ }
+ last_ip_stream_field = ip_stream_field;
+
+ field_length = field->length;
+ if (field->length != 0) {
+ field_length = field->length;
+ } else {
+ pos += vluimsbf8(buffer + pos, size - pos, &field_length);
+ }
+
+ switch (field->encoding) {
+ case 0x0000: {
+ if (partition->overlapping == 1) {
+ field_value = (union esg_session_ip_stream_field_value *) malloc(sizeof(union esg_session_ip_stream_field_value));
+ memset(field_value, 0, sizeof(union esg_session_ip_stream_field_value));
+ ip_stream_field->start_field_value = field_value;
+
+ field_buffer = (uint8_t *) malloc(field_length);
+ memset(field_buffer, 0, field_length);
+ memcpy(field_buffer, buffer + pos, field_length);
+
+ ip_stream_field->start_field_value->string = field_buffer;
+ pos += field_length;
+ }
+ field_value = (union esg_session_ip_stream_field_value *) malloc(sizeof(union esg_session_ip_stream_field_value));
+ memset(field_value, 0, sizeof(union esg_session_ip_stream_field_value));
+ ip_stream_field->end_field_value = field_value;
+
+ field_buffer = (uint8_t *) malloc(field_length);
+ memset(field_buffer, 0, field_length);
+ memcpy(field_buffer, buffer + pos, field_length);
+
+ ip_stream_field->end_field_value->string = field_buffer;
+ pos += field_length;
+
+ break;
+ }
+ case 0x0101: {
+ if (partition->overlapping == 1) {
+ field_value = (union esg_session_ip_stream_field_value *) malloc(sizeof(union esg_session_ip_stream_field_value));
+ memset(field_value, 0, sizeof(union esg_session_ip_stream_field_value));
+ ip_stream_field->start_field_value = field_value;
+
+ ip_stream_field->start_field_value->unsigned_short = (buffer[pos] << 8) | buffer[pos+1];
+ pos += field_length;
+ }
+ field_value = (union esg_session_ip_stream_field_value *) malloc(sizeof(union esg_session_ip_stream_field_value));
+ memset(field_value, 0, sizeof(union esg_session_ip_stream_field_value));
+ ip_stream_field->end_field_value = field_value;
+
+ ip_stream_field->end_field_value->unsigned_short = (buffer[pos] << 8) | buffer[pos+1];
+ pos += field_length;
+
+ break;
+ }
+ default: {
+ esg_session_partition_declaration_free(partition);
+ return NULL;
+ }
+ }
+ }
+ }
+
+ return partition;
+}
+
+void esg_session_partition_declaration_free(struct esg_session_partition_declaration *partition) {
+ struct esg_session_field *field;
+ struct esg_session_field *next_field;
+ struct esg_session_ip_stream *ip_stream;
+ struct esg_session_ip_stream *next_ip_stream;
+ struct esg_session_ip_stream_field *ip_stream_field;
+ struct esg_session_ip_stream_field *next_ip_stream_field;
+
+ if (partition == NULL) {
+ return;
+ }
+
+ for(ip_stream = partition->ip_stream_list; ip_stream; ip_stream = next_ip_stream) {
+ next_ip_stream = ip_stream->_next;
+
+ field = partition->field_list;
+ for(ip_stream_field = next_ip_stream->field_list; ip_stream_field; ip_stream_field = next_ip_stream_field) {
+ next_ip_stream_field = ip_stream_field->_next;
+
+ switch (field->encoding) {
+ case 0x0000: {
+ if (ip_stream_field->start_field_value != NULL) {
+ free(ip_stream_field->start_field_value->string);
+ }
+ free(ip_stream_field->end_field_value->string);
+ break;
+ }
+ case 0x0101: {
+ // Nothing to free
+ break;
+ }
+ }
+
+ free(ip_stream_field);
+
+ field = field->_next;
+ }
+
+ free(ip_stream);
+ }
+
+ for(field = partition->field_list; field; field = next_field) {
+ next_field = field->_next;
+ free(field);
+ }
+
+ free(partition);
+}
diff --git a/lib/libesg/transport/session_partition_declaration.h b/lib/libesg/transport/session_partition_declaration.h
new file mode 100644
index 0000000..8f2fa1a
--- /dev/null
+++ b/lib/libesg/transport/session_partition_declaration.h
@@ -0,0 +1,139 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _ESG_TRANSPORT_SESSION_PARTITION_DECLARATION_H
+#define _ESG_TRANSPORT_SESSION_PARTITION_DECLARATION_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <libesg/types.h>
+
+/**
+ * esg_session_field structure.
+ */
+struct esg_session_field {
+ uint16_t identifier;
+ uint16_t encoding;
+ uint8_t length;
+
+ struct esg_session_field *_next;
+};
+
+/**
+ * esg_session_ip_stream_field_value union.
+ */
+union esg_session_ip_stream_field_value {
+ uint8_t *string;
+ uint16_t unsigned_short;
+};
+
+/**
+ * esg_session_ip_stream_field structure.
+ */
+struct esg_session_ip_stream_field {
+ union esg_session_ip_stream_field_value *start_field_value;
+ union esg_session_ip_stream_field_value *end_field_value;
+
+ struct esg_session_ip_stream_field *_next;
+};
+
+/**
+ * esg_session_ip_stream structure.
+ */
+struct esg_session_ip_stream {
+ uint8_t id;
+ union esg_ip_address source_ip;
+ union esg_ip_address destination_ip;
+ uint16_t port;
+ uint16_t session_id;
+ struct esg_session_ip_stream_field *field_list;
+
+ struct esg_session_ip_stream *_next;
+};
+
+/**
+ * esg_session_partition_declaration structure.
+ */
+struct esg_session_partition_declaration {
+ uint8_t num_fields;
+ uint8_t overlapping;
+ struct esg_session_field *field_list;
+ uint8_t n_o_ip_streams;
+ uint8_t ip_version_6;
+ struct esg_session_ip_stream *ip_stream_list;
+};
+
+/**
+ * Process an esg_session_partition_declaration.
+ *
+ * @param buffer Binary buffer to decode.
+ * @param size Binary buffer size.
+ * @return Pointer to an esg_session_partition_declaration structure, or NULL on error.
+ */
+extern struct esg_session_partition_declaration *esg_session_partition_declaration_decode(uint8_t *buffer, uint32_t size);
+
+/**
+ * Free an esg_session_partition_declaration.
+ *
+ * @param esg Pointer to an esg_session_partition_declaration structure.
+ */
+extern void esg_session_partition_declaration_free(struct esg_session_partition_declaration *partition);
+
+/**
+ * Convenience iterator for field_list field of an esg_session_partition_declaration.
+ *
+ * @param partition The esg_session_partition_declaration pointer.
+ * @param field Variable holding a pointer to the current esg_session_field.
+ */
+#define esg_session_partition_declaration_field_list_for_each(partition, field) \
+ for ((field) = (partition)->field_list; \
+ (field); \
+ (field) = (field)->_next)
+
+/**
+ * Convenience iterator for ip_stream_list field of an esg_session_partition_declaration.
+ *
+ * @param partition The esg_session_partition_declaration pointer.
+ * @param ip_stream Variable holding a pointer to the current esg_session_ip_stream.
+ */
+#define esg_session_partition_declaration_ip_stream_list_for_each(partition, ip_stream) \
+ for ((ip_stream) = (partition)->ip_stream_list; \
+ (ip_stream); \
+ (ip_stream) = (ip_stream)->_next)
+
+/**
+ * Convenience iterator for field_list field of an esg_session_ip_stream.
+ *
+ * @param ip_stream The esg_session_ip_stream pointer.
+ * @param field Variable holding a pointer to the current esg_session_ip_stream.
+ */
+#define esg_session_ip_stream_field_list_for_each(ip_stream, field) \
+ for ((field) = (ip_stream)->field_list; \
+ (field); \
+ (field) = (field)->_next)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libesg/types.c b/lib/libesg/types.c
new file mode 100644
index 0000000..51f1cbd
--- /dev/null
+++ b/lib/libesg/types.c
@@ -0,0 +1,37 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <libesg/types.h>
+
+uint8_t vluimsbf8(uint8_t *buffer, uint32_t size, uint32_t *length) {
+ uint8_t offset = 0;
+ *length = 0;
+
+ do {
+ if (size < offset) {
+ offset = 0;
+ *length = 0;
+ break;
+ }
+ *length = (*length << 7) + (buffer[offset] & 0x7F);
+ } while (buffer[offset++] & 0x80);
+
+ return offset;
+}
diff --git a/lib/libesg/types.h b/lib/libesg/types.h
new file mode 100644
index 0000000..b6725af
--- /dev/null
+++ b/lib/libesg/types.h
@@ -0,0 +1,53 @@
+/*
+ * ESG parser
+ *
+ * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _ESG_TYPES_H
+#define _ESG_TYPES_H 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdint.h>
+
+/**
+ * esg_ip_address
+ */
+union esg_ip_address {
+ uint8_t ipv4[4];
+ uint8_t ipv6[16];
+};
+
+/**
+ * Process a vluimsbf8 length.
+ *
+ * @param buffer Binary buffer to decode.
+ * @param size Binary buffer size.
+ * @param length Read length value
+ * @return vluimsbf8 size
+ */
+extern uint8_t vluimsbf8(uint8_t *buffer, uint32_t size, uint32_t *length);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lib/libesg/xml/provider_discovery_descriptor.xsd b/lib/libesg/xml/provider_discovery_descriptor.xsd
new file mode 100644
index 0000000..5956343
--- /dev/null
+++ b/lib/libesg/xml/provider_discovery_descriptor.xsd
@@ -0,0 +1,22 @@
+<schema targetNamespace="urn:dvb:ipdc:esgbs:2005" xmlns:bs="urn:dvb:ipdc:esgbs:2005"
+ xmlns:mpeg7="urn:mpeg:mpeg7:schema:2001" xmlns="http://www.w3.org/2001/XMLSchema"
+ elementFormDefault="qualified" attributeFormDefault="unqualified">
+ <import namespace="urn:mpeg:mpeg7:schema:2001" />
+ <complexType name="ESGProviderType">
+ <sequence>
+ <element name="ProviderURI" type="anyURI"/>
+ <element name="ProviderName" type="mpeg7:TextualType"/>
+ <element name="ProviderLogo" type="mpeg7:TitleMediaType" minOccurs="0"/>
+ <element name="ProviderID" type="positiveInteger"/>
+ <element name="ProviderInformationURL" type="anyURI" minOccurs="0"/>
+ <element name="PrivateAuxiliaryData" type="anyType" minOccurs="0"/>
+ </sequence>
+ </complexType>
+ <element name="ESGProviderDiscovery">
+ <complexType>
+ <sequence>
+ <element name="ServiceProvider" type="bs:ESGProviderType" maxOccurs="unbounded"/>
+ </sequence>
+ </complexType>
+ </element>
+</schema>