Server IP : 104.21.38.3 / Your IP : 172.70.208.9 Web Server : Apache System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /www/server/mysql/src/rapid/plugin/x/src/ |
Upload File : |
/* * Copyright (c) 2015, 2023, Oracle and/or its affiliates. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2.0, * as published by the Free Software Foundation. * * This program is also distributed with certain software (including * but not limited to OpenSSL) that is licensed under separate terms, * as designated in a particular file or component or in included license * documentation. The authors of MySQL hereby grant you an additional * permission to link the program and your derivative works with the * separately licensed software that they have included with MySQL. * * 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 General Public License, version 2.0, for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA */ #include "json_utils.h" #include "my_dbug.h" #include <ctype.h> #include "xpl_error.h" #if 0 bool xpl::validate_json_string(const char *s, size_t length) { const char *c = s; const char *end = s + length; if (*c == '"') // string literal { ++c; while (c < end) { if (iscntrl(*c) || *c == 0) { return false; } if (*c == '\\') { if (c >= end-1) return false; /* The allowed escape codes: \" \\ \/ \b \f \n \r \t \u four-hex-digits */ ++c; switch (*c) { case '"': case '\\': case '/': case 'b': case 'f': case 'n': case 'r': case 't': ++c; break; case 'u': if (c < end - 5 && isxdigit(c[1]) && isxdigit(c[2]) && isxdigit(c[3]) && isxdigit(c[4])) c += 5; else return false; break; default: return false; } } else if (*c == '"') break; else ++c; } if (*c != '"') return false; ++c; } else return false; return true; } bool xpl::validate_json_string(const std::string &s) { return xpl::validate_json_string(s.data(), s.length()); } ngs::Error_code xpl::validate_json_document_path(const std::string &s) { if (s.empty()) return ngs::Error(ER_X_BAD_DOC_PATH, "Empty document path"); return ngs::Error_code(); } #endif std::string xpl::quote_json(const std::string &s) { std::string out; size_t i, end = s.length(); out.reserve(s.length() * 2 + 1); out.push_back('"'); for (i = 0; i < end; ++i) { switch (s[i]) { case '"': out.append("\\\""); break; case '\\': out.append("\\\\"); break; case '/': out.append("\\/"); break; case '\b': out.append("\\b"); break; case'\f': out.append("\\f"); break; case '\n': out.append("\\n"); break; case '\r': out.append("\\r"); break; case '\t': out.append("\\t"); break; default: out.push_back(s[i]); break; } } out.push_back('"'); return out; } std::string xpl::quote_json_if_needed(const std::string &s) { size_t i, end = s.length(); if (isalpha(s[0]) || s[0] == '_') { for (i = 1; i < end && (isdigit(s[i]) || isalpha(s[i]) || s[i] == '_'); i++) {} if (i == end) return s; } return quote_json(s); }