mirror of https://github.com/Icinga/icinga2.git
Remove the ZlibStream class and the stream_bio functionality.
Fixes #6119
This commit is contained in:
parent
7b9efdb63b
commit
dade476533
|
@ -100,7 +100,6 @@ check_function_exists(vfork HAVE_VFORK)
|
|||
check_function_exists(backtrace_symbols HAVE_BACKTRACE_SYMBOLS)
|
||||
check_function_exists(pipe2 HAVE_PIPE2)
|
||||
check_library_exists(dl dladdr "dlfcn.h" HAVE_DLADDR)
|
||||
check_library_exists(crypto BIO_f_zlib "" HAVE_BIOZLIB)
|
||||
check_library_exists(execinfo backtrace_symbols "" HAVE_LIBEXECINFO)
|
||||
|
||||
if(HAVE_LIBEXECINFO)
|
||||
|
@ -159,4 +158,4 @@ if(WIN32)
|
|||
)
|
||||
endif()
|
||||
|
||||
include(CPack)
|
||||
include(CPack)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#cmakedefine HAVE_BIOZLIB
|
||||
#cmakedefine HAVE_BACKTRACE_SYMBOLS
|
||||
#cmakedefine HAVE_PIPE2
|
||||
#cmakedefine HAVE_VFORK
|
||||
|
|
|
@ -29,10 +29,10 @@ add_library(base SHARED
|
|||
netstring.cpp networkstream.cpp object.cpp objectlock.cpp process.cpp
|
||||
qstring.cpp ringbuffer.cpp scriptfunction.cpp scriptfunctionwrapper.cpp
|
||||
scriptutils.cpp scriptvariable.cpp serializer.cpp socket.cpp stacktrace.cpp
|
||||
statsfunction.cpp stdiostream.cpp stream_bio.cpp stream.cpp streamlogger.cpp streamlogger.th
|
||||
statsfunction.cpp stdiostream.cpp stream.cpp streamlogger.cpp streamlogger.th
|
||||
sysloglogger.cpp sysloglogger.th tcpsocket.cpp threadpool.cpp timer.cpp
|
||||
tlsstream.cpp tlsutility.cpp type.cpp unixsocket.cpp utility.cpp value.cpp
|
||||
value-operators.cpp workqueue.cpp zlibstream.cpp
|
||||
value-operators.cpp workqueue.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(base ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} cJSON mmatch)
|
||||
|
|
|
@ -1,137 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "base/stream_bio.h"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
static int I2Stream_new(BIO *bi);
|
||||
static int I2Stream_free(BIO *bi);
|
||||
static int I2Stream_read(BIO *bi, char *out, int outl);
|
||||
static int I2Stream_write(BIO *bi, const char *in, int inl);
|
||||
static long I2Stream_ctrl(BIO *bi, int cmd, long num, void *ptr);
|
||||
|
||||
#define BIO_TYPE_I2STREAM (99|0x0400|0x0100)
|
||||
|
||||
static BIO_METHOD I2Stream_method =
|
||||
{
|
||||
BIO_TYPE_I2STREAM,
|
||||
"Icinga Stream",
|
||||
I2Stream_write,
|
||||
I2Stream_read,
|
||||
NULL,
|
||||
NULL,
|
||||
I2Stream_ctrl,
|
||||
I2Stream_new,
|
||||
I2Stream_free,
|
||||
NULL,
|
||||
};
|
||||
|
||||
typedef struct I2Stream_bio_s
|
||||
{
|
||||
Stream::Ptr StreamObj;
|
||||
boost::exception_ptr Exception;
|
||||
} I2Stream_bio_t;
|
||||
|
||||
BIO_METHOD *BIO_s_I2Stream(void)
|
||||
{
|
||||
return &I2Stream_method;
|
||||
}
|
||||
|
||||
BIO *icinga::BIO_new_I2Stream(const Stream::Ptr& stream)
|
||||
{
|
||||
BIO *bi = BIO_new(BIO_s_I2Stream());
|
||||
|
||||
if (bi == NULL)
|
||||
return NULL;
|
||||
|
||||
I2Stream_bio_t *bp = (I2Stream_bio_t *)bi->ptr;
|
||||
|
||||
bp->StreamObj = stream;
|
||||
|
||||
return bi;
|
||||
}
|
||||
|
||||
void icinga::I2Stream_check_exception(BIO *bi) {
|
||||
I2Stream_bio_t *bp = (I2Stream_bio_t *)bi->ptr;
|
||||
|
||||
if (bp->Exception) {
|
||||
boost::exception_ptr ptr = bp->Exception;
|
||||
bp->Exception = boost::exception_ptr();
|
||||
rethrow_exception(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
static int I2Stream_new(BIO *bi)
|
||||
{
|
||||
bi->shutdown = 0;
|
||||
bi->init = 1;
|
||||
bi->num = -1;
|
||||
bi->ptr = new I2Stream_bio_t;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int I2Stream_free(BIO *bi)
|
||||
{
|
||||
I2Stream_bio_t *bp = (I2Stream_bio_t *)bi->ptr;
|
||||
delete bp;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int I2Stream_read(BIO *bi, char *out, int outl)
|
||||
{
|
||||
I2Stream_bio_t *bp = (I2Stream_bio_t *)bi->ptr;
|
||||
|
||||
size_t data_read;
|
||||
|
||||
BIO_clear_retry_flags(bi);
|
||||
|
||||
try {
|
||||
data_read = bp->StreamObj->Read(out, outl);
|
||||
} catch (...) {
|
||||
bp->Exception = boost::current_exception();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (data_read == 0 && !bp->StreamObj->IsEof()) {
|
||||
BIO_set_retry_read(bi);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return data_read;
|
||||
}
|
||||
|
||||
static int I2Stream_write(BIO *bi, const char *in, int inl)
|
||||
{
|
||||
I2Stream_bio_t *bp = (I2Stream_bio_t *)bi->ptr;
|
||||
bp->StreamObj->Write(in, inl);
|
||||
return inl;
|
||||
}
|
||||
|
||||
static long I2Stream_ctrl(BIO *, int cmd, long, void *)
|
||||
{
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_FLUSH:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef STREAMBIO_H
|
||||
#define STREAMBIO_H
|
||||
|
||||
#include "base/i2-base.h"
|
||||
#include "base/stream.h"
|
||||
#include "base/tlsutility.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
BIO *BIO_new_I2Stream(const Stream::Ptr& stream);
|
||||
void I2Stream_check_exception(BIO *bi);
|
||||
|
||||
}
|
||||
|
||||
#endif /* STREAMBIO_H */
|
|
@ -1,82 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "base/zlibstream.h"
|
||||
#include "base/objectlock.h"
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#ifdef HAVE_BIOZLIB
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
extern "C" BIO_METHOD *BIO_f_zlib(void);
|
||||
|
||||
/**
|
||||
* Constructor for the ZlibStream class.
|
||||
*
|
||||
* @param innerStream The inner stream.
|
||||
* @param compress Whether we're compressing, false if we're decompressing.
|
||||
*/
|
||||
ZlibStream::ZlibStream(const Stream::Ptr& innerStream)
|
||||
: m_InnerStream(innerStream)
|
||||
{
|
||||
BIO *ibio = BIO_new_I2Stream(innerStream);
|
||||
BIO *zbio = BIO_new(BIO_f_zlib());
|
||||
m_BIO = BIO_push(zbio, ibio);
|
||||
}
|
||||
|
||||
ZlibStream::~ZlibStream(void)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
size_t ZlibStream::Read(void *buffer, size_t size)
|
||||
{
|
||||
ObjectLock olock(this);
|
||||
|
||||
return BIO_read(m_BIO, buffer, size);
|
||||
}
|
||||
|
||||
void ZlibStream::Write(const void *buffer, size_t size)
|
||||
{
|
||||
ObjectLock olock(this);
|
||||
|
||||
BIO_write(m_BIO, buffer, size);
|
||||
}
|
||||
|
||||
void ZlibStream::Close(void)
|
||||
{
|
||||
ObjectLock olock(this);
|
||||
|
||||
if (m_BIO) {
|
||||
BIO_free_all(m_BIO);
|
||||
m_BIO = NULL;
|
||||
|
||||
m_InnerStream->Close();
|
||||
}
|
||||
}
|
||||
|
||||
bool ZlibStream::IsEof(void) const
|
||||
{
|
||||
ObjectLock olock(this);
|
||||
|
||||
return BIO_eof(m_BIO);
|
||||
}
|
||||
|
||||
#endif /* HAVE_BIOZLIB */
|
|
@ -1,55 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ZLIBSTREAM_H
|
||||
#define ZLIBSTREAM_H
|
||||
|
||||
#include "base/i2-base.h"
|
||||
#include "base/stream_bio.h"
|
||||
#include <iostream>
|
||||
|
||||
#ifdef HAVE_BIOZLIB
|
||||
|
||||
namespace icinga {
|
||||
|
||||
class I2_BASE_API ZlibStream : public Stream
|
||||
{
|
||||
public:
|
||||
DECLARE_PTR_TYPEDEFS(ZlibStream);
|
||||
|
||||
ZlibStream(const Stream::Ptr& innerStream);
|
||||
~ZlibStream(void);
|
||||
|
||||
virtual size_t Read(void *buffer, size_t size);
|
||||
virtual void Write(const void *buffer, size_t size);
|
||||
|
||||
virtual void Close(void);
|
||||
|
||||
virtual bool IsEof(void) const;
|
||||
|
||||
private:
|
||||
Stream::Ptr m_InnerStream;
|
||||
BIO *m_BIO;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* HAVE_BIOZLIB */
|
||||
|
||||
#endif /* ZLIBSTREAM_H */
|
|
@ -28,7 +28,6 @@
|
|||
#include "base/objectlock.h"
|
||||
#include "base/stdiostream.h"
|
||||
#include "base/networkstream.h"
|
||||
#include "base/zlibstream.h"
|
||||
#include "base/application.h"
|
||||
#include "base/context.h"
|
||||
#include "base/statsfunction.h"
|
||||
|
@ -456,12 +455,7 @@ void ApiListener::OpenLogFile(void)
|
|||
return;
|
||||
}
|
||||
|
||||
StdioStream::Ptr logStream = make_shared<StdioStream>(fp, true);
|
||||
#ifdef HAVE_BIOZLIB
|
||||
m_LogFile = make_shared<ZlibStream>(logStream);
|
||||
#else /* HAVE_BIOZLIB */
|
||||
m_LogFile = logStream;
|
||||
#endif /* HAVE_BIOZLIB */
|
||||
m_LogFile = make_shared<StdioStream>(fp, true);
|
||||
m_LogMessageCount = 0;
|
||||
SetLogMessageTimestamp(Utility::GetTime());
|
||||
}
|
||||
|
@ -544,18 +538,13 @@ void ApiListener::ReplayLog(const ApiClient::Ptr& client)
|
|||
|
||||
std::fstream *fp = new std::fstream(path.CStr(), std::fstream::in);
|
||||
StdioStream::Ptr logStream = make_shared<StdioStream>(fp, true);
|
||||
#ifdef HAVE_BIOZLIB
|
||||
ZlibStream::Ptr lstream = make_shared<ZlibStream>(logStream);
|
||||
#else /* HAVE_BIOZLIB */
|
||||
Stream::Ptr lstream = logStream;
|
||||
#endif /* HAVE_BIOZLIB */
|
||||
|
||||
String message;
|
||||
while (true) {
|
||||
Dictionary::Ptr pmessage;
|
||||
|
||||
try {
|
||||
if (!NetString::ReadStringFromStream(lstream, &message))
|
||||
if (!NetString::ReadStringFromStream(logStream, &message))
|
||||
break;
|
||||
|
||||
pmessage = JsonDeserialize(message);
|
||||
|
@ -575,7 +564,7 @@ void ApiListener::ReplayLog(const ApiClient::Ptr& client)
|
|||
peer_ts = pmessage->Get("timestamp");
|
||||
}
|
||||
|
||||
lstream->Close();
|
||||
logStream->Close();
|
||||
}
|
||||
|
||||
Log(LogInformation, "cluster", "Replayed " + Convert::ToString(count) + " messages.");
|
||||
|
@ -666,4 +655,4 @@ std::set<ApiClient::Ptr> ApiListener::GetAnonymousClients(void) const
|
|||
{
|
||||
ObjectLock olock(this);
|
||||
return m_AnonymousClients;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue