Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // main.cpp SNF-SDK-WIN CPP OEM Demonstration Code
  2. // Copyright (C) 2009 ARM Research Labs, LLC
  3. //
  4. // This app simply exercises the API provided by snfmultidll.
  5. #include <iostream>
  6. #include <string>
  7. #include "../include/snfmultidll.h"
  8. using namespace std;
  9. //// Setup the basics we need to run this test.
  10. const string LicenseID = "licensid"; // SNF License ID can be passed
  11. const string Authentication = "authenticationxx"; // directly or read from the
  12. const string ConfigurationPath = "snf_engine.xml"; // configuration. OEMs go direct!
  13. const unsigned int IPToTest = 0x0c22384e; // Same as IP 12.34.56.78
  14. const string SampleMessage =
  15. "Received: from mx-out.example.com [12.34.56.78] (HELO Somebody)\r\n"
  16. " by mx-in.example.com (nosuchserver v1.0) for nobody@example.com\r\n"
  17. "From: <somebody@example.com>\r\n"
  18. "To: <nobody@example.com>\r\n"
  19. "Subject: Nothing to see here\r\n"
  20. "\r\n"
  21. "So this is the big thing that's not here to see.\r\n"
  22. "I thought it would be more interesting than this.\r\n"
  23. "\r\n"
  24. "_M\r\n"
  25. ".\r\n";
  26. //// Here is a simple example. Startup, exercise the API, shut down.
  27. //// Note that we're doing this in a very "C" style becuase the DLL API is C
  28. int main() {
  29. int Result = 0;
  30. Result = startupSNF(const_cast<char*>(ConfigurationPath.c_str()));
  31. // Result = startupSNFAuthenticated(
  32. // const_cast<char*>(ConfigurationPath.c_str()),
  33. // const_cast<char*>(LicenseID.c_str()),
  34. // const_cast<char*>(Authentication.c_str())
  35. // );
  36. cout << "Started with config " << ConfigurationPath << " Result: " << Result << endl;
  37. // IP tests can be done asynchrounously - they do not have to be part of any particular scan.
  38. Result = testIP(IPToTest);
  39. cout << "IP test result: " << Result << endl;
  40. double IPReputation = getIPReputation(IPToTest);
  41. cout << "IP Reputation: " << IPReputation << endl;
  42. // Messgae scans happen in a scan, read, close cycle as shown inside this loop.
  43. const int NumberOfScans = 10;
  44. for(int i = 0; i < NumberOfScans; i++) {
  45. // Show how the IP reputation changes over time.
  46. double IPReputation = getIPReputation(IPToTest);
  47. cout << "IP Reputation: " << IPReputation << endl;
  48. // Scan a message from a buffer.
  49. int SetupTime = 12;
  50. int ScanHandle = 0;
  51. unsigned char* MsgBuffer = (unsigned char*) SampleMessage.c_str();
  52. unsigned int MsgBufferLength = (unsigned int) SampleMessage.length();
  53. ScanHandle = scanBuffer(MsgBuffer, MsgBufferLength, "TestMessage", SetupTime);
  54. cout << "Scan Handle: " << ScanHandle << endl;
  55. // Retrieve the X-Headers for the scan.
  56. char* XHeadersBuffer = 0;
  57. int XHeadersLength = 0;
  58. int ScanResult = 0;
  59. ScanResult = getScanXHeaders(ScanHandle, &XHeadersBuffer, &XHeadersLength);
  60. string XHeaders(XHeadersBuffer);
  61. // Close the scan.
  62. Result = closeScan(ScanHandle);
  63. cout << "Scan Close Result: " << Result << endl;
  64. // X- headers were captured in a string BEFORE closing the scan so we can
  65. // use them here.
  66. cout << "Scan result code: " << ScanResult << endl;
  67. cout << "Scan X- headers: " << XHeaders << endl;
  68. }
  69. // Now that all scanning is done we shut down.
  70. Result = shutdownSNF();
  71. return Result;
  72. }