4 * TCLink Copyright (c) 2010-2020 TrustCommerce.
5 * http://www.trustcommerce.com
6 * techsupport@trustcommerce.com
9 * PHP Port Copyright (c) 2000
10 * Andrew Barnett <andrew@dataclarity.com>
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "php_config.h"
35 #include "php_tclink.h"
37 #if PHP_API_VERSION >= 20151012
38 #include "ext/standard/info.h"
43 zend_function_entry php_tclink_functions
[] = {
44 PHP_FE(tclink_send
, NULL
)
45 PHP_FE(tclink_getversion
, NULL
)
49 zend_module_entry php_tclink_module_entry
= {
50 #ifdef STANDARD_MODULE_HEADER
51 STANDARD_MODULE_HEADER
,
61 #if PHP_API_VERSION < 20090626
62 STANDARD_MODULE_PROPERTIES
69 STANDARD_MODULE_PROPERTIES_EX
73 #define PHP_TCLINK_DEFAULT_BUFFER_SIZE 8196
75 #ifdef COMPILE_DL_TCLINK
76 ZEND_GET_MODULE(php_tclink
)
79 PHP_MINFO_FUNCTION(tclink
)
81 char *tmp
= (char *)malloc(1024);
82 php_info_print_table_start();
84 php_info_print_table_row(2, "TCLink PHP Module", "enabled");
86 php_info_print_table_row(2, "TCLink PHP Module", TCLinkGetVersion(tmp
));
89 php_info_print_table_end();
92 /* {{{ proto void tclink_send(array params)
93 Send the transaction in for processing. */
94 PHP_FUNCTION(tclink_send
)
96 /* start with a clean break using PHP7 APIs */
97 #if PHP_API_VERSION >= 20151012
104 char *key
, *value
, *next_key
;
106 if (ZEND_NUM_ARGS() != 1)
111 /* initialize it here so that it always has a return value is always something */
112 array_init(return_value
);
113 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a", &arr
) == FAILURE
) {
117 tclink
= TCLinkCreate();
120 ZEND_HASH_FOREACH_STR_KEY_VAL(hash
, zkey
, zvalue
)
121 /* there aren't any numeric keys in tclink parameters */
124 /* for converting the numeric values in case they are provided */
125 if (Z_TYPE_P(zvalue
) != IS_STRING
)
127 convert_to_string(zvalue
);
129 TCLinkPushParam(tclink
, ZSTR_VAL(zkey
), Z_STRVAL_P(zvalue
));
131 ZEND_HASH_FOREACH_END();
133 /* send the transaction */
136 /* pull out the parameters and put them in a hash */
137 TCLinkGetEntireResponse(tclink
, buf
, sizeof(buf
));
140 while (key
&& (value
= strchr(key
, '=')))
143 next_key
= strchr(value
, '\n');
144 if (next_key
) *next_key
++ = 0;
146 add_assoc_string(return_value
, key
, value
);
151 TCLinkDestroy(tclink
);
152 /* for older PHP 4 / PHP 5 clients */
154 zval
**params
, **zvalue
;
156 char *key
, *value
, *next_key
;
161 /* check parameters */
162 if((ZEND_NUM_ARGS() != 1) ||
163 (zend_get_parameters_ex(1, ¶ms
) == FAILURE
)) {
167 convert_to_array_ex(params
);
171 /* grab the hash and stuff each parameter set into TCLink */
172 hash
= HASH_OF(*params
);
173 zend_hash_internal_pointer_reset(hash
);
174 while (zend_hash_get_current_data(hash
, (void **)&zvalue
) == SUCCESS
)
176 /* The Zend API added an extra parameter between 4.04 (sometime in
177 * 1999) and 4.06 (in early 2001). Assume that anything prior to
178 * 1/1/2001 is the older version. */
179 #if PHP_API_VERSION < 20000101
180 zend_hash_get_current_key(hash
, &key
, NULL
);
182 zend_hash_get_current_key(hash
, &key
, NULL
, 0);
184 convert_to_string_ex(zvalue
);
185 value
= Z_STRVAL_PP(zvalue
);
186 TCLinkPushParam(h
, key
, value
);
187 zend_hash_move_forward(hash
);
190 /* send the transaction */
193 /* pull out the parameters and put them in a hash */
194 TCLinkGetEntireResponse(h
, buf
, sizeof(buf
));
196 array_init(return_value
);
199 while (key
&& (value
= strchr(key
, '=')))
202 next_key
= strchr(value
, '\n');
203 if (next_key
) *next_key
++ = 0;
205 add_assoc_string(return_value
, key
, value
, 1);
212 /* return_value is returned automatically, we need not explictly call a
218 /* {{{ proto string tclink_getversion()
219 returns the API version information */
220 PHP_FUNCTION(tclink_getversion
)
224 TCLinkGetVersion(version
);
226 #if PHP_API_VERSION >= 20151012
227 char *str
= estrdup(version
);
230 RETURN_STRING(version
, 1);