-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp_shoco.c
142 lines (120 loc) · 4.03 KB
/
php_shoco.c
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* Copyright (c) anno Domini nostri Jesu Christi MMXVI-MMXXIV John Boehr & contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "main/php.h"
#include "main/php_ini.h"
#include "ext/standard/info.h"
#include "ext/spl/spl_exceptions.h"
#include "zend_API.h"
#include "zend_exceptions.h"
#include "shoco.h"
#include "php_shoco.h"
/* {{{ Argument Info */
#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(shoco_args, IS_STRING, NULL, 0)
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
ZEND_END_ARG_INFO()
#else
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(shoco_args, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
ZEND_END_ARG_INFO()
#endif
/* }}} */
extern const char *PHP_SHOCO_MOTD =
"Think not that I am come to send peace on earth: I came not to send peace, but a sword. Matthew 10:34";
/* {{{ proto string shoco_compress($input) */
PHP_FUNCTION(shoco_compress)
{
zend_string *in = NULL;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR(in)
ZEND_PARSE_PARAMETERS_END();
size_t buf_size = ZSTR_LEN(in) * 3;
char *out = alloca(buf_size);
size_t out_length = shoco_compress(ZSTR_VAL(in), ZSTR_LEN(in), out, buf_size);
if (out_length > buf_size) {
zend_throw_exception(spl_ce_RuntimeException, "Shoco compression failed", 0);
} else {
RETVAL_STRINGL(out, out_length);
}
}
/* }}} */
/* {{{ proto string shoco_decompress($input) */
PHP_FUNCTION(shoco_decompress)
{
zend_string *in = NULL;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR(in)
ZEND_PARSE_PARAMETERS_END();
size_t buf_size = ZSTR_LEN(in) * 3;
char *out = alloca(buf_size);
size_t out_length = shoco_decompress(ZSTR_VAL(in), ZSTR_LEN(in), out, buf_size);
if (out_length > buf_size) {
zend_throw_exception(spl_ce_RuntimeException, "Shoco compression failed", 0);
} else {
RETVAL_STRINGL(out, out_length);
}
}
/* }}} */
/* {{{ PHP_MINIT_FUNCTION */
static PHP_MINFO_FUNCTION(shoco)
{
php_info_print_table_start();
php_info_print_table_row(2, "Version", PHP_SHOCO_VERSION);
php_info_print_table_row(2, "Released", PHP_SHOCO_RELEASE);
php_info_print_table_row(2, "Authors", PHP_SHOCO_AUTHORS);
php_info_print_table_end();
php_info_print_box_start(0);
PUTS(PHP_SHOCO_MOTD);
php_info_print_box_end();
DISPLAY_INI_ENTRIES();
}
/* }}} */
/* {{{ function_entry */
static zend_function_entry shoco_functions[] = {PHP_FE(shoco_compress, shoco_args) PHP_FE(shoco_decompress, shoco_args)
PHP_FE_END};
/* }}} */
/* {{{ shoco_deps */
static const zend_module_dep shoco_deps[] = {ZEND_MOD_REQUIRED("spl") ZEND_MOD_END};
/* }}} */
zend_module_entry shoco_module_entry = {
STANDARD_MODULE_HEADER_EX,
NULL,
shoco_deps, /* Deps */
PHP_SHOCO_NAME, /* Name */
shoco_functions, /* Functions */
NULL, /* MINIT */
NULL, /* MSHUTDOWN */
NULL, /* RINIT */
NULL, /* RSHUTDOWN */
PHP_MINFO(shoco), /* MINFO */
PHP_SHOCO_VERSION, /* Version */
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_SHOCO
ZEND_GET_MODULE(shoco) // Common for all PHP extensions which are build as shared modules
#endif
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: fdm=marker
* vim: et sw=4 ts=4
*/