1 /*****************************************************************************
2  * desc_40.h: ETSI EN 300 468 Descriptor 0x40: Network name descriptor
3  *****************************************************************************
4  * Copyright (C) 2009-2010 VideoLAN
5  *
6  * Authors: Christophe Massiot <massiot@via.ecp.fr>
7  *          Georgi Chorbadzhiyski <georgi@unixsol.org>
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject
15  * to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  *****************************************************************************/
28 
29 /*
30  * Normative references:
31  *  - ETSI EN 300 468 V1.11.1 (2010-04) (SI in DVB systems)
32  */
33 
34 #ifndef __BITSTREAM_DVB_DESC_40_H__
35 #define __BITSTREAM_DVB_DESC_40_H__
36 
37 #include <bitstream/common.h>
38 #include <bitstream/mpeg/psi/descriptors.h>
39 #include <bitstream/dvb/si/strings.h>
40 
41 #ifdef __cplusplus
42 extern "C"
43 {
44 #endif
45 
46 /*****************************************************************************
47  * Descriptor 0x40: Network name descriptor
48  *****************************************************************************/
49 #define DESC40_HEADER_SIZE      DESC_HEADER_SIZE
50 
desc40_init(uint8_t * p_desc)51 static inline void desc40_init(uint8_t *p_desc)
52 {
53     desc_set_tag(p_desc, 0x40);
54 }
55 
desc40_set_networkname(uint8_t * p_desc,const uint8_t * p_network_name,uint8_t i_length)56 static inline void desc40_set_networkname(uint8_t *p_desc,
57                                           const uint8_t *p_network_name,
58                                           uint8_t i_length)
59 {
60     desc_set_length(p_desc, i_length);
61     memcpy(p_desc + 2, p_network_name, i_length);
62 }
63 
desc40_get_networkname(const uint8_t * p_desc,uint8_t * pi_length)64 static inline const uint8_t *desc40_get_networkname(const uint8_t *p_desc,
65                                                     uint8_t *pi_length)
66 {
67     *pi_length = desc_get_length(p_desc);
68     return p_desc + 2;
69 }
70 
desc40_validate(const uint8_t * p_desc)71 static inline bool desc40_validate(const uint8_t *p_desc)
72 {
73     (void) p_desc;
74 
75     return true;
76 }
77 
desc40_print(const uint8_t * p_desc,f_print pf_print,void * print_opaque,f_iconv pf_iconv,void * iconv_opaque,print_type_t i_print_type)78 static inline void desc40_print(const uint8_t *p_desc,
79                                 f_print pf_print, void *print_opaque,
80                                 f_iconv pf_iconv, void *iconv_opaque,
81                                 print_type_t i_print_type)
82 {
83     uint8_t i_network_name_length;
84     bool b_bouquet_name = desc_get_tag(p_desc) == 0x47;
85     const uint8_t *p_network_name = desc40_get_networkname(p_desc,
86                                                      &i_network_name_length);
87     char *psz_network_name = dvb_string_get(p_network_name,
88                                             i_network_name_length,
89                                             pf_iconv, iconv_opaque);
90 
91     switch (i_print_type) {
92     case PRINT_XML:
93         psz_network_name = dvb_string_xml_escape(psz_network_name);
94         if ( !b_bouquet_name )
95             pf_print(print_opaque, "<NETWORK_NAME_DESC networkname=\"%s\"/>",
96                      psz_network_name);
97         else
98             pf_print(print_opaque, "<BOUQUET_NAME_DESC bouquetname=\"%s\"/>",
99                      psz_network_name);
100         break;
101     default:
102         if ( !b_bouquet_name )
103             pf_print(print_opaque, "    - desc 40 networkname=\"%s\"",
104                      psz_network_name);
105         else
106             pf_print(print_opaque, "    - desc 47 bouquetname=\"%s\"",
107                      psz_network_name);
108     }
109     free(psz_network_name);
110 }
111 
112 #ifdef __cplusplus
113 }
114 #endif
115 
116 #endif
117