Merge pull request #1129 from jmarshallnz/remove_smb_auth_details_in_add_source
[vuplus_xbmc] / lib / cmyth / libcmyth / cmyth_local.h
1 /*
2  *  Copyright (C) 2004-2012, Eric Lund, Jon Gettler
3  *  http://www.mvpmc.org/
4  *
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.
9  *
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.
14  *
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
18  */
19
20 /**
21  * \file cmyth_local.h
22  * Local definitions which are internal to libcmyth.
23  */
24
25 #ifndef __CMYTH_LOCAL_H
26 #define __CMYTH_LOCAL_H
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #if !defined(_MSC_VER)
31 #include <sys/time.h>
32 #endif
33 #include <refmem/refmem.h>
34 #include <cmyth/cmyth.h>
35 #include <time.h>
36 #include <stdint.h>
37 #include <mysql/mysql.h>
38
39 #if defined(_MSC_VER)
40 #include "cmyth_msc.h"
41 #else
42 #include <unistd.h>
43 #include <sys/types.h>
44 #include <sys/socket.h>
45 #include <sys/select.h>
46 #include <netinet/in.h>
47 #include <netdb.h>
48 #include <arpa/inet.h>
49 #include <pthread.h>
50
51 typedef int cmyth_socket_t;
52 #define closesocket(fd) close(fd)
53 #endif /* _MSC_VER */
54
55 #define mutex __cmyth_mutex
56 extern pthread_mutex_t mutex;
57
58 /*
59  * Some useful constants
60  */
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
72
73 /**
74  * MythTV backend connection
75  */
76 struct cmyth_conn {
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 */
85 };
86
87 /* Sergio: Added to support new livetv protocol */
88 struct cmyth_livetv_chain {
89         char *chainid;
90         int chain_ct;
91         int chain_switch_on_create;
92         int chain_current;
93         void (*prog_update_callback)(cmyth_proginfo_t prog);
94         cmyth_proginfo_t *progs;
95         char **chain_urls;
96         cmyth_file_t *chain_files; /* File pointers for the urls */
97 };
98
99 /* Sergio: Added to clean up database interaction */
100 struct cmyth_database {
101         char * db_host;
102         char * db_user;
103         char * db_pass;
104         char * db_name;
105         MYSQL * mysql;
106 };      
107
108 /* Sergio: Added to clean up channel list handling */
109 struct cmyth_channel {
110         long chanid;
111         int channum;
112         char chanstr[10];
113         long cardids;/* A bit array of recorders/tuners supporting the channel */
114         char *callsign;
115         char *name;
116         char *icon;
117         int visible;
118 };
119
120 struct cmyth_chanlist {
121         cmyth_channel_t *chanlist_list;
122         int chanlist_count;
123 };
124
125 /* Sergio: Added to support the tvguide functionality */
126 struct cmyth_tvguide_progs {
127         cmyth_program_t * progs;
128         int count;
129         int alloc;
130 };
131
132 struct cmyth_recorder {
133         unsigned rec_have_stream;
134         unsigned rec_id;
135         char *rec_server;
136         int rec_port;
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;
143 };
144
145 /**
146  * MythTV file connection
147  */
148 struct cmyth_file {
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 */
158 };
159
160 struct cmyth_ringbuf {
161         cmyth_conn_t conn_data;
162         long file_id;
163         char *ringbuf_url;
164         uint64_t ringbuf_size;
165         uint64_t file_length;
166         uint64_t file_pos;
167         uint64_t ringbuf_fill;
168         char *ringbuf_hostname;
169         int ringbuf_port;
170 };
171
172 struct cmyth_rec_num {
173         char *recnum_host;
174         unsigned short recnum_port;
175         unsigned recnum_id;
176 };
177
178 struct cmyth_keyframe {
179         unsigned long keyframe_number;
180         uint64_t keyframe_pos;
181 };
182
183 struct cmyth_posmap {
184         unsigned posmap_count;
185         struct cmyth_keyframe **posmap_list;
186 };
187
188 struct cmyth_freespace {
189         uint64_t freespace_total;
190         uint64_t freespace_used;
191 };
192
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;
200         int timestamp_isdst;
201 };
202
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 */
215         char *proginfo_url;
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;
248         int proginfo_port;
249         unsigned long proginfo_hasairdate;
250         char *proginfo_host;
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 */
260 };
261
262 struct cmyth_proglist {
263         cmyth_proginfo_t *proglist_list;
264         long proglist_count;
265 };
266
267 /*
268  * Private funtions in socket.c
269  */
270 #define cmyth_send_message __cmyth_send_message
271 extern int cmyth_send_message(cmyth_conn_t conn, char *request);
272
273 #define cmyth_rcv_length __cmyth_rcv_length
274 extern int cmyth_rcv_length(cmyth_conn_t conn);
275
276 #define cmyth_rcv_string __cmyth_rcv_string
277 extern int cmyth_rcv_string(cmyth_conn_t conn,
278                             int *err,
279                             char *buf, int buflen,
280                             int count);
281
282 #define cmyth_rcv_okay __cmyth_rcv_okay
283 extern int cmyth_rcv_okay(cmyth_conn_t conn, char *ok);
284
285 #define cmyth_rcv_version __cmyth_rcv_version
286 extern int cmyth_rcv_version(cmyth_conn_t conn, unsigned long *vers);
287
288 #define cmyth_rcv_byte __cmyth_rcv_byte
289 extern int cmyth_rcv_byte(cmyth_conn_t conn, int *err, char *buf, int count);
290
291 #define cmyth_rcv_short __cmyth_rcv_short
292 extern int cmyth_rcv_short(cmyth_conn_t conn, int *err, short *buf, int count);
293
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)
297
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,
300                                int count);
301
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);
305
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,
308                                 int count);
309
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);
313
314 #define cmyth_rcv_int64(conn, err, buf, count)  \
315         cmyth_rcv_new_int64(conn, err, buf, count, 0)
316
317 #define cmyth_rcv_uint64(conn, err, buf, count) \
318         cmyth_rcv_new_uint64(conn, err, buf, count, 0)
319
320 #define cmyth_rcv_ubyte __cmyth_rcv_ubyte
321 extern int cmyth_rcv_ubyte(cmyth_conn_t conn, int *err, unsigned char *buf,
322                            int count);
323
324 #define cmyth_rcv_ushort __cmyth_rcv_ushort
325 extern int cmyth_rcv_ushort(cmyth_conn_t conn, int *err, unsigned short *buf,
326                             int count);
327
328 #define cmyth_rcv_ulong __cmyth_rcv_ulong
329 extern int cmyth_rcv_ulong(cmyth_conn_t conn, int *err, unsigned long *buf,
330                            int count);
331
332 #define cmyth_rcv_ulong_long __cmyth_rcv_ulong_long
333 extern int cmyth_rcv_ulong_long(cmyth_conn_t conn,
334                                 int *err,
335                                 unsigned long long *buf,
336                                 int count);
337
338 #define cmyth_rcv_data __cmyth_rcv_data
339 extern int cmyth_rcv_data(cmyth_conn_t conn, int *err, unsigned char *buf,
340                           int count);
341
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,
345                                int count);
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,
349                               int count);
350
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,
354                               int count);
355
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,
359                               int count);
360
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,
364                               int count);
365
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,
369                               int count);
370
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,
374                                int count);
375
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,
379                               int count);
380
381 #define cmyth_rcv_ringbuf __cmyth_rcv_ringbuf
382 extern int cmyth_rcv_ringbuf(cmyth_conn_t conn, int *err, cmyth_ringbuf_t buf,
383                              int count);
384 #define cmyth_datetime_to_dbstring __cmyth_datetime_to_dbstring
385 extern int cmyth_datetime_to_dbstring(char *str, cmyth_timestamp_t ts);
386
387 /*
388  * From proginfo.c
389  */
390 #define cmyth_proginfo_string __cmyth_proginfo_string
391 extern char *cmyth_proginfo_string(cmyth_proginfo_t prog);
392
393 #define cmyth_chaninfo_string __cmyth_chaninfo_string
394 extern char *cmyth_chaninfo_string(cmyth_proginfo_t prog);
395
396 /*
397  * From file.c
398  */
399 #define cmyth_file_create __cmyth_file_create
400 extern cmyth_file_t cmyth_file_create(cmyth_conn_t control);
401
402 /*
403  * From timestamp.c
404  */
405 #define cmyth_timestamp_diff __cmyth_timestamp_diff
406 extern int cmyth_timestamp_diff(cmyth_timestamp_t, cmyth_timestamp_t);
407
408 /*
409  * From mythtv_mysql.c
410  */
411
412 extern MYSQL * cmyth_db_get_connection(cmyth_database_t db);
413
414
415 /*
416  * From mysql_query.c
417  */
418
419 typedef struct cmyth_mysql_query_s cmyth_mysql_query_t;
420
421 extern cmyth_mysql_query_t * cmyth_mysql_query_create(cmyth_database_t db, const char * query_string);
422
423 extern void cmyth_mysql_query_reset(cmyth_mysql_query_t *query);
424
425 extern int cmyth_mysql_query_param_long(cmyth_mysql_query_t * query,long param);
426
427 extern int cmyth_mysql_query_param_ulong(cmyth_mysql_query_t * query,unsigned long param);
428
429 extern int cmyth_mysql_query_param_int(cmyth_mysql_query_t * query,int param);
430
431 extern int cmyth_mysql_query_param_uint(cmyth_mysql_query_t * query,int param);
432
433 extern int cmyth_mysql_query_param_unixtime(cmyth_mysql_query_t * query, time_t param);
434
435 extern int cmyth_mysql_query_param_str(cmyth_mysql_query_t * query, const char *param);
436
437 extern char * cmyth_mysql_query_string(cmyth_mysql_query_t * query);
438
439 extern MYSQL_RES * cmyth_mysql_query_result(cmyth_mysql_query_t * query);
440
441 extern int cmyth_mysql_query(cmyth_mysql_query_t * query);
442
443 extern char* cmyth_utf8tolatin1(char* s);
444
445 #endif /* __CMYTH_LOCAL_H */