1 /*
2  * section and descriptor parser
3  *
4  * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
19  */
20 
21 #include <string.h>
22 #include "libucsi/atsc/types.h"
23 
24 /* GPS epoch == unix time_t at 06/Jan/1980 */
25 #define GPS_EPOCH 315964800
26 
27 
atsc_text_validate(uint8_t * buf,int len)28 int atsc_text_validate(uint8_t *buf, int len)
29 {
30 	int i;
31 	int j;
32 	int number_strings;
33 	int number_segments;
34 	int number_bytes;
35 	int pos = 0;
36 
37 	if (len == 0)
38 		return 0;
39 	number_strings = buf[pos];
40 	pos++;
41 
42 	for(i=0; i< number_strings; i++) {
43 		if (len < (pos+4))
44 			return -1;
45 		number_segments = buf[pos+3];
46 		pos+=4;
47 
48 		for(j=0; j < number_segments; j++) {
49 			if (len < (pos+3))
50 				return -1;
51 			number_bytes = buf[pos+2];
52 			pos+=3;
53 
54 			if (len < (pos + number_bytes))
55 				return -1;
56 			pos += number_bytes;
57 		}
58 	}
59 
60 	return 0;
61 }
62 
atsctime_to_unixtime(atsctime_t atsc)63 time_t atsctime_to_unixtime(atsctime_t atsc)
64 {
65 	return atsc + GPS_EPOCH;
66 }
67 
unixtime_to_atsctime(time_t t)68 atsctime_t unixtime_to_atsctime(time_t t)
69 {
70 	return t - GPS_EPOCH;
71 }
72