2 * Copyright (C) 2004-2012, Eric Lund, Jon Gettler
3 * http://www.mvpmc.org/
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Local definitions which are internal to libcmyth.
25 #ifndef __CMYTH_LOCAL_H
26 #define __CMYTH_LOCAL_H
30 #if !defined(_MSC_VER)
33 #include <refmem/refmem.h>
34 #include <cmyth/cmyth.h>
37 #include <mysql/mysql.h>
40 #include "cmyth_msc.h"
43 #include <sys/types.h>
44 #include <sys/socket.h>
45 #include <sys/select.h>
46 #include <netinet/in.h>
48 #include <arpa/inet.h>
51 typedef int cmyth_socket_t;
52 #define closesocket(fd) close(fd)
55 #define mutex __cmyth_mutex
56 extern pthread_mutex_t mutex;
59 * Some useful constants
61 #define CMYTH_LONGLONG_LEN (sizeof("-18446744073709551616") - 1)
62 #define CMYTH_LONG_LEN (sizeof("-4294967296") - 1)
63 #define CMYTH_SHORT_LEN (sizeof("-65536") - 1)
64 #define CMYTH_BYTE_LEN (sizeof("-256") - 1)
65 #define CMYTH_TIMESTAMP_LEN (sizeof("YYYY-MM-DDTHH:MM:SS") - 1)
66 #define CMYTH_DATESTAMP_LEN (sizeof("YYYY-MM-DD") - 1)
67 #define CMYTH_UTC_LEN (sizeof("1240120680") - 1)
68 #define CMYTH_COMMBREAK_START 4
69 #define CMYTH_COMMBREAK_END 5
70 #define CMYTH_CUTLIST_START 1
71 #define CMYTH_CUTLIST_END 0
74 * MythTV backend connection
77 cmyth_socket_t conn_fd; /**< socket file descriptor */
78 unsigned char *conn_buf; /**< connection buffer */
79 int conn_buflen; /**< buffer size */
80 int conn_len; /**< amount of data in buffer */
81 int conn_pos; /**< current position in buffer */
82 unsigned long conn_version; /**< protocol version */
83 volatile int conn_hang; /**< is connection stuck? */
84 int conn_tcp_rcvbuf;/**< TCP receive buffer size */
87 /* Sergio: Added to support new livetv protocol */
88 struct cmyth_livetv_chain {
91 int chain_switch_on_create;
93 void (*prog_update_callback)(cmyth_proginfo_t prog);
94 cmyth_proginfo_t *progs;
96 cmyth_file_t *chain_files; /* File pointers for the urls */
99 /* Sergio: Added to clean up database interaction */
100 struct cmyth_database {
108 /* Sergio: Added to clean up channel list handling */
109 struct cmyth_channel {
113 long cardids;/* A bit array of recorders/tuners supporting the channel */
120 struct cmyth_chanlist {
121 cmyth_channel_t *chanlist_list;
125 /* Sergio: Added to support the tvguide functionality */
126 struct cmyth_tvguide_progs {
127 cmyth_program_t * progs;
132 struct cmyth_recorder {
133 unsigned rec_have_stream;
137 cmyth_ringbuf_t rec_ring;
138 cmyth_conn_t rec_conn;
139 /* Sergio: Added to support new livetv protocol */
140 cmyth_livetv_chain_t rec_livetv_chain;
141 cmyth_file_t rec_livetv_file;
142 double rec_framerate;
146 * MythTV file connection
149 cmyth_conn_t file_data; /**< backend connection */
150 long file_id; /**< file identifier */
151 /** callback when close is completed */
152 void (*closed_callback)(cmyth_file_t file);
153 uint64_t file_start; /**< file start offest */
154 uint64_t file_length; /**< file length */
155 uint64_t file_pos; /**< current file position */
156 uint64_t file_req; /**< current file position requested */
157 cmyth_conn_t file_control; /**< master backend connection */
160 struct cmyth_ringbuf {
161 cmyth_conn_t conn_data;
164 uint64_t ringbuf_size;
165 uint64_t file_length;
167 uint64_t ringbuf_fill;
168 char *ringbuf_hostname;
172 struct cmyth_rec_num {
174 unsigned short recnum_port;
178 struct cmyth_keyframe {
179 unsigned long keyframe_number;
180 uint64_t keyframe_pos;
183 struct cmyth_posmap {
184 unsigned posmap_count;
185 struct cmyth_keyframe **posmap_list;
188 struct cmyth_freespace {
189 uint64_t freespace_total;
190 uint64_t freespace_used;
193 struct cmyth_timestamp {
194 unsigned long timestamp_year;
195 unsigned long timestamp_month;
196 unsigned long timestamp_day;
197 unsigned long timestamp_hour;
198 unsigned long timestamp_minute;
199 unsigned long timestamp_second;
203 struct cmyth_proginfo {
204 char *proginfo_title;
205 char *proginfo_subtitle;
206 char *proginfo_description;
207 unsigned short proginfo_season; /* new in V67 */
208 unsigned short proginfo_episode; /* new in V67 */
209 char *proginfo_category;
210 long proginfo_chanId;
211 char *proginfo_chanstr;
212 char *proginfo_chansign;
213 char *proginfo_channame; /* Deprecated in V8, simulated for compat. */
214 char *proginfo_chanicon; /* New in V8 */
216 int64_t proginfo_Length;
217 cmyth_timestamp_t proginfo_start_ts;
218 cmyth_timestamp_t proginfo_end_ts;
219 unsigned long proginfo_conflicting; /* Deprecated in V8, always 0 */
220 char *proginfo_unknown_0; /* May be new 'conflicting' in V8 */
221 unsigned long proginfo_recording;
222 unsigned long proginfo_override;
223 char *proginfo_hostname;
224 long proginfo_source_id; /* ??? in V8 */
225 long proginfo_card_id; /* ??? in V8 */
226 long proginfo_input_id; /* ??? in V8 */
227 char *proginfo_rec_priority; /* ??? in V8 */
228 long proginfo_rec_status; /* ??? in V8 */
229 unsigned long proginfo_record_id; /* ??? in V8 */
230 unsigned long proginfo_rec_type; /* ??? in V8 */
231 unsigned long proginfo_rec_dups; /* ??? in V8 */
232 unsigned long proginfo_unknown_1; /* new in V8 */
233 cmyth_timestamp_t proginfo_rec_start_ts;
234 cmyth_timestamp_t proginfo_rec_end_ts;
235 unsigned long proginfo_repeat; /* ??? in V8 */
236 unsigned long proginfo_program_flags;
237 char *proginfo_rec_profile; /* new in V8 */
238 char *proginfo_recgroup; /* new in V8 */
239 char *proginfo_chancommfree; /* new in V8 */
240 char *proginfo_chan_output_filters; /* new in V8 */
241 char *proginfo_seriesid; /* new in V8 */
242 char *proginfo_programid; /* new in V12 */
243 char *proginfo_inetref; /* new in V67 */
244 cmyth_timestamp_t proginfo_lastmodified; /* new in V12 */
245 char *proginfo_stars; /* new in V12 */
246 cmyth_timestamp_t proginfo_originalairdate; /* new in V12 */
247 char *proginfo_pathname;
249 unsigned long proginfo_hasairdate;
251 unsigned long proginfo_version;
252 char *proginfo_playgroup; /* new in v18 */
253 char *proginfo_recpriority_2; /* new in V25 */
254 long proginfo_parentid; /* new in V31 */
255 char *proginfo_storagegroup; /* new in v32 */
256 unsigned long proginfo_audioproperties; /* new in v35 */
257 unsigned long proginfo_videoproperties; /* new in v35 */
258 unsigned long proginfo_subtitletype; /* new in v35 */
259 unsigned short proginfo_year; /* new in v43 */
262 struct cmyth_proglist {
263 cmyth_proginfo_t *proglist_list;
268 * Private funtions in socket.c
270 #define cmyth_send_message __cmyth_send_message
271 extern int cmyth_send_message(cmyth_conn_t conn, char *request);
273 #define cmyth_rcv_length __cmyth_rcv_length
274 extern int cmyth_rcv_length(cmyth_conn_t conn);
276 #define cmyth_rcv_string __cmyth_rcv_string
277 extern int cmyth_rcv_string(cmyth_conn_t conn,
279 char *buf, int buflen,
282 #define cmyth_rcv_okay __cmyth_rcv_okay
283 extern int cmyth_rcv_okay(cmyth_conn_t conn, char *ok);
285 #define cmyth_rcv_version __cmyth_rcv_version
286 extern int cmyth_rcv_version(cmyth_conn_t conn, unsigned long *vers);
288 #define cmyth_rcv_byte __cmyth_rcv_byte
289 extern int cmyth_rcv_byte(cmyth_conn_t conn, int *err, char *buf, int count);
291 #define cmyth_rcv_short __cmyth_rcv_short
292 extern int cmyth_rcv_short(cmyth_conn_t conn, int *err, short *buf, int count);
294 #define cmyth_rcv_long __cmyth_rcv_long
295 extern int cmyth_rcv_long(cmyth_conn_t conn, int *err, long *buf, int count);
296 #define cmyth_rcv_u_long(c, e, b, n) cmyth_rcv_long(c, e, (long*)b, n)
298 #define cmyth_rcv_old_int64 __cmyth_rcv_old_int64
299 extern int cmyth_rcv_old_int64(cmyth_conn_t conn, int *err, int64_t *buf,
302 #define cmyth_rcv_new_int64 __cmyth_rcv_new_int64
303 extern int cmyth_rcv_new_int64(cmyth_conn_t conn, int *err, int64_t *buf,
304 int count, int forced);
306 #define cmyth_rcv_old_uint64 __cmyth_rcv_old_uint64
307 extern int cmyth_rcv_old_uint64(cmyth_conn_t conn, int *err, uint64_t *buf,
310 #define cmyth_rcv_new_uint64 __cmyth_rcv_new_uint64
311 extern int cmyth_rcv_new_uint64(cmyth_conn_t conn, int *err, uint64_t *buf,
312 int count, int forced);
314 #define cmyth_rcv_int64(conn, err, buf, count) \
315 cmyth_rcv_new_int64(conn, err, buf, count, 0)
317 #define cmyth_rcv_uint64(conn, err, buf, count) \
318 cmyth_rcv_new_uint64(conn, err, buf, count, 0)
320 #define cmyth_rcv_ubyte __cmyth_rcv_ubyte
321 extern int cmyth_rcv_ubyte(cmyth_conn_t conn, int *err, unsigned char *buf,
324 #define cmyth_rcv_ushort __cmyth_rcv_ushort
325 extern int cmyth_rcv_ushort(cmyth_conn_t conn, int *err, unsigned short *buf,
328 #define cmyth_rcv_ulong __cmyth_rcv_ulong
329 extern int cmyth_rcv_ulong(cmyth_conn_t conn, int *err, unsigned long *buf,
332 #define cmyth_rcv_ulong_long __cmyth_rcv_ulong_long
333 extern int cmyth_rcv_ulong_long(cmyth_conn_t conn,
335 unsigned long long *buf,
338 #define cmyth_rcv_data __cmyth_rcv_data
339 extern int cmyth_rcv_data(cmyth_conn_t conn, int *err, unsigned char *buf,
342 #define cmyth_rcv_timestamp __cmyth_rcv_timestamp
343 extern int cmyth_rcv_timestamp(cmyth_conn_t conn, int *err,
344 cmyth_timestamp_t *ts_p,
346 #define cmyth_rcv_datetime __cmyth_rcv_datetime
347 extern int cmyth_rcv_datetime(cmyth_conn_t conn, int *err,
348 cmyth_timestamp_t *ts_p,
351 #define cmyth_rcv_proginfo __cmyth_rcv_proginfo
352 extern int cmyth_rcv_proginfo(cmyth_conn_t conn, int *err,
353 cmyth_proginfo_t buf,
356 #define cmyth_rcv_chaninfo __cmyth_rcv_chaninfo
357 extern int cmyth_rcv_chaninfo(cmyth_conn_t conn, int *err,
358 cmyth_proginfo_t buf,
361 #define cmyth_rcv_proglist __cmyth_rcv_proglist
362 extern int cmyth_rcv_proglist(cmyth_conn_t conn, int *err,
363 cmyth_proglist_t buf,
366 #define cmyth_rcv_keyframe __cmyth_rcv_keyframe
367 extern int cmyth_rcv_keyframe(cmyth_conn_t conn, int *err,
368 cmyth_keyframe_t buf,
371 #define cmyth_rcv_freespace __cmyth_rcv_freespace
372 extern int cmyth_rcv_freespace(cmyth_conn_t conn, int *err,
373 cmyth_freespace_t buf,
376 #define cmyth_rcv_recorder __cmyth_rcv_recorder
377 extern int cmyth_rcv_recorder(cmyth_conn_t conn, int *err,
378 cmyth_recorder_t buf,
381 #define cmyth_rcv_ringbuf __cmyth_rcv_ringbuf
382 extern int cmyth_rcv_ringbuf(cmyth_conn_t conn, int *err, cmyth_ringbuf_t buf,
384 #define cmyth_datetime_to_dbstring __cmyth_datetime_to_dbstring
385 extern int cmyth_datetime_to_dbstring(char *str, cmyth_timestamp_t ts);
390 #define cmyth_proginfo_string __cmyth_proginfo_string
391 extern char *cmyth_proginfo_string(cmyth_proginfo_t prog);
393 #define cmyth_chaninfo_string __cmyth_chaninfo_string
394 extern char *cmyth_chaninfo_string(cmyth_proginfo_t prog);
399 #define cmyth_file_create __cmyth_file_create
400 extern cmyth_file_t cmyth_file_create(cmyth_conn_t control);
405 #define cmyth_timestamp_diff __cmyth_timestamp_diff
406 extern int cmyth_timestamp_diff(cmyth_timestamp_t, cmyth_timestamp_t);
409 * From mythtv_mysql.c
412 extern MYSQL * cmyth_db_get_connection(cmyth_database_t db);
419 typedef struct cmyth_mysql_query_s cmyth_mysql_query_t;
421 extern cmyth_mysql_query_t * cmyth_mysql_query_create(cmyth_database_t db, const char * query_string);
423 extern void cmyth_mysql_query_reset(cmyth_mysql_query_t *query);
425 extern int cmyth_mysql_query_param_long(cmyth_mysql_query_t * query,long param);
427 extern int cmyth_mysql_query_param_ulong(cmyth_mysql_query_t * query,unsigned long param);
429 extern int cmyth_mysql_query_param_int(cmyth_mysql_query_t * query,int param);
431 extern int cmyth_mysql_query_param_uint(cmyth_mysql_query_t * query,int param);
433 extern int cmyth_mysql_query_param_unixtime(cmyth_mysql_query_t * query, time_t param);
435 extern int cmyth_mysql_query_param_str(cmyth_mysql_query_t * query, const char *param);
437 extern char * cmyth_mysql_query_string(cmyth_mysql_query_t * query);
439 extern MYSQL_RES * cmyth_mysql_query_result(cmyth_mysql_query_t * query);
441 extern int cmyth_mysql_query(cmyth_mysql_query_t * query);
443 extern char* cmyth_utf8tolatin1(char* s);
445 #endif /* __CMYTH_LOCAL_H */