2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
15 php_http_version_t
*php_http_version_init(php_http_version_t
*v
, unsigned major
, unsigned minor
)
18 v
= emalloc(sizeof(*v
));
27 php_http_version_t
*php_http_version_parse(php_http_version_t
*v
, const char *str
)
31 register const char *ptr
= str
;
36 ++ptr
; if (*ptr
!= 't' && *ptr
!= 'T') break;
37 ++ptr
; if (*ptr
!= 't' && *ptr
!= 'T') break;
38 ++ptr
; if (*ptr
!= 'p' && *ptr
!= 'P') break;
39 ++ptr
; if (*ptr
!= '/') break;
43 /* rfc7230#2.6 The HTTP version number consists of two decimal digits separated by a "." (period or decimal point) */
45 if (major
>= 0 && major
<= 9) {
49 php_error_docref(NULL
, E_NOTICE
, "Non-standard version separator '%c' in HTTP protocol version '%s'", separator
, ptr
- 2);
63 if (minor
>= 0 && minor
<= 9) {
64 return php_http_version_init(v
, major
, minor
);
70 php_error_docref(NULL
, E_WARNING
, "Could not parse HTTP protocol version '%s'", str
);
74 void php_http_version_to_string(php_http_version_t
*v
, char **str
, size_t *len
, const char *pre
, const char *post
)
76 /* different semantics for different versions */
78 *len
= spprintf(str
, 0, "%s2%s", STR_PTR(pre
), STR_PTR(post
));
80 *len
= spprintf(str
, 0, "%s%u.%u%s", STR_PTR(pre
), v
->major
, v
->minor
, STR_PTR(post
));
84 void php_http_version_dtor(php_http_version_t
*v
)
89 void php_http_version_free(php_http_version_t
**v
)
92 php_http_version_dtor(*v
);
103 * vim600: noet sw=4 ts=4 fdm=marker
104 * vim<600: noet sw=4 ts=4