⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filters_8cpp-source.html

📁 Crypto++是一个非常强大的密码学库,主要是功能全
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<!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>Crypto++: filters.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.2 --><div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Compound&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Compound&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div><h1>filters.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// filters.cpp - written and placed in the public domain by Wei Dai</span>00002 00003 <span class="preprocessor">#include "pch.h"</span>00004 00005 <span class="preprocessor">#ifndef CRYPTOPP_IMPORTS</span>00006 <span class="preprocessor"></span>00007 <span class="preprocessor">#include "filters.h"</span>00008 <span class="preprocessor">#include "mqueue.h"</span>00009 <span class="preprocessor">#include "fltrimpl.h"</span>00010 <span class="preprocessor">#include "argnames.h"</span>00011 <span class="preprocessor">#include &lt;memory&gt;</span>00012 <span class="preprocessor">#include &lt;functional&gt;</span>00013 00014 NAMESPACE_BEGIN(CryptoPP)00015 00016 Filter::Filter(<a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *attachment)00017         : m_attachment(attachment), m_continueAt(0)00018 {00019 }00020 00021 <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> * Filter::NewDefaultAttachment()<span class="keyword"> const</span>00022 <span class="keyword"></span>{00023         <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="class_message_queue.html">MessageQueue</a>;00024 }00025 <a name="l00026"></a><a class="code" href="class_filter.html#_zlib_decompressora8">00026</a> <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> * <a class="code" href="class_filter.html#_zlib_decompressora8">Filter::AttachedTransformation</a>()00027 {00028         <span class="keywordflow">if</span> (m_attachment.get() == NULL)00029                 m_attachment.reset(NewDefaultAttachment());00030         <span class="keywordflow">return</span> m_attachment.get();00031 }00032 00033 <span class="keyword">const</span> <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *<a class="code" href="class_filter.html#_zlib_decompressora8">Filter::AttachedTransformation</a>()<span class="keyword"> const</span>00034 <span class="keyword"></span>{00035         <span class="keywordflow">if</span> (m_attachment.get() == NULL)00036                 const_cast&lt;Filter *&gt;(<span class="keyword">this</span>)-&gt;m_attachment.reset(NewDefaultAttachment());00037         <span class="keywordflow">return</span> m_attachment.get();00038 }00039 <a name="l00040"></a><a class="code" href="class_filter.html#_zlib_decompressora10">00040</a> <span class="keywordtype">void</span> <a class="code" href="class_filter.html#_zlib_decompressora10">Filter::Detach</a>(<a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *newOut)00041 {00042         m_attachment.reset(newOut);00043         NotifyAttachmentChange();00044 }00045 00046 <span class="keywordtype">void</span> Filter::Insert(<a class="code" href="class_filter.html">Filter</a> *filter)00047 {00048         filter-&gt;<a class="code" href="class_filter.html#_filterr0">m_attachment</a>.reset(m_attachment.release());00049         m_attachment.reset(filter);00050         NotifyAttachmentChange();00051 }00052 00053 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Filter::CopyRangeTo2(<a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> &amp;target, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> &amp;begin, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> end, <span class="keyword">const</span> std::string &amp;channel, <span class="keywordtype">bool</span> blocking)<span class="keyword"> const</span>00054 <span class="keyword"></span>{00055         <span class="keywordflow">return</span> <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_storez11_1">CopyRangeTo2</a>(target, begin, end, channel, blocking);00056 }00057 <a name="l00058"></a><a class="code" href="class_filter.html#_zlib_decompressora11">00058</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_filter.html#_zlib_decompressora11">Filter::TransferTo2</a>(<a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> &amp;target, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> &amp;transferBytes, <span class="keyword">const</span> std::string &amp;channel, <span class="keywordtype">bool</span> blocking)00059 {00060         <span class="keywordflow">return</span> <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_storez11_0">TransferTo2</a>(target, transferBytes, channel, blocking);00061 }00062 <a name="l00063"></a><a class="code" href="class_filter.html#_zlib_decompressora13">00063</a> <span class="keywordtype">void</span> <a class="code" href="class_filter.html#_zlib_decompressora13">Filter::Initialize</a>(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html">NameValuePairs</a> &amp;parameters, <span class="keywordtype">int</span> propagation)00064 {00065         m_continueAt = 0;00066         IsolatedInitialize(parameters);00067         PropagateInitialize(parameters, propagation);00068 }00069 <a name="l00070"></a><a class="code" href="class_filter.html#_zlib_decompressora14">00070</a> <span class="keywordtype">bool</span> <a class="code" href="class_filter.html#_zlib_decompressora14">Filter::Flush</a>(<span class="keywordtype">bool</span> hardFlush, <span class="keywordtype">int</span> propagation, <span class="keywordtype">bool</span> blocking)00071 {00072         <span class="keywordflow">switch</span> (m_continueAt)00073         {00074         <span class="keywordflow">case</span> 0:00075                 <span class="keywordflow">if</span> (IsolatedFlush(hardFlush, blocking))00076                         <span class="keywordflow">return</span> <span class="keyword">true</span>;00077         <span class="keywordflow">case</span> 1:00078                 <span class="keywordflow">if</span> (OutputFlush(1, hardFlush, propagation, blocking))00079                         <span class="keywordflow">return</span> <span class="keyword">true</span>;00080         }00081         <span class="keywordflow">return</span> <span class="keyword">false</span>;00082 }00083 <a name="l00084"></a><a class="code" href="class_filter.html#_zlib_decompressora15">00084</a> <span class="keywordtype">bool</span> <a class="code" href="class_filter.html#_zlib_decompressora15">Filter::MessageSeriesEnd</a>(<span class="keywordtype">int</span> propagation, <span class="keywordtype">bool</span> blocking)00085 {00086         <span class="keywordflow">switch</span> (m_continueAt)00087         {00088         <span class="keywordflow">case</span> 0:00089                 <span class="keywordflow">if</span> (IsolatedMessageSeriesEnd(blocking))00090                         <span class="keywordflow">return</span> <span class="keyword">true</span>;00091         <span class="keywordflow">case</span> 1:00092                 <span class="keywordflow">if</span> (ShouldPropagateMessageSeriesEnd() &amp;&amp; OutputMessageSeriesEnd(1, propagation, blocking))00093                         <span class="keywordflow">return</span> <span class="keyword">true</span>;00094         }00095         <span class="keywordflow">return</span> <span class="keyword">false</span>;00096 }00097 00098 <span class="keywordtype">void</span> Filter::PropagateInitialize(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html">NameValuePairs</a> &amp;parameters, <span class="keywordtype">int</span> propagation, <span class="keyword">const</span> std::string &amp;channel)00099 {00100         <span class="keywordflow">if</span> (propagation)00101                 <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz13_10">ChannelInitialize</a>(channel, parameters, propagation-1);00102 }00103 00104 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Filter::Output(<span class="keywordtype">int</span> outputSite, <span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length, <span class="keywordtype">int</span> messageEnd, <span class="keywordtype">bool</span> blocking, <span class="keyword">const</span> std::string &amp;channel)00105 {00106         <span class="keywordflow">if</span> (messageEnd)00107                 messageEnd--;00108         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> result = <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_unflushable_3_01_sink_01_4z1_9">Put2</a>(inString, length, messageEnd, blocking);00109         m_continueAt = result ? outputSite : 0;00110         <span class="keywordflow">return</span> result;00111 }00112 00113 <span class="keywordtype">bool</span> Filter::OutputFlush(<span class="keywordtype">int</span> outputSite, <span class="keywordtype">bool</span> hardFlush, <span class="keywordtype">int</span> propagation, <span class="keywordtype">bool</span> blocking, <span class="keyword">const</span> std::string &amp;channel)00114 {00115         <span class="keywordflow">if</span> (propagation &amp;&amp; <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz13_11">ChannelFlush</a>(channel, hardFlush, propagation-1, blocking))00116         {00117                 m_continueAt = outputSite;00118                 <span class="keywordflow">return</span> <span class="keyword">true</span>;00119         }00120         m_continueAt = 0;00121         <span class="keywordflow">return</span> <span class="keyword">false</span>;00122 }00123 00124 <span class="keywordtype">bool</span> Filter::OutputMessageSeriesEnd(<span class="keywordtype">int</span> outputSite, <span class="keywordtype">int</span> propagation, <span class="keywordtype">bool</span> blocking, <span class="keyword">const</span> std::string &amp;channel)00125 {00126         <span class="keywordflow">if</span> (propagation &amp;&amp; <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-&gt;<a class="code" href="class_buffered_transformation.html#_zlib_decompressorz13_12">ChannelMessageSeriesEnd</a>(channel, propagation-1, blocking))00127         {00128                 m_continueAt = outputSite;00129                 <span class="keywordflow">return</span> <span class="keyword">true</span>;00130         }00131         m_continueAt = 0;00132         <span class="keywordflow">return</span> <span class="keyword">false</span>;00133 }00134 00135 <span class="comment">// *************************************************************</span>00136 <a name="l00137"></a><a class="code" href="class_meter_filter.html#_transparent_filtera8">00137</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_meter_filter.html#_transparent_filtera8">MeterFilter::Put2</a>(<span class="keyword">const</span> byte *begin, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length, <span class="keywordtype">int</span> messageEnd, <span class="keywordtype">bool</span> blocking)00138 {00139         FILTER_BEGIN;00140         m_currentMessageBytes += length;00141         m_totalBytes += length;00142 00143         <span class="keywordflow">if</span> (messageEnd)00144         {00145                 m_currentMessageBytes = 0;00146                 m_currentSeriesMessages++;00147                 m_totalMessages++;00148         }00149         00150         FILTER_OUTPUT(1, begin, length, messageEnd);00151         FILTER_END;00152 }00153 00154 <span class="keywordtype">bool</span> MeterFilter::IsolatedMessageSeriesEnd(<span class="keywordtype">bool</span> blocking)00155 {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -