php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
php_odbc_utils.c
Go to the documentation of this file.
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 | Authors: Calvin Buckley <calvin@cmpct.info> |
14 +----------------------------------------------------------------------+
15*/
16
17#ifdef HAVE_CONFIG_H
18#include <config.h>
19#endif
20
21#include "php.h"
22
23/*
24 * This files contains functions shared between ext/pdo_odbc and ext/odbc,
25 * relating to i.e. connection string quoting rules.
26 *
27 * The declarations are PHPAPI due to being available for shared/static
28 * versions.
29 */
30
40{
41 /* ODBC quotes are curly braces */
42 if (str[0] != '{') {
43 return false;
44 }
45 /* Check for } that aren't doubled up or at the end of the string */
46 size_t length = strlen(str);
47 for (size_t i = 0; i < length; i++) {
48 if (str[i] == '}' && str[i + 1] == '}') {
49 /* Skip over so we don't count it again */
50 i++;
51 } else if (str[i] == '}' && str[i + 1] != '\0') {
52 /* If not at the end, not quoted */
53 return false;
54 }
55 }
56 return true;
57}
58
71{
72 return strpbrk(str, "[]{}(),;?*=!@") != NULL;
73}
74
79{
80 /* Assume all '}'. Include '{,' '}', and the null terminator too */
81 return (strlen(in_str) * 2) + 3;
82}
83
91PHPAPI size_t php_odbc_connstr_quote(char *out_str, const char *in_str, size_t out_str_size)
92{
93 *out_str++ = '{';
94 out_str_size--;
95 while (out_str_size > 2) {
96 if (*in_str == '\0') {
97 break;
98 } else if (*in_str == '}' && out_str_size - 1 > 2) {
99 /* enough room to append */
100 *out_str++ = '}';
101 *out_str++ = *in_str++;
102 out_str_size -= 2;
103 } else if (*in_str == '}') {
104 /* not enough, truncate here */
105 break;
106 } else {
107 *out_str++ = *in_str++;
108 out_str_size--;
109 }
110 }
111 /* append termination */
112 *out_str++ = '}';
113 *out_str++ = '\0';
114 out_str_size -= 2;
115 /* return how many characters were left */
116 return strlen(in_str);
117}
strpbrk(string $string, string $characters)
#define NULL
Definition gdcache.h:45
#define PHPAPI
Definition php.h:71
PHPAPI size_t php_odbc_connstr_estimate_quote_length(const char *in_str)
PHPAPI bool php_odbc_connstr_is_quoted(const char *str)
PHPAPI size_t php_odbc_connstr_quote(char *out_str, const char *in_str, size_t out_str_size)
PHPAPI bool php_odbc_connstr_should_quote(const char *str)
strlen(string $string)