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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
|
/* Copyright (c) 2015, 2025, 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 designed to work 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 either included with
the program or referenced in the documentation.
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 */
#ifndef PROTOCOL_CALLBACK_INCLUDED
#define PROTOCOL_CALLBACK_INCLUDED
/**
@file
Interface of the Protocol_callback class, which is used by the Command
service as proxy protocol.
*/
#include <stddef.h>
#include <sys/types.h>
#include "m_ctype.h"
#include "my_command.h"
#include "my_inttypes.h"
#include "mysql/service_command.h"
#include "mysql_time.h"
#include "sql/protocol.h"
#include "violite.h"
class Item_param;
class Send_field;
class String;
class my_decimal;
template <class T>
class List;
union COM_DATA;
class Protocol_callback final : public Protocol {
public:
Protocol_callback(const struct st_command_service_cbs *cbs,
enum cs_text_or_binary t_or_b, void *cbs_ctx)
: callbacks_ctx(cbs_ctx),
callbacks(*cbs),
client_capabilities(0),
client_capabilities_set(false),
text_or_binary(t_or_b),
in_meta_sending(false) {}
/**
Forces read of packet from the connection
@return bytes read
@retval -1 failure
*/
int read_packet() override;
/**
Reads from the line and parses the data into union COM_DATA
@return bytes read
@retval -1 failure
*/
int get_command(COM_DATA *com_data, enum_server_command *cmd) override;
/**
Returns the type of the protocol
@retval false success
@retval true failure
*/
enum enum_protocol_type type() const override { return PROTOCOL_PLUGIN; }
/**
Returns the type of the connection
@return enum enum_vio_type
*/
enum enum_vio_type connection_type() const override;
/**
Sends null value
@retval false success
@retval true failure
*/
bool store_null() override;
/**
Sends TINYINT value
@param from value
@retval false success
@retval true failure
*/
bool store_tiny(longlong from, uint32) override;
/**
Sends SMALLINT value
@param from value
@retval false success
@retval true failure
*/
bool store_short(longlong from, uint32) override;
/**
Sends INT/INTEGER value
@param from value
@retval false success
@retval true failure
*/
bool store_long(longlong from, uint32) override;
/**
Sends BIGINT value
@param from value
@param is_unsigned from is unsigned
@retval false success
@retval true failure
*/
bool store_longlong(longlong from, bool is_unsigned, uint32) override;
/**
Sends DECIMAL value
@param d value
@retval false success
@retval true failure
*/
bool store_decimal(const my_decimal *d, uint, uint) override;
/**
Sends string (CHAR/VARCHAR/TEXT/BLOB) value
@retval false success
@retval true failure
*/
bool store_string(const char *from, size_t length,
const CHARSET_INFO *fromcs) override;
/**
Sends FLOAT value
@param from value
@param decimals number of digits to use after decimal point, unless it is
DECIMAL_NOT_SPECIFIED
@retval false success
@retval true failure
*/
bool store_float(float from, uint32 decimals, uint32) override;
/**
Sends DOUBLE value
@param from value
@param decimals number of digits to use after decimal point, unless it is
DECIMAL_NOT_SPECIFIED
@retval false success
@retval true failure
*/
bool store_double(double from, uint32 decimals, uint32) override;
/**
Sends DATETIME value
@param time value
@param precision fractional seconds precision. 0 ... DATETIME_MAX_DECIMALS
@retval false success
@retval true failure
*/
bool store_datetime(const MYSQL_TIME &time, uint precision) override;
/**
Sends DATE value
@param time value
@retval false success
@retval true failure
*/
bool store_date(const MYSQL_TIME &time) override;
/**
Sends TIME value
@param time value
@param precision fractional seconds precision. 0 ... DATETIME_MAX_DECIMALS
@retval false success
@retval true failure
*/
bool store_time(const MYSQL_TIME &time, uint precision) override;
/**
Sends Field
@param field the field to be sent through the protocol
@retval false success
@retval true failure
*/
bool store_field(const Field *field) override;
/**
Returns the capabilities supported by the protocol
*/
ulong get_client_capabilities() override;
/**
Checks if the protocol supports a capability
@param capability the capability
@retval true supports
@retval false does not support
*/
bool has_client_capability(unsigned long capability) override;
/**
Called BEFORE sending data row or before field_metadata
*/
void start_row() override;
/**
Called AFTER sending data row or before field_metadata
*/
bool end_row() override;
/**
Called when a row is aborted
*/
void abort_row() override;
/**
Called in case of error while sending data
*/
void end_partial_result_set() override;
/**
Called when the server shuts down the connection (THD is being destroyed).
In this regard, this is also called when the server shuts down. The callback
implementor can differentiate between those 2 events by inspecting the
shutdown_type parameter.
@param server_shutdown Whether this is a normal connection shutdown (false)
or a server shutdown (true).
@retval 0 success
@retval !0 failure
*/
int shutdown(bool server_shutdown = false) override;
/**
This function always returns true as in many places in the server this
is a prerequisite for continuing operations.
@retval true alive
*/
bool connection_alive() const override;
/**
Should return protocol's reading/writing status. Returns 0 (idle) as it
this is the best guess that can be made as there is no callback for
get_rw_status().
*/
uint get_rw_status() override;
/**
Checks if compression is enabled
@retval true enabled
@retval false disabled
*/
bool get_compression() override;
/**
Checks if compression is enabled and return compression method name
@return algorithm name if compression is supported else null
*/
char *get_compression_algorithm() override;
/**
Checks if compression is enabled and return compression level.
@return compression level if compression is supported else 0
*/
uint get_compression_level() override;
/**
Called BEFORE sending metadata
@param num_cols Number of columns in the result set
@param flags flags to be used to alter the way the messages are sent to
the client, see Protocol class for SEND_NUM_ROWS, SEND_DEFAULTS,
SEND_EOF
@param resultcs The character set of the results. Can be different from the
one in the field metadata.
@retval true failure
@retval false success
*/
bool start_result_metadata(uint num_cols, uint flags,
const CHARSET_INFO *resultcs) override;
/**
Sends metadata of one field. Called for every column in the result set.
@param field Field's metadata
@param cs Charset
@retval true failure
@retval false success
*/
bool send_field_metadata(Send_field *field, const CHARSET_INFO *cs) override;
/**
Called AFTER sending metadata
@retval true failure
@retval false success
*/
bool end_result_metadata() override;
/**
Sends OK
@param server_status Bit field with different statuses. See SERVER_STATUS_*
@param warn_count Warning count from the execution
@param affected_rows Rows changed/deleted during the operation
@param last_insert_id ID of the last insert row, which has AUTO_INCROMENT
column
@param message Textual message from the execution. May be NULL.
@retval true failure
@retval false success
*/
bool send_ok(uint server_status, uint warn_count, ulonglong affected_rows,
ulonglong last_insert_id, const char *message) override;
/**
Sends end of file.
This will be called once all data has been sent.
@param server_status Bit field with different statuses. See SERVER_STATUS_*
@param warn_count The warning count generated by the execution of the
statement.
@retval true failure
@retval false success
*/
bool send_eof(uint server_status, uint warn_count) override;
/**
Sends error
@param sql_errno Error number, beginning from 1000
@param err_msg The error message
@param sql_state The SQL state - 5 char string
@retval true failure
@retval false success
*/
bool send_error(uint sql_errno, const char *err_msg,
const char *sql_state) override;
bool store_ps_status(ulong stmt_id, uint column_count, uint param_count,
ulong cond_count) override;
bool send_parameters(List<Item_param> *parameters,
bool is_sql_prepare) override;
bool flush() override;
using Protocol::store_long;
using Protocol::store_short;
private:
/**
Set output parameters to variables bound at PS execution.
This method handles the case when preparing and executing was done
through SQL (not by COM_STMT_PREPARE/COM_STMT_EXECUTE) in which
output parameters are not going to be send to client (or
'st_command_service_cbs'), instead they will set concrete session
variables.
@param parameters List of PS/SP parameters (both input and output).
@retval false success
@retval true failure
*/
bool set_variables_from_parameters(List<Item_param> *parameters);
void *callbacks_ctx;
struct st_command_service_cbs callbacks;
unsigned long client_capabilities;
bool client_capabilities_set;
enum cs_text_or_binary text_or_binary;
bool in_meta_sending;
};
#endif /* PROTOCOL_CALLBACK_INCLUDED */
|