From 66b89006d55460c3b69f39a61a1a535fa36238bd Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 3 Sep 2013 09:02:34 +0200 Subject: [PATCH] nghttp2_version: new function, returns info about this nghttp2 This returns run-time information about the lib --- lib/Makefile.am | 4 ++-- lib/includes/nghttp2/nghttp2.h | 30 +++++++++++++++++++++++++ lib/nghttp2_version.c | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 lib/nghttp2_version.c diff --git a/lib/Makefile.am b/lib/Makefile.am index 7fe9c75e..b321693e 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -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 \ diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index f1069ba6..251a4b97 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -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 diff --git a/lib/nghttp2_version.c b/lib/nghttp2_version.c new file mode 100644 index 00000000..c7ec420d --- /dev/null +++ b/lib/nghttp2_version.c @@ -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 + +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; +}