123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <html>
- <head>
- <title>C:\M\Projects\MessageSniffer\PKG-SNF-SDK-WIN_Work\PKG-SNF-SDK-WIN\CPPSample\main.cpp</title>
- <style>
- body { background-color: #ffffff; font-family: "Courier New"; font-size:10.0pt; font-style: normal; font-weight: normal; text-decoration: none; }
- .se2 { color: #000000; background-color: #ffffff; } /* Window Text */
- .se17 { color: #800080; background-color: #ffffff; } /* Keyword */
- .se19 { color: #000080; background-color: #ffffff; } /* Number */
- .se20 { color: #008080; background-color: #ffffff; } /* String */
- .se22 { color: #808000; background-color: #ffffff; } /* Preprocessor */
- .se23 { color: #800000; background-color: #ffffff; } /* Punctuation */
- .se24 { color: #c04000; background-color: #ffffff; } /* Library Symbol */
- .se25 { color: #000000; background-color: #ffffff; } /* Operator */
- .se28 { color: #000000; background-color: #ffffff; font-weight: bolder; } /* Function */
- .se49 { color: #008000; background-color: #ffffff; font-style: italic; } /* Comment */
- .se50 { color: #004080; background-color: #ffffff; font-style: italic; } /* Comment */
- .se55 { color: #000000; background-color: #ffffff; } /* Window Text */
- .se57 { color: #000080; background-color: #ffffff; } /* Number */
- </style>
- </head>
- <body>
- <pre>
- <span class="se49">// main.cpp SNF-SDK-WIN CPP OEM Demonstration Code</span>
- <span class="se49">// Copyright (C) 2009 ARM Research Labs, LLC</span>
- <span class="se49">//</span>
- <span class="se49">// This app simply exercises the API provided by snfmultidll.</span>
-
- <span class="se22">#include</span><span class="se2"> </span><span class="se23"><</span><span class="se2">iostream</span><span class="se23">></span>
- <span class="se22">#include</span><span class="se2"> </span><span class="se23"><</span><span class="se2">string</span><span class="se23">></span>
- <span class="se22">#include</span><span class="se2"> </span><span class="se20">"../include/snfmultidll.h"</span>
-
- <span class="se17">using</span><span class="se2"> </span><span class="se17">namespace</span><span class="se2"> </span><span class="se24">std</span><span class="se25">;</span>
-
- <span class="se50">//// Setup the basics we need to run this test.</span>
-
- <span class="se17">const</span><span class="se2"> </span><span class="se24">string</span><span class="se2"> </span><span class="se55">LicenseID</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"licensid"</span><span class="se25">;</span><span class="se2"> </span><span class="se49">// SNF License ID can be passed</span>
- <span class="se17">const</span><span class="se2"> </span><span class="se24">string</span><span class="se2"> </span><span class="se55">Authentication</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"authenticationxx"</span><span class="se25">;</span><span class="se2"> </span><span class="se49">// directly or read from the</span>
- <span class="se17">const</span><span class="se2"> </span><span class="se24">string</span><span class="se2"> </span><span class="se55">ConfigurationPath</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"snf_engine.xml"</span><span class="se25">;</span><span class="se2"> </span><span class="se49">// configuration. OEMs go direct!</span>
-
-
- <span class="se17">const</span><span class="se2"> </span><span class="se17">unsigned</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">IPToTest</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se57">0x0c22384e</span><span class="se25">;</span><span class="se2"> </span><span class="se49">// Same as IP 12.34.56.78</span>
-
- <span class="se17">const</span><span class="se2"> </span><span class="se24">string</span><span class="se2"> </span><span class="se55">SampleMessage</span><span class="se2"> </span><span class="se25">=</span>
- <span class="se2"> </span><span class="se20">"Received: from mx-out.example.com [12.34.56.78] (HELO Somebody)\r\n"</span>
- <span class="se2"> </span><span class="se20">" by mx-in.example.com (nosuchserver v1.0) for nobody@example.com\r\n"</span>
- <span class="se2"> </span><span class="se20">"From: <somebody@example.com>\r\n"</span>
- <span class="se2"> </span><span class="se20">"To: <nobody@example.com>\r\n"</span>
- <span class="se2"> </span><span class="se20">"Subject: Nothing to see here\r\n"</span>
- <span class="se2"> </span><span class="se20">"\r\n"</span>
- <span class="se2"> </span><span class="se20">"So this is the big thing that's not here to see.\r\n"</span>
- <span class="se2"> </span><span class="se20">"I thought it would be more interesting than this.\r\n"</span>
- <span class="se2"> </span><span class="se20">"\r\n"</span>
- <span class="se2"> </span><span class="se20">"_M\r\n"</span>
- <span class="se2"> </span><span class="se20">".\r\n"</span><span class="se25">;</span>
-
- <span class="se50">//// Here is a simple example. Startup, exercise the API, shut down.</span>
- <span class="se50">//// Note that we're doing this in a very "C" style becuase the DLL API is C</span>
-
- <span class="se17">int</span><span class="se2"> </span><span class="se28">main</span><span class="se2">() </span><span class="se23">{</span>
-
- <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">startupSNF</span><span class="se2">(</span><span class="se17">const_cast</span><span class="se25"><</span><span class="se17">char</span><span class="se25">*></span><span class="se2">(</span><span class="se55">ConfigurationPath</span><span class="se2">.</span><span class="se28">c_str</span><span class="se2">()))</span><span class="se25">;</span>
-
- <span class="se49">// Result = startupSNFAuthenticated(</span>
- <span class="se49">// const_cast<char*>(ConfigurationPath.c_str()),</span>
- <span class="se49">// const_cast<char*>(LicenseID.c_str()),</span>
- <span class="se49">// const_cast<char*>(Authentication.c_str())</span>
- <span class="se49">// );</span>
-
- <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se20">"Started with config "</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se55">ConfigurationPath</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se20">" Result: "</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// IP tests can be done asynchrounously - they do not have to be part of any particular scan.</span>
-
- <span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">testIP</span><span class="se2">(</span><span class="se55">IPToTest</span><span class="se2">)</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se20">"IP test result: "</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se17">double</span><span class="se2"> </span><span class="se55">IPReputation</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">getIPReputation</span><span class="se2">(</span><span class="se55">IPToTest</span><span class="se2">)</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se20">"IP Reputation: "</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se55">IPReputation</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// Messgae scans happen in a scan, read, close cycle as shown inside this loop.</span>
-
- <span class="se2"> </span><span class="se17">const</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">NumberOfScans</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">10</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se17">for</span><span class="se2">(</span><span class="se17">int</span><span class="se2"> </span><span class="se55">i</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span><span class="se2"> </span><span class="se55">i</span><span class="se2"> </span><span class="se25"><</span><span class="se2"> </span><span class="se55">NumberOfScans</span><span class="se25">;</span><span class="se2"> </span><span class="se55">i</span><span class="se25">++</span><span class="se2">) </span><span class="se23">{</span>
-
- <span class="se2"> </span><span class="se49">// Show how the IP reputation changes over time.</span>
-
- <span class="se2"> </span><span class="se17">double</span><span class="se2"> </span><span class="se55">IPReputation</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">getIPReputation</span><span class="se2">(</span><span class="se55">IPToTest</span><span class="se2">)</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se20">"IP Reputation: "</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se55">IPReputation</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// Scan a message from a buffer.</span>
-
- <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">SetupTime</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">12</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">ScanHandle</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se17">unsigned</span><span class="se2"> </span><span class="se17">char</span><span class="se25">*</span><span class="se2"> </span><span class="se55">MsgBuffer</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> (</span><span class="se17">unsigned</span><span class="se2"> </span><span class="se17">char</span><span class="se25">*</span><span class="se2">) </span><span class="se55">SampleMessage</span><span class="se2">.</span><span class="se28">c_str</span><span class="se2">()</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se17">unsigned</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">MsgBufferLength</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> (</span><span class="se17">unsigned</span><span class="se2"> </span><span class="se17">int</span><span class="se2">) </span><span class="se55">SampleMessage</span><span class="se2">.</span><span class="se28">length</span><span class="se2">()</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se55">ScanHandle</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">scanBuffer</span><span class="se2">(</span><span class="se55">MsgBuffer</span><span class="se2">, </span><span class="se55">MsgBufferLength</span><span class="se2">, </span><span class="se20">"TestMessage"</span><span class="se2">, </span><span class="se55">SetupTime</span><span class="se2">)</span><span class="se25">;</span>
-
-
- <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se20">"Scan Handle: "</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se55">ScanHandle</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// Retrieve the X-Headers for the scan.</span>
-
- <span class="se2"> </span><span class="se17">char</span><span class="se25">*</span><span class="se2"> </span><span class="se55">XHeadersBuffer</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">XHeadersLength</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">ScanResult</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se55">ScanResult</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">getScanXHeaders</span><span class="se2">(</span><span class="se55">ScanHandle</span><span class="se2">, </span><span class="se25">&</span><span class="se55">XHeadersBuffer</span><span class="se2">, </span><span class="se25">&</span><span class="se55">XHeadersLength</span><span class="se2">)</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se24">string</span><span class="se2"> </span><span class="se28">XHeaders</span><span class="se2">(</span><span class="se55">XHeadersBuffer</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// Close the scan.</span>
-
- <span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">closeScan</span><span class="se2">(</span><span class="se55">ScanHandle</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se20">"Scan Close Result: "</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// X- headers were captured in a string BEFORE closing the scan so we can</span>
- <span class="se2"> </span><span class="se49">// use them here.</span>
-
- <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se20">"Scan result code: "</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se55">ScanResult</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se20">"Scan X- headers: "</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se55">XHeaders</span><span class="se2"> </span><span class="se25"><<</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se23">}</span>
-
- <span class="se2"> </span><span class="se49">// Now that all scanning is done we shut down.</span>
-
- <span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">shutdownSNF</span><span class="se2">()</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se17">return</span><span class="se2"> </span><span class="se55">Result</span><span class="se25">;</span>
-
- <span class="se23">}</span>
- </pre>
- </body>
- </html>
|