<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>DTN Reference Implementation: MetadataBlockProcessor.cc Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.6 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="main.html"><span>Main 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> <h1>MetadataBlockProcessor.cc</h1><a href="MetadataBlockProcessor_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> * Copyright 2006-2007 The MITRE Corporation</span> <a name="l00003"></a>00003 <span class="comment"> * </span> <a name="l00004"></a>00004 <span class="comment"> * Licensed under the Apache License, Version 2.0 (the "License");</span> <a name="l00005"></a>00005 <span class="comment"> * you may not use this file except in compliance with the License.</span> <a name="l00006"></a>00006 <span class="comment"> * You may obtain a copy of the License at</span> <a name="l00007"></a>00007 <span class="comment"> * </span> <a name="l00008"></a>00008 <span class="comment"> * http://www.apache.org/licenses/LICENSE-2.0</span> <a name="l00009"></a>00009 <span class="comment"> * </span> <a name="l00010"></a>00010 <span class="comment"> * Unless required by applicable law or agreed to in writing, software</span> <a name="l00011"></a>00011 <span class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</span> <a name="l00012"></a>00012 <span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span> <a name="l00013"></a>00013 <span class="comment"> * See the License for the specific language governing permissions and</span> <a name="l00014"></a>00014 <span class="comment"> * limitations under the License.</span> <a name="l00015"></a>00015 <span class="comment"> *</span> <a name="l00016"></a>00016 <span class="comment"> * The US Government will not be charged any license fee and/or royalties</span> <a name="l00017"></a>00017 <span class="comment"> * related to this software. Neither name of The MITRE Corporation; nor the</span> <a name="l00018"></a>00018 <span class="comment"> * names of its contributors may be used to endorse or promote products</span> <a name="l00019"></a>00019 <span class="comment"> * derived from this software without specific prior written permission.</span> <a name="l00020"></a>00020 <span class="comment"> */</span> <a name="l00021"></a>00021 <a name="l00022"></a>00022 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span> <a name="l00023"></a>00023 <span class="preprocessor"></span><span class="preprocessor"># include <<a class="code" href="dtn-config_8h.html">dtn-config.h</a>></span> <a name="l00024"></a>00024 <span class="preprocessor">#endif</span> <a name="l00025"></a>00025 <span class="preprocessor"></span> <a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="MetadataBlockProcessor_8h.html">MetadataBlockProcessor.h</a>"</span> <a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="MetadataBlock_8h.html">MetadataBlock.h</a>"</span> <a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="bundling_2Bundle_8h.html">Bundle.h</a>"</span> <a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="SDNV_8h.html">SDNV.h</a>"</span> <a name="l00030"></a>00030 <a name="l00031"></a>00031 <span class="keyword">namespace </span>dtn { <a name="l00032"></a>00032 <a name="l00033"></a>00033 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00034"></a><a class="code" href="classdtn_1_1MetadataBlockProcessor.html#22ff548d14306f6a42313b241bac5882">00034</a> <a class="code" href="classdtn_1_1MetadataBlockProcessor.html#22ff548d14306f6a42313b241bac5882" title="Constructor.">MetadataBlockProcessor::MetadataBlockProcessor</a>() <a name="l00035"></a>00035 : <a class="code" href="classdtn_1_1BlockProcessor.html" title="Base class for the protocol handling of bundle blocks, including the core primary...">BlockProcessor</a>(<a class="code" href="classdtn_1_1BundleProtocol.html" title="Centralized class used to convert a Bundle to / from the bundle protocol specification...">BundleProtocol</a>::METADATA_BLOCK) <a name="l00036"></a>00036 { <a name="l00037"></a>00037 } <a name="l00038"></a>00038 <a name="l00039"></a>00039 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00040"></a>00040 <span class="keywordtype">int</span> <a name="l00041"></a><a class="code" href="classdtn_1_1MetadataBlockProcessor.html#92e1b37e43c0bbd92f328d3ede10b78e">00041</a> MetadataBlockProcessor::consume(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle, <a name="l00042"></a>00042 <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>* block, <a name="l00043"></a>00043 u_char* <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>, <a name="l00044"></a>00044 <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>) <a name="l00045"></a>00045 { <a name="l00046"></a>00046 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(bundle != NULL); <a name="l00047"></a>00047 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block != NULL); <a name="l00048"></a>00048 <a name="l00049"></a>00049 <span class="keywordtype">int</span> cc = <a class="code" href="classdtn_1_1BlockProcessor.html#1f73d119593ef13da9c5ee845fd5ec00" title="First callback for parsing blocks that is expected to append a chunk of the given...">BlockProcessor::consume</a>(bundle, block, buf, len); <a name="l00050"></a>00050 <a name="l00051"></a>00051 <span class="keywordflow">if</span> (cc == -1) { <a name="l00052"></a>00052 <span class="keywordflow">return</span> -1; <span class="comment">// protocol error</span> <a name="l00053"></a>00053 } <a name="l00054"></a>00054 <a name="l00055"></a>00055 <span class="keywordflow">if</span> (!block-><a class="code" href="classdtn_1_1BlockInfo.html#a70c73cf28ec51a265dc5ac077c56975" title="Accessors.">complete</a>()) { <a name="l00056"></a>00056 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(cc == (<span class="keywordtype">int</span>)len); <a name="l00057"></a>00057 <span class="keywordflow">return</span> cc; <a name="l00058"></a>00058 } <a name="l00059"></a>00059 <a name="l00060"></a>00060 <a class="code" href="classdtn_1_1MetadataBlockProcessor.html#5ca13fab01ec05d27f372dd0b76fd7d1" title="Parses a metadata extension block.">parse_metadata</a>(bundle, block); <a name="l00061"></a>00061 <a name="l00062"></a>00062 <span class="keywordflow">return</span> cc; <a name="l00063"></a>00063 } <a name="l00064"></a>00064 <a name="l00065"></a>00065 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00066"></a>00066 <span class="keywordtype">bool</span> <a name="l00067"></a><a class="code" href="classdtn_1_1MetadataBlockProcessor.html#679fdea0736757a843cc9075d22ff515">00067</a> <a class="code" href="classdtn_1_1MetadataBlockProcessor.html#679fdea0736757a843cc9075d22ff515" title="Virtual from BlockProcessor.">MetadataBlockProcessor::validate</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle, <a name="l00068"></a>00068 <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* block_list, <a name="l00069"></a>00069 <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>* block, <a name="l00070"></a>00070 <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917" title="Bundle Status Report &quot;Reason Code&quot; flags.">status_report_reason_t</a>* reception_reason, <a name="l00071"></a>00071 <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917" title="Bundle Status Report &quot;Reason Code&quot; flags.">status_report_reason_t</a>* deletion_reason) <a name="l00072"></a>00072 { <a name="l00073"></a>00073 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="namespacedtn.html#68bf4270dd0a7e5e8390869b83889922">log</a> = <span class="stringliteral">"/dtn/bundle/protocol"</span>; <a name="l00074"></a>00074 (void)log; <a name="l00075"></a>00075 <a name="l00076"></a>00076 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(bundle != NULL); <a name="l00077"></a>00077 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block != NULL); <a name="l00078"></a>00078 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-><a class="code" href="classdtn_1_1BlockInfo.html#bc48fc2f7f543561e26a8a9e32aceda2" title="Accessors.">owner</a>() == <span class="keyword">this</span>); <a name="l00079"></a>00079 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-><a class="code" href="classdtn_1_1BlockInfo.html#46e4157d30528eae60a1cd240e58b495">type</a>() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca7f69759524468f2b1c3f7f1c2f6619f39" title="NOT IN SPEC YET.">BundleProtocol::METADATA_BLOCK</a>); <a name="l00080"></a>00080 <a name="l00081"></a>00081 <a class="code" href="classdtn_1_1MetadataBlock.html" title="The representation of a metadata extension block.">MetadataBlock</a> *metablock = <span class="keyword">dynamic_cast<</span><a class="code" href="classdtn_1_1MetadataBlock.html" title="The representation of a metadata extension block.">MetadataBlock</a>*<span class="keyword">></span>(block-><a class="code" href="classdtn_1_1BlockInfo.html#f0f4b8768d0879f3077f2c4bb067bada" title="Accessors.">locals</a>()); <a name="l00082"></a>00082 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(metablock != NULL); <a name="l00083"></a>00083 <a name="l00084"></a>00084 <span class="keywordflow">if</span> (metablock->error()) { <a name="l00085"></a>00085 log_debug_p(log, <span class="stringliteral">"MetadataBlockProcessor::validate: "</span> <a name="l00086"></a>00086 <span class="stringliteral">"error in metadata block preamble"</span>); <a name="l00087"></a>00087 <span class="keywordflow">return</span> <a class="code" href="classdtn_1_1MetadataBlockProcessor.html#63b2d0b1bb0f10657bf8b2a57276e73b" title="Handles a metadata extension block processing error based on the block preamble flags...">handle_error</a>(block, reception_reason, deletion_reason); <a name="l00088"></a>00088 } <a name="l00089"></a>00089 <a name="l00090"></a>00090 <span class="comment">// Check for generic block errors.</span> <a name="l00091"></a>00091 <span class="keywordflow">if</span> (!<a class="code" href="classdtn_1_1BlockProcessor.html#14242dcdb094a179f718a5eaee23cabd" title="Validate the block.">BlockProcessor::validate</a>(bundle, block_list, block, <a name="l00092"></a>00092 reception_reason, deletion_reason)) { <a name="l00093"></a>00093 metablock->set_block_error(); <a name="l00094"></a>00094 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00095"></a>00095 } <a name="l00096"></a>00096 <a name="l00097"></a>00097 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00098"></a>00098 } <a name="l00099"></a>00099 <a name="l00100"></a>00100 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00101"></a>00101 <span class="keywordtype">int</span> <a name="l00102"></a><a class="code" href="classdtn_1_1MetadataBlockProcessor.html#63f5d0f32404210cd68b6601d7abc748">00102</a> <a class="code" href="classdtn_1_1MetadataBlockProcessor.html#63f5d0f32404210cd68b6601d7abc748" title="Virtual from BlockProcessor.">MetadataBlockProcessor::prepare</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle, <a name="l00103"></a>00103 <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* xmit_blocks, <a name="l00104"></a>00104 <span class="keyword">const</span> <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>* source, <a name="l00105"></a>00105 <span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>& link, <a name="l00106"></a>00106 <a class="code" href="classdtn_1_1BlockInfo.html#3d0bc8cd207912ac5406fde3fc2c8d1c" title="List owner indicator (not transmitted).">list_owner_t</a> list) <a name="l00107"></a>00107 { <a name="l00108"></a>00108 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="namespacedtn.html#68bf4270dd0a7e5e8390869b83889922">log</a> = <span class="stringliteral">"/dtn/bundle/protocol"</span>; <a name="l00109"></a>00109 (void)log; <a name="l00110"></a>00110 <a name="l00111"></a>00111 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(bundle != NULL); <a name="l00112"></a>00112 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(xmit_blocks != NULL); <a name="l00113"></a>00113 <a name="l00114"></a>00114 <span class="comment">// Do not include metadata unless there is a received source block.</span> <a name="l00115"></a>00115 <span class="keywordflow">if</span> (source == NULL) { <a name="l00116"></a>00116 <span class="keywordflow">return</span> <a class="code" href="BlockProcessor_8h.html#cce9a45a37bad1da41648533b0e15457">BP_FAIL</a>; <a name="l00117"></a>00117 } <a name="l00118"></a>00118 <a name="l00119"></a>00119 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(source != NULL); <a name="l00120"></a>00120 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(source-><a class="code" href="classdtn_1_1BlockInfo.html#bc48fc2f7f543561e26a8a9e32aceda2" title="Accessors.">owner</a>() == <span class="keyword">this</span>); <a name="l00121"></a>00121 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(source-><a class="code" href="classdtn_1_1BlockInfo.html#46e4157d30528eae60a1cd240e58b495">type</a>() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca7f69759524468f2b1c3f7f1c2f6619f39" title="NOT IN SPEC YET.">BundleProtocol::METADATA_BLOCK</a>); <a name="l00122"></a>00122 <a name="l00123"></a>00123 <a class="code" href="classdtn_1_1MetadataBlock.html" title="The representation of a metadata extension block.">MetadataBlock</a>* source_metadata = <a name="l00124"></a>00124 <span class="keyword">dynamic_cast<</span><a class="code" href="classdtn_1_1MetadataBlock.html" title="The representation of a metadata extension block.">MetadataBlock</a>*<span class="keyword">></span>(source-><a class="code" href="classdtn_1_1BlockInfo.html#f0f4b8768d0879f3077f2c4bb067bada" title="Accessors.">locals</a>()); <a name="l00125"></a>00125 <a name="l00126"></a>00126 <span class="comment">// if the source metadata locals is null just return </span> <a name="l00127"></a>00127 <span class="comment">// XXX this indicates a bug in the Ref class or a race elsewhere</span> <a name="l00128"></a>00128 <span class="keywordflow">if</span> (source_metadata == NULL) { <a name="l00129"></a>00129 log_debug_p(log, <span class="stringliteral">"MetadataBlockProcessor::prepare: "</span> <a name="l00130"></a>00130 <span class="stringliteral">"invalid NULL source metadata"</span>); <a name="l00131"></a>00131 <span class="keywordflow">return</span> <a class="code" href="BlockProcessor_8h.html#cce9a45a37bad1da41648533b0e15457">BP_FAIL</a>; <a name="l00132"></a>00132 } <a name="l00133"></a>00133 <a name="l00134"></a>00134 oasys::ScopeLock metadata_lock(source_metadata->lock(), <a name="l00135"></a>00135 <span class="stringliteral">"MetadataBlockProcessor::prepare"</span>); <a name="l00136"></a>00136 <a name="l00137"></a>00137 <span class="comment">// Do not include invalid metadata if block flags indicate as such.</span> <a name="l00138"></a>00138 <span class="keywordflow">if</span> (source_metadata->error() && <a name="l00139"></a>00139 (source-><a class="code" href="classdtn_1_1BlockInfo.html#51f21d5cf4aef2550b605ab90961e045">flags</a>() & <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b92bb8f5c147c6963041f7bc20cfe6e29">BundleProtocol::BLOCK_FLAG_DISCARD_BLOCK_ONERROR</a>)) { <a name="l00140"></a>00140 <span class="keywordflow">return</span> <a class="code" href="BlockProcessor_8h.html#cce9a45a37bad1da41648533b0e15457">BP_FAIL</a>; <a name="l00141"></a>00141 } <a name="l00142"></a>00142 <a name="l00143"></a>00143 <span class="comment">// Do not include metadata that has been marked for removal.</span> <a name="l00144"></a>00144 <span class="keywordflow">if</span> (source_metadata->metadata_removed(link)) { <a name="l00145"></a>00145 <span class="keywordflow">return</span> <a class="code" href="BlockProcessor_8h.html#cce9a45a37bad1da41648533b0e15457">BP_FAIL</a>; <a name="l00146"></a>00146 } <a name="l00147"></a>00147 <a name="l00148"></a>00148 <a class="code" href="classdtn_1_1BlockProcessor.html#f7c21ecdcbbb4f2060c7f5f865415c48" title="First callback to generate blocks for the output pass.">BlockProcessor::prepare</a>(bundle, xmit_blocks, source, link, list); <a name="l00149"></a>00149 <a name="l00150"></a>00150 <span class="keywordflow">return</span> <a class="code" href="BlockProcessor_8h.html#446572d61c813971cb4d5ce4ee1b9c0b">BP_SUCCESS</a>; <a name="l00151"></a>00151 } <a name="l00152"></a>00152 <a name="l00153"></a>00153 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00154"></a>00154 <span class="keywordtype">void</span> <a name="l00155"></a><a class="code" href="classdtn_1_1MetadataBlockProcessor.html#34c1cf9074a51a3f0524e7d4d1ca5ea7">00155</a> <a class="code" href="classdtn_1_1MetadataBlockProcessor.html#34c1cf9074a51a3f0524e7d4d1ca5ea7" title="Determines the generated metadata (not received metadata, which is handled by the...">MetadataBlockProcessor::prepare_generated_metadata</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle, <a name="l00156"></a>00156 <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* blocks, <a name="l00157"></a>00157 <span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>& link) <a name="l00158"></a>00158 { <a name="l00159"></a>00159 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(bundle != NULL); <a name="l00160"></a>00160 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(blocks != NULL); <a name="l00161"></a>00161 <a name="l00162"></a>00162 oasys::ScopeLock bundle_lock(bundle-><a class="code" href="classdtn_1_1Bundle.html#5152156c37574a7939c6b4740fa44c66" title="Accessors.">lock</a>(), <a name="l00163"></a>00163 <span class="stringliteral">"MetadataBlockProcessor::prepare_generated_metadata"</span>); <a name="l00164"></a>00164 <a name="l00165"></a>00165 <span class="comment">// Include metadata generated specifically for the outgoing link.</span> <a name="l00166"></a>00166 <span class="keyword">const</span> <a class="code" href="classdtn_1_1MetadataVec.html" title="A vector of Metadata Block references.">MetadataVec</a>* metadata = <a name="l00167"></a>00167 bundle-><a class="code" href="classdtn_1_1Bundle.html#2942a5a96aa7bb476abd7a2887939f96" title="Accessors.">generated_metadata</a>().<a class="code" href="classdtn_1_1LinkMetadataSet.html#22821194a9b073c1aae57dd79c86a69b">find_blocks</a>(link); <a name="l00168"></a>00168 <span class="keywordflow">if</span> (metadata != NULL) { <a name="l00169"></a>00169 MetadataVec::const_iterator iter; <a name="l00170"></a>00170 <span class="keywordflow">for</span> (iter = metadata->begin(); iter != metadata->end(); ++iter) { <a name="l00171"></a>00171 <span class="keywordflow">if</span> ((*iter)->metadata_len() > 0) { <a name="l00172"></a>00172 blocks->push_back(<a class="code" href="classdtn_1_1BlockProcessor.html#f60b1c05e77bb387f21aaff2c8ac532b">BlockInfo</a>(<span class="keyword">this</span>)); <a name="l00173"></a>00173 blocks->back().set_locals(iter->object()); <a name="l00174"></a>00174 } <a name="l00175"></a>00175 } <a name="l00176"></a>00176 } <a name="l00177"></a>00177 <a name="l00178"></a>00178 <span class="comment">// Include metadata generated for all outgoing links.</span> <a name="l00179"></a>00179 <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a> null_link(<span class="stringliteral">"MetadataBlockProcessor::prepare_generated_metadata"</span>); <a name="l00180"></a>00180 <span class="keyword">const</span> <a class="code" href="classdtn_1_1MetadataVec.html" title="A vector of Metadata Block references.">MetadataVec</a>* <a name="l00181"></a>00181 nulldata = bundle-><a class="code" href="classdtn_1_1Bundle.html#2942a5a96aa7bb476abd7a2887939f96" title="Accessors.">generated_metadata</a>().<a class="code" href="classdtn_1_1LinkMetadataSet.html#22821194a9b073c1aae57dd79c86a69b">find_blocks</a>(null_link); <a name="l00182"></a>00182 <a name="l00183"></a>00183 <span class="keywordflow">if</span> (nulldata != NULL) { <a name="l00184"></a>00184 MetadataVec::const_iterator iter; <a name="l00185"></a>00185 <span class="keywordflow">for</span> (iter = nulldata->begin(); iter != nulldata->end(); ++iter) { <a name="l00186"></a>00186 <span class="keywordtype">bool</span> link_specific = <span class="keyword">false</span>; <a name="l00187"></a>00187 <span class="keywordflow">if</span> (metadata != NULL) { <a name="l00188"></a>00188 MetadataVec::const_iterator liter = metadata->begin(); <a name="l00189"></a>00189 <span class="keywordflow">for</span> ( ; liter != metadata->end(); ++liter) { <a name="l00190"></a>00190 <span class="keywordflow">if</span> ((*liter)->source() && <a name="l00191"></a>00191 ((*liter)->source_id() == (*iter)->id())) { <a name="l00192"></a>00192 link_specific = <span class="keyword">true</span>; <a name="l00193"></a>00193 <span class="keywordflow">break</span>; <a name="l00194"></a>00194 } <a name="l00195"></a>00195 } <a name="l00196"></a>00196 } <a name="l00197"></a>00197 <a name="l00198"></a>00198 <span class="keywordflow">if</span> (link_specific) { <a name="l00199"></a>00199 <span class="keywordflow">continue</span>; <a name="l00200"></a>00200 } <a name="l00201"></a>00201 <a name="l00202"></a>00202 blocks->push_back(<a class="code" href="classdtn_1_1BlockProcessor.html#f60b1c05e77bb387f21aaff2c8ac532b">BlockInfo</a>(<span class="keyword">this</span>)); <a name="l00203"></a>00203 blocks->back().set_locals(iter->object()); <a name="l00204"></a>00204 } <a name="l00205"></a>00205 } <a name="l00206"></a>00206 } <a name="l00207"></a>00207 <a name="l00208"></a>00208 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00209"></a>00209 <span class="keywordtype">int</span> <a name="l00210"></a><a class="code" href="classdtn_1_1MetadataBlockProcessor.html#3bb5baa33e5a4ab2883ce70907d9934c">00210</a> <a class="code" href="classdtn_1_1MetadataBlockProcessor.html#3bb5baa33e5a4ab2883ce70907d9934c" title="Virtual from BlockProcessor.">MetadataBlockProcessor::generate</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle, <a name="l00211"></a>00211 <a class="code" href="classdtn_1_1BlockInfoVec.html" title="Class for a vector of BlockInfo structures.">BlockInfoVec</a>* xmit_blocks, <a name="l00212"></a>00212 <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>* block, <a name="l00213"></a>00213 <span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>& link, <a name="l00214"></a>00214 <span class="keywordtype">bool</span> last) <a name="l00215"></a>00215 { <a name="l00216"></a>00216 (void)xmit_blocks; <a name="l00217"></a>00217 <a name="l00218"></a>00218 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(bundle != NULL); <a name="l00219"></a>00219 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block != NULL); <a name="l00220"></a>00220 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-><a class="code" href="classdtn_1_1BlockInfo.html#bc48fc2f7f543561e26a8a9e32aceda2" title="Accessors.">owner</a>() == <span class="keyword">this</span>); <a name="l00221"></a>00221 <a name="l00222"></a>00222 <span class="comment">// Determine if the outgoing metadata block was received in the</span> <a name="l00223"></a>00223 <span class="comment">// bundle or newly generated; however, both should not be true.</span> <a name="l00224"></a>00224 <a class="code" href="classdtn_1_1MetadataBlock.html" title="The representation of a metadata extension block.">MetadataBlock</a>* metadata = NULL; <a name="l00225"></a>00225 <span class="keywordtype">bool</span> received_block = <span class="keyword">false</span>; <a name="l00226"></a>00226 <span class="keywordtype">bool</span> generated_block = <span class="keyword">false</span>; <a name="l00227"></a>00227 <a name="l00228"></a>00228 <span class="keywordflow">if</span> (block-><a class="code" href="classdtn_1_1BlockInfo.html#f11df0a802e40fd503e49ee6580f585d" title="Accessors.">source</a>() != NULL) { <a name="l00229"></a>00229 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-><a class="code" href="classdtn_1_1BlockInfo.html#f11df0a802e40fd503e49ee6580f585d" title="Accessors.">source</a>()-><a class="code" href="classdtn_1_1BlockInfo.html#bc48fc2f7f543561e26a8a9e32aceda2" title="Accessors.">owner</a>() == <span class="keyword">this</span>); <a name="l00230"></a>00230 received_block = <span class="keyword">true</span>; <a name="l00231"></a>00231 metadata = <span class="keyword">dynamic_cast<</span><a class="code" href="classdtn_1_1MetadataBlock.html" title="The representation of a metadata extension block.">MetadataBlock</a>*<span class="keyword">></span>(block-><a class="code" href="classdtn_1_1BlockInfo.html#f11df0a802e40fd503e49ee6580f585d" title="Accessors.">source</a>()-><a class="code" href="classdtn_1_1BlockInfo.html#f0f4b8768d0879f3077f2c4bb067bada" title="Accessors.">locals</a>()); <a name="l00232"></a>00232 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(metadata != NULL); <a name="l00233"></a>00233 } <a name="l00234"></a>00234 <a name="l00235"></a>00235 <span class="keywordflow">if</span> (block-><a class="code" href="classdtn_1_1BlockInfo.html#f0f4b8768d0879f3077f2c4bb067bada" title="Accessors.">locals</a>() != NULL) { <a name="l00236"></a>00236 generated_block = <span class="keyword">true</span>; <a name="l00237"></a>00237 metadata = <span class="keyword">dynamic_cast<</span><a class="code" href="classdtn_1_1MetadataBlock.html" title="The representation of a metadata extension block.">MetadataBlock</a>*<span class="keyword">></span>(block-><a class="code" href="classdtn_1_1BlockInfo.html#f0f4b8768d0879f3077f2c4bb067bada" title="Accessors.">locals</a>()); <a name="l00238"></a>00238 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(metadata != NULL); <a name="l00239"></a>00239 } <a name="l00240"></a>00240 <a name="l00241"></a>00241 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(received_block || generated_block); <a name="l00242"></a>00242 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(!(received_block && generated_block)); <a name="l00243"></a>00243 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(metadata != NULL); <a name="l00244"></a>00244 <a name="l00245"></a>00245 oasys::ScopeLock metadata_lock(metadata->lock(), <a name="l00246"></a>00246 <span class="stringliteral">"MetadataBlockProcessor::generate"</span>); <a name="l00247"></a>00247 <a name="l00248"></a>00248 <span class="keywordflow">if</span> (received_block && metadata->error()) { <a name="l00249"></a>00249 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>((block-><a class="code" href="classdtn_1_1BlockInfo.html#f11df0a802e40fd503e49ee6580f585d" title="Accessors.">source</a>()-><a class="code" href="classdtn_1_1BlockInfo.html#51f21d5cf4aef2550b605ab90961e045">flags</a>() & <a name="l00250"></a>00250 <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b0b657a90e3033d112835cf7df7a4855b">BundleProtocol::BLOCK_FLAG_DISCARD_BUNDLE_ONERROR</a>) == 0); <a name="l00251"></a>00251 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>((block-><a class="code" href="classdtn_1_1BlockInfo.html#f11df0a802e40fd503e49ee6580f585d" title="Accessors.">source</a>()-><a class="code" href="classdtn_1_1BlockInfo.html#51f21d5cf4aef2550b605ab90961e045">flags</a>() & <a name="l00252"></a>00252 <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b92bb8f5c147c6963041f7bc20cfe6e29">BundleProtocol::BLOCK_FLAG_DISCARD_BLOCK_ONERROR</a>) == 0); <a name="l00253"></a>00253 } <a name="l00254"></a>00254 <a name="l00255"></a>00255 <span class="comment">// Buffer to the metadata block ontology-specific data.</span> <a name="l00256"></a>00256 u_char* <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a> = NULL; <a name="l00257"></a>00257 u_int32_t <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a> = 0; <a name="l00258"></a>00258 <a name="l00259"></a>00259 <span class="comment">// Determine if the outgoing metadata block was modified.</span> <a name="l00260"></a>00260 <span class="comment">// NOTE: metadata_modified() will set buf and len if it returns true.</span> <a name="l00261"></a>00261 <span class="keywordtype">bool</span> modified = (received_block ? <a name="l00262"></a>00262 metadata->metadata_modified(link, &buf, len) : <span class="keyword">false</span>); <a name="l00263"></a>00263 <a name="l00264"></a>00264 <span class="comment">// Determine the outgoing metadata block length.</span> <a name="l00265"></a>00265 <span class="keywordtype">size_t</span> block_data_len; <a name="l00266"></a>00266 <span class="keywordflow">if</span> (received_block && !modified) { <a name="l00267"></a>00267 block_data_len = block-><a class="code" href="classdtn_1_1BlockInfo.html#f11df0a802e40fd503e49ee6580f585d" title="Accessors.">source</a>()-><a class="code" href="classdtn_1_1BlockInfo.html#cb7676dfe53630699317388ad32e8d99" title="Accessors.">data_length</a>(); <a name="l00268"></a>00268 <a name="l00269"></a>00269 } <span class="keywordflow">else</span> { <a name="l00270"></a>00270 <span class="keywordflow">if</span> (!modified) { <a name="l00271"></a>00271 buf = metadata->metadata(); <a name="l00272"></a>00272 len = metadata->metadata_len(); <a name="l00273"></a>00273 } <a name="l00274"></a>00274 <a name="l00275"></a>00275 <span class="comment">// If it is modified, len and buf were set by metadata_modified().</span> <a name="l00276"></a>00276 <a name="l00277"></a>00277 block_data_len = <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(metadata->ontology()) + <a name="l00278"></a>00278 <a class="code" href="SDNV_8cc.html#46f4c114c92230c80f6714318251b542">SDNV::encoding_len</a>(len) + len; <a name="l00279"></a>00279 } <a name="l00280"></a>00280 <a name="l00281"></a>00281 <span class="comment">// Determine the preamble flags for the outgoing metadata block.</span> <a name="l00282"></a>00282 u_int8_t flags = 0; <a name="l00283"></a>00283 <span class="keywordflow">if</span> (received_block) { <a name="l00284"></a>00284 flags = block-><a class="code" href="classdtn_1_1BlockInfo.html#f11df0a802e40fd503e49ee6580f585d" title="Accessors.">source</a>()-><a class="code" href="classdtn_1_1BlockInfo.html#51f21d5cf4aef2550b605ab90961e045">flags</a>(); <a name="l00285"></a>00285 } <span class="keywordflow">else</span> { <a name="l00286"></a>00286 flags |= metadata->flags(); <a name="l00287"></a>00287 } <a name="l00288"></a>00288 <span class="keywordflow">if</span> (last) { <a name="l00289"></a>00289 flags |= <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b60a3533536c98ae651d4533edd238037">BundleProtocol::BLOCK_FLAG_LAST_BLOCK</a>; <a name="l00290"></a>00290 } <span class="keywordflow">else</span> { <a name="l00291"></a>00291 flags &= ~<a class="code" href="classdtn_1_1BundleProtocol.html" title="Centralized class used to convert a Bundle to / from the bundle protocol specification...">BundleProtocol</a>::BLOCK_FLAG_LAST_BLOCK; <a name="l00292"></a>00292 } <a name="l00293"></a>00293 <a name="l00294"></a>00294 <span class="comment">// Generate the generic block preamble and reserve</span> <a name="l00295"></a>00295 <span class="comment">// buffer space for the block-specific data.</span> <a name="l00296"></a>00296 <a class="code" href="classdtn_1_1BlockProcessor.html#c08f7b82f6049f30710a5dcdebb61ce7" title="Generate the standard preamble for the given block type, flags, EID-list and content...">generate_preamble</a>(xmit_blocks, block, <a class="code" href="classdtn_1_1BlockProcessor.html#5a5794eea1bd61dfbef1a691ef9f8d97" title="Accessors.">block_type</a>(), flags, block_data_len); <a name="l00297"></a>00297 block-><a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()->reserve(block-><a class="code" href="classdtn_1_1BlockInfo.html#590c483ae6cc403c5062b8b3acc51ae3" title="Accessors.">data_offset</a>() + block_data_len); <a name="l00298"></a>00298 block-><a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()->set_len(block-><a class="code" href="classdtn_1_1BlockInfo.html#590c483ae6cc403c5062b8b3acc51ae3" title="Accessors.">data_offset</a>() + block_data_len); <a name="l00299"></a>00299 <a name="l00300"></a>00300 <span class="comment">// Simply copy the incoming metadata to the outgoing buffer</span> <a name="l00301"></a>00301 <span class="comment">// if the block was originally received with the bundle and</span> <a name="l00302"></a>00302 <span class="comment">// subsequently not modified.</span> <a name="l00303"></a>00303 <span class="keywordflow">if</span> (received_block && !modified) { <a name="l00304"></a>00304 memcpy(block-><a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()->buf() + block-><a class="code" href="classdtn_1_1BlockInfo.html#590c483ae6cc403c5062b8b3acc51ae3" title="Accessors.">data_offset</a>(), <a name="l00305"></a>00305 block-><a class="code" href="classdtn_1_1BlockInfo.html#f11df0a802e40fd503e49ee6580f585d" title="Accessors.">source</a>()-><a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().buf() + block-><a class="code" href="classdtn_1_1BlockInfo.html#590c483ae6cc403c5062b8b3acc51ae3" title="Accessors.">data_offset</a>(), <a name="l00306"></a>00306 block-><a class="code" href="classdtn_1_1BlockInfo.html#cb7676dfe53630699317388ad32e8d99" title="Accessors.">data_length</a>()); <a name="l00307"></a>00307 <span class="keywordflow">return</span> <a class="code" href="BlockProcessor_8h.html#446572d61c813971cb4d5ce4ee1b9c0b">BP_SUCCESS</a>; <a name="l00308"></a>00308 } <a name="l00309"></a>00309 <a name="l00310"></a>00310 <span class="comment">// Write the metadata block to the outgoing buffer.</span> <a name="l00311"></a>00311 u_char* outgoing_buf = block-><a class="code" href="classdtn_1_1BlockInfo.html#2b1a3f8f9c10d722bc4313781aac8e19" title="Mutating accessors.">writable_contents</a>()->buf() + <a name="l00312"></a>00312 block-><a class="code" href="classdtn_1_1BlockInfo.html#590c483ae6cc403c5062b8b3acc51ae3" title="Accessors.">data_offset</a>(); <a name="l00313"></a>00313 u_int32_t outgoing_len = block_data_len; <a name="l00314"></a>00314 <a name="l00315"></a>00315 <span class="comment">// Write the ontology type.</span> <a name="l00316"></a>00316 <span class="keywordtype">size_t</span> sdnv_len = <a class="code" href="SDNV_8cc.html#21c54ef3a5345647ad1cada265a03eb4">SDNV::encode</a>(metadata->ontology(), <a name="l00317"></a>00317 outgoing_buf, outgoing_len); <a name="l00318"></a>00318 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(sdnv_len > 0); <a name="l00319"></a>00319 outgoing_buf += sdnv_len; <a name="l00320"></a>00320 outgoing_len -= sdnv_len; <a name="l00321"></a>00321 <a name="l00322"></a>00322 <span class="comment">// Write the ontology data length.</span> <a name="l00323"></a>00323 sdnv_len = <a class="code" href="SDNV_8cc.html#21c54ef3a5345647ad1cada265a03eb4">SDNV::encode</a>(len, outgoing_buf, outgoing_len); <a name="l00324"></a>00324 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(sdnv_len > 0); <a name="l00325"></a>00325 outgoing_buf += sdnv_len; <a name="l00326"></a>00326 outgoing_len -= sdnv_len; <a name="l00327"></a>00327 <a name="l00328"></a>00328 <span class="comment">// Write the ontology data.</span> <a name="l00329"></a>00329 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-><a class="code" href="classdtn_1_1BlockInfo.html#40fee1299938523234d3ae8c80661e22" title="Accessors.">contents</a>().nfree() >= len); <a name="l00330"></a>00330 memcpy(outgoing_buf, buf, outgoing_len); <a name="l00331"></a>00331 <a name="l00332"></a>00332 <span class="keywordflow">return</span> <a class="code" href="BlockProcessor_8h.html#446572d61c813971cb4d5ce4ee1b9c0b">BP_SUCCESS</a>; <a name="l00333"></a>00333 } <a name="l00334"></a>00334 <a name="l00335"></a>00335 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00336"></a>00336 <span class="keywordtype">bool</span> <a name="l00337"></a><a class="code" href="classdtn_1_1MetadataBlockProcessor.html#5ca13fab01ec05d27f372dd0b76fd7d1">00337</a> <a class="code" href="classdtn_1_1MetadataBlockProcessor.html#5ca13fab01ec05d27f372dd0b76fd7d1" title="Parses a metadata extension block.">MetadataBlockProcessor::parse_metadata</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle, <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>* block) <a name="l00338"></a>00338 { <a name="l00339"></a>00339 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="namespacedtn.html#68bf4270dd0a7e5e8390869b83889922">log</a> = <span class="stringliteral">"/dtn/bundle/protocol"</span>; <a name="l00340"></a>00340 <a name="l00341"></a>00341 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(bundle != NULL); <a name="l00342"></a>00342 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block != NULL); <a name="l00343"></a>00343 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-><a class="code" href="classdtn_1_1BlockInfo.html#bc48fc2f7f543561e26a8a9e32aceda2" title="Accessors.">owner</a>() == <span class="keyword">this</span>); <a name="l00344"></a>00344 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-><a class="code" href="classdtn_1_1BlockInfo.html#46e4157d30528eae60a1cd240e58b495">type</a>() == <a class="code" href="classdtn_1_1BundleProtocol.html#54a44c247b3c20b4ed11e29494284ca7f69759524468f2b1c3f7f1c2f6619f39" title="NOT IN SPEC YET.">BundleProtocol::METADATA_BLOCK</a>); <a name="l00345"></a>00345 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-><a class="code" href="classdtn_1_1BlockInfo.html#a70c73cf28ec51a265dc5ac077c56975" title="Accessors.">complete</a>()); <a name="l00346"></a>00346 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(block-><a class="code" href="classdtn_1_1BlockInfo.html#590c483ae6cc403c5062b8b3acc51ae3" title="Accessors.">data_offset</a>() > 0); <a name="l00347"></a>00347 <a name="l00348"></a>00348 <span class="comment">// Generate metadata block state that is maintained by</span> <a name="l00349"></a>00349 <span class="comment">// the bundle and referenced by the generic block state.</span> <a name="l00350"></a>00350 <a class="code" href="classdtn_1_1MetadataBlock.html" title="The representation of a metadata extension block.">MetadataBlock</a>* metadata = <span class="keyword">new</span> <a class="code" href="classdtn_1_1MetadataBlock.html" title="The representation of a metadata extension block.">MetadataBlock</a>(block); <a name="l00351"></a>00351 bundle-><a class="code" href="classdtn_1_1Bundle.html#c0e5096b00ca3f36b5513a13dccf5241" title="Setters and mutable accessors.">mutable_recv_metadata</a>()-><a class="code" href="classdtn_1_1MetadataVec.html#c07f1f60e7dcdd37fb101886e6b174ab" title="Wrapper around push_back that takes a vanilla MetadataBlock pointer.">push_back</a>(metadata); <a name="l00352"></a>00352 <a name="l00353"></a>00353 block-><a class="code" href="classdtn_1_1BlockInfo.html#906e126f23448f7164e4876810743ee9" title="Mutating accessors.">set_locals</a>(metadata); <a name="l00354"></a>00354 <a name="l00355"></a>00355 <span class="comment">// Parse the metadata block.</span> <a name="l00356"></a>00356 u_char * <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a> = block-><a class="code" href="classdtn_1_1BlockInfo.html#0a211825b5545e2e3068766633502c07" title="Accessors.">data</a>(); <a name="l00357"></a>00357 u_int32_t <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a> = block-><a class="code" href="classdtn_1_1BlockInfo.html#cb7676dfe53630699317388ad32e8d99" title="Accessors.">data_length</a>(); <a name="l00358"></a>00358 <a name="l00359"></a>00359 <span class="comment">// Read the metadata block ontology.</span> <a name="l00360"></a>00360 <span class="keywordtype">int</span> ontology_len = 0; <a name="l00361"></a>00361 u_int64_t ontology = 0; <a name="l00362"></a>00362 <span class="keywordflow">if</span> ((ontology_len = <a class="code" href="SDNV_8cc.html#151d178617a7c2f598cfd7630ebeb7b4">SDNV::decode</a>(buf, len, &ontology)) < 0) { <a name="l00363"></a>00363 <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log, <span class="stringliteral">"MetadataBlockProcessor::parse_metadata_ontology: "</span> <a name="l00364"></a>00364 <span class="stringliteral">"invalid ontology field length"</span>); <a name="l00365"></a>00365 metadata->set_block_error(); <a name="l00366"></a>00366 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00367"></a>00367 } <a name="l00368"></a>00368 buf += ontology_len; <a name="l00369"></a>00369 len -= ontology_len; <a name="l00370"></a>00370 <a name="l00371"></a>00371 metadata->set_ontology(ontology); <a name="l00372"></a>00372 <a name="l00373"></a>00373 <span class="comment">// XXX/demmer this doesn't seem to conform to the spec... instead</span> <a name="l00374"></a>00374 <span class="comment">// the length should be whatever is left in len after the SDNV for</span> <a name="l00375"></a>00375 <span class="comment">// the ontology</span> <a name="l00376"></a>00376 <a name="l00377"></a>00377 <span class="comment">// Read the metadata block data length.</span> <a name="l00378"></a>00378 <span class="keywordtype">int</span> length_len = 0; <a name="l00379"></a>00379 u_int64_t length = 0; <a name="l00380"></a>00380 <span class="keywordflow">if</span> ((length_len = <a class="code" href="SDNV_8cc.html#151d178617a7c2f598cfd7630ebeb7b4">SDNV::decode</a>(buf, len, &length)) < 0) { <a name="l00381"></a>00381 <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log, <span class="stringliteral">"MetadataBlockProcessor::parse_metadata_ontology: "</span> <a name="l00382"></a>00382 <span class="stringliteral">"invalid ontology length field length"</span>); <a name="l00383"></a>00383 metadata->set_block_error(); <a name="l00384"></a>00384 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00385"></a>00385 } <a name="l00386"></a>00386 buf += length_len; <a name="l00387"></a>00387 len -= length_len; <a name="l00388"></a>00388 <a name="l00389"></a>00389 <span class="keywordflow">if</span> (len != length) { <a name="l00390"></a>00390 <a class="code" href="SDNV_8cc.html#3f24cadc9f28aba33472df0500092dcb">log_err_p</a>(log, <span class="stringliteral">"MetadataBlockProcessor::parse_metadata_ontology: "</span> <a name="l00391"></a>00391 <span class="stringliteral">"ontology length fails to match remaining block length"</span>); <a name="l00392"></a>00392 metadata->set_block_error(); <a name="l00393"></a>00393 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00394"></a>00394 } <a name="l00395"></a>00395 <a name="l00396"></a>00396 <span class="comment">// Set the offset within the buffer to the metadata block ontology data.</span> <a name="l00397"></a>00397 metadata->set_metadata(buf, len); <a name="l00398"></a>00398 <a name="l00399"></a>00399 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00400"></a>00400 } <a name="l00401"></a>00401 <a name="l00402"></a>00402 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00403"></a>00403 <span class="keywordtype">bool</span> <a name="l00404"></a><a class="code" href="classdtn_1_1MetadataBlockProcessor.html#63b2d0b1bb0f10657bf8b2a57276e73b">00404</a> <a class="code" href="classdtn_1_1MetadataBlockProcessor.html#63b2d0b1bb0f10657bf8b2a57276e73b" title="Handles a metadata extension block processing error based on the block preamble flags...">MetadataBlockProcessor::handle_error</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1BlockInfo.html" title="Class used to store unparsed bundle blocks and associated metadata about them.">BlockInfo</a>* block, <a name="l00405"></a>00405 <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917" title="Bundle Status Report &quot;Reason Code&quot; flags.">status_report_reason_t</a>* reception_reason, <a name="l00406"></a>00406 <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917" title="Bundle Status Report &quot;Reason Code&quot; flags.">status_report_reason_t</a>* deletion_reason) <a name="l00407"></a>00407 { <a name="l00408"></a>00408 <span class="keywordflow">if</span> (block-><a class="code" href="classdtn_1_1BlockInfo.html#51f21d5cf4aef2550b605ab90961e045">flags</a>() & <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b08e26de152eecfd35ff1081abf480309">BundleProtocol::BLOCK_FLAG_REPORT_ONERROR</a>) { <a name="l00409"></a>00409 *reception_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>; <a name="l00410"></a>00410 } <a name="l00411"></a>00411 <a name="l00412"></a>00412 <span class="keywordflow">if</span> (block-><a class="code" href="classdtn_1_1BlockInfo.html#51f21d5cf4aef2550b605ab90961e045">flags</a>() & <a class="code" href="classdtn_1_1BundleProtocol.html#cd56fabd4393bd86ffc295bafaba540b0b657a90e3033d112835cf7df7a4855b">BundleProtocol::BLOCK_FLAG_DISCARD_BUNDLE_ONERROR</a>) { <a name="l00413"></a>00413 *deletion_reason = <a class="code" href="classdtn_1_1BundleProtocol.html#37b000d94172c06970bb8af32889f917a86c9900fe5641754acdcdb326b79b2c">BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE</a>; <a name="l00414"></a>00414 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00415"></a>00415 } <a name="l00416"></a>00416 <a name="l00417"></a>00417 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00418"></a>00418 } <a name="l00419"></a>00419 <a name="l00420"></a>00420 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00421"></a>00421 <span class="keywordtype">void</span> <a name="l00422"></a><a class="code" href="classdtn_1_1MetadataBlockProcessor.html#7ad78787a5ed3be4d082c529aaa8fa0a">00422</a> <a class="code" href="classdtn_1_1MetadataBlockProcessor.html#7ad78787a5ed3be4d082c529aaa8fa0a" title="Deletes bundle state maintained for generated metadata.">MetadataBlockProcessor::delete_generated_metadata</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle, <a name="l00423"></a>00423 <span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>& link) <a name="l00424"></a>00424 { <a name="l00425"></a>00425 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(bundle != NULL); <a name="l00426"></a>00426 <a name="l00427"></a>00427 bundle-><a class="code" href="classdtn_1_1Bundle.html#1a77b94b46d2034dff2ea4eb339d9a58" title="Setters and mutable accessors.">mutable_generated_metadata</a>()-><a class="code" href="classdtn_1_1LinkMetadataSet.html#c7d96aecb020ca97d6cf9956686abff0">delete_blocks</a>(link); <a name="l00428"></a>00428 <a name="l00429"></a>00429 MetadataVec::const_iterator iter; <a name="l00430"></a>00430 <span class="keywordflow">for</span> (iter = bundle-><a class="code" href="classdtn_1_1Bundle.html#212b7cf608e211050ca40ec0e6f0259d" title="Accessors.">recv_metadata</a>().begin(); <a name="l00431"></a>00431 iter != bundle-><a class="code" href="classdtn_1_1Bundle.html#212b7cf608e211050ca40ec0e6f0259d" title="Accessors.">recv_metadata</a>().end(); ++iter) <a name="l00432"></a>00432 { <a name="l00433"></a>00433 (*iter)->delete_outgoing_metadata(link); <a name="l00434"></a>00434 } <a name="l00435"></a>00435 } <a name="l00436"></a>00436 <a name="l00437"></a>00437 } <span class="comment">// namespace dtn</span> </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 21 14:09:46 2008 for DTN Reference Implementation by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> </body> </html>