Changeset c5ec0c8 in nscp for include


Ignore:
Timestamp:
01/31/12 22:20:51 (16 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
a06e6af
Parents:
56724a4
Message:
  • Fixed issue with parsing "invalid external commands". If parsing fails it will notify you but use the legacy split string method instead.
  • LuaScript? module is now modern (ie. works with 0.4.0) Should be 99% compatible (function needs to be defined before registration) but all old scripts should work now (I think)
  • LuaScript? module has been modernized The new API is very similar to Python Concepts are working but not all commands have been implements (and no testcases either) The old API will still work
  • Fixed issue with
  • Changed CheckCounter format option to take a coma separated list of keyword from the below list:

nocap100: Counter values above 100 (for example, counter values measuring the processor load on multiprocessor computers) will not be reset to 100. The default behavior is that counter values are capped at a value of 100.
1000: Multiply the actual value by 1000.
noscale: Do not apply the default scaling factor.
So format=nocap100,noscale would combine the two aspects above.

  • Fixed issue with parsing multiple performance data items (internally)
  • Added option to CheckCounter format=nocap100 to not cap counters at 100% (for multi cpu machines)
  • Fixed help when specifying invalid options on command line
  • Eradicated a potential memory leak in the NSCA encryption library
Location:
include
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • include/luna.h

    r1ff950c rc5ec0c8  
    5050 
    5151    // 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++) { 
    5353    /* edited by Snaily: shouldn't it be const RegType *l ... ? */ 
    5454      lua_pushstring(L, l->name); 
  • include/nsca/nsca_enrypt.hpp

    r2ec2eb6 rc5ec0c8  
    159159    class any_encryption { 
    160160    public: 
     161      virtual ~any_encryption() {} 
    161162      virtual void init(std::string password, std::string iv) = 0; 
    162163      virtual void encrypt(std::string &buffer) = 0; 
     
    180181      cryptopp_encryption() : keysize_(TMethod::DEFAULT_KEYLENGTH) {} 
    181182      cryptopp_encryption(int keysize) : keysize_(keysize) {} 
     183      virtual ~cryptopp_encryption() {} 
    182184      int get_keySize() { 
    183185        return keysize_; 
     
    188190 
    189191      virtual void init(std::string password, std::string iv) { 
    190         init(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 
    195197        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) 
    199200          throw encryption_exception("Could not allocate memory for encryption/decryption key"); 
    200         } 
    201201        memset(key, 0, keysize); 
    202202        using namespace std; 
    203203        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; 
    221206 
    222207        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); 
    226211        } catch (...) { 
    227212          throw encryption_exception("Unknown exception when trying to setup crypto"); 
    228213        } 
    229         delete [] iv; 
    230         delete [] key; 
    231214      } 
    232215      void encrypt(std::string &buffer) { 
     
    439422        throw encryption_exception("Failed to get encryption module for: " + boost::lexical_cast<std::string>(encryption_method)); 
    440423 
    441       /* server generates IV used for encryption */ 
     424      // server generates IV used for encryption  
    442425      if (received_iv.empty()) { 
    443426        std::string iv = generate_transmitted_iv(); 
    444427        core_->init(password, iv); 
    445       } else  /* client receives IV from server */ 
     428      } else  // client receives IV from server 
    446429        core_->init(password, received_iv); 
    447430    } 
  • include/nsca/nsca_socket.hpp

    r2ec2eb6 rc5ec0c8  
    1616  private: 
    1717    boost::shared_ptr<tcp::socket> socket_; 
     18    boost::asio::io_service &io_service_; 
    1819    nsca_encrypt crypt_inst; 
    1920  public: 
     
    2122 
    2223  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_)); 
    2526    } 
    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(); 
    3331    } 
    3432 
    3533    virtual void connect(std::string host, std::string port) { 
    3634      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_); 
    3836      tcp::resolver::query query(host, port); 
    3937 
     
    4442      while (error && endpoint_iterator != end) { 
    4543        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); 
    4846        NSC_DEBUG_MSG(_T("Connected to: ") + to_wstring(ep.address().to_string())); 
    4947      } 
    50       if (error) 
     48      if (error) { 
     49        NSC_DEBUG_MSG(_T("Failed to connect to:") + utf8::to_unicode(host)); 
    5150        throw boost::system::system_error(error); 
     51      } 
    5252    } 
    5353 
    54     ~socket() { 
    55       get_socket().close(); 
    56     } 
    5754 
    5855    virtual void shutdown() { 
     
    6057      // Initiate graceful connection closure. 
    6158      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(); 
    6366    }; 
    6467 
    6568    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...")); 
    6871        return; 
    6972      } 
     
    7578    } 
    7679    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...")); 
    7982        return false; 
    8083      } 
     
    8588        return false; 
    8689      } 
    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())); 
    8991      std::string iv = iv_packet.get_iv(); 
    9092      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)); 
     
    9395    } 
    9496    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); 
    9698    } 
    9799    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); 
    99101    } 
    100102  }; 
  • include/nscapi/functions.hpp

    r8013c0c rc5ec0c8  
    788788        } else { 
    789789          chunk = perf.substr(0, p); 
     790          p = perf.find_first_not_of(tokenizer_data.perf_separator, p); 
    790791          perf = perf.substr(p); 
    791792        } 
  • include/pdh/collectors.hpp

    rd66ccee rc5ec0c8  
    121121    virtual __int64 get_int64() = 0; 
    122122    virtual double get_average(int backlog) = 0; 
     123    virtual void set_extra_format(DWORD format) = 0; 
    123124  }; 
    124125 
     
    135136    std::wstring lastError_; 
    136137    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) {} 
    139141    virtual void collect(const PDH::PDHCounter &counter) { 
    140142      PDHCounterMutexHandler mutex(&mutex_); 
     
    154156      return value_; 
    155157    } 
     158    void set_extra_format(DWORD format) { 
     159      extra_format = format; 
     160    } 
    156161    DWORD getFormat() const { 
    157       return format_double; 
     162      return format_double|extra_format; 
    158163    } 
    159164  public: 
     
    184189    bool hasValue_; 
    185190    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) {} 
    188194    virtual void collect(const PDH::PDHCounter &counter) { 
    189195      PDHCounterMutexHandler mutex(&mutex_); 
     
    203209      return value_; 
    204210    } 
     211    void set_extra_format(DWORD format) { 
     212      extra_format = format; 
     213    } 
    205214    DWORD getFormat() const { 
    206       return format_long; 
     215      return format_long|extra_format; 
    207216    } 
    208217    inline std::wstring get_string() { 
     
    232241    bool hasValue_; 
    233242    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) {} 
    236246    virtual void collect(const PDH::PDHCounter &counter) { 
    237247      PDHCounterMutexHandler mutex(&mutex_); 
     
    251261      return value_; 
    252262    } 
     263    void set_extra_format(DWORD format) { 
     264      extra_format = format; 
     265    } 
    253266    DWORD getFormat() const { 
    254       return format_large; 
     267      return format_large|extra_format; 
    255268    } 
    256269    inline std::wstring get_string() { 
     
    284297    const PDH::PDHCounter *parent_; 
    285298  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) {} 
    287301    RoundINTPDHBufferListenerImpl(int length_) : buffer(NULL), length(0), current(0), hasValue_(false), parent_(NULL) { 
    288302      resize(length_); 
     
    293307        return; 
    294308      delete [] buffer; 
     309    } 
     310 
     311    virtual void set_extra_format(DWORD format) { 
     312      extra_format = format; 
    295313    } 
    296314 
     
    396414    } 
    397415    virtual DWORD getFormat() const { 
    398       return format_double; 
     416      return format_double|extra_format; 
    399417    } 
    400418  }; 
     
    410428    } 
    411429    virtual DWORD getFormat() const { 
    412       return format_long; 
     430      return format_long|extra_format; 
    413431    } 
    414432  }; 
     
    424442    } 
    425443    virtual DWORD getFormat() const { 
    426       return format_large; 
     444      return format_large|extra_format; 
    427445    } 
    428446  }; 
Note: See TracChangeset for help on using the changeset viewer.