Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
centreon
centreon-connectors
Commits
32b41a8d
Commit
32b41a8d
authored
Jan 09, 2012
by
Dorian Guillois
Browse files
Merge branch 'master' of
http://git.centreon.com/centreon-connector
into icmp_v2
parents
ee809bfe
8925a181
Changes
8
Hide whitespace changes
Inline
Side-by-side
ssh/inc/com/centreon/connector/ssh/policy.hh
View file @
32b41a8d
...
...
@@ -28,8 +28,7 @@
# include "com/centreon/connector/ssh/orders/parser.hh"
# include "com/centreon/connector/ssh/reporter.hh"
# include "com/centreon/connector/ssh/sessions/credentials.hh"
# include "com/centreon/io/standard_input.hh"
# include "com/centreon/io/standard_output.hh"
# include "com/centreon/io/file_stream.hh"
CCCS_BEGIN
()
...
...
@@ -77,8 +76,8 @@ private:
reporter
_reporter
;
std
::
map
<
sessions
::
credentials
,
sessions
::
session
*>
_sessions
;
io
::
standard_input
_sin
;
io
::
standard_output
_sout
;
io
::
file_stream
_sin
;
io
::
file_stream
_sout
;
};
CCCS_END
()
...
...
ssh/inc/com/centreon/connector/ssh/sessions/socket_handle.hh
View file @
32b41a8d
/*
** Copyright 2011 Merethis
** Copyright 2011
-2012
Merethis
**
** This file is part of Centreon Connector SSH.
**
...
...
@@ -35,16 +35,20 @@ namespace sessions {
*/
class
socket_handle
:
public
com
::
centreon
::
handle
{
public:
socket_handle
(
native_handle
internal_handle
=
-
1
);
socket_handle
(
native_handle
handl
=
native_handle_null
);
~
socket_handle
()
throw
();
void
close
();
native_handle
get_native_handle
();
unsigned
long
read
(
void
*
data
,
unsigned
long
size
);
void
set_native_handle
(
native_handle
internal_
handl
e
);
void
set_native_handle
(
native_handle
handl
);
unsigned
long
write
(
void
const
*
data
,
unsigned
long
size
);
private:
socket_handle
(
socket_handle
const
&
sh
);
socket_handle
&
operator
=
(
socket_handle
const
&
sh
);
native_handle
_handl
;
};
}
...
...
ssh/src/checks/check.cc
View file @
32b41a8d
...
...
@@ -44,7 +44,8 @@ check::check()
_cmd_id
(
0
),
_listnr
(
NULL
),
_session
(
NULL
),
_step
(
chan_open
)
{}
_step
(
chan_open
),
_timeout
(
0
)
{}
/**
* Destructor.
...
...
ssh/src/policy.cc
View file @
32b41a8d
...
...
@@ -20,7 +20,10 @@
#include <assert.h>
#include <memory>
#include <stdio.h>
#include <stdlib.h>
#include "com/centreon/concurrency/locker.hh"
#include "com/centreon/concurrency/mutex.hh"
#include "com/centreon/connector/ssh/checks/check.hh"
#include "com/centreon/connector/ssh/checks/result.hh"
#include "com/centreon/connector/ssh/multiplexer.hh"
...
...
@@ -43,7 +46,7 @@ extern volatile bool should_exit;
/**
* Default constructor.
*/
policy
::
policy
()
{
policy
::
policy
()
:
_sin
(
stdin
),
_sout
(
stdout
)
{
// Send information back.
multiplexer
::
instance
().
handle_manager
::
add
(
&
_sout
,
&
_reporter
);
...
...
@@ -190,6 +193,11 @@ void policy::on_quit() {
* @param[in] r Check result.
*/
void
policy
::
on_result
(
checks
::
result
const
&
r
)
{
static
concurrency
::
mutex
processing_mutex
;
// Lock mutex.
concurrency
::
locker
lock
(
&
processing_mutex
);
// Remove check from list.
std
::
map
<
unsigned
long
long
,
std
::
pair
<
checks
::
check
*
,
sessions
::
session
*>
>::
iterator
chk
;
chk
=
_checks
.
find
(
r
.
get_command_id
());
...
...
@@ -244,6 +252,7 @@ void policy::on_result(checks::result const& r) {
}
}
}
lock
.
unlock
();
// Send check result back to monitoring engine.
_reporter
.
send_result
(
r
);
...
...
ssh/src/sessions/session.cc
View file @
32b41a8d
...
...
@@ -219,7 +219,7 @@ void session::connect() {
_socket
.
set_native_handle
(
mysocket
);
// Register with multiplexer.
multiplexer
::
instance
().
handle_manager
::
add
(
&
_socket
,
this
);
multiplexer
::
instance
().
handle_manager
::
add
(
&
_socket
,
this
,
true
);
// Launch the connection process.
logging
::
debug
(
logging
::
medium
)
...
...
@@ -525,7 +525,7 @@ void session::_startup() {
// Exchange banners, keys, setup crypto, compression, ...
int
retval
(
libssh2_session_startup
(
_session
,
_socket
.
get_
internal
_handle
()));
_socket
.
get_
native
_handle
()));
if
(
retval
)
{
if
(
retval
!=
LIBSSH2_ERROR_EAGAIN
)
{
// Fatal failure.
char
*
msg
;
...
...
ssh/src/sessions/socket_handle.cc
View file @
32b41a8d
/*
** Copyright 2011 Merethis
** Copyright 2011
-2012
Merethis
**
** This file is part of Centreon Connector SSH.
**
...
...
@@ -38,10 +38,9 @@ using namespace com::centreon::connector::ssh::sessions;
/**
* Default constructor.
*
* @param[in]
internal_
handl
e
Native socket descriptor.
* @param[in] handl Native socket descriptor.
*/
socket_handle
::
socket_handle
(
native_handle
internal_handle
)
:
handle
(
internal_handle
)
{}
socket_handle
::
socket_handle
(
native_handle
handl
)
:
_handl
(
handl
)
{}
/**
* Destructor.
...
...
@@ -54,14 +53,23 @@ socket_handle::~socket_handle() throw () {
* Close socket descriptor.
*/
void
socket_handle
::
close
()
{
if
(
_
internal
_handle
>=
0
)
{
shutdown
(
_
internal_
handl
e
,
SHUT_RDWR
);
::
close
(
_
internal_
handl
e
);
_
internal
_handle
=
-
1
;
if
(
_
handl
!=
native
_handle
_null
)
{
shutdown
(
_handl
,
SHUT_RDWR
);
::
close
(
_handl
);
_
handl
=
native
_handle
_null
;
}
return
;
}
/**
* Get the native socket handle.
*
* @return Native socket handle.
*/
native_handle
socket_handle
::
get_native_handle
()
{
return
(
_handl
);
}
/**
* Read from socket descriptor.
*
...
...
@@ -71,7 +79,7 @@ void socket_handle::close() {
* @return Number of bytes actually read.
*/
unsigned
long
socket_handle
::
read
(
void
*
data
,
unsigned
long
size
)
{
ssize_t
rb
(
::
read
(
_
internal_
handl
e
,
data
,
size
));
ssize_t
rb
(
::
read
(
_handl
,
data
,
size
));
if
(
rb
<
0
)
{
char
const
*
msg
(
strerror
(
errno
));
throw
(
basic_error
()
<<
"socket read error: "
<<
msg
);
...
...
@@ -82,11 +90,11 @@ unsigned long socket_handle::read(void* data, unsigned long size) {
/**
* Set socket descriptor.
*
* @param[in]
internal_
handl
e
Native socket descriptor.
* @param[in] handl Native socket descriptor.
*/
void
socket_handle
::
set_native_handle
(
native_handle
internal_
handl
e
)
{
void
socket_handle
::
set_native_handle
(
native_handle
handl
)
{
this
->
close
();
_internal
_handl
e
=
internal_
handl
e
;
_handl
=
handl
;
return
;
}
...
...
@@ -101,7 +109,7 @@ void socket_handle::set_native_handle(native_handle internal_handle) {
unsigned
long
socket_handle
::
write
(
void
const
*
data
,
unsigned
long
size
)
{
ssize_t
wb
(
::
write
(
_
internal_
handl
e
,
data
,
size
));
ssize_t
wb
(
::
write
(
_handl
,
data
,
size
));
if
(
wb
<
0
)
{
char
const
*
msg
(
strerror
(
errno
));
throw
(
basic_error
()
<<
"socket write error: "
<<
msg
);
...
...
ssh/test/orders/buffer_handle.cc
View file @
32b41a8d
/*
** Copyright 2011 Merethis
** Copyright 2011
-2012
Merethis
**
** This file is part of Centreon Connector SSH.
**
...
...
@@ -74,6 +74,15 @@ bool buffer_handle::empty() const {
return
(
_buffer
.
empty
());
}
/**
* Get the native handle.
*
* @return Invalid handle.
*/
native_handle
buffer_handle
::
get_native_handle
()
{
return
(
native_handle_null
);
}
/**
* Read data.
*
...
...
ssh/test/orders/buffer_handle.hh
View file @
32b41a8d
/*
** Copyright 2011 Merethis
** Copyright 2011
-2012
Merethis
**
** This file is part of Centreon Connector SSH.
**
...
...
@@ -38,6 +38,8 @@ public:
buffer_handle
&
operator
=
(
buffer_handle
const
&
bh
);
void
close
();
bool
empty
()
const
;
com
::
centreon
::
native_handle
get_native_handle
();
unsigned
long
read
(
void
*
data
,
unsigned
long
size
);
unsigned
long
write
(
void
const
*
data
,
unsigned
long
size
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment