Changeset 90:a4dbc92ef913 in roaraudio for roard/meta.c
- Timestamp:
- 07/13/08 01:02:28 (16 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roard/meta.c
r88 r90 3 3 #include "roard.h" 4 4 5 int 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 23 int 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 return 0; 51 } 52 } 53 54 return -1; 55 } 56 57 int stream_meta_get (int id, int type, char * name, char * val, size_t len) { 58 int i; 59 struct roar_stream_server * s = g_streams[id]; 60 61 if ( s == NULL ) 62 return -1; 63 64 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) { 65 if ( s->meta[i].type == type ) { 66 if ( name != NULL ) 67 if ( strncmp(s->meta[i].key, name, ROAR_META_MAX_NAMELEN) != 0 ) 68 continue; 69 70 if ( strlen(s->meta[i].value) > (len - 1) ) 71 return -1; 72 73 strcpy(val, s->meta[i].value); 74 75 return 0; 76 } 77 } 78 79 return -1; 80 } 81 82 int stream_meta_clear (int id) { 83 int i; 84 struct roar_stream_server * s = g_streams[id]; 85 86 if ( s == NULL ) 87 return -1; 88 89 for (i = 0; i < ROAR_META_MAX_PER_STREAM; i++) { 90 s->meta[i].type = ROAR_META_TYPE_NONE; 91 if ( s->meta[i].value ) 92 free(s->meta[i].value); 93 s->meta[i].value = NULL; 94 s->meta[i].key[0] = 0; 95 } 96 97 return 0; 98 } 99 5 100 //ll
Note: See TracChangeset
for help on using the changeset viewer.