From d3264312e131bd281007eaad6909f2d2fba01e5f Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 15 Nov 2012 17:05:40 +0100 Subject: [PATCH] Add function http_parser_version(). Fixes #115. --- http_parser.c | 7 +++++++ http_parser.h | 13 +++++++++++++ test.c | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/http_parser.c b/http_parser.c index ed3a923..50795e9 100644 --- a/http_parser.c +++ b/http_parser.c @@ -2173,3 +2173,10 @@ int http_body_is_final(const struct http_parser *parser) { return parser->state == s_message_done; } + +unsigned long +http_parser_version(void) { + return HTTP_PARSER_VERSION_MAJOR * 0x10000 | + HTTP_PARSER_VERSION_MINOR * 0x00100 | + HTTP_PARSER_VERSION_PATCH * 0x00001; +} diff --git a/http_parser.h b/http_parser.h index f624f86..98c0905 100644 --- a/http_parser.h +++ b/http_parser.h @@ -27,6 +27,7 @@ extern "C" { /* Also update SONAME in the Makefile whenever you change these. */ #define HTTP_PARSER_VERSION_MAJOR 2 #define HTTP_PARSER_VERSION_MINOR 1 +#define HTTP_PARSER_VERSION_PATCH 0 #include #if defined(_WIN32) && !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER<1600) @@ -262,6 +263,18 @@ struct http_parser_url { }; +/* Returns the library version. Bits 16-23 contain the major version number, + * bits 8-15 the minor version number and bits 0-7 the patch level. + * Usage example: + * + * unsigned long version = http_parser_version(); + * unsigned major = (version >> 16) & 255; + * unsigned minor = (version >> 8) & 255; + * unsigned patch = version & 255; + * printf("http_parser v%u.%u.%u\n", major, minor, version); + */ +unsigned long http_parser_version(void); + void http_parser_init(http_parser *parser, enum http_parser_type type); diff --git a/test.c b/test.c index 83723b7..995874c 100644 --- a/test.c +++ b/test.c @@ -3170,6 +3170,16 @@ main (void) int i, j, k; int request_count; int response_count; + unsigned long version; + unsigned major; + unsigned minor; + unsigned patch; + + version = http_parser_version(); + major = (version >> 16) & 255; + minor = (version >> 8) & 255; + patch = version & 255; + printf("http_parser v%u.%u.%u (0x%06lx)\n", major, minor, patch, version); printf("sizeof(http_parser) = %u\n", (unsigned int)sizeof(http_parser));