source: roaraudio/roard/meta.c @ 96:95f59231f310

Last change on this file since 96:95f59231f310 was 96:95f59231f310, checked in by phi, 16 years ago

added ROAR_DBG()-line

File size: 2.0 KB
Line 
1//meta.c:
2
3#include "roard.h"
4
5int stream_meta_set   (int id, int type, char * name, char * val) {
6 int i;
7 struct roar_stream_server * s = g_streams[id];
8
9 if ( s == NULL )
10  return -1;
11
12 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++)
13  if ( s->meta[i].type == type ) {
14   s->meta[i].type = ROAR_META_TYPE_NONE;
15   if ( s->meta[i].value )
16    free(s->meta[i].value);
17   s->meta[i].value = NULL;
18  }
19
20 return stream_meta_add(id, type, name, val);
21}
22
23int stream_meta_add   (int id, int type, char * name, char * val) {
24 int i;
25 char * c;
26 struct roar_stream_server * s = g_streams[id];
27
28 if ( s == NULL )
29  return -1;
30
31 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
32  if ( s->meta[i].type == ROAR_META_TYPE_NONE ) {
33   s->meta[i].type = type;
34
35   if ( name == NULL ) {
36    s->meta[i].key[0] = 0;
37   } else {
38    strncpy(s->meta[i].key, name, ROAR_META_MAX_NAMELEN);
39   }
40
41   if ( (c = malloc(strlen(val))) == NULL ) {
42    s->meta[i].type = ROAR_META_TYPE_NONE;
43    s->meta[i].key[0] = 0;
44    return -1;
45   }
46
47   strcpy(c, val);
48   s->meta[i].value = c;
49
50   ROAR_DBG("stream_meta_add(id=%i, type=%i, name='%s', val='%s') = 0", id, type, name, val);
51
52   return 0;
53  }
54 }
55
56 return -1;
57}
58
59int stream_meta_get   (int id, int type, char * name, char * val, size_t len) {
60 int i;
61 struct roar_stream_server * s = g_streams[id];
62
63 if ( s == NULL )
64  return -1;
65
66 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
67  if ( s->meta[i].type == type ) {
68   if ( name != NULL )
69    if ( strncmp(s->meta[i].key, name, ROAR_META_MAX_NAMELEN) != 0 )
70     continue;
71
72   if ( strlen(s->meta[i].value) > (len - 1) )
73    return -1;
74
75   strcpy(val, s->meta[i].value);
76
77   return 0;
78  }
79 }
80
81 return -1;
82}
83
84int stream_meta_clear (int id) {
85 int i;
86 struct roar_stream_server * s = g_streams[id];
87
88 if ( s == NULL )
89  return -1;
90
91 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) {
92  s->meta[i].type   = ROAR_META_TYPE_NONE;
93  if ( s->meta[i].value )
94   free(s->meta[i].value);
95  s->meta[i].value  = NULL;
96  s->meta[i].key[0] = 0;
97 }
98
99 return 0;
100}
101
102//ll
Note: See TracBrowser for help on using the repository browser.