Merge pull request #1129 from jmarshallnz/remove_smb_auth_details_in_add_source
[vuplus_xbmc] / lib / cmyth / libcmyth / keyframe.c
1 /*
2  *  Copyright (C) 2004-2010, Eric Lund
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  * keyframe.c - functions to manage key frame structures.  Mostly
22  *              just allocating, freeing, and filling them out.
23  */
24 #include <sys/types.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdio.h>
28 #include <cmyth_local.h>
29
30 /*
31  * cmyth_keyframe_create(void)
32  * 
33  * Scope: PUBLIC
34  *
35  * Description
36  *
37  * Create a key frame structure.
38  *
39  * Return Value:
40  *
41  * Success: A non-NULL cmyth_keyframe_t (this type is a pointer)
42  *
43  * Failure: A NULL cmyth_keyframe_t
44  */
45 cmyth_keyframe_t
46 cmyth_keyframe_create(void)
47 {
48         cmyth_keyframe_t ret = ref_alloc(sizeof(*ret));
49
50         cmyth_dbg(CMYTH_DBG_DEBUG, "%s {\n", __FUNCTION__);
51         if (!ret) {
52                 cmyth_dbg(CMYTH_DBG_DEBUG, "%s } !\n", __FUNCTION__);
53                 return NULL;
54         }
55         ret->keyframe_number = 0;
56         ret->keyframe_pos = 0;
57         cmyth_dbg(CMYTH_DBG_DEBUG, "%s }\n", __FUNCTION__);
58         return ret;
59 }
60
61 /*
62  * cmyth_keyframe_fill(cmyth_keyframe_t kf,
63  *                     unsigned long keynum,
64  *                     unsigned long long pos)
65  * 
66  * Scope: PUBLIC
67  *
68  * Description
69  *
70  * Fill out the contents of the recorder number structure 'rn' using
71  * the values 'keynum' and 'pos'.
72  *
73  * Return Value:
74  *
75  * Success: 0
76  *
77  * Failure: -(ERRNO)
78  */
79 cmyth_keyframe_t
80 cmyth_keyframe_fill(unsigned long keynum, unsigned long long pos)
81 {
82         cmyth_keyframe_t ret = cmyth_keyframe_create();
83
84         if (!ret) {
85                 return NULL;
86         }
87
88         ret->keyframe_number = keynum;
89         ret->keyframe_pos = pos;
90         return ret;
91 }
92
93 /*
94  * cmyth_keyframe_string(cmyth_keyframe_t kf)
95  * 
96  * Scope: PUBLIC
97  *
98  * Description
99  *
100  * Compose a MythTV protocol string from a keyframe structure and
101  * return a pointer to a malloc'ed buffer containing the string.
102  *
103  * Return Value:
104  *
105  * Success: A non-NULL malloc'ed character buffer pointer.
106  *
107  * Failure: NULL
108  */
109 char *
110 cmyth_keyframe_string(cmyth_keyframe_t kf)
111 {
112         unsigned len = sizeof("[]:[]");
113         char key[32];
114         char pos[32];
115         char *ret;
116
117         if (!kf) {
118                 return NULL;
119         }
120         sprintf(pos, "%lld", kf->keyframe_pos);
121         len += strlen(pos);
122         sprintf(key, "%ld", kf->keyframe_number);
123         len += strlen(key);
124         ret = malloc(len * sizeof(char));
125         if (!ret) {
126                 return NULL;
127         }
128         strcpy(ret, key);
129         strcat(ret, "[]:[]");
130         strcat(ret, pos);
131         return ret;
132 }