Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 8ae7ec6813c5bf60cf058a6da524a0db > files > 284

id3lib-devel-3.8.3-25.fc15.i686.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>id3lib: src/tag_parse_musicmatch.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="id3lib.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.3 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">id3lib&#160;<span id="projectnumber">3.8.3</span></div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<h1>src/tag_parse_musicmatch.cpp</h1>  </div>
</div>
<div class="contents">
<a href="tag__parse__musicmatch_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// $Id: tag_parse_musicmatch.cpp,v 1.19 2002/07/02 22:15:18 t1mpy Exp $</span>
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 <span class="comment">// id3lib: a C++ library for creating and manipulating id3v1/v2 tags</span>
<a name="l00004"></a>00004 <span class="comment">// Copyright 1999, 2000  Scott Thomas Haug</span>
<a name="l00005"></a>00005 
<a name="l00006"></a>00006 <span class="comment">// This library is free software; you can redistribute it and/or modify it</span>
<a name="l00007"></a>00007 <span class="comment">// under the terms of the GNU Library General Public License as published by</span>
<a name="l00008"></a>00008 <span class="comment">// the Free Software Foundation; either version 2 of the License, or (at your</span>
<a name="l00009"></a>00009 <span class="comment">// option) any later version.</span>
<a name="l00010"></a>00010 <span class="comment">//</span>
<a name="l00011"></a>00011 <span class="comment">// This library is distributed in the hope that it will be useful, but WITHOUT</span>
<a name="l00012"></a>00012 <span class="comment">// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or</span>
<a name="l00013"></a>00013 <span class="comment">// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public</span>
<a name="l00014"></a>00014 <span class="comment">// License for more details.</span>
<a name="l00015"></a>00015 <span class="comment">//</span>
<a name="l00016"></a>00016 <span class="comment">// You should have received a copy of the GNU Library General Public License</span>
<a name="l00017"></a>00017 <span class="comment">// along with this library; if not, write to the Free Software Foundation,</span>
<a name="l00018"></a>00018 <span class="comment">// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 <span class="comment">// The id3lib authors encourage improvements and optimisations to be sent to</span>
<a name="l00021"></a>00021 <span class="comment">// the id3lib coordinator.  Please see the README file for details on where to</span>
<a name="l00022"></a>00022 <span class="comment">// send such submissions.  See the AUTHORS file for a list of people who have</span>
<a name="l00023"></a>00023 <span class="comment">// contributed to id3lib.  See the ChangeLog file for a list of changes to</span>
<a name="l00024"></a>00024 <span class="comment">// id3lib.  These files are distributed with id3lib at</span>
<a name="l00025"></a>00025 <span class="comment">// http://download.sourceforge.net/id3lib/</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="preprocessor">#if defined HAVE_CONFIG_H</span>
<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#include &lt;config.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span>
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;ctype.h&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &quot;<a class="code" href="tag__impl_8h.html">tag_impl.h</a>&quot;</span> <span class="comment">//has &lt;stdio.h&gt; &quot;tag.h&quot; &quot;header_tag.h&quot; &quot;frame.h&quot; &quot;field.h&quot; &quot;spec.h&quot; &quot;id3lib_strings.h&quot; &quot;utils.h&quot;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &quot;helpers.h&quot;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &quot;id3/io_decorators.h&quot;</span> <span class="comment">//has &quot;readers.h&quot; &quot;io_helpers.h&quot; &quot;utils.h&quot;</span>
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 <span class="keyword">using namespace </span>dami;
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 <span class="keyword">namespace </span>
<a name="l00040"></a>00040 {
<a name="l00041"></a>00041   uint32 readSeconds(<a class="code" href="class_i_d3___reader.html">ID3_Reader</a>&amp; reader, <span class="keywordtype">size_t</span> len)
<a name="l00042"></a>00042   {
<a name="l00043"></a>00043     io::ExitTrigger et(reader);
<a name="l00044"></a>00044     io::WindowedReader wr(reader, len);
<a name="l00045"></a>00045     <a class="code" href="class_i_d3___reader.html#a83194ea4d4e04e81302b095e9aa2275a">ID3_Reader::pos_type</a> beg = wr.getCur();
<a name="l00046"></a>00046     uint32 seconds = 0;
<a name="l00047"></a>00047     uint32 cur = 0;
<a name="l00048"></a>00048     <span class="keywordflow">while</span> (!wr.atEnd())
<a name="l00049"></a>00049     {
<a name="l00050"></a>00050       <a class="code" href="class_i_d3___reader.html#abc80771e4ce81188082eaa8fa90a67e6">ID3_Reader::char_type</a> ch = wr.readChar();
<a name="l00051"></a>00051       <span class="keywordflow">if</span> (<span class="charliteral">&#39;:&#39;</span> == ch)
<a name="l00052"></a>00052       {
<a name="l00053"></a>00053         seconds += 60 * cur;
<a name="l00054"></a>00054         cur = 0;
<a name="l00055"></a>00055       }
<a name="l00056"></a>00056       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!isdigit(ch))
<a name="l00057"></a>00057       {
<a name="l00058"></a>00058         <span class="keywordflow">return</span> 0;
<a name="l00059"></a>00059       }
<a name="l00060"></a>00060       <span class="keywordflow">else</span>
<a name="l00061"></a>00061       {
<a name="l00062"></a>00062         cur = cur * 10 + (ch - <span class="charliteral">&#39;0&#39;</span>);
<a name="l00063"></a>00063       }
<a name="l00064"></a>00064     }
<a name="l00065"></a>00065     et.release();
<a name="l00066"></a>00066     <span class="keywordflow">return</span> seconds + cur;
<a name="l00067"></a>00067   }
<a name="l00068"></a>00068   
<a name="l00069"></a>00069   <a class="code" href="class_i_d3___frame.html" title="The representative class of an id3v2 frame.">ID3_Frame</a>* readTextFrame(<a class="code" href="class_i_d3___reader.html">ID3_Reader</a>&amp; reader, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8a" title="Enumeration of the different types of frames recognized by id3lib.">ID3_FrameID</a> <span class="keywordtype">id</span>, <span class="keyword">const</span> String desc = <span class="stringliteral">&quot;&quot;</span>)
<a name="l00070"></a>00070   {
<a name="l00071"></a>00071     uint32 size = io::readLENumber(reader, 2);
<a name="l00072"></a>00072     ID3D_NOTICE( <span class="stringliteral">&quot;readTextFrame: size = &quot;</span> &lt;&lt; size );
<a name="l00073"></a>00073     <span class="keywordflow">if</span> (size == 0)
<a name="l00074"></a>00074     {
<a name="l00075"></a>00075       <span class="keywordflow">return</span> <a class="code" href="globals_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00076"></a>00076     }
<a name="l00077"></a>00077     
<a name="l00078"></a>00078     String text;
<a name="l00079"></a>00079     <span class="keywordflow">if</span> (<a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aaa2047f42426480aac38e6e10d49918aa" title="Length.">ID3FID_SONGLEN</a> != <span class="keywordtype">id</span>)
<a name="l00080"></a>00080     {
<a name="l00081"></a>00081       io::LineFeedReader lfr(reader);
<a name="l00082"></a>00082       text = io::readText(lfr, size);
<a name="l00083"></a>00083       ID3D_NOTICE( <span class="stringliteral">&quot;readTextFrame: text = &quot;</span> &lt;&lt; text );
<a name="l00084"></a>00084     }
<a name="l00085"></a>00085     <span class="keywordflow">else</span>
<a name="l00086"></a>00086     {
<a name="l00087"></a>00087       text = toString(readSeconds(reader, size) * 1000);
<a name="l00088"></a>00088       ID3D_NOTICE( <span class="stringliteral">&quot;readTextFrame: songlen = &quot;</span> &lt;&lt; text );
<a name="l00089"></a>00089     }
<a name="l00090"></a>00090     
<a name="l00091"></a>00091     <a class="code" href="class_i_d3___frame.html" title="The representative class of an id3v2 frame.">ID3_Frame</a>* frame = <span class="keyword">new</span> <a class="code" href="class_i_d3___frame.html" title="The representative class of an id3v2 frame.">ID3_Frame</a>(<span class="keywordtype">id</span>);
<a name="l00092"></a>00092     <span class="keywordflow">if</span> (frame)
<a name="l00093"></a>00093     {
<a name="l00094"></a>00094       <span class="keywordflow">if</span> (frame-&gt;<a class="code" href="class_i_d3___frame.html#ad5d20e40b233e124a9bd84c6a8947fee">Contains</a>(<a class="code" href="globals_8h.html#a23cab982426a968437cd731900cfeb2cab4a3b9cafedc2cede90380c79edca044" title="Text field.">ID3FN_TEXT</a>))
<a name="l00095"></a>00095       {
<a name="l00096"></a>00096         frame-&gt;<a class="code" href="class_i_d3___frame.html#a6491b36aee70776ed656896daa42ef80">GetField</a>(<a class="code" href="globals_8h.html#a23cab982426a968437cd731900cfeb2cab4a3b9cafedc2cede90380c79edca044" title="Text field.">ID3FN_TEXT</a>)-&gt;<a class="code" href="class_i_d3___field.html#a16387cf6c54df5432a0c048d6a931f03">Set</a>(text.c_str());
<a name="l00097"></a>00097       }
<a name="l00098"></a>00098       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (frame-&gt;<a class="code" href="class_i_d3___frame.html#ad5d20e40b233e124a9bd84c6a8947fee">Contains</a>(<a class="code" href="globals_8h.html#a23cab982426a968437cd731900cfeb2cabab371e3f25ac3376924280e298cf9f0" title="A URL.">ID3FN_URL</a>))
<a name="l00099"></a>00099       {
<a name="l00100"></a>00100         frame-&gt;<a class="code" href="class_i_d3___frame.html#a6491b36aee70776ed656896daa42ef80">GetField</a>(<a class="code" href="globals_8h.html#a23cab982426a968437cd731900cfeb2cabab371e3f25ac3376924280e298cf9f0" title="A URL.">ID3FN_URL</a>)-&gt;<a class="code" href="class_i_d3___field.html#a16387cf6c54df5432a0c048d6a931f03">Set</a>(text.c_str());
<a name="l00101"></a>00101       }
<a name="l00102"></a>00102       <span class="keywordflow">if</span> (frame-&gt;<a class="code" href="class_i_d3___frame.html#ad5d20e40b233e124a9bd84c6a8947fee">Contains</a>(<a class="code" href="globals_8h.html#a23cab982426a968437cd731900cfeb2caae0e0a0e19501463ffb19f355fb36768" title="Language field.">ID3FN_LANGUAGE</a>))
<a name="l00103"></a>00103       {
<a name="l00104"></a>00104         frame-&gt;<a class="code" href="class_i_d3___frame.html#a6491b36aee70776ed656896daa42ef80">GetField</a>(<a class="code" href="globals_8h.html#a23cab982426a968437cd731900cfeb2caae0e0a0e19501463ffb19f355fb36768" title="Language field.">ID3FN_LANGUAGE</a>)-&gt;<a class="code" href="class_i_d3___field.html#a16387cf6c54df5432a0c048d6a931f03">Set</a>(<span class="stringliteral">&quot;XXX&quot;</span>);
<a name="l00105"></a>00105       }
<a name="l00106"></a>00106       <span class="keywordflow">if</span> (frame-&gt;<a class="code" href="class_i_d3___frame.html#ad5d20e40b233e124a9bd84c6a8947fee">Contains</a>(<a class="code" href="globals_8h.html#a23cab982426a968437cd731900cfeb2ca6898b894ce725eb89b42dc6f4f9117e5" title="Description field.">ID3FN_DESCRIPTION</a>))
<a name="l00107"></a>00107       {
<a name="l00108"></a>00108         frame-&gt;<a class="code" href="class_i_d3___frame.html#a6491b36aee70776ed656896daa42ef80">GetField</a>(<a class="code" href="globals_8h.html#a23cab982426a968437cd731900cfeb2ca6898b894ce725eb89b42dc6f4f9117e5" title="Description field.">ID3FN_DESCRIPTION</a>)-&gt;<a class="code" href="class_i_d3___field.html#a16387cf6c54df5432a0c048d6a931f03">Set</a>(desc.c_str());
<a name="l00109"></a>00109       }
<a name="l00110"></a>00110     }
<a name="l00111"></a>00111     <span class="keywordflow">return</span> frame;
<a name="l00112"></a>00112   }
<a name="l00113"></a>00113 };
<a name="l00114"></a>00114   
<a name="l00115"></a><a class="code" href="namespacedami_1_1mm.html#a89e914b3a9c702961c3f5df58369e77a">00115</a> <span class="keywordtype">bool</span> <a class="code" href="namespacedami_1_1mm.html#a89e914b3a9c702961c3f5df58369e77a">mm::parse</a>(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>&amp; tag, <a class="code" href="class_i_d3___reader.html">ID3_Reader</a>&amp; rdr)
<a name="l00116"></a>00116 {
<a name="l00117"></a>00117   io::ExitTrigger et(rdr);
<a name="l00118"></a>00118   <a class="code" href="class_i_d3___reader.html#a83194ea4d4e04e81302b095e9aa2275a">ID3_Reader::pos_type</a> end = rdr.<a class="code" href="class_i_d3___reader.html#a232935e138e44ea49e5a289fb8d7ac94" title="Return the current position in the reader.">getCur</a>();
<a name="l00119"></a>00119   <span class="keywordflow">if</span> (end &lt; rdr.<a class="code" href="class_i_d3___reader.html#aeaf468ffe03c08731dcaf268fff3391b" title="Return the beginning position in the reader.">getBeg</a>() + 48)
<a name="l00120"></a>00120   {
<a name="l00121"></a>00121     ID3D_NOTICE( <span class="stringliteral">&quot;mm::parse: bailing, not enough bytes to parse, pos = &quot;</span> &lt;&lt; end );
<a name="l00122"></a>00122     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00123"></a>00123   }
<a name="l00124"></a>00124   
<a name="l00125"></a>00125   rdr.<a class="code" href="class_i_d3___reader.html#a1630f369cc7aa65a2279542715e9f483" title="Set the value of the current position for reading.">setCur</a>(end - 48);
<a name="l00126"></a>00126   String version;
<a name="l00127"></a>00127   
<a name="l00128"></a>00128   {
<a name="l00129"></a>00129     <span class="keywordflow">if</span> (io::readText(rdr, 32) != <span class="stringliteral">&quot;Brava Software Inc.             &quot;</span>)
<a name="l00130"></a>00130     {
<a name="l00131"></a>00131       ID3D_NOTICE( <span class="stringliteral">&quot;mm::parse: bailing, couldn&#39;t find footer&quot;</span> );
<a name="l00132"></a>00132       <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00133"></a>00133     }
<a name="l00134"></a>00134     
<a name="l00135"></a>00135     version = io::readText(rdr, 4);
<a name="l00136"></a>00136     <span class="keywordflow">if</span> (version.size() != 4 || 
<a name="l00137"></a>00137         !isdigit(version[0]) || version[1] != <span class="charliteral">&#39;.&#39;</span> ||
<a name="l00138"></a>00138         !isdigit(version[2]) || 
<a name="l00139"></a>00139         !isdigit(version[3]))
<a name="l00140"></a>00140     {
<a name="l00141"></a>00141       ID3D_WARNING( <span class="stringliteral">&quot;mm::parse: bailing, nonstandard version = &quot;</span> &lt;&lt; version );
<a name="l00142"></a>00142       <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00143"></a>00143     }
<a name="l00144"></a>00144   }
<a name="l00145"></a>00145     
<a name="l00146"></a>00146   <a class="code" href="class_i_d3___reader.html#a83194ea4d4e04e81302b095e9aa2275a">ID3_Reader::pos_type</a> beg = rdr.<a class="code" href="class_i_d3___reader.html#a1630f369cc7aa65a2279542715e9f483" title="Set the value of the current position for reading.">setCur</a>(end - 48);
<a name="l00147"></a>00147   et.setExitPos(beg);
<a name="l00148"></a>00148   <span class="keywordflow">if</span> (end &lt; 68)
<a name="l00149"></a>00149   {
<a name="l00150"></a>00150     ID3D_NOTICE( <span class="stringliteral">&quot;mm::parse: bailing, not enough bytes to parse offsets, pos = &quot;</span> &lt;&lt; end );
<a name="l00151"></a>00151     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00152"></a>00152   }
<a name="l00153"></a>00153   rdr.<a class="code" href="class_i_d3___reader.html#a1630f369cc7aa65a2279542715e9f483" title="Set the value of the current position for reading.">setCur</a>(end - 68);
<a name="l00154"></a>00154     
<a name="l00155"></a>00155   io::WindowedReader dataWindow(rdr);
<a name="l00156"></a>00156   dataWindow.setEnd(rdr.<a class="code" href="class_i_d3___reader.html#a232935e138e44ea49e5a289fb8d7ac94" title="Return the current position in the reader.">getCur</a>());
<a name="l00157"></a>00157 
<a name="l00158"></a>00158   uint32 offsets[5];
<a name="l00159"></a>00159     
<a name="l00160"></a>00160   io::WindowedReader offsetWindow(rdr, 20);
<a name="l00161"></a>00161   <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; 5; ++i)
<a name="l00162"></a>00162   {
<a name="l00163"></a>00163     offsets[i] = io::readLENumber(rdr, <span class="keyword">sizeof</span>(uint32));
<a name="l00164"></a>00164   }
<a name="l00165"></a>00165 
<a name="l00166"></a>00166   <span class="keywordtype">size_t</span> metadataSize = 0;
<a name="l00167"></a>00167   <span class="keywordflow">if</span> (version &lt;= <span class="stringliteral">&quot;3.00&quot;</span>)
<a name="l00168"></a>00168   {
<a name="l00169"></a>00169     <span class="comment">// All MusicMatch tags up to and including version 3.0 had metadata </span>
<a name="l00170"></a>00170     <span class="comment">// sections exactly 7868 bytes in length.</span>
<a name="l00171"></a>00171     metadataSize = 7868;
<a name="l00172"></a>00172   }
<a name="l00173"></a>00173   <span class="keywordflow">else</span>
<a name="l00174"></a>00174   {
<a name="l00175"></a>00175     <span class="comment">// MusicMatch tags after version 3.0 had three possible lengths for their</span>
<a name="l00176"></a>00176     <span class="comment">// metadata sections.  We can determine which it was by searching for</span>
<a name="l00177"></a>00177     <span class="comment">// the version section signature that should precede the metadata section</span>
<a name="l00178"></a>00178     <span class="comment">// by exactly 256 bytes.</span>
<a name="l00179"></a>00179     <span class="keywordtype">size_t</span> possibleSizes[] = { 8132, 8004, 7936 };
<a name="l00180"></a>00180       
<a name="l00181"></a>00181     <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; <span class="keyword">sizeof</span>(possibleSizes)/<span class="keyword">sizeof</span>(<span class="keywordtype">size_t</span>); ++i)
<a name="l00182"></a>00182     {
<a name="l00183"></a>00183       dataWindow.setCur(dataWindow.getEnd());
<a name="l00184"></a>00184         
<a name="l00185"></a>00185       <span class="comment">// Our offset will be exactly 256 bytes prior to our potential metadata</span>
<a name="l00186"></a>00186       <span class="comment">// section</span>
<a name="l00187"></a>00187       <span class="keywordtype">size_t</span> offset = possibleSizes[i] + 256;
<a name="l00188"></a>00188       <span class="keywordflow">if</span> (dataWindow.getCur() &lt; offset)
<a name="l00189"></a>00189       {
<a name="l00190"></a>00190         <span class="comment">// if our filesize is less than the offset, then it can&#39;t possibly</span>
<a name="l00191"></a>00191         <span class="comment">// be the correct offset, so try again.</span>
<a name="l00192"></a>00192         <span class="keywordflow">continue</span>;
<a name="l00193"></a>00193       }
<a name="l00194"></a>00194       dataWindow.setCur(dataWindow.getCur() - offset);
<a name="l00195"></a>00195         
<a name="l00196"></a>00196       <span class="comment">// now read in the signature to see if it&#39;s a match</span>
<a name="l00197"></a>00197       <span class="keywordflow">if</span> (io::readText(dataWindow, 8) == <span class="stringliteral">&quot;18273645&quot;</span>)
<a name="l00198"></a>00198       {
<a name="l00199"></a>00199         metadataSize = possibleSizes[i];
<a name="l00200"></a>00200         <span class="keywordflow">break</span>;
<a name="l00201"></a>00201       }
<a name="l00202"></a>00202     }
<a name="l00203"></a>00203   }
<a name="l00204"></a>00204   <span class="keywordflow">if</span> (0 == metadataSize)
<a name="l00205"></a>00205   {
<a name="l00206"></a>00206     <span class="comment">// if we didn&#39;t establish a size for the metadata, then something is</span>
<a name="l00207"></a>00207     <span class="comment">// wrong.  probably should log this.</span>
<a name="l00208"></a>00208     ID3D_WARNING( <span class="stringliteral">&quot;mm::parse: bailing, couldn&#39;t find meta data signature, end = &quot;</span> &lt;&lt; end );
<a name="l00209"></a>00209     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00210"></a>00210   }
<a name="l00211"></a>00211     
<a name="l00212"></a>00212   <span class="comment">// parse the offset pointers to determine the actual sizes of all the </span>
<a name="l00213"></a>00213   <span class="comment">// sections</span>
<a name="l00214"></a>00214   <span class="keywordtype">size_t</span> sectionSizes[5];
<a name="l00215"></a>00215   <span class="keywordtype">size_t</span> tagSize = metadataSize;
<a name="l00216"></a>00216     
<a name="l00217"></a>00217   <span class="comment">// we already know the size of the last section</span>
<a name="l00218"></a>00218   sectionSizes[4] = metadataSize;
<a name="l00219"></a>00219     
<a name="l00220"></a>00220   <span class="keywordtype">size_t</span> lastOffset = 0;
<a name="l00221"></a>00221   <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 5; i++)
<a name="l00222"></a>00222   {
<a name="l00223"></a>00223     <span class="keywordtype">size_t</span> thisOffset = offsets[i];
<a name="l00224"></a>00224     <span class="comment">//ASSERT(thisOffset &gt; lastOffset);</span>
<a name="l00225"></a>00225     <span class="keywordflow">if</span> (i &gt; 0)
<a name="l00226"></a>00226     {
<a name="l00227"></a>00227       <span class="keywordtype">size_t</span> sectionSize = thisOffset - lastOffset;
<a name="l00228"></a>00228       sectionSizes[i-1] = sectionSize;
<a name="l00229"></a>00229       tagSize += sectionSize;
<a name="l00230"></a>00230     }
<a name="l00231"></a>00231     lastOffset = thisOffset;
<a name="l00232"></a>00232   }
<a name="l00233"></a>00233     
<a name="l00234"></a>00234   <span class="comment">// now check to see that our tag size is reasonable</span>
<a name="l00235"></a>00235   <span class="keywordflow">if</span> (dataWindow.getEnd() &lt; tagSize)
<a name="l00236"></a>00236   {
<a name="l00237"></a>00237     <span class="comment">// Ack!  The tag size doesn&#39;t jive with the tag&#39;s ending position in</span>
<a name="l00238"></a>00238     <span class="comment">// the file.  Bail!</span>
<a name="l00239"></a>00239     ID3D_WARNING( <span class="stringliteral">&quot;mm::parse: bailing, tag size is too big, tag size = &quot;</span> &lt;&lt; tagSize &lt;&lt; <span class="stringliteral">&quot;, end = &quot;</span> &lt;&lt; end );
<a name="l00240"></a>00240     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00241"></a>00241   }
<a name="l00242"></a>00242 
<a name="l00243"></a>00243   dataWindow.setBeg(dataWindow.getEnd() - tagSize);
<a name="l00244"></a>00244   dataWindow.setCur(dataWindow.getBeg());
<a name="l00245"></a>00245     
<a name="l00246"></a>00246   <span class="comment">// Now calculate the adjusted offsets</span>
<a name="l00247"></a>00247   offsets[0] = dataWindow.getBeg();
<a name="l00248"></a>00248   <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; 4; ++i)
<a name="l00249"></a>00249   {
<a name="l00250"></a>00250     offsets[i+1] = offsets[i] + sectionSizes[i];
<a name="l00251"></a>00251   }
<a name="l00252"></a>00252     
<a name="l00253"></a>00253   <span class="comment">// now check for a tag header and adjust the tag_beg pointer appropriately</span>
<a name="l00254"></a>00254   <span class="keywordflow">if</span> (dataWindow.getBeg() &gt;= 256)
<a name="l00255"></a>00255   {
<a name="l00256"></a>00256     rdr.<a class="code" href="class_i_d3___reader.html#a1630f369cc7aa65a2279542715e9f483" title="Set the value of the current position for reading.">setCur</a>(dataWindow.getBeg() - 256);
<a name="l00257"></a>00257     <span class="keywordflow">if</span> (io::readText(rdr, 8) == <span class="stringliteral">&quot;18273645&quot;</span>)
<a name="l00258"></a>00258     {
<a name="l00259"></a>00259       et.setExitPos(rdr.<a class="code" href="class_i_d3___reader.html#a232935e138e44ea49e5a289fb8d7ac94" title="Return the current position in the reader.">getCur</a>() - 8);
<a name="l00260"></a>00260     }
<a name="l00261"></a>00261     <span class="keywordflow">else</span>
<a name="l00262"></a>00262     {
<a name="l00263"></a>00263       et.setExitPos(dataWindow.getBeg());
<a name="l00264"></a>00264     }
<a name="l00265"></a>00265     dataWindow.setCur(dataWindow.getBeg());
<a name="l00266"></a>00266   }
<a name="l00267"></a>00267     
<a name="l00268"></a>00268   <span class="comment">// Now parse the various sections...</span>
<a name="l00269"></a>00269     
<a name="l00270"></a>00270   <span class="comment">// Parse the image extension at offset 0</span>
<a name="l00271"></a>00271   dataWindow.setCur(offsets[0]);
<a name="l00272"></a>00272   String imgExt = io::readTrailingSpaces(dataWindow, 4);
<a name="l00273"></a>00273     
<a name="l00274"></a>00274   <span class="comment">// Parse the image binary at offset 1</span>
<a name="l00275"></a>00275   dataWindow.setCur(offsets[1]);
<a name="l00276"></a>00276   uint32 imgSize = io::readLENumber(dataWindow, 4);
<a name="l00277"></a>00277   <span class="keywordflow">if</span> (imgSize == 0)
<a name="l00278"></a>00278   {
<a name="l00279"></a>00279     <span class="comment">// no image binary.  don&#39;t do anything.</span>
<a name="l00280"></a>00280   }
<a name="l00281"></a>00281   <span class="keywordflow">else</span>
<a name="l00282"></a>00282   {
<a name="l00283"></a>00283     io::WindowedReader imgWindow(dataWindow, imgSize);
<a name="l00284"></a>00284     <span class="keywordflow">if</span> (imgWindow.getEnd() &lt; imgWindow.getBeg() + imgSize)
<a name="l00285"></a>00285     {
<a name="l00286"></a>00286       <span class="comment">// Ack!  The image size given extends beyond the next offset!  This is </span>
<a name="l00287"></a>00287       <span class="comment">// not good...  log?</span>
<a name="l00288"></a>00288     }
<a name="l00289"></a>00289     <span class="keywordflow">else</span>
<a name="l00290"></a>00290     {
<a name="l00291"></a>00291       BString imgData = io::readAllBinary(imgWindow);
<a name="l00292"></a>00292       <a class="code" href="class_i_d3___frame.html" title="The representative class of an id3v2 frame.">ID3_Frame</a>* frame = <span class="keyword">new</span> <a class="code" href="class_i_d3___frame.html" title="The representative class of an id3v2 frame.">ID3_Frame</a>(<a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aacdd599f7b0f4a6081cf714a7232acf71" title="Attached picture.">ID3FID_PICTURE</a>);
<a name="l00293"></a>00293       <span class="keywordflow">if</span> (frame)
<a name="l00294"></a>00294       {
<a name="l00295"></a>00295         String mimetype(<span class="stringliteral">&quot;image/&quot;</span>);
<a name="l00296"></a>00296         mimetype += imgExt;
<a name="l00297"></a>00297         frame-&gt;<a class="code" href="class_i_d3___frame.html#a6491b36aee70776ed656896daa42ef80">GetField</a>(<a class="code" href="globals_8h.html#a23cab982426a968437cd731900cfeb2ca0500bcc349631be7bf2c67e1a0033169" title="Mimetype field.">ID3FN_MIMETYPE</a>)-&gt;<a class="code" href="class_i_d3___field.html#a16387cf6c54df5432a0c048d6a931f03">Set</a>(mimetype.c_str());
<a name="l00298"></a>00298         frame-&gt;<a class="code" href="class_i_d3___frame.html#a6491b36aee70776ed656896daa42ef80">GetField</a>(<a class="code" href="globals_8h.html#a23cab982426a968437cd731900cfeb2ca6a302fcdbf395861bc6d0f9878d6cffc" title="Image format field.">ID3FN_IMAGEFORMAT</a>)-&gt;<a class="code" href="class_i_d3___field.html#a16387cf6c54df5432a0c048d6a931f03">Set</a>(<span class="stringliteral">&quot;&quot;</span>);
<a name="l00299"></a>00299         frame-&gt;<a class="code" href="class_i_d3___frame.html#a6491b36aee70776ed656896daa42ef80">GetField</a>(<a class="code" href="globals_8h.html#a23cab982426a968437cd731900cfeb2cacf3efb9534c1200db2f003f5837bb1ad" title="Picture type field.">ID3FN_PICTURETYPE</a>)-&gt;<a class="code" href="class_i_d3___field.html#a16387cf6c54df5432a0c048d6a931f03">Set</a>(static_cast&lt;unsigned int&gt;(0));
<a name="l00300"></a>00300         frame-&gt;<a class="code" href="class_i_d3___frame.html#a6491b36aee70776ed656896daa42ef80">GetField</a>(<a class="code" href="globals_8h.html#a23cab982426a968437cd731900cfeb2ca6898b894ce725eb89b42dc6f4f9117e5" title="Description field.">ID3FN_DESCRIPTION</a>)-&gt;<a class="code" href="class_i_d3___field.html#a16387cf6c54df5432a0c048d6a931f03">Set</a>(<span class="stringliteral">&quot;&quot;</span>);
<a name="l00301"></a>00301         frame-&gt;<a class="code" href="class_i_d3___frame.html#a6491b36aee70776ed656896daa42ef80">GetField</a>(<a class="code" href="globals_8h.html#a23cab982426a968437cd731900cfeb2cabd5e1e87686d7a1fc9ba291023e9ccc0" title="Data field.">ID3FN_DATA</a>)-&gt;<a class="code" href="class_i_d3___field.html#a16387cf6c54df5432a0c048d6a931f03">Set</a>(reinterpret_cast&lt;const uchar*&gt;(imgData.data()), imgData.size());
<a name="l00302"></a>00302         tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(frame);
<a name="l00303"></a>00303       }
<a name="l00304"></a>00304     }
<a name="l00305"></a>00305   }
<a name="l00306"></a>00306     
<a name="l00307"></a>00307   <span class="comment">//file.seekg(offsets[2]);</span>
<a name="l00308"></a>00308   <span class="comment">//file.seekg(offsets[3]);</span>
<a name="l00309"></a>00309   dataWindow.setCur(offsets[4]);
<a name="l00310"></a>00310     
<a name="l00311"></a>00311   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aaf7e8a066a7c9debd6dfd742cfb5a080b" title="Title/songname/content description.">ID3FID_TITLE</a>));
<a name="l00312"></a>00312   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aa8b1cc72205175363486074e6e56b072a" title="Album/Movie/Show title.">ID3FID_ALBUM</a>));
<a name="l00313"></a>00313   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aa01ed8e673c6a4b5b55cca106cd35a961" title="Lead performer(s)/Soloist(s)">ID3FID_LEADARTIST</a>));
<a name="l00314"></a>00314   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aa040eba7064ed2c884233113486dbdd54" title="Content type.">ID3FID_CONTENTTYPE</a>));
<a name="l00315"></a>00315   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aa8df694633e118d601850e497b132de0f" title="Comments.">ID3FID_COMMENT</a>, <span class="stringliteral">&quot;MusicMatch_Tempo&quot;</span>));
<a name="l00316"></a>00316   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aa8df694633e118d601850e497b132de0f" title="Comments.">ID3FID_COMMENT</a>, <span class="stringliteral">&quot;MusicMatch_Mood&quot;</span>));
<a name="l00317"></a>00317   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aa8df694633e118d601850e497b132de0f" title="Comments.">ID3FID_COMMENT</a>, <span class="stringliteral">&quot;MusicMatch_Situation&quot;</span>));
<a name="l00318"></a>00318   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aa8df694633e118d601850e497b132de0f" title="Comments.">ID3FID_COMMENT</a>, <span class="stringliteral">&quot;MusicMatch_Preference&quot;</span>));
<a name="l00319"></a>00319   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aaa2047f42426480aac38e6e10d49918aa" title="Length.">ID3FID_SONGLEN</a>));
<a name="l00320"></a>00320     
<a name="l00321"></a>00321   <span class="comment">// The next 12 bytes can be ignored.  The first 8 represent the </span>
<a name="l00322"></a>00322   <span class="comment">// creation date as a 64 bit floating point number.  The last 4 are</span>
<a name="l00323"></a>00323   <span class="comment">// for a play counter.</span>
<a name="l00324"></a>00324   dataWindow.skipChars(12);
<a name="l00325"></a>00325     
<a name="l00326"></a>00326   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aa8df694633e118d601850e497b132de0f" title="Comments.">ID3FID_COMMENT</a>, <span class="stringliteral">&quot;MusicMatch_Path&quot;</span>));
<a name="l00327"></a>00327   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aa8df694633e118d601850e497b132de0f" title="Comments.">ID3FID_COMMENT</a>, <span class="stringliteral">&quot;MusicMatch_Serial&quot;</span>));
<a name="l00328"></a>00328     
<a name="l00329"></a>00329   <span class="comment">// 2 bytes for track</span>
<a name="l00330"></a>00330   uint32 trkNum = io::readLENumber(dataWindow, 2);
<a name="l00331"></a>00331   <span class="keywordflow">if</span> (trkNum &gt; 0)
<a name="l00332"></a>00332   {
<a name="l00333"></a>00333     String trkStr = toString(trkNum);
<a name="l00334"></a>00334     <a class="code" href="class_i_d3___frame.html" title="The representative class of an id3v2 frame.">ID3_Frame</a>* frame = <span class="keyword">new</span> <a class="code" href="class_i_d3___frame.html" title="The representative class of an id3v2 frame.">ID3_Frame</a>(<a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aace6669093c3bc849a75098d59f504759" title="Track number/Position in set.">ID3FID_TRACKNUM</a>);
<a name="l00335"></a>00335     <span class="keywordflow">if</span> (frame)
<a name="l00336"></a>00336     {
<a name="l00337"></a>00337       frame-&gt;<a class="code" href="class_i_d3___frame.html#a6491b36aee70776ed656896daa42ef80">GetField</a>(<a class="code" href="globals_8h.html#a23cab982426a968437cd731900cfeb2cab4a3b9cafedc2cede90380c79edca044" title="Text field.">ID3FN_TEXT</a>)-&gt;<a class="code" href="class_i_d3___field.html#a16387cf6c54df5432a0c048d6a931f03">Set</a>(trkStr.c_str());
<a name="l00338"></a>00338       tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(frame);
<a name="l00339"></a>00339     }
<a name="l00340"></a>00340   }
<a name="l00341"></a>00341     
<a name="l00342"></a>00342   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aa8df694633e118d601850e497b132de0f" title="Comments.">ID3FID_COMMENT</a>, <span class="stringliteral">&quot;MusicMatch_Notes&quot;</span>));
<a name="l00343"></a>00343   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aa8df694633e118d601850e497b132de0f" title="Comments.">ID3FID_COMMENT</a>, <span class="stringliteral">&quot;MusicMatch_Bio&quot;</span>));
<a name="l00344"></a>00344   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aada871da61c6d5e3aac17c3a0c833baea" title="Unsynchronized lyric/text transcription.">ID3FID_UNSYNCEDLYRICS</a>));
<a name="l00345"></a>00345   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aa462644eb93ef4e225ca44998ac09b2c7" title="Official artist/performer webpage.">ID3FID_WWWARTIST</a>));
<a name="l00346"></a>00346   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aabd590e94ed2a4917457e097be62a955e" title="Commercial information.">ID3FID_WWWCOMMERCIALINFO</a>));
<a name="l00347"></a>00347   tag.<a class="code" href="class_i_d3___tag_impl.html#adaf0656b5f9424cbefb336e48c711398">AttachFrame</a>(readTextFrame(dataWindow, <a class="code" href="globals_8h.html#a78f454bf66f16b1e1c9f8e37bda9ab8aa8df694633e118d601850e497b132de0f" title="Comments.">ID3FID_COMMENT</a>, <span class="stringliteral">&quot;MusicMatch_ArtistEmail&quot;</span>));
<a name="l00348"></a>00348     
<a name="l00349"></a>00349   <span class="comment">// email?</span>
<a name="l00350"></a>00350 
<a name="l00351"></a>00351   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00352"></a>00352 }
<a name="l00353"></a>00353 
</pre></div></div>
</div>
<hr size="1"><address style="text-align: right;"><small>
Generated for id3lib by&nbsp;<a href="http://www.doxygen.org/
index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a>
1.7.3</small></address></body></html>