MySQL 8.0.37
Source Code Documentation
fido_common.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 Without limiting anything contained in the foregoing, this file,
16 which is part of C Driver for MySQL (Connector/C), is also subject to the
17 Universal FOSS Exception, version 1.0, a copy of which can be found at
18 http://oss.oracle.com/licenses/universal-foss-exception.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License, version 2.0, for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
28
29#ifndef FIDO_COMMON_H_
30#define FIDO_COMMON_H_
31
32#include <cstring>
33#include <iostream>
34#include <sstream>
35
36#include "my_byteorder.h"
37#include "my_inttypes.h"
38
39typedef void (*plugin_messages_callback)(const char *msg);
41
42/* Define type of message */
43enum class message_type {
44 INFO, /* directed to stdout */
45 ERROR, /* directed to stderr */
46};
47
48/*
49 Helper method to redirect plugin specific messages to a registered callback
50 method or to stdout/stderr.
51*/
52void get_plugin_messages(const std::string &msg, message_type type);
53
55 if (length < (ulonglong)251LL) {
56 *packet = (uchar)length;
57 return packet + 1;
58 }
59 /* 251 is reserved for NULL */
60 if (length < (ulonglong)65536LL) {
61 *packet++ = 252;
62 int2store(packet, (uint)length);
63 return packet + 2;
64 }
65 if (length < (ulonglong)16777216LL) {
66 *packet++ = 253;
67 int3store(packet, (ulong)length);
68 return packet + 3;
69 }
70 *packet++ = 254;
71 int8store(packet, length);
72 return packet + 8;
73}
74
76 if (num < 251ULL) return 1;
77 if (num < 65536LL) return 3;
78 if (num < 16777216ULL) return 4;
79 return 9;
80}
81
82/* The same as above but returns longlong */
83inline uint64_t net_field_length_ll(uchar **packet) {
84 const uchar *pos = *packet;
85 if (*pos < 251) {
86 (*packet)++;
87 return (uint64_t)*pos;
88 }
89 if (*pos == 251) {
90 (*packet)++;
91 return (uint64_t)((unsigned long)~0);
92 }
93 if (*pos == 252) {
94 (*packet) += 3;
95 return (uint64_t)uint2korr(pos + 1);
96 }
97 if (*pos == 253) {
98 (*packet) += 4;
99 return (uint64_t)uint3korr(pos + 1);
100 }
101 (*packet) += 9; /* Must be 254 when here */
102 return (uint64_t)uint8korr(pos + 1);
103}
104
105#endif // FIDO_COMMON_H_
uint net_length_size(ulonglong num)
Definition: fido_common.h:75
plugin_messages_callback mc
Definition: fido_client_plugin.cc:52
message_type
Definition: fido_common.h:43
uint64_t net_field_length_ll(uchar **packet)
Definition: fido_common.h:83
uchar * net_store_length(uchar *packet, ulonglong length)
Definition: fido_common.h:54
void get_plugin_messages(const std::string &msg, message_type type)
Definition: fido_client_plugin.cc:58
void(* plugin_messages_callback)(const char *msg)
Definition: fido_common.h:39
Functions for reading and storing in machine-independent format.
void int3store(char *pT, uint A)
Definition: my_byteorder.h:169
ulonglong uint8korr(const char *pT)
Definition: my_byteorder.h:157
uint32 uint3korr(const char *pT)
Definition: my_byteorder.h:137
void int8store(char *pT, ulonglong A)
Definition: my_byteorder.h:185
uint16 uint2korr(const char *pT)
Definition: my_byteorder.h:133
void int2store(char *pT, uint16 A)
Definition: my_byteorder.h:165
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
unsigned char uchar
Definition: my_inttypes.h:52
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
required string type
Definition: replication_group_member_actions.proto:34
unsigned int uint
Definition: uca9-dump.cc:75