Skip to content

Commit 622f676

Browse files
committed
Expose ODBC connection string funcs in standard
This is because the code exists in main/, and are shared between both ODBC extensions, so it doesn't make sense for it to only exist in one or the other. There may be a better spot for it.
1 parent 1a886b0 commit 622f676

File tree

5 files changed

+95
-3
lines changed

5 files changed

+95
-3
lines changed

ext/standard/basic_functions.stub.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,14 @@ function gettimeofday(bool $as_float = false): array|float {}
16081608
function getrusage(int $mode = 0): array|false {}
16091609
#endif
16101610

1611+
/* odbc_utils.c */
1612+
1613+
function odbc_connection_string_is_quoted(string $str): bool {}
1614+
1615+
function odbc_connection_string_should_quote(string $str): bool {}
1616+
1617+
function odbc_connection_string_quote(string $str): string {}
1618+
16111619
/* pack.c */
16121620

16131621
/** @refcount 1 */

ext/standard/basic_functions_arginfo.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: bbcebdb57572133d5f442f220f1e98a1320ed0f6 */
2+
* Stub hash: ad5d1c6846c5258e85bf29cbccc63e1cff391f1a */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
55
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
@@ -1747,6 +1747,16 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_getrusage, 0, 0, MAY_BE_ARRAY|MA
17471747
ZEND_END_ARG_INFO()
17481748
#endif
17491749

1750+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_odbc_connection_string_is_quoted, 0, 1, _IS_BOOL, 0)
1751+
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
1752+
ZEND_END_ARG_INFO()
1753+
1754+
#define arginfo_odbc_connection_string_should_quote arginfo_odbc_connection_string_is_quoted
1755+
1756+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_odbc_connection_string_quote, 0, 1, IS_STRING, 0)
1757+
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
1758+
ZEND_END_ARG_INFO()
1759+
17501760
#define arginfo_pack arginfo_sprintf
17511761

