| 1 |
/* |
| 2 |
* Copyright (c) 2011-2012 - Mauro Carvalho Chehab |
| 3 |
* Copyright (c) 2012 - Andre Roth <[email protected]> |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU Lesser General Public License as published by |
| 7 |
* the Free Software Foundation version 2.1 of the License. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU Lesser General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU Lesser General Public License |
| 15 |
* along with this program; if not, write to the Free Software |
| 16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 |
* Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
#include <libdvbv5/desc_service.h> |
| 22 |
#include <libdvbv5/dvb-fe.h> |
| 23 |
#include <parse_string.h> |
| 24 |
|
| 25 |
#if __GNUC__ >= 9 |
| 26 |
#pragma GCC diagnostic ignored "-Waddress-of-packed-member" |
| 27 |
#endif |
| 28 |
|
| 29 |
int dvb_desc_service_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, struct dvb_desc *desc) |
| 30 |
{ |
| 31 |
struct dvb_desc_service *service = (struct dvb_desc_service *) desc; |
| 32 |
const uint8_t *endbuf = buf + desc->length; |
| 33 |
uint8_t len; /* the length of the string in the input data */ |
| 34 |
uint8_t len1, len2; /* the lenght of the output strings */ |
| 35 |
|
| 36 |
service->provider = NULL; |
| 37 |
service->provider_emph = NULL; |
| 38 |
service->name = NULL; |
| 39 |
service->name_emph = NULL; |
| 40 |
|
| 41 |
if (buf + 1 > endbuf) { |
| 42 |
dvb_logerr("%s: short read %d bytes", __func__, 1); |
| 43 |
return -1; |
| 44 |
} |
| 45 |
service->service_type = buf[0]; |
| 46 |
buf++; |
| 47 |
|
| 48 |
if (buf + 1 > endbuf) { |
| 49 |
dvb_logerr("%s: a short read %d bytes", __func__, 1); |
| 50 |
return -1; |
| 51 |
} |
| 52 |
|
| 53 |
len = buf[0]; |
| 54 |
len1 = len; |
| 55 |
buf++; |
| 56 |
|
| 57 |
if (buf + len > endbuf) { |
| 58 |
dvb_logerr("%s: b short read %d bytes", __func__, len); |
| 59 |
return -1; |
| 60 |
} |
| 61 |
|
| 62 |
if (len) { |
| 63 |
dvb_parse_string(parms, &service->provider, &service->provider_emph, buf, len1); |
| 64 |
buf += len; |
| 65 |
} |
| 66 |
|
| 67 |
if (buf + 1 > endbuf) { |
| 68 |
dvb_logerr("%s: c short read %d bytes", __func__, 1); |
| 69 |
return -1; |
| 70 |
} |
| 71 |
|
| 72 |
len = buf[0]; |
| 73 |
len2 = len; |
| 74 |
buf++; |
| 75 |
|
| 76 |
if (buf + len > endbuf) { |
| 77 |
dvb_logerr("%s: d short read %d bytes", __func__, len); |
| 78 |
return -1; |
| 79 |
} |
| 80 |
|
| 81 |
if (len) { |
| 82 |
dvb_parse_string(parms, &service->name, &service->name_emph, buf, len2); |
| 83 |
buf += len; |
| 84 |
} |
| 85 |
return 0; |
| 86 |
} |
| 87 |
|
| 88 |
void dvb_desc_service_free(struct dvb_desc *desc) |
| 89 |
{ |
| 90 |
struct dvb_desc_service *service = (struct dvb_desc_service *) desc; |
| 91 |
free(service->provider); |
| 92 |
free(service->provider_emph); |
| 93 |
free(service->name); |
| 94 |
free(service->name_emph); |
| 95 |
} |
| 96 |
|
| 97 |
void dvb_desc_service_print(struct dvb_v5_fe_parms *parms, const struct dvb_desc *desc) |
| 98 |
{ |
| 99 |
const struct dvb_desc_service *service = (const struct dvb_desc_service *) desc; |
| 100 |
dvb_loginfo("| service type %d", service->service_type); |
| 101 |
dvb_loginfo("| provider '%s'", service->provider); |
| 102 |
dvb_loginfo("| name '%s'", service->name); |
| 103 |
} |
| 104 |
|