nghttp2_version: new function, returns info about this nghttp2

This returns run-time information about the lib
This commit is contained in:
Daniel Stenberg 2013-09-03 09:02:34 +02:00 committed by Tatsuhiro Tsujikawa
parent e8ca112749
commit 66b89006d5
3 changed files with 72 additions and 2 deletions

View File

@ -1,6 +1,6 @@
# nghttp2 - HTTP/2.0 C Library
# Copyright (c) 2012 Tatsuhiro Tsujikawa
# Copyright (c) 2012, 2013 Tatsuhiro Tsujikawa
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@ -37,7 +37,7 @@ OBJECTS = nghttp2_pq.c nghttp2_map.c nghttp2_queue.c \
nghttp2_session.c nghttp2_submit.c \
nghttp2_helper.c \
nghttp2_npn.c nghttp2_gzip.c \
nghttp2_hd.c
nghttp2_hd.c nghttp2_version.c
HFILES = nghttp2_pq.h nghttp2_int.h nghttp2_map.h nghttp2_queue.h \
nghttp2_buffer.h nghttp2_frame.h \

View File

@ -58,6 +58,25 @@ struct nghttp2_session;
*/
typedef struct nghttp2_session nghttp2_session;
#define NGHTTP2_VERSION_AGE 1
struct nghttp2_info {
int age; /* Age of this struct. This instance of nghttp2 sets it to
NGHTTP2_VERSION_AGE but a future version may bump it and add
more struct fields at the bottom */
int version_num; /* the NGHTTP2_VERSION_NUM number */
const char *version_str; /* points to the NGHTTP2_VERSION string */
const char *proto_str; /* points to the NGHTTP2_PROTO_VERSION_ID string
this instance implements */
/* -------- the above fields all exist when age == 1 */
};
/**
* @struct
*
* This struct is what nghttp2_version() returns. It holds information about
* the particular nghttp2 version.
*/
typedef struct nghttp2_info nghttp2_info;
/**
* @macro
*
@ -1976,6 +1995,17 @@ int nghttp2_gzip_inflate(nghttp2_gzip *inflater,
uint8_t *out, size_t *outlen_ptr,
const uint8_t *in, size_t *inlen_ptr);
/**
* @function
*
* Returns a pointer to a nghttp2_info struct with version information about
* the run-time library in use. The |least_version| argument can be set to a
* 24 bit numerical value for the least accepted version number and if the
* condition is not met, this function will return a NULL. Pass in 0 to skip
* the version checking.
*/
nghttp2_info *nghttp2_version(int least_version);
#ifdef __cplusplus
}
#endif

40
lib/nghttp2_version.c Normal file
View File

@ -0,0 +1,40 @@
/*
* nghttp2 - HTTP/2.0 C Library
*
* Copyright (c) 2012, 2013 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <nghttp2/nghttp2.h>
static nghttp2_info version = {
NGHTTP2_VERSION_AGE,
NGHTTP2_VERSION_NUM,
NGHTTP2_VERSION,
NGHTTP2_PROTO_VERSION_ID
};
nghttp2_info *nghttp2_version(int least_version)
{
if(least_version > NGHTTP2_VERSION_NUM)
return NULL;
return &version;
}