Coverage Report

Created: 2024-09-06 07:53

/src/theora/lib/info.c
Line
Count
Source (jump to first uncovered line)
1
/********************************************************************
2
 *                                                                  *
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.       *
7
 *                                                                  *
8
 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009                *
9
 * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
10
 *                                                                  *
11
 ********************************************************************
12
13
  function:
14
    last mod: $Id$
15
16
 ********************************************************************/
17
18
#include <stdlib.h>
19
#include <ctype.h>
20
#include <string.h>
21
#include "internal.h"
22
23
24
25
/*This is more or less the same as strncasecmp, but that doesn't exist
26
   everywhere, and this is a fairly trivial function, so we include it.
27
  Note: We take advantage of the fact that we know _n is less than or equal to
28
   the length of at least one of the strings.*/
29
0
static int oc_tagcompare(const char *_s1,const char *_s2,int _n){
30
0
  int c;
31
0
  for(c=0;c<_n;c++){
32
0
    if(toupper(_s1[c])!=toupper(_s2[c]))return !0;
33
0
  }
34
0
  return _s1[c]!='=';
35
0
}
36
37
38
39
3.44k
void th_info_init(th_info *_info){
40
3.44k
  memset(_info,0,sizeof(*_info));
41
3.44k
  _info->version_major=TH_VERSION_MAJOR;
42
3.44k
  _info->version_minor=TH_VERSION_MINOR;
43
3.44k
  _info->version_subminor=TH_VERSION_SUB;
44
3.44k
  _info->keyframe_granule_shift=6;
45
3.44k
}
46
47
3.44k
void th_info_clear(th_info *_info){
48
3.44k
  memset(_info,0,sizeof(*_info));
49
3.44k
}
50
51
52
53
3.44k
void th_comment_init(th_comment *_tc){
54
3.44k
  memset(_tc,0,sizeof(*_tc));
55
3.44k
}
56
57
0
void th_comment_add(th_comment *_tc,const char *_comment){
58
0
  char **user_comments;
59
0
  int   *comment_lengths;
60
0
  int    comment_len;
61
0
  user_comments=_ogg_realloc(_tc->user_comments,
62
0
   (_tc->comments+2)*sizeof(*_tc->user_comments));
63
0
  if(user_comments==NULL)return;
64
0
  _tc->user_comments=user_comments;
65
0
  comment_lengths=_ogg_realloc(_tc->comment_lengths,
66
0
   (_tc->comments+2)*sizeof(*_tc->comment_lengths));
67
0
  if(comment_lengths==NULL)return;
68
0
  _tc->comment_lengths=comment_lengths;
69
0
  comment_len=strlen(_comment);
70
0
  comment_lengths[_tc->comments]=comment_len;
71
0
  user_comments[_tc->comments]=_ogg_malloc(comment_len+1);
72
0
  if(user_comments[_tc->comments]==NULL)return;
73
0
  memcpy(_tc->user_comments[_tc->comments],_comment,comment_len+1);
74
0
  _tc->comments++;
75
0
  _tc->user_comments[_tc->comments]=NULL;
76
0
}
77
78
0
void th_comment_add_tag(th_comment *_tc,const char *_tag,const char *_val){
79
0
  char *comment;
80
0
  int   tag_len;
81
0
  int   val_len;
82
0
  tag_len=strlen(_tag);
83
0
  val_len=strlen(_val);
84
  /*+2 for '=' and '\0'.*/
85
0
  comment=_ogg_malloc(tag_len+val_len+2);
86
0
  if(comment==NULL)return;
87
0
  memcpy(comment,_tag,tag_len);
88
0
  comment[tag_len]='=';
89
0
  memcpy(comment+tag_len+1,_val,val_len+1);
90
0
  th_comment_add(_tc,comment);
91
0
  _ogg_free(comment);
92
0
}
93
94
0
char *th_comment_query(th_comment *_tc,const char *_tag,int _count){
95
0
  long i;
96
0
  int  found;
97
0
  int  tag_len;
98
0
  tag_len=strlen(_tag);
99
0
  found=0;
100
0
  for(i=0;i<_tc->comments;i++){
101
0
    if(!oc_tagcompare(_tc->user_comments[i],_tag,tag_len)){
102
      /*We return a pointer to the data, not a copy.*/
103
0
      if(_count==found++)return _tc->user_comments[i]+tag_len+1;
104
0
    }
105
0
  }
106
  /*Didn't find anything.*/
107
0
  return NULL;
108
0
}
109
110
0
int th_comment_query_count(th_comment *_tc,const char *_tag){
111
0
  long i;
112
0
  int  tag_len;
113
0
  int  count;
114
0
  tag_len=strlen(_tag);
115
0
  count=0;
116
0
  for(i=0;i<_tc->comments;i++){
117
0
    if(!oc_tagcompare(_tc->user_comments[i],_tag,tag_len))count++;
118
0
  }
119
0
  return count;
120
0
}
121
122
3.44k
void th_comment_clear(th_comment *_tc){
123
3.44k
  if(_tc!=NULL){
124
3.44k
    long i;
125
3.44k
    for(i=0;i<_tc->comments;i++)_ogg_free(_tc->user_comments[i]);
126
3.44k
    _ogg_free(_tc->user_comments);
127
3.44k
    _ogg_free(_tc->comment_lengths);
128
3.44k
    _ogg_free(_tc->vendor);
129
3.44k
    memset(_tc,0,sizeof(*_tc));
130
3.44k
  }
131
3.44k
}