17521762
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_unpack, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE)
@@ -2710,6 +2720,9 @@ ZEND_FUNCTION(gettimeofday);
27102720
#if defined(HAVE_GETRUSAGE)
27112721
ZEND_FUNCTION(getrusage);
27122722
#endif
2723+
ZEND_FUNCTION(odbc_connection_string_is_quoted);
2724+
ZEND_FUNCTION(odbc_connection_string_should_quote);
2725+
ZEND_FUNCTION(odbc_connection_string_quote);
27132726
ZEND_FUNCTION(pack);
27142727
ZEND_FUNCTION(unpack);
27152728
ZEND_FUNCTION(password_get_info);
@@ -3354,6 +3367,9 @@ static const zend_function_entry ext_functions[] = {
33543367
#if defined(HAVE_GETRUSAGE)
33553368
ZEND_FE(getrusage, arginfo_getrusage)
33563369
#endif
3370+
ZEND_FE(odbc_connection_string_is_quoted, arginfo_odbc_connection_string_is_quoted)
3371+
ZEND_FE(odbc_connection_string_should_quote, arginfo_odbc_connection_string_should_quote)
3372+
ZEND_FE(odbc_connection_string_quote, arginfo_odbc_connection_string_quote)
33573373
ZEND_FE(pack, arginfo_pack)
33583374
ZEND_FE(unpack, arginfo_unpack)
33593375
ZEND_FE(password_get_info, arginfo_password_get_info)

ext/standard/config.m4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ PHP_NEW_EXTENSION(standard, array.c base64.c basic_functions.c browscap.c crc32.
460460
http_fopen_wrapper.c php_fopen_wrapper.c credits.c css.c \
461461
var_unserializer.c ftok.c sha1.c user_filters.c uuencode.c \
462462
filters.c proc_open.c streamsfuncs.c http.c password.c \
463-
random.c net.c hrtime.c crc32_x86.c libavifinfo/avifinfo.c,,,
463+
random.c net.c hrtime.c crc32_x86.c libavifinfo/avifinfo.c \
464+
odbc_utils.c,,,
464465
-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
465466

466467
PHP_ADD_BUILD_DIR($ext_builddir/libavifinfo)

ext/standard/config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ EXTENSION("standard", "array.c base64.c basic_functions.c browscap.c \
3535
url_scanner_ex.c ftp_fopen_wrapper.c http_fopen_wrapper.c \
3636
php_fopen_wrapper.c credits.c css.c var_unserializer.c ftok.c sha1.c \
3737
user_filters.c uuencode.c filters.c proc_open.c password.c \
38-
streamsfuncs.c http.c flock_compat.c random.c hrtime.c", false /* never shared */,
38+
streamsfuncs.c http.c flock_compat.c random.c hrtime.c odbc_utils.c", false /* never shared */,
3939
'/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
4040
ADD_SOURCES("ext/standard/libavifinfo", "avifinfo.c", "standard");
4141
PHP_STANDARD = "yes";

ext/standard/odbc_utils.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Copyright (c) The PHP Group |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to version 3.01 of the PHP license, |
6+
| that is bundled with this package in the file LICENSE, and is |
7+
| available through the world-wide-web at the following url: |
8+
| https://www.php.net/license/3_01.txt |
9+
| If you did not receive a copy of the PHP license and are unable to |
10+
| obtain it through the world-wide-web, please send a note to |
11+
| license@php.net so we can mail you a copy immediately. |
12+
+----------------------------------------------------------------------+
13+
| Author: Calvin Buckley <calvin@cmpct.info> |
14+
+----------------------------------------------------------------------+
15+
*/
16+
17+
#include "php.h"
18+
#include "php_odbc_utils.h"
19+
20+
/*
21+
* This contains functionality shared between odbc and PDO_ODBC, so it makes
22+
* sense for this to be in standard.
23+
*/
24+
25+
PHP_FUNCTION(odbc_connection_string_is_quoted)
26+
{
27+
zend_string *str;
28+
29+
ZEND_PARSE_PARAMETERS_START(1, 1)
30+
Z_PARAM_STR(str)
31+
ZEND_PARSE_PARAMETERS_END();
32+
33+
bool is_quoted = php_odbc_connstr_is_quoted(ZSTR_VAL(str));
34+
//fprintf(stderr, "!%s!%d!\n", ZSTR_VAL(str), is_quoted);
35+
36+
RETURN_BOOL(is_quoted);
37+
}
38+
39+
PHP_FUNCTION(odbc_connection_string_should_quote)
40+
{
41+
zend_string *str;
42+
43+
ZEND_PARSE_PARAMETERS_START(1, 1)
44+
Z_PARAM_STR(str)
45+
ZEND_PARSE_PARAMETERS_END();
46+
47+
bool should_quote = php_odbc_connstr_should_quote(ZSTR_VAL(str));
48+
49+
//fprintf(stderr, "!%s!%d!\n", ZSTR_VAL(str), should_quote);
50+
RETURN_BOOL(should_quote);
51+
}
52+
53+
PHP_FUNCTION(odbc_connection_string_quote)
54+
{
55+
zend_string *str;
56+
57+
ZEND_PARSE_PARAMETERS_START(1, 1)
58+
Z_PARAM_STR(str)
59+
ZEND_PARSE_PARAMETERS_END();
60+
61+
size_t new_size = php_odbc_connstr_estimate_quote_length(ZSTR_VAL(str));
62+
zend_string *new_string = zend_string_alloc(new_size, 0);
63+
php_odbc_connstr_quote(ZSTR_VAL(new_string), ZSTR_VAL(str), new_size);
64+
/* reset length */
65+
ZSTR_LEN(new_string) = strlen(ZSTR_VAL(new_string));
66+
RETURN_STR(new_string);
67+
}

0 commit comments

Comments
 (0)