diff --git a/NEWS b/NEWS index 8343029..3cc1539 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,6 @@ +- (Feb 23 2009) Added libssh2_version() + - (Feb 20 2009) libssh2_channel_direct_tcpip_ex() bug #1902169 fixed, which caused it to fail when called a second time. diff --git a/docs/Makefile.am b/docs/Makefile.am index c638ba2..3e448aa 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.31 2008/12/26 07:46:45 bagder Exp $ +# $Id: Makefile.am,v 1.32 2009/02/23 16:22:46 bagder Exp $ EXTRA_DIST = template.3 @@ -67,4 +67,5 @@ dist_man_MANS = \ libssh2_userauth_password_ex.3 \ libssh2_userauth_publickey_fromfile.3 \ libssh2_base64_decode.3 \ - libssh2_trace.3 + libssh2_trace.3 \ + libssh2_version.3 diff --git a/docs/libssh2_version.3 b/docs/libssh2_version.3 new file mode 100644 index 0000000..3f4480c --- /dev/null +++ b/docs/libssh2_version.3 @@ -0,0 +1,38 @@ +.\" $Id: libssh2_version.3,v 1.1 2009/02/23 16:22:46 bagder Exp $ +.\" +.TH libssh2_version 3 "23 Feb 2009" "libssh2 1.1" "libssh2 manual" +.SH NAME +libssh2_version - return the libssh2 version number +.SH SYNOPSIS +#include + +const char * +libssh2_version(int required_version); +.SH DESCRIPTION +If \fIrequired_version\fP is lower than or equal to the version number of the +libssh2 in use, the version number of libssh2 is returned as a pointer to a +zero terminated string. + +The \fIrequired_version\fP should be the version number as constructed by the +LIBSSH2_VERSION_NUM define in the libssh2.h public header file, which is a 24 +bit number in the 0xMMmmpp format. MM for major, mm for minor and pp for patch +number. +.SH RETURN VALUE +The version number of libssh2 is returned as a pointer to a zero terminated +string or NULL if the \fIrequired_version\fP isn't fulfilled. +.SH EXAMPLE +To make sure you run with the correct libssh2 version: + +.nf +if (!libssh2_version(LIBSSH2_VERSION_NUM)) { + fprintf (stderr, \&"Runtime libssh2 version too old!\&"); + exit(1); +} +.fi + +Unconditionally get the version number: + +printf(\&"libssh2 version: %s\&", libssh2_version(0) ); +.SH AVAILABILITY +This function was added in libssh2 1.1, in previous versions there way no way +to extract this info in run-time. diff --git a/include/libssh2.h b/include/libssh2.h index a70478f..1771052 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -652,6 +652,10 @@ LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest, unsigned int *dest_len, const char *src, unsigned int src_len); +LIBSSH2_API +const char *libssh2_version(int req_version_num); + + /* NOTE NOTE NOTE libssh2_trace() has no function in builds that aren't built with debug enabled diff --git a/src/Makefile.am b/src/Makefile.am index 7f7e498..8766b97 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,9 +1,9 @@ -# $Id: Makefile.am,v 1.14 2009/02/16 21:49:31 jas4711 Exp $ +# $Id: Makefile.am,v 1.15 2009/02/23 16:22:46 bagder Exp $ AUTOMAKE_OPTIONS = foreign nostdinc libssh2_la_SOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c \ misc.c packet.c publickey.c scp.c session.c sftp.c userauth.c \ -libssh2_priv.h openssl.h libgcrypt.h transport.c +libssh2_priv.h openssl.h libgcrypt.h transport.c version.c if LIBGCRYPT libssh2_la_SOURCES += libgcrypt.c pem.c diff --git a/src/version.c b/src/version.c new file mode 100644 index 0000000..df83018 --- /dev/null +++ b/src/version.c @@ -0,0 +1,54 @@ +/* Copyright (C) 2009 Daniel Stenberg. All rights reserved. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of the copyright holder nor the names + * of any other contributors may be used to endorse or + * promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + */ + +#include "libssh2.h" + +/* + libssh2_version() can be used like this: + + if (!libssh2_version(LIBSSH2_VERSION_NUM)) { + fprintf (stderr, "Runtime libssh2 version too old!\n"); + exit(1); + } +*/ +LIBSSH2_API +const char *libssh2_version(int req_version_num) +{ + if(req_version_num <= LIBSSH2_VERSION_NUM) + return LIBSSH2_VERSION; + return NULL; /* this is not a suitable library! */ +}