File: php_http_version.c

package info (click to toggle)
php-pecl-http 2.0.4-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,436 kB
  • ctags: 1,839
  • sloc: ansic: 15,322; php: 726; xml: 254; makefile: 10; pascal: 3
file content (72 lines) | stat: -rw-r--r-- 2,128 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
    +--------------------------------------------------------------------+
    | PECL :: http                                                       |
    +--------------------------------------------------------------------+
    | Redistribution and use in source and binary forms, with or without |
    | modification, are permitted provided that the conditions mentioned |
    | in the accompanying LICENSE file are met.                          |
    +--------------------------------------------------------------------+
    | Copyright (c) 2004-2014, Michael Wallner <mike@php.net>            |
    +--------------------------------------------------------------------+
*/

#include "php_http_api.h"

php_http_version_t *php_http_version_init(php_http_version_t *v, unsigned major, unsigned minor TSRMLS_DC)
{
	if (!v) {
		v = emalloc(sizeof(*v));
	}

	v->major = major;
	v->minor = minor;

	return v;
}

php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *str TSRMLS_DC)
{
	php_http_version_t tmp;
	char separator = 0;

	if (3 != sscanf(str, "HTTP/%u%c%u", &tmp.major, &separator, &tmp.minor)
	&&	3 != sscanf(str, "%u%c%u", &tmp.major, &separator, &tmp.minor)) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse HTTP protocol version '%s'", str);
		return NULL;
	}

	if (separator && separator != '.' && separator != ',') {
		php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Non-standard version separator '%c' in HTTP protocol version '%s'", separator, str);
	}

	return php_http_version_init(v, tmp.major, tmp.minor TSRMLS_CC);
}

void php_http_version_to_string(php_http_version_t *v, char **str, size_t *len, const char *pre, const char *post TSRMLS_DC)
{
	*len = spprintf(str, 0, "%s%u.%u%s", pre ? pre : "", v->major, v->minor, post ? post : "");
}

void php_http_version_dtor(php_http_version_t *v)
{
	(void) v;
}

void php_http_version_free(php_http_version_t **v)
{
	if (*v) {
		php_http_version_dtor(*v);
		efree(*v);
		*v = NULL;
	}
}

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: noet sw=4 ts=4 fdm=marker
 * vim<600: noet sw=4 ts=4
 */