- Timestamp:
- 01/31/12 22:20:51 (16 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- a06e6af
- Parents:
- 56724a4
- Location:
- include
- Files:
-
- 5 edited
-
luna.h (modified) (1 diff)
-
nsca/nsca_enrypt.hpp (modified) (4 diffs)
-
nsca/nsca_socket.hpp (modified) (7 diffs)
-
nscapi/functions.hpp (modified) (1 diff)
-
pdh/collectors.hpp (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
include/luna.h
r1ff950c rc5ec0c8 50 50 51 51 // fill method table with methods from class T 52 for ( RegType *l = T::methods; l->name; l++) {52 for (const RegType *l = T::methods; l->name; l++) { 53 53 /* edited by Snaily: shouldn't it be const RegType *l ... ? */ 54 54 lua_pushstring(L, l->name); -
include/nsca/nsca_enrypt.hpp
r2ec2eb6 rc5ec0c8 159 159 class any_encryption { 160 160 public: 161 virtual ~any_encryption() {} 161 162 virtual void init(std::string password, std::string iv) = 0; 162 163 virtual void encrypt(std::string &buffer) = 0; … … 180 181 cryptopp_encryption() : keysize_(TMethod::DEFAULT_KEYLENGTH) {} 181 182 cryptopp_encryption(int keysize) : keysize_(keysize) {} 183 virtual ~cryptopp_encryption() {} 182 184 int get_keySize() { 183 185 return keysize_; … … 188 190 189 191 virtual void init(std::string password, std::string iv) { 190 in it(password, (unsigned char*)&*iv.begin(), iv.size());191 192 }193 void init(std::string password, unsigned char *transmitted_iv, int iv_size) { 194 / * generate an encryption/description key using the password */192 int blocksize = get_blockSize(); 193 if(blocksize>iv.size()) 194 throw encryption_exception("IV size for crypto algorithm exceeds limits"); 195 196 // Generate key buffer 195 197 std::string::size_type keysize=get_keySize(); 196 197 unsigned char *key = new unsigned char[keysize+1]; 198 if (key == NULL){ 198 char *key = new char[keysize+1]; 199 if (key == NULL) 199 200 throw encryption_exception("Could not allocate memory for encryption/decryption key"); 200 }201 201 memset(key, 0, keysize); 202 202 using namespace std; 203 203 memcpy(key,password.c_str(),min(keysize,password.length())); 204 205 206 /* determine size of IV buffer for this algorithm */ 207 int blocksize = get_blockSize(); 208 if(blocksize>iv_size){ 209 throw encryption_exception("IV size for crypto algorithm exceeds limits"); 210 } 211 212 /* allocate memory for IV buffer */ 213 unsigned char *iv = new unsigned char[blocksize+1]; 214 if (iv == NULL){ 215 throw encryption_exception("Could not allocate memory for IV buffer"); 216 } 217 memset(iv, 0, blocksize); 218 219 /* fill IV buffer with first bytes of IV that is going to be used to crypt (determined by server) */ 220 memcpy(iv, transmitted_iv, sizeof(unsigned char)*blocksize); 204 std::string skey(key, keysize); 205 delete [] key; 221 206 222 207 try { 223 cipher_.SetKey( key, keysize);224 crypto_.SetCipherWithIV(cipher_, iv, 1);225 decrypto_.SetCipherWithIV(cipher_, iv, 1);208 cipher_.SetKey((const byte*)skey.c_str(), keysize); 209 crypto_.SetCipherWithIV(cipher_, (const byte*)iv.c_str(), 1); 210 decrypto_.SetCipherWithIV(cipher_, (const byte*)iv.c_str(), 1); 226 211 } catch (...) { 227 212 throw encryption_exception("Unknown exception when trying to setup crypto"); 228 213 } 229 delete [] iv;230 delete [] key;231 214 } 232 215 void encrypt(std::string &buffer) { … … 439 422 throw encryption_exception("Failed to get encryption module for: " + boost::lexical_cast<std::string>(encryption_method)); 440 423 441 / * server generates IV used for encryption */424 // server generates IV used for encryption 442 425 if (received_iv.empty()) { 443 426 std::string iv = generate_transmitted_iv(); 444 427 core_->init(password, iv); 445 } else / * client receives IV from server */428 } else // client receives IV from server 446 429 core_->init(password, received_iv); 447 430 } -
include/nsca/nsca_socket.hpp
r2ec2eb6 rc5ec0c8 16 16 private: 17 17 boost::shared_ptr<tcp::socket> socket_; 18 boost::asio::io_service &io_service_; 18 19 nsca_encrypt crypt_inst; 19 20 public: … … 21 22 22 23 public: 23 socket(boost::asio::io_service &io_service) {24 socket_.reset(new tcp::socket(io_service ));24 socket(boost::asio::io_service &io_service) : io_service_(io_service) { 25 socket_.reset(new tcp::socket(io_service_)); 25 26 } 26 socket() {} 27 28 virtual boost::asio::io_service& get_io_service() { 29 return socket_->get_io_service(); 30 } 31 virtual basic_socket_type& get_socket() { 32 return *socket_; 27 ~socket() { 28 if (socket_) 29 socket_->close(); 30 socket_.reset(); 33 31 } 34 32 35 33 virtual void connect(std::string host, std::string port) { 36 34 NSC_DEBUG_MSG(_T("Connecting to: ") + to_wstring(host) + _T(" (") + to_wstring(port) + _T(")")); 37 tcp::resolver resolver( get_io_service());35 tcp::resolver resolver(io_service_); 38 36 tcp::resolver::query query(host, port); 39 37 … … 44 42 while (error && endpoint_iterator != end) { 45 43 tcp::resolver::endpoint_type ep = *endpoint_iterator; 46 get_socket().close();47 get_socket().lowest_layer().connect(*endpoint_iterator++, error);44 socket_->close(); 45 socket_->connect(*endpoint_iterator++, error); 48 46 NSC_DEBUG_MSG(_T("Connected to: ") + to_wstring(ep.address().to_string())); 49 47 } 50 if (error) 48 if (error) { 49 NSC_DEBUG_MSG(_T("Failed to connect to:") + utf8::to_unicode(host)); 51 50 throw boost::system::system_error(error); 51 } 52 52 } 53 53 54 ~socket() {55 get_socket().close();56 }57 54 58 55 virtual void shutdown() { … … 60 57 // Initiate graceful connection closure. 61 58 boost::system::error_code ignored_ec; 62 get_socket().lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec); 59 if (socket_) 60 socket_->shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec); 61 }; 62 virtual void close() { 63 if (socket_) 64 socket_->close(); 65 socket_.reset(); 63 66 }; 64 67 65 68 virtual void send_nsca(const nsca::packet &packet, const boost::posix_time::seconds timeout) { 66 if (! get_socket().is_open()) {67 NSC_ DEBUG_MSG(_T("is closed..."));69 if (!socket_ || !socket_->is_open()) { 70 NSC_LOG_ERROR_STD(_T("Socket was closed when trying to send data...")); 68 71 return; 69 72 } … … 75 78 } 76 79 virtual bool recv_iv(std::string password, int encryption_method, boost::posix_time::seconds timeout) { 77 if (! get_socket().is_open()) {78 NSC_ DEBUG_MSG(_T("is closed..."));80 if (!socket_ || !socket_->is_open()) { 81 NSC_LOG_ERROR_STD(_T("Socket was closed when trying to read data...")); 79 82 return false; 80 83 } … … 85 88 return false; 86 89 } 87 std::string tmp = std::string(buf.begin(), buf.end()); 88 nsca::iv_packet iv_packet(tmp); 90 nsca::iv_packet iv_packet(std::string(buf.begin(), buf.end())); 89 91 std::string iv = iv_packet.get_iv(); 90 92 NSC_DEBUG_MSG(_T("Encrypting using when sending: ") + utf8::cvt<std::wstring>(nsca::nsca_encrypt::helpers::encryption_to_string(encryption_method)) + _T(" and ") + utf8::cvt<std::wstring>(password)); … … 93 95 } 94 96 virtual bool read_with_timeout(std::vector<char> &buf, boost::posix_time::seconds timeout) { 95 return socket_helpers::io::read_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout);97 return socket_helpers::io::read_with_timeout(*socket_, *socket_, boost::asio::buffer(buf), timeout); 96 98 } 97 99 virtual void write_with_timeout(std::string &buf, boost::posix_time::seconds timeout) { 98 socket_helpers::io::write_with_timeout(*socket_, get_socket(), boost::asio::buffer(buf), timeout);100 socket_helpers::io::write_with_timeout(*socket_, *socket_, boost::asio::buffer(buf), timeout); 99 101 } 100 102 }; -
include/nscapi/functions.hpp
r8013c0c rc5ec0c8 788 788 } else { 789 789 chunk = perf.substr(0, p); 790 p = perf.find_first_not_of(tokenizer_data.perf_separator, p); 790 791 perf = perf.substr(p); 791 792 } -
include/pdh/collectors.hpp
rd66ccee rc5ec0c8 121 121 virtual __int64 get_int64() = 0; 122 122 virtual double get_average(int backlog) = 0; 123 virtual void set_extra_format(DWORD format) = 0; 123 124 }; 124 125 … … 135 136 std::wstring lastError_; 136 137 const PDH::PDHCounter *parent_; 137 public: 138 StaticPDHCounterListener() : value_(0), hasValue_(false), parent_(NULL) {} 138 DWORD extra_format; 139 public: 140 StaticPDHCounterListener() : value_(0), hasValue_(false), parent_(NULL), extra_format(0) {} 139 141 virtual void collect(const PDH::PDHCounter &counter) { 140 142 PDHCounterMutexHandler mutex(&mutex_); … … 154 156 return value_; 155 157 } 158 void set_extra_format(DWORD format) { 159 extra_format = format; 160 } 156 161 DWORD getFormat() const { 157 return format_double ;162 return format_double|extra_format; 158 163 } 159 164 public: … … 184 189 bool hasValue_; 185 190 const PDH::PDHCounter *parent_; 186 public: 187 StaticPDHCounterListener() : value_(0), hasValue_(false), parent_(NULL) {} 191 DWORD extra_format; 192 public: 193 StaticPDHCounterListener() : value_(0), hasValue_(false), parent_(NULL), extra_format(0) {} 188 194 virtual void collect(const PDH::PDHCounter &counter) { 189 195 PDHCounterMutexHandler mutex(&mutex_); … … 203 209 return value_; 204 210 } 211 void set_extra_format(DWORD format) { 212 extra_format = format; 213 } 205 214 DWORD getFormat() const { 206 return format_long ;215 return format_long|extra_format; 207 216 } 208 217 inline std::wstring get_string() { … … 232 241 bool hasValue_; 233 242 const PDH::PDHCounter *parent_; 234 public: 235 StaticPDHCounterListener() : value_(0), hasValue_(false), parent_(NULL) {} 243 DWORD extra_format; 244 public: 245 StaticPDHCounterListener() : value_(0), hasValue_(false), parent_(NULL), extra_format(0) {} 236 246 virtual void collect(const PDH::PDHCounter &counter) { 237 247 PDHCounterMutexHandler mutex(&mutex_); … … 251 261 return value_; 252 262 } 263 void set_extra_format(DWORD format) { 264 extra_format = format; 265 } 253 266 DWORD getFormat() const { 254 return format_large ;267 return format_large|extra_format; 255 268 } 256 269 inline std::wstring get_string() { … … 284 297 const PDH::PDHCounter *parent_; 285 298 public: 286 RoundINTPDHBufferListenerImpl() : buffer(NULL), length(0), current(0), hasValue_(false), parent_(NULL) {} 299 DWORD extra_format; 300 RoundINTPDHBufferListenerImpl() : buffer(NULL), length(0), current(0), hasValue_(false), parent_(NULL), extra_format(0) {} 287 301 RoundINTPDHBufferListenerImpl(int length_) : buffer(NULL), length(0), current(0), hasValue_(false), parent_(NULL) { 288 302 resize(length_); … … 293 307 return; 294 308 delete [] buffer; 309 } 310 311 virtual void set_extra_format(DWORD format) { 312 extra_format = format; 295 313 } 296 314 … … 396 414 } 397 415 virtual DWORD getFormat() const { 398 return format_double ;416 return format_double|extra_format; 399 417 } 400 418 }; … … 410 428 } 411 429 virtual DWORD getFormat() const { 412 return format_long ;430 return format_long|extra_format; 413 431 } 414 432 }; … … 424 442 } 425 443 virtual DWORD getFormat() const { 426 return format_large ;444 return format_large|extra_format; 427 445 } 428 446 };
Note: See TracChangeset
for help on using the changeset viewer.








