PageRenderTime 359ms CodeModel.GetById 41ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/cmyth/libcmyth/cmyth_local.h

https://github.com/energy6/xbmc
C Header | 445 lines | 318 code | 72 blank | 55 comment | 0 complexity | 48493c916fd58ef32fe3a9418a90edb6 MD5 | raw file
  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. * \file cmyth_local.h
  21. * Local definitions which are internal to libcmyth.
  22. */
  23. #ifndef __CMYTH_LOCAL_H
  24. #define __CMYTH_LOCAL_H
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #if !defined(_MSC_VER)
  28. #include <sys/time.h>
  29. #endif
  30. #include <refmem/refmem.h>
  31. #include <cmyth/cmyth.h>
  32. #include <time.h>
  33. #include <stdint.h>
  34. #include <mysql/mysql.h>
  35. #if defined(_MSC_VER)
  36. #include "cmyth_msc.h"
  37. #else
  38. #include <unistd.h>
  39. #include <sys/types.h>
  40. #include <sys/socket.h>
  41. #include <sys/select.h>
  42. #include <netinet/in.h>
  43. #include <netdb.h>
  44. #include <arpa/inet.h>
  45. #include <pthread.h>
  46. typedef int cmyth_socket_t;
  47. #define closesocket(fd) close(fd)
  48. #endif /* _MSC_VER */
  49. #define mutex __cmyth_mutex
  50. extern pthread_mutex_t mutex;
  51. /*
  52. * Some useful constants
  53. */
  54. #define CMYTH_LONGLONG_LEN (sizeof("-18446744073709551616") - 1)
  55. #define CMYTH_LONG_LEN (sizeof("-4294967296") - 1)
  56. #define CMYTH_SHORT_LEN (sizeof("-65536") - 1)
  57. #define CMYTH_BYTE_LEN (sizeof("-256") - 1)
  58. #define CMYTH_TIMESTAMP_LEN (sizeof("YYYY-MM-DDTHH:MM:SS") - 1)
  59. #define CMYTH_DATESTAMP_LEN (sizeof("YYYY-MM-DD") - 1)
  60. #define CMYTH_UTC_LEN (sizeof("1240120680") - 1)
  61. #define CMYTH_COMMBREAK_START 4
  62. #define CMYTH_COMMBREAK_END 5
  63. #define CMYTH_CUTLIST_START 1
  64. #define CMYTH_CUTLIST_END 0
  65. /**
  66. * MythTV backend connection
  67. */
  68. struct cmyth_conn {
  69. cmyth_socket_t conn_fd; /**< socket file descriptor */
  70. unsigned char *conn_buf; /**< connection buffer */
  71. int conn_buflen; /**< buffer size */
  72. int conn_len; /**< amount of data in buffer */
  73. int conn_pos; /**< current position in buffer */
  74. unsigned long conn_version; /**< protocol version */
  75. volatile int conn_hang; /**< is connection stuck? */
  76. int conn_tcp_rcvbuf;/**< TCP receive buffer size */
  77. };
  78. /* Sergio: Added to support new livetv protocol */
  79. struct cmyth_livetv_chain {
  80. char *chainid;
  81. int chain_ct;
  82. int chain_switch_on_create;
  83. int chain_current;
  84. void (*prog_update_callback)(cmyth_proginfo_t prog);
  85. cmyth_proginfo_t *progs;
  86. char **chain_urls;
  87. cmyth_file_t *chain_files; /* File pointers for the urls */
  88. };
  89. /* Sergio: Added to clean up database interaction */
  90. struct cmyth_database {
  91. char * db_host;
  92. char * db_user;
  93. char * db_pass;
  94. char * db_name;
  95. MYSQL * mysql;
  96. };
  97. /* Sergio: Added to clean up channel list handling */
  98. struct cmyth_channel {
  99. long chanid;
  100. int channum;
  101. char chanstr[10];
  102. long cardids;/* A bit array of recorders/tuners supporting the channel */
  103. char *callsign;
  104. char *name;
  105. char *icon;
  106. int visible;
  107. };
  108. struct cmyth_chanlist {
  109. cmyth_channel_t *chanlist_list;
  110. int chanlist_count;
  111. };
  112. /* Sergio: Added to support the tvguide functionality */
  113. struct cmyth_tvguide_progs {
  114. cmyth_program_t * progs;
  115. int count;
  116. int alloc;
  117. };
  118. struct cmyth_recorder {
  119. unsigned rec_have_stream;
  120. unsigned rec_id;
  121. char *rec_server;
  122. int rec_port;
  123. cmyth_ringbuf_t rec_ring;
  124. cmyth_conn_t rec_conn;
  125. /* Sergio: Added to support new livetv protocol */
  126. cmyth_livetv_chain_t rec_livetv_chain;
  127. cmyth_file_t rec_livetv_file;
  128. double rec_framerate;
  129. };
  130. /**
  131. * MythTV file connection
  132. */
  133. struct cmyth_file {
  134. cmyth_conn_t file_data; /**< backend connection */
  135. long file_id; /**< file identifier */
  136. /** callback when close is completed */
  137. void (*closed_callback)(cmyth_file_t file);
  138. uint64_t file_start; /**< file start offest */
  139. uint64_t file_length; /**< file length */
  140. uint64_t file_pos; /**< current file position */
  141. uint64_t file_req; /**< current file position requested */
  142. cmyth_conn_t file_control; /**< master backend connection */
  143. };
  144. struct cmyth_ringbuf {
  145. cmyth_conn_t conn_data;
  146. long file_id;
  147. char *ringbuf_url;
  148. uint64_t ringbuf_size;
  149. uint64_t file_length;
  150. uint64_t file_pos;
  151. uint64_t ringbuf_fill;
  152. char *ringbuf_hostname;
  153. int ringbuf_port;
  154. };
  155. struct cmyth_rec_num {
  156. char *recnum_host;
  157. unsigned short recnum_port;
  158. unsigned recnum_id;
  159. };
  160. struct cmyth_keyframe {
  161. unsigned long keyframe_number;
  162. uint64_t keyframe_pos;
  163. };
  164. struct cmyth_posmap {
  165. unsigned posmap_count;
  166. struct cmyth_keyframe **posmap_list;
  167. };
  168. struct cmyth_freespace {
  169. uint64_t freespace_total;
  170. uint64_t freespace_used;
  171. };
  172. struct cmyth_timestamp {
  173. unsigned long timestamp_year;
  174. unsigned long timestamp_month;
  175. unsigned long timestamp_day;
  176. unsigned long timestamp_hour;
  177. unsigned long timestamp_minute;
  178. unsigned long timestamp_second;
  179. int timestamp_isdst;
  180. };
  181. struct cmyth_proginfo {
  182. char *proginfo_title;
  183. char *proginfo_subtitle;
  184. char *proginfo_description;
  185. unsigned short proginfo_season; /* new in V67 */
  186. unsigned short proginfo_episode; /* new in V67 */
  187. char *proginfo_category;
  188. long proginfo_chanId;
  189. char *proginfo_chanstr;
  190. char *proginfo_chansign;
  191. char *proginfo_channame; /* Deprecated in V8, simulated for compat. */
  192. char *proginfo_chanicon; /* New in V8 */
  193. char *proginfo_url;
  194. int64_t proginfo_Length;
  195. cmyth_timestamp_t proginfo_start_ts;
  196. cmyth_timestamp_t proginfo_end_ts;
  197. unsigned long proginfo_conflicting; /* Deprecated in V8, always 0 */
  198. char *proginfo_unknown_0; /* May be new 'conflicting' in V8 */
  199. unsigned long proginfo_recording;
  200. unsigned long proginfo_override;
  201. char *proginfo_hostname;
  202. long proginfo_source_id; /* ??? in V8 */
  203. long proginfo_card_id; /* ??? in V8 */
  204. long proginfo_input_id; /* ??? in V8 */
  205. char *proginfo_rec_priority; /* ??? in V8 */
  206. long proginfo_rec_status; /* ??? in V8 */
  207. unsigned long proginfo_record_id; /* ??? in V8 */
  208. unsigned long proginfo_rec_type; /* ??? in V8 */
  209. unsigned long proginfo_rec_dups; /* ??? in V8 */
  210. unsigned long proginfo_unknown_1; /* new in V8 */
  211. cmyth_timestamp_t proginfo_rec_start_ts;
  212. cmyth_timestamp_t proginfo_rec_end_ts;
  213. unsigned long proginfo_repeat; /* ??? in V8 */
  214. unsigned long proginfo_program_flags;
  215. char *proginfo_rec_profile; /* new in V8 */
  216. char *proginfo_recgroup; /* new in V8 */
  217. char *proginfo_chancommfree; /* new in V8 */
  218. char *proginfo_chan_output_filters; /* new in V8 */
  219. char *proginfo_seriesid; /* new in V8 */
  220. char *proginfo_programid; /* new in V12 */
  221. char *proginfo_inetref; /* new in V67 */
  222. cmyth_timestamp_t proginfo_lastmodified; /* new in V12 */
  223. char *proginfo_stars; /* new in V12 */
  224. cmyth_timestamp_t proginfo_originalairdate; /* new in V12 */
  225. char *proginfo_pathname;
  226. int proginfo_port;
  227. unsigned long proginfo_hasairdate;
  228. char *proginfo_host;
  229. unsigned long proginfo_version;
  230. char *proginfo_playgroup; /* new in v18 */
  231. char *proginfo_recpriority_2; /* new in V25 */
  232. long proginfo_parentid; /* new in V31 */
  233. char *proginfo_storagegroup; /* new in v32 */
  234. unsigned long proginfo_audioproperties; /* new in v35 */
  235. unsigned long proginfo_videoproperties; /* new in v35 */
  236. unsigned long proginfo_subtitletype; /* new in v35 */
  237. unsigned short proginfo_year; /* new in v43 */
  238. };
  239. struct cmyth_proglist {
  240. cmyth_proginfo_t *proglist_list;
  241. long proglist_count;
  242. };
  243. /*
  244. * Private funtions in socket.c
  245. */
  246. #define cmyth_send_message __cmyth_send_message
  247. extern int cmyth_send_message(cmyth_conn_t conn, char *request);
  248. #define cmyth_rcv_length __cmyth_rcv_length
  249. extern int cmyth_rcv_length(cmyth_conn_t conn);
  250. #define cmyth_rcv_string __cmyth_rcv_string
  251. extern int cmyth_rcv_string(cmyth_conn_t conn,
  252. int *err,
  253. char *buf, int buflen,
  254. int count);
  255. #define cmyth_rcv_okay __cmyth_rcv_okay
  256. extern int cmyth_rcv_okay(cmyth_conn_t conn, char *ok);
  257. #define cmyth_rcv_version __cmyth_rcv_version
  258. extern int cmyth_rcv_version(cmyth_conn_t conn, unsigned long *vers);
  259. #define cmyth_rcv_byte __cmyth_rcv_byte
  260. extern int cmyth_rcv_byte(cmyth_conn_t conn, int *err, char *buf, int count);
  261. #define cmyth_rcv_short __cmyth_rcv_short
  262. extern int cmyth_rcv_short(cmyth_conn_t conn, int *err, short *buf, int count);
  263. #define cmyth_rcv_long __cmyth_rcv_long
  264. extern int cmyth_rcv_long(cmyth_conn_t conn, int *err, long *buf, int count);
  265. #define cmyth_rcv_u_long(c, e, b, n) cmyth_rcv_long(c, e, (long*)b, n)
  266. #define cmyth_rcv_old_int64 __cmyth_rcv_old_int64
  267. extern int cmyth_rcv_old_int64(cmyth_conn_t conn, int *err, int64_t *buf,
  268. int count);
  269. #define cmyth_rcv_new_int64 __cmyth_rcv_new_int64
  270. extern int cmyth_rcv_new_int64(cmyth_conn_t conn, int *err, int64_t *buf,
  271. int count, int forced);
  272. #define cmyth_rcv_old_uint64 __cmyth_rcv_old_uint64
  273. extern int cmyth_rcv_old_uint64(cmyth_conn_t conn, int *err, uint64_t *buf,
  274. int count);
  275. #define cmyth_rcv_new_uint64 __cmyth_rcv_new_uint64
  276. extern int cmyth_rcv_new_uint64(cmyth_conn_t conn, int *err, uint64_t *buf,
  277. int count, int forced);
  278. #define cmyth_rcv_int64(conn, err, buf, count) \
  279. cmyth_rcv_new_int64(conn, err, buf, count, 0)
  280. #define cmyth_rcv_uint64(conn, err, buf, count) \
  281. cmyth_rcv_new_uint64(conn, err, buf, count, 0)
  282. #define cmyth_rcv_ubyte __cmyth_rcv_ubyte
  283. extern int cmyth_rcv_ubyte(cmyth_conn_t conn, int *err, unsigned char *buf,
  284. int count);
  285. #define cmyth_rcv_ushort __cmyth_rcv_ushort
  286. extern int cmyth_rcv_ushort(cmyth_conn_t conn, int *err, unsigned short *buf,
  287. int count);
  288. #define cmyth_rcv_ulong __cmyth_rcv_ulong
  289. extern int cmyth_rcv_ulong(cmyth_conn_t conn, int *err, unsigned long *buf,
  290. int count);
  291. #define cmyth_rcv_ulong_long __cmyth_rcv_ulong_long
  292. extern int cmyth_rcv_ulong_long(cmyth_conn_t conn,
  293. int *err,
  294. unsigned long long *buf,
  295. int count);
  296. #define cmyth_rcv_data __cmyth_rcv_data
  297. extern int cmyth_rcv_data(cmyth_conn_t conn, int *err, unsigned char *buf,
  298. int count);
  299. #define cmyth_rcv_timestamp __cmyth_rcv_timestamp
  300. extern int cmyth_rcv_timestamp(cmyth_conn_t conn, int *err,
  301. cmyth_timestamp_t *ts_p,
  302. int count);
  303. #define cmyth_rcv_datetime __cmyth_rcv_datetime
  304. extern int cmyth_rcv_datetime(cmyth_conn_t conn, int *err,
  305. cmyth_timestamp_t *ts_p,
  306. int count);
  307. #define cmyth_rcv_proginfo __cmyth_rcv_proginfo
  308. extern int cmyth_rcv_proginfo(cmyth_conn_t conn, int *err,
  309. cmyth_proginfo_t buf,
  310. int count);
  311. #define cmyth_rcv_chaninfo __cmyth_rcv_chaninfo
  312. extern int cmyth_rcv_chaninfo(cmyth_conn_t conn, int *err,
  313. cmyth_proginfo_t buf,
  314. int count);
  315. #define cmyth_rcv_proglist __cmyth_rcv_proglist
  316. extern int cmyth_rcv_proglist(cmyth_conn_t conn, int *err,
  317. cmyth_proglist_t buf,
  318. int count);
  319. #define cmyth_rcv_keyframe __cmyth_rcv_keyframe
  320. extern int cmyth_rcv_keyframe(cmyth_conn_t conn, int *err,
  321. cmyth_keyframe_t buf,
  322. int count);
  323. #define cmyth_rcv_freespace __cmyth_rcv_freespace
  324. extern int cmyth_rcv_freespace(cmyth_conn_t conn, int *err,
  325. cmyth_freespace_t buf,
  326. int count);
  327. #define cmyth_rcv_recorder __cmyth_rcv_recorder
  328. extern int cmyth_rcv_recorder(cmyth_conn_t conn, int *err,
  329. cmyth_recorder_t buf,
  330. int count);
  331. #define cmyth_rcv_ringbuf __cmyth_rcv_ringbuf
  332. extern int cmyth_rcv_ringbuf(cmyth_conn_t conn, int *err, cmyth_ringbuf_t buf,
  333. int count);
  334. #define cmyth_datetime_to_dbstring __cmyth_datetime_to_dbstring
  335. extern int cmyth_datetime_to_dbstring(char *str, cmyth_timestamp_t ts);
  336. /*
  337. * From proginfo.c
  338. */
  339. #define cmyth_proginfo_string __cmyth_proginfo_string
  340. extern char *cmyth_proginfo_string(cmyth_proginfo_t prog);
  341. #define cmyth_chaninfo_string __cmyth_chaninfo_string
  342. extern char *cmyth_chaninfo_string(cmyth_proginfo_t prog);
  343. /*
  344. * From file.c
  345. */
  346. #define cmyth_file_create __cmyth_file_create
  347. extern cmyth_file_t cmyth_file_create(cmyth_conn_t control);
  348. /*
  349. * From timestamp.c
  350. */
  351. #define cmyth_timestamp_diff __cmyth_timestamp_diff
  352. extern int cmyth_timestamp_diff(cmyth_timestamp_t, cmyth_timestamp_t);
  353. /*
  354. * From mythtv_mysql.c
  355. */
  356. extern MYSQL * cmyth_db_get_connection(cmyth_database_t db);
  357. /*
  358. * From mysql_query.c
  359. */
  360. typedef struct cmyth_mysql_query_s cmyth_mysql_query_t;
  361. extern cmyth_mysql_query_t * cmyth_mysql_query_create(cmyth_database_t db, const char * query_string);
  362. extern void cmyth_mysql_query_reset(cmyth_mysql_query_t *query);
  363. extern int cmyth_mysql_query_param_long(cmyth_mysql_query_t * query,long param);
  364. extern int cmyth_mysql_query_param_ulong(cmyth_mysql_query_t * query,unsigned long param);
  365. extern int cmyth_mysql_query_param_int(cmyth_mysql_query_t * query,int param);
  366. extern int cmyth_mysql_query_param_uint(cmyth_mysql_query_t * query,int param);
  367. extern int cmyth_mysql_query_param_unixtime(cmyth_mysql_query_t * query, time_t param);
  368. extern int cmyth_mysql_query_param_str(cmyth_mysql_query_t * query, const char *param);
  369. extern char * cmyth_mysql_query_string(cmyth_mysql_query_t * query);
  370. extern MYSQL_RES * cmyth_mysql_query_result(cmyth_mysql_query_t * query);
  371. extern int cmyth_mysql_query(cmyth_mysql_query_t * query);
  372. extern char* cmyth_utf8tolatin1(char* s);
  373. #endif /* __CMYTH_LOCAL_H */