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