Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /******************************************************************** |
michael@0 | 2 | * * |
michael@0 | 3 | * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. * |
michael@0 | 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
michael@0 | 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
michael@0 | 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
michael@0 | 7 | * * |
michael@0 | 8 | * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 * |
michael@0 | 9 | * by the Xiph.Org Foundation and contributors http://www.xiph.org/ * |
michael@0 | 10 | * * |
michael@0 | 11 | ******************************************************************** |
michael@0 | 12 | |
michael@0 | 13 | function: |
michael@0 | 14 | last mod: $Id: info.c 16503 2009-08-22 18:14:02Z giles $ |
michael@0 | 15 | |
michael@0 | 16 | ********************************************************************/ |
michael@0 | 17 | |
michael@0 | 18 | #include <stdlib.h> |
michael@0 | 19 | #include <ctype.h> |
michael@0 | 20 | #include <string.h> |
michael@0 | 21 | #include "internal.h" |
michael@0 | 22 | |
michael@0 | 23 | |
michael@0 | 24 | |
michael@0 | 25 | /*This is more or less the same as strncasecmp, but that doesn't exist |
michael@0 | 26 | everywhere, and this is a fairly trivial function, so we include it. |
michael@0 | 27 | Note: We take advantage of the fact that we know _n is less than or equal to |
michael@0 | 28 | the length of at least one of the strings.*/ |
michael@0 | 29 | static int oc_tagcompare(const char *_s1,const char *_s2,int _n){ |
michael@0 | 30 | int c; |
michael@0 | 31 | for(c=0;c<_n;c++){ |
michael@0 | 32 | if(toupper(_s1[c])!=toupper(_s2[c]))return !0; |
michael@0 | 33 | } |
michael@0 | 34 | return _s1[c]!='='; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | |
michael@0 | 38 | |
michael@0 | 39 | void th_info_init(th_info *_info){ |
michael@0 | 40 | memset(_info,0,sizeof(*_info)); |
michael@0 | 41 | _info->version_major=TH_VERSION_MAJOR; |
michael@0 | 42 | _info->version_minor=TH_VERSION_MINOR; |
michael@0 | 43 | _info->version_subminor=TH_VERSION_SUB; |
michael@0 | 44 | _info->keyframe_granule_shift=6; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | void th_info_clear(th_info *_info){ |
michael@0 | 48 | memset(_info,0,sizeof(*_info)); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | |
michael@0 | 52 | |
michael@0 | 53 | void th_comment_init(th_comment *_tc){ |
michael@0 | 54 | memset(_tc,0,sizeof(*_tc)); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | void th_comment_add(th_comment *_tc,char *_comment){ |
michael@0 | 58 | char **user_comments; |
michael@0 | 59 | int *comment_lengths; |
michael@0 | 60 | int comment_len; |
michael@0 | 61 | user_comments=_ogg_realloc(_tc->user_comments, |
michael@0 | 62 | (_tc->comments+2)*sizeof(*_tc->user_comments)); |
michael@0 | 63 | if(user_comments==NULL)return; |
michael@0 | 64 | _tc->user_comments=user_comments; |
michael@0 | 65 | comment_lengths=_ogg_realloc(_tc->comment_lengths, |
michael@0 | 66 | (_tc->comments+2)*sizeof(*_tc->comment_lengths)); |
michael@0 | 67 | if(comment_lengths==NULL)return; |
michael@0 | 68 | _tc->comment_lengths=comment_lengths; |
michael@0 | 69 | comment_len=strlen(_comment); |
michael@0 | 70 | comment_lengths[_tc->comments]=comment_len; |
michael@0 | 71 | user_comments[_tc->comments]=_ogg_malloc(comment_len+1); |
michael@0 | 72 | if(user_comments[_tc->comments]==NULL)return; |
michael@0 | 73 | memcpy(_tc->user_comments[_tc->comments],_comment,comment_len+1); |
michael@0 | 74 | _tc->comments++; |
michael@0 | 75 | _tc->user_comments[_tc->comments]=NULL; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | void th_comment_add_tag(th_comment *_tc,char *_tag,char *_val){ |
michael@0 | 79 | char *comment; |
michael@0 | 80 | int tag_len; |
michael@0 | 81 | int val_len; |
michael@0 | 82 | tag_len=strlen(_tag); |
michael@0 | 83 | val_len=strlen(_val); |
michael@0 | 84 | /*+2 for '=' and '\0'.*/ |
michael@0 | 85 | comment=_ogg_malloc(tag_len+val_len+2); |
michael@0 | 86 | if(comment==NULL)return; |
michael@0 | 87 | memcpy(comment,_tag,tag_len); |
michael@0 | 88 | comment[tag_len]='='; |
michael@0 | 89 | memcpy(comment+tag_len+1,_val,val_len+1); |
michael@0 | 90 | th_comment_add(_tc,comment); |
michael@0 | 91 | _ogg_free(comment); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | char *th_comment_query(th_comment *_tc,char *_tag,int _count){ |
michael@0 | 95 | long i; |
michael@0 | 96 | int found; |
michael@0 | 97 | int tag_len; |
michael@0 | 98 | tag_len=strlen(_tag); |
michael@0 | 99 | found=0; |
michael@0 | 100 | for(i=0;i<_tc->comments;i++){ |
michael@0 | 101 | if(!oc_tagcompare(_tc->user_comments[i],_tag,tag_len)){ |
michael@0 | 102 | /*We return a pointer to the data, not a copy.*/ |
michael@0 | 103 | if(_count==found++)return _tc->user_comments[i]+tag_len+1; |
michael@0 | 104 | } |
michael@0 | 105 | } |
michael@0 | 106 | /*Didn't find anything.*/ |
michael@0 | 107 | return NULL; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | int th_comment_query_count(th_comment *_tc,char *_tag){ |
michael@0 | 111 | long i; |
michael@0 | 112 | int tag_len; |
michael@0 | 113 | int count; |
michael@0 | 114 | tag_len=strlen(_tag); |
michael@0 | 115 | count=0; |
michael@0 | 116 | for(i=0;i<_tc->comments;i++){ |
michael@0 | 117 | if(!oc_tagcompare(_tc->user_comments[i],_tag,tag_len))count++; |
michael@0 | 118 | } |
michael@0 | 119 | return count; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | void th_comment_clear(th_comment *_tc){ |
michael@0 | 123 | if(_tc!=NULL){ |
michael@0 | 124 | long i; |
michael@0 | 125 | for(i=0;i<_tc->comments;i++)_ogg_free(_tc->user_comments[i]); |
michael@0 | 126 | _ogg_free(_tc->user_comments); |
michael@0 | 127 | _ogg_free(_tc->comment_lengths); |
michael@0 | 128 | _ogg_free(_tc->vendor); |
michael@0 | 129 | memset(_tc,0,sizeof(*_tc)); |
michael@0 | 130 | } |
michael@0 | 131 | } |