CommonUtilities.cpp

Go to the documentation of this file.
00001 #include "dds/DCPS/security/CommonUtilities.h"
00002 
00003 #include <string>
00004 #include <cstdio>
00005 #include <vector>
00006 
00007 namespace OpenDDS {
00008 namespace Security {
00009 namespace CommonUtilities {
00010 
00011 URI::URI(const std::string& src)
00012   : scheme(URI_UNKNOWN), everything_else("") //authority(), path(""), query(""), fragment("")
00013 {
00014   typedef std::vector<std::pair<std::string, Scheme> > uri_pattern_t;
00015 
00016   uri_pattern_t uri_patterns;
00017   uri_patterns.push_back(std::make_pair("file:", URI_FILE));
00018   uri_patterns.push_back(std::make_pair("data:", URI_DATA));
00019   uri_patterns.push_back(std::make_pair("pkcs11:", URI_PKCS11));
00020 
00021   for (uri_pattern_t::iterator i = uri_patterns.begin();
00022        i != uri_patterns.end(); ++i) {
00023     const std::string& pfx = i->first;
00024     size_t pfx_end = pfx.length();
00025 
00026     if (src.substr(0, pfx_end) == pfx) {
00027       everything_else = src.substr(pfx_end, std::string::npos);
00028       scheme = i->second;
00029       break;
00030     }
00031   }
00032 }
00033 
00034 int increment_handle(int& next)
00035 {
00036   // handles are 32-bit signed values (int on all supported platforms)
00037   // the only special value is 0 for HANDLE_NIL, 'next' starts at 1
00038   // signed increment is not guaranteed to roll over so we implement our own
00039   static const int LAST_POSITIVE_HANDLE(0x7fffffff);
00040   static const int FIRST_NEGATIVE_HANDLE(-LAST_POSITIVE_HANDLE);
00041   if (next == 0) {
00042     ACE_ERROR((LM_ERROR, "(%P|%t) OpenDDS::Security::CommonUtilities::"
00043                "increment_handle ERROR - out of handles\n"));
00044     return 0;
00045   }
00046   const int h = next;
00047   if (next == LAST_POSITIVE_HANDLE) {
00048     next = FIRST_NEGATIVE_HANDLE;
00049   } else {
00050     ++next;
00051   }
00052   return h;
00053 }
00054 
00055 void set_security_error(DDS::Security::SecurityException& ex,
00056                         int code,
00057                         int minor_code,
00058                         const char* message)
00059 {
00060   ex.code = code;
00061   ex.minor_code = minor_code;
00062   ex.message = message;
00063 }
00064 
00065 void set_security_error(DDS::Security::SecurityException& ex,
00066                         int code,
00067                         int minor_code,
00068                         const char* message,
00069                         const unsigned char (&a1)[4],
00070                         const unsigned char (&a2)[4])
00071 {
00072   std::string full(message);
00073   const size_t i = full.size();
00074   full.resize(i + 25);
00075   std::sprintf(&full[i], " %.2x %.2x %.2x %.2x, %.2x %.2x %.2x %.2x",
00076                a1[0], a1[1], a1[2], a1[3], a2[0], a2[1], a2[2], a2[3]);
00077   set_security_error(ex, code, minor_code, full.c_str());
00078 }
00079 
00080 }
00081 }
00082 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1