1 /********************************************************************
3 * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2003 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
11 ********************************************************************
13 function: read/write and client interface for comment header packet
16 ********************************************************************/
21 #include "codec_internal.h"
23 void theora_comment_init(theora_comment
*tc
){
24 memset(tc
,0,sizeof(*tc
));
27 void theora_comment_add(theora_comment
*tc
,char *comment
){
28 tc
->user_comments
=_ogg_realloc(tc
->user_comments
,
29 (tc
->comments
+2)*sizeof(*tc
->user_comments
));
30 tc
->comment_lengths
=_ogg_realloc(tc
->comment_lengths
,
31 (tc
->comments
+2)*sizeof(*tc
->comment_lengths
));
32 tc
->comment_lengths
[tc
->comments
]=strlen(comment
);
33 tc
->user_comments
[tc
->comments
]=_ogg_malloc(tc
->comment_lengths
[tc
->comments
]+1);
34 strcpy(tc
->user_comments
[tc
->comments
], comment
);
36 tc
->user_comments
[tc
->comments
]=NULL
;
39 void theora_comment_add_tag(theora_comment
*tc
, char *tag
, char *value
){
40 char *comment
=_ogg_malloc(strlen(tag
)+strlen(value
)+2); /* +2 for = and \0 */
43 strcat(comment
, value
);
44 theora_comment_add(tc
, comment
);
48 /* This is more or less the same as strncasecmp - but that doesn't exist
49 * everywhere, and this is a fairly trivial function, so we include it */
50 static int tagcompare(const char *s1
, const char *s2
, int n
){
53 if(toupper(s1
[c
]) != toupper(s2
[c
]))
60 char *theora_comment_query(theora_comment
*tc
, char *tag
, int count
){
63 int taglen
= strlen(tag
)+1; /* +1 for the = we append */
64 char *fulltag
= _ogg_malloc(taglen
+ 1);
69 for(i
=0;i
<tc
->comments
;i
++){
70 if(!tagcompare(tc
->user_comments
[i
], fulltag
, taglen
)){
73 /* We return a pointer to the data, not a copy */
74 return tc
->user_comments
[i
] + taglen
;
81 return NULL
; /* didn't find anything */
84 int theora_comment_query_count(theora_comment
*tc
, char *tag
){
86 int taglen
= strlen(tag
)+1; /* +1 for the = we append */
87 char *fulltag
= _ogg_malloc(taglen
+1);
91 for(i
=0;i
<tc
->comments
;i
++){
92 if(!tagcompare(tc
->user_comments
[i
], fulltag
, taglen
))
99 void theora_comment_clear(theora_comment
*tc
){
102 for(i
=0;i
<tc
->comments
;i
++)
103 if(tc
->user_comments
[i
])_ogg_free(tc
->user_comments
[i
]);
104 if(tc
->user_comments
)_ogg_free(tc
->user_comments
);
105 if(tc
->comment_lengths
)_ogg_free(tc
->comment_lengths
);
106 if(tc
->vendor
)_ogg_free(tc
->vendor
);
107 memset(tc
,0,sizeof(*tc
));