Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 2c9d30f3cf217a6cae41860ebc0d6704 > files > 118

libid3lib3.8_0-devel-3.8.0-0.pre2.1.1mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>src/frame_parse.cpp Source File</title>
<link href="id3lib.css" rel="stylesheet" type="text/css">
</head><body bgcolor="#ffffff">
<!-- Generated by Doxygen 1.2.12 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center>
<hr><h1>src/frame_parse.cpp</h1><a href="frame__parse_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// $Id: frame_parse.cpp,v 1.31 2001/08/05 21:18:26 abscess Exp $</font>
00002 
00003 <font class="comment">// id3lib: a C++ library for creating and manipulating id3v1/v2 tags</font>
00004 <font class="comment">// Copyright 1999, 2000  Scott Thomas Haug</font>
00005 
00006 <font class="comment">// This library is free software; you can redistribute it and/or modify it</font>
00007 <font class="comment">// under the terms of the GNU Library General Public License as published by</font>
00008 <font class="comment">// the Free Software Foundation; either version 2 of the License, or (at your</font>
00009 <font class="comment">// option) any later version.</font>
00010 <font class="comment">//</font>
00011 <font class="comment">// This library is distributed in the hope that it will be useful, but WITHOUT</font>
00012 <font class="comment">// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or</font>
00013 <font class="comment">// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public</font>
00014 <font class="comment">// License for more details.</font>
00015 <font class="comment">//</font>
00016 <font class="comment">// You should have received a copy of the GNU Library General Public License</font>
00017 <font class="comment">// along with this library; if not, write to the Free Software Foundation,</font>
00018 <font class="comment">// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</font>
00019 
00020 <font class="comment">// The id3lib authors encourage improvements and optimisations to be sent to</font>
00021 <font class="comment">// the id3lib coordinator.  Please see the README file for details on where to</font>
00022 <font class="comment">// send such submissions.  See the AUTHORS file for a list of people who have</font>
00023 <font class="comment">// contributed to id3lib.  See the ChangeLog file for a list of changes to</font>
00024 <font class="comment">// id3lib.  These files are distributed with id3lib at</font>
00025 <font class="comment">// http://download.sourceforge.net/id3lib/</font>
00026 
00027 <font class="preprocessor">#if defined HAVE_CONFIG_H</font>
00028 <font class="preprocessor"></font><font class="preprocessor">#include &lt;config.h&gt;</font>
00029 <font class="preprocessor">#endif</font>
00030 <font class="preprocessor"></font>
00031 
00032 
00033 <font class="preprocessor">#include "<a class="code" href="frame__impl_8h.html">frame_impl.h</a>"</font>
00034 <font class="preprocessor">#include "utils.h"</font>
00035 <font class="preprocessor">#include "io_decorators.h"</font>
00036 
00037 <font class="keyword">using</font> <font class="keyword">namespace </font>dami;
00038 
00039 <font class="keyword">namespace</font>
00040 <font class="keyword"></font>{
00041   <font class="keywordtype">bool</font> parseFields(<a class="code" href="class_i_d3___reader.html">ID3_Reader</a>&amp; rdr, <a class="code" href="class_i_d3___frame_impl.html">ID3_FrameImpl</a>&amp; frame)
00042   {
00043     io::ExitTrigger et(rdr);
00044     <a class="code" href="globals_8h.html#a214">ID3_TextEnc</a> enc = <a class="code" href="globals_8h.html#a214a47">ID3TE_ASCII</a>;  <font class="comment">// set the default encoding </font>
00045     <a class="code" href="globals_8h.html#a216">ID3_V2Spec</a> spec = frame.<a class="code" href="class_i_d3___frame_impl.html#a18">GetSpec</a>(); 
00046     <font class="comment">// parse the frame's fields  </font>
00047     ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): num_fields = "</font> &lt;&lt; 
00048                  frame.<a class="code" href="class_i_d3___frame_impl.html#a8">NumFields</a>() );
00049     <font class="keywordflow">for</font> (<a class="code" href="class_i_d3___frame_impl.html#s0">ID3_FrameImpl::iterator</a> fi = frame.<a class="code" href="class_i_d3___frame_impl.html#a26">begin</a>(); fi != frame.<a class="code" href="class_i_d3___frame_impl.html#a27">end</a>(); ++fi)
00050     {
00051       <a class="code" href="class_i_d3___field.html">ID3_Field</a>* fp = *fi;
00052 
00053       <font class="keywordflow">if</font> (rdr.<a class="code" href="class_i_d3___reader.html#a11">atEnd</a>())
00054       { 
00055         <font class="comment">// there's no remaining data to parse! </font>
00056         ID3D_WARNING( <font class="stringliteral">"ID3_FrameImpl::Parse(): out of data at postion "</font> &lt;&lt;
00057                       rdr.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() );
00058         <font class="keywordflow">if</font>(fp-&gt;<a class="code" href="class_i_d3___field.html#a29">GetType</a>() == <a class="code" href="globals_8h.html#a222a189">ID3FTY_TEXTSTRING</a>)  <font class="comment">//correct handling of winamp-esque empty frames</font>
00059                 {
00060                         <font class="comment">// Exit the loop (don't just return true).</font>
00061                         <font class="comment">// This will set the current "pointer" of the reader to the correct value</font>
00062                         <font class="keywordflow">break</font>;
00063                 }
00064 
00065         <font class="keywordflow">return</font> <font class="keyword">false</font>;
00066       } 
00067       
00068       <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == fp)
00069       {
00070         <font class="comment">// Ack!  Why is the field NULL?  Log this...</font>
00071         ID3D_WARNING( <font class="stringliteral">"ID3_FrameImpl::Parse(): field is null"</font> );
00072         <font class="keywordflow">continue</font>;
00073       }
00074       
00075       <font class="keywordflow">if</font> (!fp-&gt;<a class="code" href="class_i_d3___field.html#a27">InScope</a>(spec)) 
00076       {
00077         ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): field is not in scope"</font> );
00078         <font class="comment">// continue with the rest of the fields</font>
00079         <font class="keywordflow">continue</font>; 
00080       }
00081       
00082       ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): setting enc to "</font> &lt;&lt; enc );
00083       fp-&gt;<a class="code" href="class_i_d3___field.html#a30">SetEncoding</a>(enc);
00084       <a class="code" href="class_i_d3___reader.html#s2">ID3_Reader::pos_type</a> beg = rdr.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>();
00085       et.setExitPos(beg);
00086       ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): parsing field, cur = "</font> &lt;&lt; beg );
00087       ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): parsing field, end = "</font> &lt;&lt; 
00088                    rdr.<a class="code" href="class_i_d3___reader.html#a2">getEnd</a>() );
00089       <font class="keywordflow">if</font> (!fp-&gt;<a class="code" href="class_i_d3___field.html#a34">Parse</a>(rdr) || rdr.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() == beg) 
00090       { 
00091         <font class="comment">// nothing to parse!  ack!  parse error... </font>
00092         ID3D_WARNING( <font class="stringliteral">"ID3_FrameImpl::Parse(): no data parsed, bad parse"</font> );
00093         <font class="keywordflow">return</font> <font class="keyword">false</font>;
00094       }
00095       
00096       <font class="keywordflow">if</font> (fp-&gt;<a class="code" href="class_i_d3___field.html#a28">GetID</a>() == <a class="code" href="globals_8h.html#a218a71">ID3FN_TEXTENC</a>)  
00097       {
00098         enc = static_cast&lt;ID3_TextEnc&gt;(fp-&gt;<a class="code" href="class_i_d3___field.html#a6">Get</a>());  
00099         ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): found encoding = "</font> &lt;&lt; enc );
00100       }
00101     }
00102     et.setExitPos(rdr.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>());
00103     
00104     <font class="keywordflow">return</font> <font class="keyword">true</font>;
00105   }
00106 };
00107 
<a name="l00108"></a><a class="code" href="class_i_d3___frame_impl.html#a13">00108</a> <font class="keywordtype">bool</font> <a class="code" href="class_i_d3___frame_impl.html#a13">ID3_FrameImpl::Parse</a>(<a class="code" href="class_i_d3___reader.html">ID3_Reader</a>&amp; reader) 
00109 { 
00110   io::ExitTrigger et(reader);
00111   ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): reader.getBeg() = "</font> &lt;&lt; reader.<a class="code" href="class_i_d3___reader.html#a1">getBeg</a>() );
00112   ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): reader.getCur() = "</font> &lt;&lt; reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() );
00113   ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): reader.getEnd() = "</font> &lt;&lt; reader.<a class="code" href="class_i_d3___reader.html#a2">getEnd</a>() );
00114   <a class="code" href="class_i_d3___reader.html#s2">ID3_Reader::pos_type</a> beg = reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>();
00115 
00116   <font class="keywordflow">if</font> (!_hdr.<a class="code" href="class_i_d3___frame_header.html#a3">Parse</a>(reader) || reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() == beg)  
00117   { 
00118     ID3D_WARNING( <font class="stringliteral">"ID3_FrameImpl::Parse(): no header to parse"</font> );
00119     <font class="keywordflow">return</font> <font class="keyword">false</font>; 
00120   }
00121   ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): after hdr, getCur() = "</font> &lt;&lt; reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() );
00122   ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): found frame! id = "</font> &lt;&lt; _hdr.<a class="code" href="class_i_d3___frame_header.html#a7">GetTextID</a>() );
00123 
00124   <font class="comment">// data is the part of the frame buffer that appears after the header  </font>
00125   <font class="keyword">const</font> size_t dataSize = _hdr.<a class="code" href="class_i_d3___header.html#a5">GetDataSize</a>();
00126   ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): dataSize = "</font> &lt;&lt; dataSize );
00127   <font class="keywordflow">if</font> (reader.<a class="code" href="class_i_d3___reader.html#a2">getEnd</a>() &lt; beg + dataSize)
00128   {
00129     ID3D_WARNING( <font class="stringliteral">"ID3_FrameImpl::Parse(): not enough data to parse frame"</font> );
00130     <font class="keywordflow">return</font> <font class="keyword">false</font>;
00131   }
00132   io::WindowedReader wr(reader, dataSize);
00133   ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): window getBeg() = "</font> &lt;&lt; wr.getBeg() );
00134   ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): window getCur() = "</font> &lt;&lt; wr.getCur() );
00135   ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): window getEnd() = "</font> &lt;&lt; wr.getEnd() );
00136   
00137   <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> origSize = 0;
00138   <font class="keywordflow">if</font> (_hdr.<a class="code" href="class_i_d3___frame_header.html#a14">GetCompression</a>())
00139   {
00140     origSize = io::readBENumber(reader, <font class="keyword">sizeof</font>(<a class="code" href="sized__types_8h.html#a4">uint32</a>));
00141     ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): frame is compressed, origSize = "</font> &lt;&lt; origSize );
00142   }
00143 
00144   <font class="keywordflow">if</font> (_hdr.<a class="code" href="class_i_d3___frame_header.html#a15">GetEncryption</a>())
00145   {
00146     <font class="keywordtype">char</font> ch = wr.readChar();
00147     this-&gt;<a class="code" href="class_i_d3___frame_impl.html#a22">SetEncryptionID</a>(ch);
00148     ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): frame is encrypted, encryption_id = "</font> &lt;&lt; (<font class="keywordtype">int</font>) ch );
00149   }
00150 
00151   <font class="keywordflow">if</font> (_hdr.<a class="code" href="class_i_d3___frame_header.html#a16">GetGrouping</a>())
00152   {
00153     <font class="keywordtype">char</font> ch = wr.readChar();
00154     this-&gt;<a class="code" href="class_i_d3___frame_impl.html#a24">SetGroupingID</a>(ch);
00155     ID3D_NOTICE( <font class="stringliteral">"ID3_FrameImpl::Parse(): frame is encrypted, grouping_id = "</font> &lt;&lt; (<font class="keywordtype">int</font>) ch );
00156   }
00157 
00158   <font class="comment">// set the type of frame based on the parsed header  </font>
00159   this-&gt;<a class="code" href="class_i_d3___frame_impl.html#b1">_ClearFields</a>(); 
00160   this-&gt;<a class="code" href="class_i_d3___frame_impl.html#b2">_InitFields</a>(); 
00161 
00162   <font class="keywordtype">bool</font> success = <font class="keyword">false</font>;
00163   <font class="comment">// expand out the data if it's compressed </font>
00164   <font class="keywordflow">if</font> (!_hdr.<a class="code" href="class_i_d3___frame_header.html#a14">GetCompression</a>())
00165   {
00166     success = parseFields(wr, *<font class="keyword">this</font>);
00167   }
00168   <font class="keywordflow">else</font>
00169   {
00170     io::CompressedReader csr(wr, origSize);
00171     success = parseFields(csr, *<font class="keyword">this</font>);
00172   }
00173   et.setExitPos(wr.getCur());
00174 
00175   _changed = <font class="keyword">false</font>;
00176   <font class="keywordflow">return</font> <font class="keyword">true</font>;
00177 } 
</pre></div><hr><address><small>Generated on Thu Jan 3 07:35:55 2002 for id3lib by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.gif" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.12 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>,
 &copy;&nbsp;1997-2001</small></address>
</body>
</html>