3 PHP_HTTP_API php_http_version_t
*php_http_version_init(php_http_version_t
*v
, unsigned major
, unsigned minor TSRMLS_DC
)
6 v
= emalloc(sizeof(*v
));
15 PHP_HTTP_API php_http_version_t
*php_http_version_parse(php_http_version_t
*v
, const char *str TSRMLS_DC
)
17 php_http_version_t tmp
;
20 if (3 != sscanf(str
, "HTTP/%u%c%u", &tmp
.major
, &separator
, &tmp
.minor
)
21 && 3 != sscanf(str
, "%u%c%u", &tmp
.major
, &separator
, &tmp
.minor
)) {
22 php_http_error(HE_WARNING
, PHP_HTTP_E_MALFORMED_HEADERS
, "Could not parse HTTP protocol version '%s'", str
);
26 if (separator
&& separator
!= '.' && separator
!= ',') {
27 php_http_error(HE_NOTICE
, PHP_HTTP_E_MALFORMED_HEADERS
, "Non-standard version separator '%c' in HTTP protocol version '%s'", separator
, str
);
30 return php_http_version_init(v
, tmp
.major
, tmp
.minor TSRMLS_CC
);
33 PHP_HTTP_API
void php_http_version_to_string(php_http_version_t
*v
, char **str
, size_t *len
, const char *pre
, const char *post TSRMLS_DC
)
35 *len
= spprintf(str
, 0, "%s%u.%u%s", pre
? pre
: "", v
->major
, v
->minor
, post
? post
: "");
38 PHP_HTTP_API
void php_http_version_to_struct(php_http_version_t
*v
, HashTable
*strct TSRMLS_DC
)
42 INIT_PZVAL_ARRAY(&tmp
, strct
);
43 add_assoc_long(&tmp
, "major", v
->major
);
44 add_assoc_long(&tmp
, "minor", v
->minor
);
47 PHP_HTTP_API
void php_http_version_dtor(php_http_version_t
*v
)
52 PHP_HTTP_API
void php_http_version_free(php_http_version_t
**v
)
55 php_http_version_dtor(*v
);