source: roaraudio/libroar/meta.c @ 690:cee9bf5fa456

Last change on this file since 690:cee9bf5fa456 was 690:cee9bf5fa456, checked in by phi, 16 years ago

added copyright statements

File size: 5.7 KB
Line 
1//meta.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of libroar a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  libroar is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 *  NOTE for everyone want's to change something and send patches:
24 *  read README and HACKING! There a addition information on
25 *  the license of this document you need to read before you send
26 *  any patches.
27 *
28 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
29 *  or libpulse*:
30 *  The libs libroaresd, libroararts and libroarpulse link this lib
31 *  and are therefore GPL. Because of this it may be illigal to use
32 *  them with any software that uses libesd, libartsc or libpulse*.
33 */
34
35#include "libroar.h"
36
37/*
38
39grep ^'#define ROAR_META_TYPE_' meta.h | cut -d' ' -f2 | while read line; do printf ' {%-30s     "%-16s},\n' $line, $(echo $line | cut -d_ -f4)\"; done
40
41*/
42
43struct {
44 int    id;
45 char * name;
46} _libroar_meta_typelist[] = {
47 {ROAR_META_TYPE_NONE,               "NONE"           },
48 {ROAR_META_TYPE_TITLE,              "TITLE"          },
49 {ROAR_META_TYPE_ALBUM,              "ALBUM"          },
50 {ROAR_META_TYPE_AUTOR,              "AUTOR"          },
51 {ROAR_META_TYPE_ARTIST,             "ARTIST"         },
52 {ROAR_META_TYPE_VERSION,            "VERSION"        },
53 {ROAR_META_TYPE_DATE,               "DATE"           },
54 {ROAR_META_TYPE_LICENSE,            "LICENSE"        },
55 {ROAR_META_TYPE_TRACKNUMBER,        "TRACKNUMBER"    },
56 {ROAR_META_TYPE_ORGANIZATION,       "ORGANIZATION"   },
57 {ROAR_META_TYPE_DESCRIPTION,        "DESCRIPTION"    },
58 {ROAR_META_TYPE_GENRE,              "GENRE"          },
59 {ROAR_META_TYPE_LOCATION,           "LOCATION"       },
60 {ROAR_META_TYPE_CONTACT,            "CONTACT"        },
61 {ROAR_META_TYPE_STREAMURL,          "STREAMURL"      },
62 {ROAR_META_TYPE_HOMEPAGE,           "HOMEPAGE"       },
63 {ROAR_META_TYPE_THUMBNAIL,          "THUMBNAIL"      },
64 {ROAR_META_TYPE_LENGTH,             "LENGTH"         },
65 {ROAR_META_TYPE_COMMENT,            "COMMENT"        },
66 {ROAR_META_TYPE_OTHER,              "OTHER"          },
67 {ROAR_META_TYPE_FILENAME,           "FILENAME"       },
68 {ROAR_META_TYPE_FILEURL,            "FILEURL"        },
69 {ROAR_META_TYPE_SERVER,             "SERVER"         },
70 {ROAR_META_TYPE_DURATION,           "DURATION"       },
71 {ROAR_META_TYPE_WWW,                "WWW"            },
72 {ROAR_META_TYPE_WOAF,               "WOAF"           },
73 {ROAR_META_TYPE_ENCODER,            "ENCODER"        },
74 {ROAR_META_TYPE_ENCODEDBY,          "ENCODEDBY"      },
75 
76 {-1, "EOL"}
77};
78
79char * roar_meta_strtype(int type) {
80 int i;
81 static char name[24];
82
83 for (i = 0; _libroar_meta_typelist[i].id != -1; i++)
84  if ( _libroar_meta_typelist[i].id == type ) {
85   strcpy(name, _libroar_meta_typelist[i].name);
86   return name;
87  }
88
89 return NULL;
90}
91
92int    roar_meta_inttype(char * type) {
93 int i;
94
95 for (i = 0; _libroar_meta_typelist[i].id != -1; i++)
96  if ( strcasecmp(_libroar_meta_typelist[i].name, type) == 0 ) {
97   return _libroar_meta_typelist[i].id;
98  }
99
100 return -1;
101}
102
103int roar_stream_meta_set (struct roar_connection * con, struct roar_stream * s, int mode, struct roar_meta * meta) {
104 struct roar_message m;
105 int len;
106
107 memset(&m, 0, sizeof(struct roar_message)); // make valgrind happy!
108
109 m.cmd     = ROAR_CMD_SET_META;
110 m.stream  = s->id;
111// m.datalen = len;
112
113 m.data[0] = 0;
114 m.data[1] = mode;
115 m.data[2] = meta->type;
116
117 m.data[3] = strlen(meta->key);
118 m.data[4] = len = strlen(meta->value);
119
120 if ( len > 255 )
121  return -1;
122
123 m.datalen = 5 + m.data[3] + m.data[4];
124 if ( m.datalen > LIBROAR_BUFFER_MSGDATA )
125  return -1;
126
127 strncpy(&(m.data[5]), meta->key, ROAR_META_MAX_NAMELEN);
128 strncpy(&(m.data[5+m.data[3]]), meta->value, len);
129
130 if ( roar_req(con, &m, NULL) == -1 )
131  return -1;
132
133 if ( m.cmd == ROAR_CMD_OK )
134  return 0;
135 return -1;
136}
137
138int roar_stream_meta_get (struct roar_connection * con, struct roar_stream * s, struct roar_meta * meta) {
139 struct roar_message m;
140 char * c;
141
142 m.cmd     = ROAR_CMD_GET_META;
143 m.stream  = s->id;
144// m.datalen = len;
145
146 m.data[0] = 0;
147 m.data[1] = meta->type;
148 m.datalen = 2;
149
150 if ( roar_req(con, &m, NULL) == -1 )
151  return -1;
152
153 if ( m.cmd != ROAR_CMD_OK )
154  return -1;
155
156 if ( m.datalen < 2 )
157  return -1;
158
159 if ( m.data[0] != 0 )
160  return -1;
161
162 if ( (c = malloc(((unsigned) m.data[1]) + 1)) == NULL )
163  return -1;
164
165 strncpy(c, &(m.data[2]), (unsigned) m.data[1]);
166 c[(unsigned) m.data[1]] = 0;
167
168 meta->value  = c;
169 meta->key[0] = 0;
170
171 return 0;
172}
173
174int roar_stream_meta_list (struct roar_connection * con, struct roar_stream * s, int * types, size_t len) {
175 int i;
176 struct roar_message m;
177
178 m.cmd     = ROAR_CMD_LIST_META;
179 m.stream  = s->id;
180
181 m.data[0] = 0;
182 m.datalen = 1;
183
184 if ( roar_req(con, &m, NULL) == -1 )
185  return -1;
186
187 if ( m.cmd != ROAR_CMD_OK )
188  return -1;
189
190 if ( m.datalen < 1 )
191  return -1;
192
193 if ( m.data[0] != 0 )
194  return -1;
195
196 if ( len < (m.datalen - 1 ) )
197  return -1;
198
199 for (i = 1; i < m.datalen; i++)
200  types[i-1] = (unsigned) m.data[i];
201
202 return m.datalen - 1;
203}
204
205int roar_meta_free (struct roar_meta * meta) {
206 if ( meta->value )
207  free(meta->value);
208
209 return 0;
210}
211
212//ll
Note: See TracBrowser for help on using the repository browser.