Bug Summary

File:mariadb-server-10.3/libmariadb/libmariadb/mariadb_lib.c
Warning:line 1014, column 5
Argument to free() is the address of the local variable 'tmp_mysql', which is not memory allocated by malloc()

Annotated Source Code

[?] Use j/k keys for keyboard navigation

1/************************************************************************************
2 Copyright (C) 2000, 2012 MySQL AB & MySQL Finland AB & TCX DataKonsult AB,
3 Monty Program AB
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not see <http://www.gnu.org/licenses>
17 or write to the Free Software Foundation, Inc.,
18 51 Franklin St., Fifth Floor, Boston, MA 02110, USA
19
20 Part of this code includes code from the PHP project which
21 is freely available from http://www.php.net
22*************************************************************************************/
23
24#include <ma_global.h>
25
26#include <ma_sys.h>
27#include <ma_string.h>
28#include <mariadb_ctype.h>
29#include <ma_common.h>
30#include "ma_context.h"
31#include "mysql.h"
32#include "mariadb_version.h"
33#include "ma_server_error.h"
34#include <mariadb/ma_io.h>
35#include "errmsg.h"
36#include <sys/stat.h>
37#include <signal.h>
38#include <time.h>
39#include <mariadb_dyncol.h>
40
41#ifdef HAVE_PWD_H1
42#include <pwd.h>
43#endif
44#if !defined(MSDOS) && !defined(_WIN32)
45#include <sys/socket.h>
46#include <netinet/in.h>
47#include <arpa/inet.h>
48#include <netdb.h>
49#ifdef HAVE_SELECT_H
50# include <select.h>
51#endif
52#ifdef HAVE_SYS_SELECT_H1
53#include <sys/select.h>
54#endif
55#endif
56#ifdef HAVE_SYS_UN_H1
57# include <sys/un.h>
58#endif
59#ifndef INADDR_NONE((in_addr_t) 0xffffffff)
60#define INADDR_NONE((in_addr_t) 0xffffffff) -1
61#endif
62#include <ma_sha1.h>
63#ifndef _WIN32
64#include <poll.h>
65#endif
66#include <ma_pvio.h>
67#ifdef HAVE_TLS1
68#include <ma_tls.h>
69#endif
70#include <mysql/client_plugin.h>
71#ifdef _WIN32
72#include "Shlwapi.h"
73#endif
74
75#define ASYNC_CONTEXT_DEFAULT_STACK_SIZE(4096*15) (4096*15)
76#define MA_RPL_VERSION_HACK"5.5.5-" "5.5.5-"
77
78#undef max_allowed_packet
79#undef net_buffer_length
80extern ulong max_allowed_packet; /* net.c */
81extern ulong net_buffer_length; /* net.c */
82
83static MYSQL_PARAMETERS mariadb_internal_parameters= {&max_allowed_packet, &net_buffer_length, 0};
84static my_bool mysql_client_init=0;
85static void mysql_close_options(MYSQL *mysql);
86extern void release_configuration_dirs();
87extern char **get_default_configuration_dirs();
88extern my_bool ma_init_done;
89extern my_bool mysql_ps_subsystem_initialized;
90extern my_bool mysql_handle_local_infile(MYSQL *mysql, const char *filename);
91extern const MARIADB_CHARSET_INFO * mysql_find_charset_nr(uint charsetnr);
92extern const MARIADB_CHARSET_INFO * mysql_find_charset_name(const char * const name);
93extern int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
94 const char *data_plugin, const char *db);
95extern int net_add_multi_command(NET *net, uchar command, const uchar *packet,
96 size_t length);
97
98extern LIST *pvio_callback;
99
100/* prepare statement methods from my_stmt.c */
101extern my_bool mthd_supported_buffer_type(enum enum_field_types type);
102extern my_bool mthd_stmt_read_prepare_response(MYSQL_STMT *stmt);
103extern my_bool mthd_stmt_get_param_metadata(MYSQL_STMT *stmt);
104extern my_bool mthd_stmt_get_result_metadata(MYSQL_STMT *stmt);
105extern int mthd_stmt_fetch_row(MYSQL_STMT *stmt, unsigned char **row);
106extern int mthd_stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row);
107extern int mthd_stmt_read_all_rows(MYSQL_STMT *stmt);
108extern void mthd_stmt_flush_unbuffered(MYSQL_STMT *stmt);
109extern my_bool _mariadb_read_options(MYSQL *mysql, const char *config_file,
110 char *group);
111extern unsigned char *mysql_net_store_length(unsigned char *packet, size_t length);
112
113extern void
114my_context_install_suspend_resume_hook(struct mysql_async_context *b,
115 void (*hook)(my_bool, void *),
116 void *user_data);
117
118uint mysql_port=0;
119my_string mysql_unix_port=0;
120
121#define CONNECT_TIMEOUT0 0
122
123struct st_mariadb_methods MARIADB_DEFAULT_METHODS;
124
125#if defined(MSDOS) || defined(_WIN32)
126// socket_errno is defined in ma_global.h for all platforms
127#define perror(A)
128#else
129#include <errno(*__errno_location ()).h>
130#define SOCKET_ERROR-1 -1
131#endif /* _WIN32 */
132
133#include <mysql/client_plugin.h>
134
135#define native_password_plugin_name"mysql_native_password" "mysql_native_password"
136
137#define IS_CONNHDLR_ACTIVE(mysql)((mysql)->extension && (mysql)->extension->conn_hdlr
)
\
138 ((mysql)->extension && (mysql)->extension->conn_hdlr)
139
140static void end_server(MYSQL *mysql);
141static void mysql_close_memory(MYSQL *mysql);
142void read_user_name(char *name);
143my_bool STDCALL mariadb_reconnect(MYSQL *mysql);
144static int cli_report_progress(MYSQL *mysql, uchar *packet, uint length);
145
146extern int mysql_client_plugin_init();
147extern void mysql_client_plugin_deinit();
148
149/* net_get_error */
150void net_get_error(char *buf, size_t buf_len,
151 char *error, size_t error_len,
152 unsigned int *error_no,
153 char *sqlstate)
154{
155 char *p= buf;
156 size_t error_msg_len= 0;
157
158 if (buf_len > 2)
159 {
160 *error_no= uint2korr(p)(uint16) (((uint16) ((uchar) (p)[0])) + ((uint16) ((uchar) (p
)[1]) << 8))
;
161 p+= 2;
162
163 /* since 4.1 sqlstate is following */
164 if (*p == '#')
165 {
166 memcpy(sqlstate, ++p, SQLSTATE_LENGTH5);
167 p+= SQLSTATE_LENGTH5;
168 }
169 error_msg_len= buf_len - (p - buf);
170 error_msg_len= MIN(error_msg_len, error_len - 1)(((error_msg_len) < (error_len - 1)) ? (error_msg_len) : (
error_len - 1))
;
171 memcpy(error, p, error_msg_len);
172 }
173 else
174 {
175 *error_no= CR_UNKNOWN_ERROR2000;
176 memcpy(sqlstate, SQLSTATE_UNKNOWN, SQLSTATE_LENGTH5);
177 }
178}
179
180/*****************************************************************************
181** read a packet from server. Give error message if socket was down
182** or packet is an error message
183*****************************************************************************/
184
185ulong
186ma_net_safe_read(MYSQL *mysql)
187{
188 NET *net= &mysql->net;
189 ulong len=0;
190
191restart:
192 if (net->pvio != 0)
193 len=ma_net_read(net);
194
195 if (len == packet_error((unsigned int) -1) || len == 0)
196 {
197 end_server(mysql);
198 my_set_error(mysql, net->last_errno == ER_NET_PACKET_TOO_LARGE1153 ?
199 CR_NET_PACKET_TOO_LARGE2020:
200 CR_SERVER_LOST2013,
201 SQLSTATE_UNKNOWN, 0, errno(*__errno_location ()));
202 return(packet_error((unsigned int) -1));
203 }
204 if (net->read_pos[0] == 255)
205 {
206 if (len > 3)
207 {
208 char *pos=(char*) net->read_pos+1;
209 uint last_errno=uint2korr(pos)(uint16) (((uint16) ((uchar) (pos)[0])) + ((uint16) ((uchar) (
pos)[1]) << 8))
;
210 pos+=2;
211 len-=2;
212
213 if (last_errno== 65535 &&
214 ((mariadb_connection(mysql) && (mysql->server_capabilities & CLIENT_PROGRESS(1UL << 29))) ||
215 (!(mysql->extension->mariadb_server_capabilities & MARIADB_CLIENT_PROGRESS(1ULL << 32) << 32))))
216 {
217 if (cli_report_progress(mysql, (uchar *)pos, (uint) (len-1)))
218 {
219 /* Wrong packet */
220 my_set_error(mysql, CR_MALFORMED_PACKET2027, SQLSTATE_UNKNOWN, 0);
221 return (packet_error((unsigned int) -1));
222 }
223 goto restart;
224 }
225 net->last_errno= last_errno;
226 if (pos[0]== '#')
227 {
228 ma_strmake(net->sqlstate, pos+1, SQLSTATE_LENGTH5);
229 pos+= SQLSTATE_LENGTH5 + 1;
230 }
231 else
232 {
233 strcpy(net->sqlstate, SQLSTATE_UNKNOWN);
234 }
235 ma_strmake(net->last_error,(char*) pos,
236 min(len,sizeof(net->last_error)-1)((len) < (sizeof(net->last_error)-1) ? (len) : (sizeof(
net->last_error)-1))
);
237 }
238 else
239 {
240 my_set_error(mysql, CR_UNKNOWN_ERROR2000, SQLSTATE_UNKNOWN, 0);
241 }
242
243 mysql->server_status&= ~SERVER_MORE_RESULTS_EXIST8;
244
245 return(packet_error((unsigned int) -1));
246 }
247 return len;
248}
249
250/*
251 Report progress to the client
252
253 RETURN VALUES
254 0 ok
255 1 error
256*/
257static int cli_report_progress(MYSQL *mysql, uchar *packet, uint length)
258{
259 uint stage, max_stage, proc_length;
260 double progress;
261 uchar *start= packet;
262
263 if (length < 5)
264 return 1; /* Wrong packet */
265
266 if (!(mysql->options.extension && mysql->options.extension->report_progress))
267 return 0; /* No callback, ignore packet */
268
269 packet++; /* Ignore number of strings */
270 stage= (uint) *packet++;
271 max_stage= (uint) *packet++;
272 progress= uint3korr(packet)(uint32) (((uint32) ((uchar) (packet)[0])) + (((uint32) ((uchar
) (packet)[1])) << 8) + (((uint32) ((uchar) (packet)[2]
)) << 16))
/1000.0;
273 packet+= 3;
274 proc_length= net_field_length(&packet);
275 if (packet + proc_length > start + length)
276 return 1; /* Wrong packet */
277 (*mysql->options.extension->report_progress)(mysql, stage, max_stage,
278 progress, (char*) packet,
279 proc_length);
280 return 0;
281}
282
283/* Get the length of next field. Change parameter to point at fieldstart */
284ulong
285net_field_length(uchar **packet)
286{
287 reg1register uchar *pos= *packet;
288 if (*pos < 251)
289 {
290 (*packet)++;
291 return (ulong) *pos;
292 }
293 if (*pos == 251)
294 {
295 (*packet)++;
296 return NULL_LENGTH((unsigned long) ~0);
297 }
298 if (*pos == 252)
299 {
300 (*packet)+=3;
301 return (ulong) uint2korr(pos+1)(uint16) (((uint16) ((uchar) (pos+1)[0])) + ((uint16) ((uchar
) (pos+1)[1]) << 8))
;
302 }
303 if (*pos == 253)
304 {
305 (*packet)+=4;
306 return (ulong) uint3korr(pos+1)(uint32) (((uint32) ((uchar) (pos+1)[0])) + (((uint32) ((uchar
) (pos+1)[1])) << 8) + (((uint32) ((uchar) (pos+1)[2]))
<< 16))
;
307 }
308 (*packet)+=9; /* Must be 254 when here */
309 return (ulong) uint4korr(pos+1)(uint32) (((uint32) ((uchar) (pos+1)[0])) + (((uint32) ((uchar
) (pos+1)[1])) << 8) + (((uint32) ((uchar) (pos+1)[2]))
<< 16) + (((uint32) ((uchar) (pos+1)[3])) << 24)
)
;
310}
311
312/* Same as above, but returns ulonglong values */
313
314static unsigned long long
315net_field_length_ll(uchar **packet)
316{
317 reg1register uchar *pos= *packet;
318 if (*pos < 251)
319 {
320 (*packet)++;
321 return (unsigned long long) *pos;
322 }
323 if (*pos == 251)
324 {
325 (*packet)++;
326 return (unsigned long long) NULL_LENGTH((unsigned long) ~0);
327 }
328 if (*pos == 252)
329 {
330 (*packet)+=3;
331 return (unsigned long long) uint2korr(pos+1)(uint16) (((uint16) ((uchar) (pos+1)[0])) + ((uint16) ((uchar
) (pos+1)[1]) << 8))
;
332 }
333 if (*pos == 253)
334 {
335 (*packet)+=4;
336 return (unsigned long long) uint3korr(pos+1)(uint32) (((uint32) ((uchar) (pos+1)[0])) + (((uint32) ((uchar
) (pos+1)[1])) << 8) + (((uint32) ((uchar) (pos+1)[2]))
<< 16))
;
337 }
338 (*packet)+=9; /* Must be 254 when here */
339#ifdef NO_CLIENT_LONGLONG
340 return (unsigned long long) uint4korr(pos+1)(uint32) (((uint32) ((uchar) (pos+1)[0])) + (((uint32) ((uchar
) (pos+1)[1])) << 8) + (((uint32) ((uchar) (pos+1)[2]))
<< 16) + (((uint32) ((uchar) (pos+1)[3])) << 24)
)
;
341#else
342 return (unsigned long long) uint8korr(pos+1)((ulonglong)(((uint32) ((uchar) (pos+1)[0])) + (((uint32) ((uchar
) (pos+1)[1])) << 8) + (((uint32) ((uchar) (pos+1)[2]))
<< 16) + (((uint32) ((uchar) (pos+1)[3])) << 24)
) + (((ulonglong) (((uint32) ((uchar) (pos+1)[4])) + (((uint32
) ((uchar) (pos+1)[5])) << 8) + (((uint32) ((uchar) (pos
+1)[6])) << 16) + (((uint32) ((uchar) (pos+1)[7])) <<
24))) << 32))
;
343#endif
344}
345
346
347void free_rows(MYSQL_DATA *cur)
348{
349 if (cur)
350 {
351 ma_free_root(&cur->alloc,MYF(0)(myf) (0));
352 free(cur);
353 }
354}
355
356int
357mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg,
358 size_t length, my_bool skipp_check, void *opt_arg)
359{
360 NET *net= &mysql->net;
361 int result= -1;
362 if (mysql->net.pvio == 0)
1
Assuming the condition is false
2
Taking false branch
363 {
364 /* Do reconnect if possible */
365 if (mariadb_reconnect(mysql))
366 return(1);
367 }
368 if (mysql->status != MYSQL_STATUS_READY ||
3
Assuming the condition is false
5
Taking false branch
369 mysql->server_status & SERVER_MORE_RESULTS_EXIST8)
4
Assuming the condition is false
370 {
371 SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2014); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2014))-2000], sizeof((mysql)->net.last_error)); }
;
372 goto end;
373 }
374
375 if (IS_CONNHDLR_ACTIVE(mysql)((mysql)->extension && (mysql)->extension->conn_hdlr
)
)
376 {
377 result= mysql->extension->conn_hdlr->plugin->set_connection(mysql, command, arg, length, skipp_check, opt_arg);
378 if (result== -1)
379 return(result);
380 }
381
382 CLEAR_CLIENT_ERROR(mysql){ (mysql)->net.last_errno= 0; strcpy((mysql)->net.sqlstate
, "00000"); (mysql)->net.last_error[0]= '\0'; }
;
383
384 mysql->info=0;
385 mysql->affected_rows= ~(unsigned long long) 0;
386 ma_net_clear(net); /* Clear receive buffer */
387 if (!arg)
6
Assuming 'arg' is non-null
7
Taking false branch
388 arg="";
389
390 if (net->extension->multi_status== COM_MULTI_ENABLED)
8
Assuming the condition is false
9
Taking false branch
391 {
392 return net_add_multi_command(net, command, (const uchar *)arg, length);
393 }
394
395 if (ma_net_write_command(net,(uchar) command,arg,
12
Assuming the condition is true
13
Taking true branch
396 length ? length : (ulong) strlen(arg), 0))
10
Assuming 'length' is 0
11
'?' condition is false
397 {
398 if (net->last_errno == ER_NET_PACKET_TOO_LARGE1153)
14
Assuming the condition is false
15
Taking false branch
399 {
400 my_set_error(mysql, CR_NET_PACKET_TOO_LARGE2020, SQLSTATE_UNKNOWN, 0);
401 goto end;
402 }
403 end_server(mysql);
404 if (mariadb_reconnect(mysql))
16
Calling 'mariadb_reconnect'
405 goto end;
406 if (ma_net_write_command(net,(uchar) command,arg,
407 length ? length : (ulong) strlen(arg), 0))
408 {
409 my_set_error(mysql, CR_SERVER_GONE_ERROR2006, SQLSTATE_UNKNOWN, 0);
410 goto end;
411 }
412 }
413 result=0;
414
415 if (net->extension->multi_status > COM_MULTI_OFF)
416 skipp_check= 1;
417
418 if (!skipp_check)
419 {
420 result= ((mysql->packet_length=ma_net_safe_read(mysql)) == packet_error((unsigned int) -1) ?
421 1 : 0);
422 }
423 end:
424 return(result);
425}
426
427int
428ma_simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
429 size_t length, my_bool skipp_check, void *opt_arg)
430{
431 return mysql->methods->db_command(mysql, command, arg, length, skipp_check, opt_arg);
432}
433
434int ma_multi_command(MYSQL *mysql, enum enum_multi_status status)
435{
436 NET *net= &mysql->net;
437
438 switch (status) {
439 case COM_MULTI_OFF:
440 ma_net_clear(net);
441 net->extension->multi_status= status;
442 return 0;
443 case COM_MULTI_ENABLED:
444 if (net->extension->multi_status > COM_MULTI_DISABLED)
445 return 1;
446 ma_net_clear(net);
447 net->extension->multi_status= status;
448 return 0;
449 case COM_MULTI_DISABLED:
450 /* Opposite to COM_MULTI_OFF we don't clear net buffer,
451 next command or com_nulti_end will flush entire buffer */
452 net->extension->multi_status= status;
453 return 0;
454 case COM_MULTI_END:
455 {
456 size_t len= net->write_pos - net->buff - NET_HEADER_SIZE4;
457
458 if (len < NET_HEADER_SIZE4) /* don't send empty COM_MULTI */
459 {
460 ma_net_clear(net);
461 return 1;
462 }
463 net->extension->multi_status= COM_MULTI_OFF;
464 return ma_net_flush(net);
465 }
466 case COM_MULTI_CANCEL:
467 ma_net_clear(net);
468 net->extension->multi_status= COM_MULTI_OFF;
469 return 0;
470 default:
471 return 1;
472 }
473}
474
475static void free_old_query(MYSQL *mysql)
476{
477 if (mysql->fields)
478 ma_free_root(&mysql->field_alloc,MYF(0)(myf) (0));
479 ma_init_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */
480 mysql->fields=0;
481 mysql->field_count=0; /* For API */
482 mysql->info= 0;
483 return;
484}
485
486#if defined(HAVE_GETPWUID1) && defined(NO_GETPWUID_DECL)
487struct passwd *getpwuid(uid_t);
488char* getlogin(void);
489#endif
490
491#if !defined(MSDOS) && ! defined(VMS) && !defined(_WIN32) && !defined(OS2)
492void read_user_name(char *name)
493{
494 if (geteuid() == 0)
495 strcpy(name,"root"); /* allow use of surun */
496 else
497 {
498#ifdef HAVE_GETPWUID1
499 struct passwd *skr;
500 const char *str;
501 if ((str=getlogin()) == NULL((void*)0))
502 {
503 if ((skr=getpwuid(geteuid())) != NULL((void*)0))
504 str=skr->pw_name;
505 else if (!(str=getenv("USER")) && !(str=getenv("LOGNAME")) &&
506 !(str=getenv("LOGIN")))
507 str="UNKNOWN_USER";
508 }
509 ma_strmake(name,str,USERNAME_LENGTH128 * 4);
510#elif HAVE_CUSERID
511 (void) cuserid(name);
512#else
513 ma_strmake(name,"UNKNOWN_USER", USERNAME_LENGTH128 * 4);
514#endif
515 }
516 return;
517}
518
519#else /* If MSDOS || VMS */
520
521void read_user_name(char *name)
522{
523 char *str=getenv("USERNAME"); /* ODBC will send user variable */
524 ma_strmake(name,str ? str : "ODBC", USERNAME_LENGTH128 * 4);
525}
526
527#endif
528
529#ifdef _WIN32
530static my_bool is_NT(void)
531{
532 char *os=getenv("OS");
533 return (os && !strcmp(os, "Windows_NT")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(os) && __builtin_constant_p ("Windows_NT") &&
(__s1_len = __builtin_strlen (os), __s2_len = __builtin_strlen
("Windows_NT"), (!((size_t)(const void *)((os) + 1) - (size_t
)(const void *)(os) == 1) || __s1_len >= 4) && (!(
(size_t)(const void *)(("Windows_NT") + 1) - (size_t)(const void
*)("Windows_NT") == 1) || __s2_len >= 4)) ? __builtin_strcmp
(os, "Windows_NT") : (__builtin_constant_p (os) && (
(size_t)(const void *)((os) + 1) - (size_t)(const void *)(os)
== 1) && (__s1_len = __builtin_strlen (os), __s1_len
< 4) ? (__builtin_constant_p ("Windows_NT") && ((
size_t)(const void *)(("Windows_NT") + 1) - (size_t)(const void
*)("Windows_NT") == 1) ? __builtin_strcmp (os, "Windows_NT")
: (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) ("Windows_NT"); int __result = (((const
unsigned char *) (const char *) (os))[0] - __s2[0]); if (__s1_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) (os))[1] - __s2[1]); if (__s1_len >
1 && __result == 0) { __result = (((const unsigned char
*) (const char *) (os))[2] - __s2[2]); if (__s1_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) (os))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
("Windows_NT") && ((size_t)(const void *)(("Windows_NT"
) + 1) - (size_t)(const void *)("Windows_NT") == 1) &&
(__s2_len = __builtin_strlen ("Windows_NT"), __s2_len < 4
) ? (__builtin_constant_p (os) && ((size_t)(const void
*)((os) + 1) - (size_t)(const void *)(os) == 1) ? __builtin_strcmp
(os, "Windows_NT") : (- (__extension__ ({ const unsigned char
*__s2 = (const unsigned char *) (const char *) (os); int __result
= (((const unsigned char *) (const char *) ("Windows_NT"))[0
] - __s2[0]); if (__s2_len > 0 && __result == 0) {
__result = (((const unsigned char *) (const char *) ("Windows_NT"
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("Windows_NT"
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("Windows_NT"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (os,
"Windows_NT")))); })
) ? 1 : 0;
534}
535#endif
536
537/**************************************************************************
538** Shut down connection
539**************************************************************************/
540
541static void
542end_server(MYSQL *mysql)
543{
544 /* if net->error 2 and reconnect is activated, we need to inforn
545 connection handler */
546 if (mysql->net.pvio != 0)
547 {
548 ma_pvio_close(mysql->net.pvio);
549 mysql->net.pvio= 0; /* Marker */
550 }
551 ma_net_end(&mysql->net);
552 free_old_query(mysql);
553 return;
554}
555
556void mthd_my_skip_result(MYSQL *mysql)
557{
558 ulong pkt_len;
559
560 do {
561 pkt_len= ma_net_safe_read(mysql);
562 if (pkt_len == packet_error((unsigned int) -1))
563 break;
564 } while (pkt_len > 8 || mysql->net.read_pos[0] != 254);
565 return;
566}
567
568void STDCALL
569mysql_free_result(MYSQL_RES *result)
570{
571 if (result)
572 {
573 if (result->handle && result->handle->status == MYSQL_STATUS_USE_RESULT)
574 {
575 result->handle->methods->db_skip_result(result->handle);
576 result->handle->status=MYSQL_STATUS_READY;
577 }
578 free_rows(result->data);
579 if (result->fields)
580 ma_free_root(&result->field_alloc,MYF(0)(myf) (0));
581 if (result->row)
582 free(result->row);
583 free(result);
584 }
585 return;
586}
587
588
589/****************************************************************************
590** Get options from my.cnf
591****************************************************************************/
592enum enum_option_type {
593 MARIADB_OPTION_NONE,
594 MARIADB_OPTION_BOOL,
595 MARIADB_OPTION_INT,
596 MARIADB_OPTION_SIZET,
597 MARIADB_OPTION_STR,
598};
599
600struct st_default_options {
601 enum mysql_option option;
602 enum enum_option_type type;
603 const char *conf_key;
604};
605
606struct st_default_options mariadb_defaults[] =
607{
608 {MARIADB_OPT_PORT, MARIADB_OPTION_INT,"port"},
609 {MARIADB_OPT_UNIXSOCKET, MARIADB_OPTION_STR, "socket"},
610 {MYSQL_OPT_COMPRESS, MARIADB_OPTION_BOOL, "compress"},
611 {MARIADB_OPT_PASSWORD, MARIADB_OPTION_STR, "password"},
612 {MYSQL_OPT_NAMED_PIPE, MARIADB_OPTION_BOOL, "pipe"},
613 {MYSQL_OPT_CONNECT_TIMEOUT, MARIADB_OPTION_INT, "timeout"},
614 {MARIADB_OPT_USER, MARIADB_OPTION_STR, "user"},
615 {MYSQL_INIT_COMMAND, MARIADB_OPTION_STR, "init-command"},
616 {MARIADB_OPT_HOST, MARIADB_OPTION_STR, "host"},
617 {MARIADB_OPT_SCHEMA, MARIADB_OPTION_STR, "database"},
618 {MARIADB_OPT_DEBUG, MARIADB_OPTION_STR, "debug"},
619 {MARIADB_OPT_FOUND_ROWS, MARIADB_OPTION_NONE, "return-found-rows"},
620 {MYSQL_OPT_SSL_KEY, MARIADB_OPTION_STR, "ssl-key"},
621 {MYSQL_OPT_SSL_CERT, MARIADB_OPTION_STR,"ssl-cert"},
622 {MYSQL_OPT_SSL_CA, MARIADB_OPTION_STR,"ssl-ca"},
623 {MYSQL_OPT_SSL_CAPATH, MARIADB_OPTION_STR,"ssl-capath"},
624 {MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MARIADB_OPTION_BOOL,"ssl-verify-server-cert"},
625 {MYSQL_SET_CHARSET_DIR, MARIADB_OPTION_STR, "character-sets-dir"},
626 {MYSQL_SET_CHARSET_NAME, MARIADB_OPTION_STR, "default-character-set"},
627 {MARIADB_OPT_INTERACTIVE, MARIADB_OPTION_NONE, "interactive-timeout"},
628 {MYSQL_OPT_CONNECT_TIMEOUT, MARIADB_OPTION_INT, "connect-timeout"},
629 {MYSQL_OPT_LOCAL_INFILE, MARIADB_OPTION_BOOL, "local-infile"},
630 {0, 0 ,"disable-local-infile",},
631 {MYSQL_OPT_SSL_CIPHER, MARIADB_OPTION_STR, "ssl-cipher"},
632 {MYSQL_OPT_MAX_ALLOWED_PACKET, MARIADB_OPTION_SIZET, "max-allowed-packet"},
633 {MYSQL_OPT_NET_BUFFER_LENGTH, MARIADB_OPTION_SIZET, "net-buffer-length"},
634 {MYSQL_OPT_PROTOCOL, MARIADB_OPTION_INT, "protocol"},
635 {MYSQL_SHARED_MEMORY_BASE_NAME, MARIADB_OPTION_STR,"shared-memory-base-name"},
636 {MARIADB_OPT_MULTI_RESULTS, MARIADB_OPTION_NONE, "multi-results"},
637 {MARIADB_OPT_MULTI_STATEMENTS, MARIADB_OPTION_STR, "multi-statements"},
638 {MARIADB_OPT_MULTI_STATEMENTS, MARIADB_OPTION_STR, "multi-queries"},
639 {MYSQL_SECURE_AUTH, MARIADB_OPTION_BOOL, "secure-auth"},
640 {MYSQL_REPORT_DATA_TRUNCATION, MARIADB_OPTION_BOOL, "report-data-truncation"},
641 {MYSQL_OPT_RECONNECT, MARIADB_OPTION_BOOL, "reconnect"},
642 {MYSQL_PLUGIN_DIR, MARIADB_OPTION_STR, "plugin-dir"},
643 {MYSQL_DEFAULT_AUTH, MARIADB_OPTION_STR, "default-auth"},
644 {MARIADB_OPT_SSL_FP, MARIADB_OPTION_STR, "ssl-fp"},
645 {MARIADB_OPT_SSL_FP_LIST, MARIADB_OPTION_STR, "ssl-fp-list"},
646 {MARIADB_OPT_SSL_FP_LIST, MARIADB_OPTION_STR, "ssl-fplist"},
647 {MARIADB_OPT_TLS_PASSPHRASE, MARIADB_OPTION_STR, "ssl-passphrase"},
648 {MARIADB_OPT_TLS_VERSION, MARIADB_OPTION_STR, "tls_version"},
649 {MYSQL_OPT_BIND, MARIADB_OPTION_STR, "bind-address"},
650 {0, 0, NULL((void*)0)}
651};
652
653#define CHECK_OPT_EXTENSION_SET(OPTS)if (!(OPTS)->extension) (OPTS)->extension= (struct st_mysql_options_extension
*) calloc(1, sizeof(struct st_mysql_options_extension));
\
654 if (!(OPTS)->extension) \
655 (OPTS)->extension= (struct st_mysql_options_extension *) \
656 calloc(1, sizeof(struct st_mysql_options_extension));
657
658#define OPT_SET_EXTENDED_VALUE_STR(OPTS, KEY, VAL)if (!(OPTS)->extension) (OPTS)->extension= (struct st_mysql_options_extension
*) calloc(1, sizeof(struct st_mysql_options_extension)); free
((gptr)(OPTS)->extension->KEY); if((VAL)) (OPTS)->extension
->KEY= (__extension__ (__builtin_constant_p ((char *)(VAL)
) && ((size_t)(const void *)(((char *)(VAL)) + 1) - (
size_t)(const void *)((char *)(VAL)) == 1) ? (((const char *)
((char *)(VAL)))[0] == '\0' ? (char *) calloc ((size_t) 1, (
size_t) 1) : ({ size_t __len = strlen ((char *)(VAL)) + 1; char
*__retval = (char *) malloc (__len); if (__retval != ((void*
)0)) __retval = (char *) memcpy (__retval, (char *)(VAL), __len
); __retval; })) : __strdup ((char *)(VAL)))); else (OPTS)->
extension->KEY= ((void*)0)
\
659 CHECK_OPT_EXTENSION_SET(OPTS)if (!(OPTS)->extension) (OPTS)->extension= (struct st_mysql_options_extension
*) calloc(1, sizeof(struct st_mysql_options_extension));
\
660 free((gptr)(OPTS)->extension->KEY); \
661 if((VAL)) \
662 (OPTS)->extension->KEY= strdup((char *)(VAL))(__extension__ (__builtin_constant_p ((char *)(VAL)) &&
((size_t)(const void *)(((char *)(VAL)) + 1) - (size_t)(const
void *)((char *)(VAL)) == 1) ? (((const char *) ((char *)(VAL
)))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : (
{ size_t __len = strlen ((char *)(VAL)) + 1; char *__retval =
(char *) malloc (__len); if (__retval != ((void*)0)) __retval
= (char *) memcpy (__retval, (char *)(VAL), __len); __retval
; })) : __strdup ((char *)(VAL))))
; \
663 else \
664 (OPTS)->extension->KEY= NULL((void*)0)
665
666#define OPT_SET_EXTENDED_VALUE(OPTS, KEY, VAL)if (!(OPTS)->extension) (OPTS)->extension= (struct st_mysql_options_extension
*) calloc(1, sizeof(struct st_mysql_options_extension)); (OPTS
)->extension->KEY= (VAL)
\
667 CHECK_OPT_EXTENSION_SET(OPTS)if (!(OPTS)->extension) (OPTS)->extension= (struct st_mysql_options_extension
*) calloc(1, sizeof(struct st_mysql_options_extension));
\
668 (OPTS)->extension->KEY= (VAL)
669
670#define OPT_SET_EXTENDED_VALUE_INT(A,B,C)if (!(A)->extension) (A)->extension= (struct st_mysql_options_extension
*) calloc(1, sizeof(struct st_mysql_options_extension)); (A)
->extension->B= (C)
OPT_SET_EXTENDED_VALUE(A,B,C)if (!(A)->extension) (A)->extension= (struct st_mysql_options_extension
*) calloc(1, sizeof(struct st_mysql_options_extension)); (A)
->extension->B= (C)
671
672#define OPT_SET_VALUE_STR(OPTS, KEY, VAL)free((OPTS)->KEY); if((VAL)) (OPTS)->KEY= (__extension__
(__builtin_constant_p ((char *)(VAL)) && ((size_t)(const
void *)(((char *)(VAL)) + 1) - (size_t)(const void *)((char *
)(VAL)) == 1) ? (((const char *) ((char *)(VAL)))[0] == '\0' ?
(char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len =
strlen ((char *)(VAL)) + 1; char *__retval = (char *) malloc
(__len); if (__retval != ((void*)0)) __retval = (char *) memcpy
(__retval, (char *)(VAL), __len); __retval; })) : __strdup (
(char *)(VAL)))); else (OPTS)->KEY= ((void*)0)
\
673 free((OPTS)->KEY); \
674 if((VAL)) \
675 (OPTS)->KEY= strdup((char *)(VAL))(__extension__ (__builtin_constant_p ((char *)(VAL)) &&
((size_t)(const void *)(((char *)(VAL)) + 1) - (size_t)(const
void *)((char *)(VAL)) == 1) ? (((const char *) ((char *)(VAL
)))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : (
{ size_t __len = strlen ((char *)(VAL)) + 1; char *__retval =
(char *) malloc (__len); if (__retval != ((void*)0)) __retval
= (char *) memcpy (__retval, (char *)(VAL), __len); __retval
; })) : __strdup ((char *)(VAL))))
; \
676 else \
677 (OPTS)->KEY= NULL((void*)0)
678
679#define OPT_SET_VALUE_INT(OPTS, KEY, VAL)(OPTS)->KEY= (VAL) \
680 (OPTS)->KEY= (VAL)
681
682static void options_add_initcommand(struct st_mysql_options *options,
683 const char *init_cmd)
684{
685 char *insert= strdup(init_cmd)(__extension__ (__builtin_constant_p (init_cmd) && ((
size_t)(const void *)((init_cmd) + 1) - (size_t)(const void *
)(init_cmd) == 1) ? (((const char *) (init_cmd))[0] == '\0' ?
(char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len =
strlen (init_cmd) + 1; char *__retval = (char *) malloc (__len
); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval
, init_cmd, __len); __retval; })) : __strdup (init_cmd)))
;
686 if (!options->init_command)
687 {
688 options->init_command= (DYNAMIC_ARRAY*)malloc(sizeof(DYNAMIC_ARRAY));
689 ma_init_dynamic_array(options->init_command, sizeof(char*), 5, 5);
690 }
691
692 if (ma_insert_dynamic(options->init_command, (gptr)&insert))
693 free(insert);
694}
695my_bool _mariadb_set_conf_option(MYSQL *mysql, const char *config_option, const char *config_value)
696{
697 if (config_option)
698 {
699 int i;
700
701 for (i=0; mariadb_defaults[i].conf_key; i++)
702 {
703 if (!strcmp(mariadb_defaults[i].conf_key, config_option)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(mariadb_defaults[i].conf_key) && __builtin_constant_p
(config_option) && (__s1_len = __builtin_strlen (mariadb_defaults
[i].conf_key), __s2_len = __builtin_strlen (config_option), (
!((size_t)(const void *)((mariadb_defaults[i].conf_key) + 1) -
(size_t)(const void *)(mariadb_defaults[i].conf_key) == 1) ||
__s1_len >= 4) && (!((size_t)(const void *)((config_option
) + 1) - (size_t)(const void *)(config_option) == 1) || __s2_len
>= 4)) ? __builtin_strcmp (mariadb_defaults[i].conf_key, config_option
) : (__builtin_constant_p (mariadb_defaults[i].conf_key) &&
((size_t)(const void *)((mariadb_defaults[i].conf_key) + 1) -
(size_t)(const void *)(mariadb_defaults[i].conf_key) == 1) &&
(__s1_len = __builtin_strlen (mariadb_defaults[i].conf_key),
__s1_len < 4) ? (__builtin_constant_p (config_option) &&
((size_t)(const void *)((config_option) + 1) - (size_t)(const
void *)(config_option) == 1) ? __builtin_strcmp (mariadb_defaults
[i].conf_key, config_option) : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) (config_option
); int __result = (((const unsigned char *) (const char *) (mariadb_defaults
[i].conf_key))[0] - __s2[0]); if (__s1_len > 0 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
mariadb_defaults[i].conf_key))[1] - __s2[1]); if (__s1_len >
1 && __result == 0) { __result = (((const unsigned char
*) (const char *) (mariadb_defaults[i].conf_key))[2] - __s2[
2]); if (__s1_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) (mariadb_defaults[i
].conf_key))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
(config_option) && ((size_t)(const void *)((config_option
) + 1) - (size_t)(const void *)(config_option) == 1) &&
(__s2_len = __builtin_strlen (config_option), __s2_len < 4
) ? (__builtin_constant_p (mariadb_defaults[i].conf_key) &&
((size_t)(const void *)((mariadb_defaults[i].conf_key) + 1) -
(size_t)(const void *)(mariadb_defaults[i].conf_key) == 1) ?
__builtin_strcmp (mariadb_defaults[i].conf_key, config_option
) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (mariadb_defaults[i].conf_key); int __result
= (((const unsigned char *) (const char *) (config_option))[
0] - __s2[0]); if (__s2_len > 0 && __result == 0) {
__result = (((const unsigned char *) (const char *) (config_option
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (config_option
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (config_option
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (mariadb_defaults
[i].conf_key, config_option)))); })
)
704 {
705 my_bool val_bool;
706 int val_int;
707 size_t val_sizet;
708 int rc;
709 void *option_val= NULL((void*)0);
710 switch (mariadb_defaults[i].type) {
711 case MARIADB_OPTION_BOOL:
712 val_bool= 0;
713 if (config_value)
714 val_bool= atoi(config_value);
715 option_val= &val_bool;
716 break;
717 case MARIADB_OPTION_INT:
718 val_int= 0;
719 if (config_value)
720 val_int= atoi(config_value);
721 option_val= &val_int;
722 break;
723 case MARIADB_OPTION_SIZET:
724 val_sizet= 0;
725 if (config_value)
726 val_sizet= strtol(config_value, NULL((void*)0), 10);
727 option_val= &val_sizet;
728 break;
729 case MARIADB_OPTION_STR:
730 option_val= (void*)config_value;
731 break;
732 case MARIADB_OPTION_NONE:
733 break;
734 }
735 rc= mysql_optionsv(mysql, mariadb_defaults[i].option, option_val);
736 return(test(rc)((rc) ? 1 : 0));
737 }
738 }
739 }
740 /* unknown key */
741 return 1;
742}
743
744/***************************************************************************
745** Change field rows to field structs
746***************************************************************************/
747
748static size_t rset_field_offsets[]= {
749 OFFSET(MYSQL_FIELD, catalog)((size_t)(char *)&((MYSQL_FIELD *)0)->catalog),
750 OFFSET(MYSQL_FIELD, catalog_length)((size_t)(char *)&((MYSQL_FIELD *)0)->catalog_length),
751 OFFSET(MYSQL_FIELD, db)((size_t)(char *)&((MYSQL_FIELD *)0)->db),
752 OFFSET(MYSQL_FIELD, db_length)((size_t)(char *)&((MYSQL_FIELD *)0)->db_length),
753 OFFSET(MYSQL_FIELD, table)((size_t)(char *)&((MYSQL_FIELD *)0)->table),
754 OFFSET(MYSQL_FIELD, table_length)((size_t)(char *)&((MYSQL_FIELD *)0)->table_length),
755 OFFSET(MYSQL_FIELD, org_table)((size_t)(char *)&((MYSQL_FIELD *)0)->org_table),
756 OFFSET(MYSQL_FIELD, org_table_length)((size_t)(char *)&((MYSQL_FIELD *)0)->org_table_length
)
,
757 OFFSET(MYSQL_FIELD, name)((size_t)(char *)&((MYSQL_FIELD *)0)->name),
758 OFFSET(MYSQL_FIELD, name_length)((size_t)(char *)&((MYSQL_FIELD *)0)->name_length),
759 OFFSET(MYSQL_FIELD, org_name)((size_t)(char *)&((MYSQL_FIELD *)0)->org_name),
760 OFFSET(MYSQL_FIELD, org_name_length)((size_t)(char *)&((MYSQL_FIELD *)0)->org_name_length)
761};
762
763MYSQL_FIELD *
764unpack_fields(MYSQL_DATA *data,MA_MEM_ROOT *alloc,uint fields,
765 my_bool default_value, my_bool long_flag_protocol __attribute__((unused)))
766{
767 MYSQL_ROWS *row;
768 MYSQL_FIELD *field,*result;
769 char *p;
770 unsigned int i, field_count= sizeof(rset_field_offsets)/sizeof(size_t)/2;
771
772 field=result=(MYSQL_FIELD*) ma_alloc_root(alloc,sizeof(MYSQL_FIELD)*fields);
773 if (!result)
774 return(0);
775
776 for (row=data->data; row ; row = row->next,field++)
777 {
778 for (i=0; i < field_count; i++)
779 {
780 switch(row->data[i][0]) {
781 case 0:
782 *(char **)(((char *)field) + rset_field_offsets[i*2])= ma_strdup_root(alloc, "");
783 *(unsigned int *)(((char *)field) + rset_field_offsets[i*2+1])= 0;
784 break;
785 default:
786 *(char **)(((char *)field) + rset_field_offsets[i*2])=
787 ma_strdup_root(alloc, (char *)row->data[i]);
788 *(unsigned int *)(((char *)field) + rset_field_offsets[i*2+1])=
789 (uint)(row->data[i+1] - row->data[i] - 1);
790 break;
791 }
792 }
793
794 p= (char *)row->data[6];
795 /* filler */
796 field->charsetnr= uint2korr(p)(uint16) (((uint16) ((uchar) (p)[0])) + ((uint16) ((uchar) (p
)[1]) << 8))
;
797 p+= 2;
798 field->length= (uint) uint4korr(p)(uint32) (((uint32) ((uchar) (p)[0])) + (((uint32) ((uchar) (
p)[1])) << 8) + (((uint32) ((uchar) (p)[2])) << 16
) + (((uint32) ((uchar) (p)[3])) << 24))
;
799 p+= 4;
800 field->type= (enum enum_field_types)uint1korr(p)(*(((uint8*)(p))));
801 p++;
802 field->flags= uint2korr(p)(uint16) (((uint16) ((uchar) (p)[0])) + ((uint16) ((uchar) (p
)[1]) << 8))
;
803 p+= 2;
804 field->decimals= (uint) p[0];
805 p++;
806
807 /* filler */
808 p+= 2;
809
810 if (INTERNAL_NUM_FIELD(field)(((field)->type <= MYSQL_TYPE_INT24 && ((field)
->type != MYSQL_TYPE_TIMESTAMP || (field)->length == 14
|| (field)->length == 8)) || (field)->type == MYSQL_TYPE_YEAR
|| (field)->type == MYSQL_TYPE_NEWDECIMAL || (field)->
type == MYSQL_TYPE_DECIMAL)
)
811 field->flags|= NUM_FLAG32768;
812
813 if (default_value && row->data[7])
814 {
815 field->def=ma_strdup_root(alloc,(char*) row->data[7]);
816 }
817 else
818 field->def=0;
819 field->max_length= 0;
820 }
821 free_rows(data); /* Free old data */
822 return(result);
823}
824
825
826/* Read all rows (fields or data) from server */
827
828MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
829 uint fields)
830{
831 uint field;
832 ulong pkt_len;
833 ulong len;
834 uchar *cp;
835 char *to, *end_to;
836 MYSQL_DATA *result;
837 MYSQL_ROWS **prev_ptr,*cur;
838 NET *net = &mysql->net;
839
840 if ((pkt_len= ma_net_safe_read(mysql)) == packet_error((unsigned int) -1))
841 return(0);
842 if (!(result=(MYSQL_DATA*) calloc(1, sizeof(MYSQL_DATA))))
843 {
844 SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2008); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2008))-2000], sizeof((mysql)->net.last_error)); }
;
845 return(0);
846 }
847 ma_init_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */
848 result->alloc.min_malloc=sizeof(MYSQL_ROWS);
849 prev_ptr= &result->data;
850 result->rows=0;
851 result->fields=fields;
852
853 while (*(cp=net->read_pos) != 254 || pkt_len >= 8)
854 {
855 result->rows++;
856 if (!(cur= (MYSQL_ROWS*) ma_alloc_root(&result->alloc,
857 sizeof(MYSQL_ROWS))) ||
858 !(cur->data= ((MYSQL_ROW)
859 ma_alloc_root(&result->alloc,
860 (fields+1)*sizeof(char *)+fields+pkt_len))))
861 {
862 free_rows(result);
863 SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2008); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2008))-2000], sizeof((mysql)->net.last_error)); }
;
864 return(0);
865 }
866 *prev_ptr=cur;
867 prev_ptr= &cur->next;
868 to= (char*) (cur->data+fields+1);
869 end_to=to+fields+pkt_len-1;
870 for (field=0 ; field < fields ; field++)
871 {
872 if ((len=(ulong) net_field_length(&cp)) == NULL_LENGTH((unsigned long) ~0))
873 { /* null field */
874 cur->data[field] = 0;
875 }
876 else
877 {
878 cur->data[field] = to;
879 if (len > (ulong) (end_to - to))
880 {
881 free_rows(result);
882 SET_CLIENT_ERROR(mysql, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2000); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2000))-2000], sizeof((mysql)->net.last_error)); }
;
883 return(0);
884 }
885 memcpy(to,(char*) cp,len); to[len]=0;
886 to+=len+1;
887 cp+=len;
888 if (mysql_fields)
889 {
890 if (mysql_fields[field].max_length < len)
891 mysql_fields[field].max_length=len;
892 }
893 }
894 }
895 cur->data[field]=to; /* End of last field */
896 if ((pkt_len=ma_net_safe_read(mysql)) == packet_error((unsigned int) -1))
897 {
898 free_rows(result);
899 return(0);
900 }
901 }
902 *prev_ptr=0; /* last pointer is null */
903 /* save status */
904 if (pkt_len > 1)
905 {
906 cp++;
907 mysql->warning_count= uint2korr(cp)(uint16) (((uint16) ((uchar) (cp)[0])) + ((uint16) ((uchar) (
cp)[1]) << 8))
;
908 cp+= 2;
909 mysql->server_status= uint2korr(cp)(uint16) (((uint16) ((uchar) (cp)[0])) + ((uint16) ((uchar) (
cp)[1]) << 8))
;
910 }
911 return(result);
912}
913
914
915/*
916** Read one row. Uses packet buffer as storage for fields.
917** When next packet is read, the previous field values are destroyed
918*/
919
920
921int mthd_my_read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths)
922{
923 uint field;
924 ulong pkt_len,len;
925 uchar *pos,*prev_pos, *end_pos;
926
927 if ((pkt_len=(uint) ma_net_safe_read(mysql)) == packet_error((unsigned int) -1))
928 return -1;
929
930 if (pkt_len <= 8 && mysql->net.read_pos[0] == 254)
931 {
932 mysql->warning_count= uint2korr(mysql->net.read_pos + 1)(uint16) (((uint16) ((uchar) (mysql->net.read_pos + 1)[0])
) + ((uint16) ((uchar) (mysql->net.read_pos + 1)[1]) <<
8))
;
933 mysql->server_status= uint2korr(mysql->net.read_pos + 3)(uint16) (((uint16) ((uchar) (mysql->net.read_pos + 3)[0])
) + ((uint16) ((uchar) (mysql->net.read_pos + 3)[1]) <<
8))
;
934 return 1; /* End of data */
935 }
936 prev_pos= 0; /* allowed to write at packet[-1] */
937 pos=mysql->net.read_pos;
938 end_pos=pos+pkt_len;
939 for (field=0 ; field < fields ; field++)
940 {
941 if ((len=(ulong) net_field_length(&pos)) == NULL_LENGTH((unsigned long) ~0))
942 { /* null field */
943 row[field] = 0;
944 *lengths++=0;
945 }
946 else
947 {
948 if (len > (ulong) (end_pos - pos))
949 {
950 mysql->net.last_errno=CR_UNKNOWN_ERROR2000;
951 strcpy(mysql->net.last_error,ER(mysql->net.last_errno)client_errors[(mysql->net.last_errno)-2000]);
952 return -1;
953 }
954 row[field] = (char*) pos;
955 pos+=len;
956 *lengths++=len;
957 }
958 if (prev_pos)
959 *prev_pos=0; /* Terminate prev field */
960 prev_pos=pos;
961 }
962 row[field]=(char*) prev_pos+1; /* End of last field */
963 *prev_pos=0; /* Terminate last field */
964 return 0;
965}
966
967/****************************************************************************
968** Init MySQL structure or allocate one
969****************************************************************************/
970
971MYSQL * STDCALL
972mysql_init(MYSQL *mysql)
973{
974 if (mysql_server_init(0, NULL((void*)0), NULL((void*)0)))
22
Assuming the condition is false
23
Taking false branch
975 return NULL((void*)0);
976 if (!mysql)
24
Taking false branch
977 {
978 if (!(mysql=(MYSQL*) calloc(1, sizeof(MYSQL))))
979 return 0;
980 mysql->free_me=1;
981 mysql->net.pvio= 0;
982 mysql->net.extension= 0;
983 }
984 else
985 {
986 memset((char*) (mysql), 0, sizeof(*(mysql)));
987 mysql->net.pvio= 0;
988 mysql->net.extension= 0;
989 }
990
991 if (!(mysql->net.extension= (struct st_mariadb_net_extension *)
25
Assuming is null
992 calloc(1, sizeof(struct st_mariadb_net_extension))) ||
993 !(mysql->extension= (struct st_mariadb_extension *)
994 calloc(1, sizeof(struct st_mariadb_extension))))
995 goto error;
26
Control jumps to line 1013
996 mysql->options.report_data_truncation= 1;
997 mysql->options.connect_timeout=CONNECT_TIMEOUT0;
998 mysql->charset= ma_default_charset_info;
999 mysql->methods= &MARIADB_DEFAULT_METHODS;
1000 strcpy(mysql->net.sqlstate, "00000");
1001 mysql->net.last_error[0]= mysql->net.last_errno= 0;
1002
1003/*
1004 Only enable LOAD DATA INFILE by default if configured with
1005 --enable-local-infile
1006*/
1007#ifdef ENABLED_LOCAL_INFILE1
1008 mysql->options.client_flag|= CLIENT_LOCAL_FILES128;
1009#endif
1010 mysql->options.reconnect= 0;
1011 return mysql;
1012error:
1013 if (mysql->free_me)
27
Assuming the condition is true
28
Taking true branch
1014 free(mysql);
29
Argument to free() is the address of the local variable 'tmp_mysql', which is not memory allocated by malloc()
1015 return 0;
1016}
1017
1018int STDCALL
1019mysql_ssl_set(MYSQL *mysql __attribute__((unused)),
1020 const char *key __attribute__((unused)),
1021 const char *cert __attribute__((unused)),
1022 const char *ca __attribute__((unused)),
1023 const char *capath __attribute__((unused)),
1024 const char *cipher __attribute__((unused)))
1025{
1026#ifdef HAVE_TLS1
1027 char enable= 1;
1028 return (mysql_optionsv(mysql, MYSQL_OPT_SSL_ENFORCE, &enable) |
1029 mysql_optionsv(mysql, MYSQL_OPT_SSL_KEY, key) |
1030 mysql_optionsv(mysql, MYSQL_OPT_SSL_CERT, cert) |
1031 mysql_optionsv(mysql, MYSQL_OPT_SSL_CA, ca) |
1032 mysql_optionsv(mysql, MYSQL_OPT_SSL_CAPATH, capath) |
1033 mysql_optionsv(mysql, MYSQL_OPT_SSL_CIPHER, cipher)) ? 1 : 0;
1034#else
1035 return 0;
1036#endif
1037}
1038
1039/**************************************************************************
1040**************************************************************************/
1041
1042const char * STDCALL
1043mysql_get_ssl_cipher(MYSQL *mysql __attribute__((unused)))
1044{
1045#ifdef HAVE_TLS1
1046 if (mysql->net.pvio && mysql->net.pvio->ctls)
1047 {
1048 return ma_pvio_tls_cipher(mysql->net.pvio->ctls);
1049 }
1050#endif
1051 return(NULL((void*)0));
1052}
1053
1054/**************************************************************************
1055** Free strings in the SSL structure and clear 'use_ssl' flag.
1056** NB! Errors are not reported until you do mysql_real_connect.
1057**************************************************************************/
1058
1059char *ma_send_connect_attr(MYSQL *mysql, unsigned char *buffer)
1060{
1061 if (mysql->server_capabilities & CLIENT_CONNECT_ATTRS(1UL << 20))
1062 {
1063 buffer= (unsigned char *)mysql_net_store_length((unsigned char *)buffer, (mysql->options.extension) ?
1064 mysql->options.extension->connect_attrs_len : 0);
1065 if (mysql->options.extension &&
1066 hash_inited(&mysql->options.extension->connect_attrs)((&mysql->options.extension->connect_attrs)->array
.buffer != 0)
)
1067 {
1068 uint i;
1069 for (i=0; i < mysql->options.extension->connect_attrs.records; i++)
1070 {
1071 size_t len;
1072 uchar *p= hash_element(&mysql->options.extension->connect_attrs, i);
1073
1074 len= strlen((char *)p);
1075 buffer= mysql_net_store_length(buffer, len);
1076 memcpy(buffer, p, len);
1077 buffer+= (len);
1078 p+= (len + 1);
1079 len= strlen((char *)p);
1080 buffer= mysql_net_store_length(buffer, len);
1081 memcpy(buffer, p, len);
1082 buffer+= len;
1083 }
1084 }
1085 }
1086 return (char *)buffer;
1087}
1088
1089/** set some default attributes */
1090static my_bool
1091ma_set_connect_attrs(MYSQL *mysql)
1092{
1093 char buffer[255];
1094 int rc= 0;
1095
1096 rc= mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_client_name") +
1097 mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_client_version") +
1098 mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_os") +
1099#ifdef _WIN32
1100 mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_thread") +
1101#endif
1102 mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_pid") +
1103 mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_platform");
1104
1105 rc+= mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_client_name", "libmariadb")
1106 + mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_client_version", MARIADB_PACKAGE_VERSION"3.0.2")
1107 + mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_os", MARIADB_SYSTEM_TYPE"Linux");
1108
1109#ifdef _WIN32
1110 snprintf(buffer, 255, "%lu", (ulong) GetCurrentThreadId())__builtin___snprintf_chk (buffer, 255, 2 - 1, __builtin_object_size
(buffer, 2 > 1), "%lu", (ulong) GetCurrentThreadId())
;
1111 rc+= mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_thread", buffer);
1112 snprintf(buffer, 255, "%lu", (ulong) GetCurrentProcessId())__builtin___snprintf_chk (buffer, 255, 2 - 1, __builtin_object_size
(buffer, 2 > 1), "%lu", (ulong) GetCurrentProcessId())
;
1113#else
1114 snprintf(buffer, 255, "%lu", (ulong) getpid())__builtin___snprintf_chk (buffer, 255, 2 - 1, __builtin_object_size
(buffer, 2 > 1), "%lu", (ulong) getpid())
;
1115#endif
1116 rc+= mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_pid", buffer);
1117
1118 rc+= mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_platform", MARIADB_MACHINE_TYPE"ppc64le");
1119 return(test(rc>0)((rc>0) ? 1 : 0));
1120}
1121
1122/*
1123** Note that the mysql argument must be initialized with mysql_init()
1124** before calling mysql_real_connect !
1125*/
1126
1127MYSQL * STDCALL
1128mysql_real_connect(MYSQL *mysql, const char *host, const char *user,
1129 const char *passwd, const char *db,
1130 uint port, const char *unix_socket,unsigned long client_flag)
1131{
1132 char *end= NULL((void*)0);
1133 char *connection_handler= (mysql->options.extension) ?
1134 mysql->options.extension->connection_handler : 0;
1135
1136 if (!mysql->methods)
1137 mysql->methods= &MARIADB_DEFAULT_METHODS;
1138
1139 if (connection_handler ||
1140 (host && (end= strstr(host, "://"))))
1141 {
1142 MARIADB_CONNECTION_PLUGIN *plugin;
1143 char plugin_name[64];
1144
1145 if (!connection_handler || !connection_handler[0])
1146 {
1147 memset(plugin_name, 0, 64);
1148 ma_strmake(plugin_name, host, MIN(end - host, 63)(((end - host) < (63)) ? (end - host) : (63)));
1149 end+= 3;
1150 }
1151 else
1152 ma_strmake(plugin_name, connection_handler, MIN(63, strlen(connection_handler))(((63) < (strlen(connection_handler))) ? (63) : (strlen(connection_handler
)))
);
1153
1154 if (!(plugin= (MARIADB_CONNECTION_PLUGIN *)mysql_client_find_plugin(mysql, plugin_name, MARIADB_CLIENT_CONNECTION_PLUGIN103)))
1155 return NULL((void*)0);
1156
1157 if (!(mysql->extension->conn_hdlr= (MA_CONNECTION_HANDLER *)calloc(1, sizeof(MA_CONNECTION_HANDLER))))
1158 {
1159 SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2008); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2008))-2000], sizeof((mysql)->net.last_error)); }
;
1160 return NULL((void*)0);
1161 }
1162
1163 /* save URL for reconnect */
1164 OPT_SET_EXTENDED_VALUE_STR(&mysql->options, url, host)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension)); free((
gptr)(&mysql->options)->extension->url); if((host
)) (&mysql->options)->extension->url= (__extension__
(__builtin_constant_p ((char *)(host)) && ((size_t)(
const void *)(((char *)(host)) + 1) - (size_t)(const void *)(
(char *)(host)) == 1) ? (((const char *) ((char *)(host)))[0]
== '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t
__len = strlen ((char *)(host)) + 1; char *__retval = (char *
) malloc (__len); if (__retval != ((void*)0)) __retval = (char
*) memcpy (__retval, (char *)(host), __len); __retval; })) :
__strdup ((char *)(host)))); else (&mysql->options)->
extension->url= ((void*)0)
;
1165
1166 mysql->extension->conn_hdlr->plugin= plugin;
1167
1168 if (plugin && plugin->connect)
1169 {
1170 MYSQL *my= plugin->connect(mysql, end, user, passwd, db, port, unix_socket, client_flag);
1171 if (!my)
1172 {
1173 free(mysql->extension->conn_hdlr);
1174 mysql->extension->conn_hdlr= NULL((void*)0);
1175 }
1176 return my;
1177 }
1178 }
1179
1180 return mysql->methods->db_connect(mysql, host, user, passwd,
1181 db, port, unix_socket, client_flag);
1182}
1183
1184MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user,
1185 const char *passwd, const char *db,
1186 uint port, const char *unix_socket, unsigned long client_flag)
1187{
1188 char buff[NAME_LEN256+USERNAME_LENGTH128 * 4+100];
1189 char *end, *end_pkt, *host_info,
1190 *charset_name= NULL((void*)0);
1191 MA_PVIO_CINFO cinfo= {NULL((void*)0), NULL((void*)0), 0, -1, NULL((void*)0)};
1192 MARIADB_PVIO *pvio= NULL((void*)0);
1193 char *scramble_data;
1194 my_bool is_maria= 0;
1195 const char *scramble_plugin;
1196 uint pkt_length, scramble_len, pkt_scramble_len= 0;
1197 NET *net= &mysql->net;
1198
1199 if (!mysql->methods)
1200 mysql->methods= &MARIADB_DEFAULT_METHODS;
1201
1202 ma_set_connect_attrs(mysql);
1203
1204 if (net->pvio) /* check if we are already connected */
1205 {
1206 SET_CLIENT_ERROR(mysql, CR_ALREADY_CONNECTED, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2058); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2058))-2000], sizeof((mysql)->net.last_error)); }
;
1207 return(NULL((void*)0));
1208 }
1209
1210 /* use default options */
1211 if (mysql->options.my_cnf_file || mysql->options.my_cnf_group)
1212 {
1213 _mariadb_read_options(mysql,
1214 (mysql->options.my_cnf_file ?
1215 mysql->options.my_cnf_file : NULL((void*)0)),
1216 mysql->options.my_cnf_group);
1217 free(mysql->options.my_cnf_file);
1218 free(mysql->options.my_cnf_group);
1219 mysql->options.my_cnf_file=mysql->options.my_cnf_group=0;
1220 }
1221
1222#ifndef WIN32
1223 if (mysql->options.protocol > MYSQL_PROTOCOL_SOCKET)
1224 {
1225 SET_CLIENT_ERROR(mysql, CR_CONN_UNKNOWN_PROTOCOL, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2047); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2047))-2000], sizeof((mysql)->net.last_error)); }
;
1226 return(NULL((void*)0));
1227 }
1228#endif
1229
1230 /* Some empty-string-tests are done because of ODBC */
1231 if (!host || !host[0])
1232 host=mysql->options.host;
1233 if (!user || !user[0])
1234 user=mysql->options.user;
1235 if (!passwd)
1236 {
1237 passwd=mysql->options.password;
1238#ifndef DONT_USE_MYSQL_PWD
1239 if (!passwd)
1240 passwd=getenv("MYSQL_PWD"); /* get it from environment (haneke) */
1241 if (!passwd)
1242 passwd= "";
1243#endif
1244 }
1245 if (!db || !db[0])
1246 db=mysql->options.db;
1247 if (!port)
1248 port=mysql->options.port;
1249 if (!unix_socket)
1250 unix_socket=mysql->options.unix_socket;
1251
1252 mysql->server_status=SERVER_STATUS_AUTOCOMMIT2;
1253
1254 /* try to connect via pvio_init */
1255 cinfo.host= host;
1256 cinfo.unix_socket= unix_socket;
1257 cinfo.port= port;
1258 cinfo.mysql= mysql;
1259
1260 /*
1261 ** Grab a socket and connect it to the server
1262 */
1263#ifndef _WIN32
1264#if defined(HAVE_SYS_UN_H1)
1265 if ((!host || strcmp(host,LOCAL_HOST)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(host) && __builtin_constant_p ("localhost") &&
(__s1_len = __builtin_strlen (host), __s2_len = __builtin_strlen
("localhost"), (!((size_t)(const void *)((host) + 1) - (size_t
)(const void *)(host) == 1) || __s1_len >= 4) && (
!((size_t)(const void *)(("localhost") + 1) - (size_t)(const void
*)("localhost") == 1) || __s2_len >= 4)) ? __builtin_strcmp
(host, "localhost") : (__builtin_constant_p (host) &&
((size_t)(const void *)((host) + 1) - (size_t)(const void *)
(host) == 1) && (__s1_len = __builtin_strlen (host), __s1_len
< 4) ? (__builtin_constant_p ("localhost") && ((size_t
)(const void *)(("localhost") + 1) - (size_t)(const void *)("localhost"
) == 1) ? __builtin_strcmp (host, "localhost") : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ("localhost"); int __result = (((const unsigned char
*) (const char *) (host))[0] - __s2[0]); if (__s1_len > 0
&& __result == 0) { __result = (((const unsigned char
*) (const char *) (host))[1] - __s2[1]); if (__s1_len > 1
&& __result == 0) { __result = (((const unsigned char
*) (const char *) (host))[2] - __s2[2]); if (__s1_len > 2
&& __result == 0) __result = (((const unsigned char *
) (const char *) (host))[3] - __s2[3]); } } __result; }))) : (
__builtin_constant_p ("localhost") && ((size_t)(const
void *)(("localhost") + 1) - (size_t)(const void *)("localhost"
) == 1) && (__s2_len = __builtin_strlen ("localhost")
, __s2_len < 4) ? (__builtin_constant_p (host) && (
(size_t)(const void *)((host) + 1) - (size_t)(const void *)(host
) == 1) ? __builtin_strcmp (host, "localhost") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (host); int __result = (((const unsigned char *) (const
char *) ("localhost"))[0] - __s2[0]); if (__s2_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("localhost"))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("localhost"))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ("localhost"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(host, "localhost")))); })
== 0) &&
1266 mysql->options.protocol != MYSQL_PROTOCOL_TCP &&
1267 (unix_socket || mysql_unix_port))
1268 {
1269 cinfo.host= LOCAL_HOST"localhost";
1270 cinfo.unix_socket= (unix_socket) ? unix_socket : mysql_unix_port;
1271 cinfo.type= PVIO_TYPE_UNIXSOCKET;
1272 sprintf(host_info=buff,ER(CR_LOCALHOST_CONNECTION),cinfo.host)__builtin___sprintf_chk (host_info=buff, 2 - 1, __builtin_object_size
(host_info=buff, 2 > 1), client_errors[(2010)-2000],cinfo
.host)
;
1273 }
1274 else
1275#endif
1276#else
1277 if (mysql->options.protocol == MYSQL_PROTOCOL_MEMORY)
1278 {
1279 cinfo.host= mysql->options.shared_memory_base_name;
1280 cinfo.type= PVIO_TYPE_SHAREDMEM;
1281 sprintf(host_info=buff,ER(CR_SHARED_MEMORY_CONNECTION), cinfo.host ? cinfo.host : SHM_DEFAULT_NAME)__builtin___sprintf_chk (host_info=buff, 2 - 1, __builtin_object_size
(host_info=buff, 2 > 1), client_errors[(2037)-2000], cinfo
.host ? cinfo.host : "MYSQL")
;
1282 }
1283 /* named pipe */
1284 else if (mysql->options.protocol == MYSQL_PROTOCOL_PIPE ||
1285 (host && strcmp(host,LOCAL_HOST_NAMEDPIPE)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(host) && __builtin_constant_p (".") && (__s1_len
= __builtin_strlen (host), __s2_len = __builtin_strlen (".")
, (!((size_t)(const void *)((host) + 1) - (size_t)(const void
*)(host) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)((".") + 1) - (size_t)(const void *)(".") == 1) || __s2_len
>= 4)) ? __builtin_strcmp (host, ".") : (__builtin_constant_p
(host) && ((size_t)(const void *)((host) + 1) - (size_t
)(const void *)(host) == 1) && (__s1_len = __builtin_strlen
(host), __s1_len < 4) ? (__builtin_constant_p (".") &&
((size_t)(const void *)((".") + 1) - (size_t)(const void *)(
".") == 1) ? __builtin_strcmp (host, ".") : (__extension__ ({
const unsigned char *__s2 = (const unsigned char *) (const char
*) ("."); int __result = (((const unsigned char *) (const char
*) (host))[0] - __s2[0]); if (__s1_len > 0 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
host))[1] - __s2[1]); if (__s1_len > 1 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
host))[2] - __s2[2]); if (__s1_len > 2 && __result
== 0) __result = (((const unsigned char *) (const char *) (host
))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (
".") && ((size_t)(const void *)((".") + 1) - (size_t)
(const void *)(".") == 1) && (__s2_len = __builtin_strlen
("."), __s2_len < 4) ? (__builtin_constant_p (host) &&
((size_t)(const void *)((host) + 1) - (size_t)(const void *)
(host) == 1) ? __builtin_strcmp (host, ".") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (host); int __result = (((const unsigned char *) (const
char *) ("."))[0] - __s2[0]); if (__s2_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("."))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("."))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ("."))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(host, ".")))); })
== 0))
1286 {
1287 cinfo.type= PVIO_TYPE_NAMEDPIPE;
1288 sprintf(host_info=buff,ER(CR_NAMEDPIPE_CONNECTION),cinfo.host)__builtin___sprintf_chk (host_info=buff, 2 - 1, __builtin_object_size
(host_info=buff, 2 > 1), client_errors[(2015)-2000],cinfo
.host)
;
1289 }
1290 else
1291#endif
1292 {
1293 cinfo.unix_socket=0; /* This is not used */
1294 if (!port)
1295 port=mysql_port;
1296 if (!host)
1297 host=LOCAL_HOST"localhost";
1298 cinfo.host= host;
1299 cinfo.port= port;
1300 cinfo.type= PVIO_TYPE_SOCKET;
1301 sprintf(host_info=buff,ER(CR_TCP_CONNECTION), cinfo.host)__builtin___sprintf_chk (host_info=buff, 2 - 1, __builtin_object_size
(host_info=buff, 2 > 1), client_errors[(2011)-2000], cinfo
.host)
;
1302 }
1303 /* Initialize and load pvio plugin */
1304 if (!(pvio= ma_pvio_init(&cinfo)))
1305 goto error;
1306
1307 /* try to connect */
1308 if (ma_pvio_connect(pvio, &cinfo) != 0)
1309 {
1310 ma_pvio_close(pvio);
1311 goto error;
1312 }
1313
1314 if (mysql->options.extension && mysql->options.extension->proxy_header)
1315 {
1316 char *hdr = mysql->options.extension->proxy_header;
1317 size_t len = mysql->options.extension->proxy_header_len;
1318 if (ma_pvio_write(pvio, (unsigned char *)hdr, len) <= 0)
1319 {
1320 ma_pvio_close(pvio);
1321 goto error;
1322 }
1323 }
1324
1325 if (ma_net_init(net, pvio))
1326 goto error;
1327
1328 if (mysql->options.max_allowed_packet)
1329 net->max_packet_size= mysql->options.max_allowed_packet;
1330
1331 ma_pvio_keepalive(net->pvio);
1332 strcpy(mysql->net.sqlstate, "00000");
1333
1334 /* Get version info */
1335 mysql->protocol_version= PROTOCOL_VERSION10; /* Assume this */
1336/*
1337 if (ma_pvio_wait_io_or_timeout(net->pvio, FALSE, 0) < 1)
1338 {
1339 my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN,
1340 ER(CR_SERVER_LOST_EXTENDED),
1341 "handshake: waiting for inital communication packet",
1342 errno);
1343 goto error;
1344 }
1345 */
1346 if ((pkt_length=ma_net_safe_read(mysql)) == packet_error((unsigned int) -1))
1347 {
1348 if (mysql->net.last_errno == CR_SERVER_LOST2013)
1349 my_set_error(mysql, CR_SERVER_LOST2013, SQLSTATE_UNKNOWN,
1350 ER(CR_SERVER_LOST_EXTENDED)client_errors[(2055)-2000],
1351 "handshake: reading inital communication packet",
1352 errno(*__errno_location ()));
1353
1354 goto error;
1355 }
1356 end= (char *)net->read_pos;
1357 end_pkt= (char *)net->read_pos + pkt_length;
1358
1359 /* Check if version of protocol matches current one */
1360
1361 mysql->protocol_version= end[0];
1362 end++;
1363
1364 /* Check if server sends an error */
1365 if (mysql->protocol_version == 0XFF)
1366 {
1367 net_get_error(end, pkt_length - 1, net->last_error, sizeof(net->last_error),
1368 &net->last_errno, net->sqlstate);
1369 /* fix for bug #26426 */
1370 if (net->last_errno == 1040)
1371 memcpy(net->sqlstate, "08004", SQLSTATE_LENGTH5);
1372 goto error;
1373 }
1374
1375 if (mysql->protocol_version < PROTOCOL_VERSION10)
1376 {
1377 net->last_errno= CR_VERSION_ERROR2007;
1378 sprintf(net->last_error, ER(CR_VERSION_ERROR), mysql->protocol_version,__builtin___sprintf_chk (net->last_error, 2 - 1, __builtin_object_size
(net->last_error, 2 > 1), client_errors[(2007)-2000], mysql
->protocol_version, 10)
1379 PROTOCOL_VERSION)__builtin___sprintf_chk (net->last_error, 2 - 1, __builtin_object_size
(net->last_error, 2 > 1), client_errors[(2007)-2000], mysql
->protocol_version, 10)
;
1380 goto error;
1381 }
1382 /* Save connection information */
1383 if (!user) user="";
1384 if (!passwd) passwd="";
1385
1386 if (!(mysql->host_info= strdup(host_info ? host_info : "")(__extension__ (__builtin_constant_p (host_info ? host_info :
"") && ((size_t)(const void *)((host_info ? host_info
: "") + 1) - (size_t)(const void *)(host_info ? host_info : ""
) == 1) ? (((const char *) (host_info ? host_info : ""))[0] ==
'\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len
= strlen (host_info ? host_info : "") + 1; char *__retval = (
char *) malloc (__len); if (__retval != ((void*)0)) __retval =
(char *) memcpy (__retval, host_info ? host_info : "", __len
); __retval; })) : __strdup (host_info ? host_info : "")))
) ||
1387 !(mysql->host= strdup(cinfo.host ? cinfo.host : "")(__extension__ (__builtin_constant_p (cinfo.host ? cinfo.host
: "") && ((size_t)(const void *)((cinfo.host ? cinfo
.host : "") + 1) - (size_t)(const void *)(cinfo.host ? cinfo.
host : "") == 1) ? (((const char *) (cinfo.host ? cinfo.host :
""))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) :
({ size_t __len = strlen (cinfo.host ? cinfo.host : "") + 1;
char *__retval = (char *) malloc (__len); if (__retval != ((
void*)0)) __retval = (char *) memcpy (__retval, cinfo.host ? cinfo
.host : "", __len); __retval; })) : __strdup (cinfo.host ? cinfo
.host : "")))
) ||
1388 !(mysql->user=strdup(user)(__extension__ (__builtin_constant_p (user) && ((size_t
)(const void *)((user) + 1) - (size_t)(const void *)(user) ==
1) ? (((const char *) (user))[0] == '\0' ? (char *) calloc (
(size_t) 1, (size_t) 1) : ({ size_t __len = strlen (user) + 1
; char *__retval = (char *) malloc (__len); if (__retval != (
(void*)0)) __retval = (char *) memcpy (__retval, user, __len)
; __retval; })) : __strdup (user)))
) ||
1389 !(mysql->passwd=strdup(passwd)(__extension__ (__builtin_constant_p (passwd) && ((size_t
)(const void *)((passwd) + 1) - (size_t)(const void *)(passwd
) == 1) ? (((const char *) (passwd))[0] == '\0' ? (char *) calloc
((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (passwd)
+ 1; char *__retval = (char *) malloc (__len); if (__retval !=
((void*)0)) __retval = (char *) memcpy (__retval, passwd, __len
); __retval; })) : __strdup (passwd)))
))
1390 {
1391 SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2008); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2008))-2000], sizeof((mysql)->net.last_error)); }
;
1392 goto error;
1393 }
1394 if (cinfo.unix_socket)
1395 mysql->unix_socket= strdup(cinfo.unix_socket)(__extension__ (__builtin_constant_p (cinfo.unix_socket) &&
((size_t)(const void *)((cinfo.unix_socket) + 1) - (size_t)(
const void *)(cinfo.unix_socket) == 1) ? (((const char *) (cinfo
.unix_socket))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t
) 1) : ({ size_t __len = strlen (cinfo.unix_socket) + 1; char
*__retval = (char *) malloc (__len); if (__retval != ((void*
)0)) __retval = (char *) memcpy (__retval, cinfo.unix_socket,
__len); __retval; })) : __strdup (cinfo.unix_socket)))
;
1396 else
1397 mysql->unix_socket=0;
1398 mysql->port=port;
1399 client_flag|=mysql->options.client_flag;
1400
1401 if (strncmp(end, MA_RPL_VERSION_HACK, sizeof(MA_RPL_VERSION_HACK) - 1)(__extension__ (__builtin_constant_p (sizeof("5.5.5-") - 1) &&
((__builtin_constant_p (end) && strlen (end) < ((
size_t) (sizeof("5.5.5-") - 1))) || (__builtin_constant_p ("5.5.5-"
) && strlen ("5.5.5-") < ((size_t) (sizeof("5.5.5-"
) - 1)))) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(end) && __builtin_constant_p ("5.5.5-") && (
__s1_len = __builtin_strlen (end), __s2_len = __builtin_strlen
("5.5.5-"), (!((size_t)(const void *)((end) + 1) - (size_t)(
const void *)(end) == 1) || __s1_len >= 4) && (!((
size_t)(const void *)(("5.5.5-") + 1) - (size_t)(const void *
)("5.5.5-") == 1) || __s2_len >= 4)) ? __builtin_strcmp (end
, "5.5.5-") : (__builtin_constant_p (end) && ((size_t
)(const void *)((end) + 1) - (size_t)(const void *)(end) == 1
) && (__s1_len = __builtin_strlen (end), __s1_len <
4) ? (__builtin_constant_p ("5.5.5-") && ((size_t)(const
void *)(("5.5.5-") + 1) - (size_t)(const void *)("5.5.5-") ==
1) ? __builtin_strcmp (end, "5.5.5-") : (__extension__ ({ const
unsigned char *__s2 = (const unsigned char *) (const char *)
("5.5.5-"); int __result = (((const unsigned char *) (const char
*) (end))[0] - __s2[0]); if (__s1_len > 0 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
end))[1] - __s2[1]); if (__s1_len > 1 && __result ==
0) { __result = (((const unsigned char *) (const char *) (end
))[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (end))[
3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("5.5.5-"
) && ((size_t)(const void *)(("5.5.5-") + 1) - (size_t
)(const void *)("5.5.5-") == 1) && (__s2_len = __builtin_strlen
("5.5.5-"), __s2_len < 4) ? (__builtin_constant_p (end) &&
((size_t)(const void *)((end) + 1) - (size_t)(const void *)(
end) == 1) ? __builtin_strcmp (end, "5.5.5-") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (end); int __result = (((const unsigned char *) (const
char *) ("5.5.5-"))[0] - __s2[0]); if (__s2_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("5.5.5-"))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("5.5.5-"))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ("5.5.5-"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(end, "5.5.5-")))); }) : strncmp (end, "5.5.5-", sizeof("5.5.5-"
) - 1)))
== 0)
1402 {
1403 mysql->server_version= strdup(end + sizeof(MA_RPL_VERSION_HACK) - 1)(__extension__ (__builtin_constant_p (end + sizeof("5.5.5-") -
1) && ((size_t)(const void *)((end + sizeof("5.5.5-"
) - 1) + 1) - (size_t)(const void *)(end + sizeof("5.5.5-") -
1) == 1) ? (((const char *) (end + sizeof("5.5.5-") - 1))[0]
== '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t
__len = strlen (end + sizeof("5.5.5-") - 1) + 1; char *__retval
= (char *) malloc (__len); if (__retval != ((void*)0)) __retval
= (char *) memcpy (__retval, end + sizeof("5.5.5-") - 1, __len
); __retval; })) : __strdup (end + sizeof("5.5.5-") - 1)))
;
1404 is_maria= 1;
1405 }
1406 else
1407 {
1408 if (!(mysql->server_version= strdup(end)(__extension__ (__builtin_constant_p (end) && ((size_t
)(const void *)((end) + 1) - (size_t)(const void *)(end) == 1
) ? (((const char *) (end))[0] == '\0' ? (char *) calloc ((size_t
) 1, (size_t) 1) : ({ size_t __len = strlen (end) + 1; char *
__retval = (char *) malloc (__len); if (__retval != ((void*)0
)) __retval = (char *) memcpy (__retval, end, __len); __retval
; })) : __strdup (end)))
))
1409 {
1410 SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2008); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2008))-2000], sizeof((mysql)->net.last_error)); }
;
1411 goto error;
1412 }
1413 }
1414 end+= strlen(end) + 1;
1415
1416 mysql->thread_id=uint4korr(end)(uint32) (((uint32) ((uchar) (end)[0])) + (((uint32) ((uchar)
(end)[1])) << 8) + (((uint32) ((uchar) (end)[2])) <<
16) + (((uint32) ((uchar) (end)[3])) << 24))
;
1417 end+=4;
1418
1419 /* This is the first part of scramble packet. In 4.1 and later
1420 a second package will follow later */
1421 scramble_data= end;
1422 scramble_len= SCRAMBLE_LENGTH_3238 + 1;
1423 scramble_plugin= old_password_plugin_name"mysql_old_password";
1424 end+= SCRAMBLE_LENGTH_3238;
1425
1426 /* 1st pad */
1427 end++;
1428
1429 if (end + 1<= end_pkt)
1430 {
1431 mysql->server_capabilities=uint2korr(end)(uint16) (((uint16) ((uchar) (end)[0])) + ((uint16) ((uchar) (
end)[1]) << 8))
;
1432 }
1433
1434 /* mysql 5.5 protocol */
1435 if (end + 18 <= end_pkt)
1436 {
1437 mysql->server_language= uint1korr(end + 2)(*(((uint8*)(end + 2))));
1438 mysql->server_status= uint2korr(end + 3)(uint16) (((uint16) ((uchar) (end + 3)[0])) + ((uint16) ((uchar
) (end + 3)[1]) << 8))
;
1439 mysql->server_capabilities|= (unsigned int)(uint2korr(end + 5)(uint16) (((uint16) ((uchar) (end + 5)[0])) + ((uint16) ((uchar
) (end + 5)[1]) << 8))
<< 16);
1440 pkt_scramble_len= uint1korr(end + 7)(*(((uint8*)(end + 7))));
1441
1442 /* check if MariaD2B specific capabilities are available */
1443 if (is_maria && !(mysql->server_capabilities & CLIENT_MYSQL1))
1444 {
1445 mysql->extension->mariadb_server_capabilities= (ulonglong) uint4korr(end + 14)(uint32) (((uint32) ((uchar) (end + 14)[0])) + (((uint32) ((uchar
) (end + 14)[1])) << 8) + (((uint32) ((uchar) (end + 14
)[2])) << 16) + (((uint32) ((uchar) (end + 14)[3])) <<
24))
;
1446 }
1447 }
1448
1449 /* pad 2 */
1450 end+= 18;
1451
1452 /* second scramble package */
1453 if (end + SCRAMBLE_LENGTH20 - SCRAMBLE_LENGTH_3238 + 1 <= end_pkt)
1454 {
1455 memcpy(end - SCRAMBLE_LENGTH_3238, scramble_data, SCRAMBLE_LENGTH_3238);
1456 scramble_data= end - SCRAMBLE_LENGTH_3238;
1457 if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH(1UL << 19))
1458 {
1459 scramble_len= pkt_scramble_len;
1460 scramble_plugin= scramble_data + scramble_len;
1461 if (scramble_data + scramble_len > end_pkt)
1462 scramble_len= (uint)(end_pkt - scramble_data);
1463 } else
1464 {
1465 scramble_len= (uint)(end_pkt - scramble_data);
1466 scramble_plugin= native_password_plugin_name"mysql_native_password";
1467 }
1468 } else
1469 {
1470 mysql->server_capabilities&= ~CLIENT_SECURE_CONNECTION32768;
1471 if (mysql->options.secure_auth)
1472 {
1473 SET_CLIENT_ERROR(mysql, CR_SECURE_AUTH, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2049); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2049))-2000], sizeof((mysql)->net.last_error)); }
;
1474 goto error;
1475 }
1476 }
1477
1478 /* Set character set */
1479 if (mysql->options.charset_name)
1480 mysql->charset= mysql_find_charset_name(mysql->options.charset_name);
1481 else if (mysql->server_language)
1482 mysql->charset= mysql_find_charset_nr(mysql->server_language);
1483 else
1484 mysql->charset=ma_default_charset_info;
1485
1486 if (!mysql->charset)
1487 {
1488 net->last_errno=CR_CANT_READ_CHARSET2019;
1489 sprintf(net->last_error,ER(net->last_errno),__builtin___sprintf_chk (net->last_error, 2 - 1, __builtin_object_size
(net->last_error, 2 > 1), client_errors[(net->last_errno
)-2000], charset_name ? charset_name : "unknown", "compiled_in"
)
1490 charset_name ? charset_name : "unknown",__builtin___sprintf_chk (net->last_error, 2 - 1, __builtin_object_size
(net->last_error, 2 > 1), client_errors[(net->last_errno
)-2000], charset_name ? charset_name : "unknown", "compiled_in"
)
1491 "compiled_in")__builtin___sprintf_chk (net->last_error, 2 - 1, __builtin_object_size
(net->last_error, 2 > 1), client_errors[(net->last_errno
)-2000], charset_name ? charset_name : "unknown", "compiled_in"
)
;
1492 goto error;
1493 }
1494
1495 mysql->client_flag= client_flag;
1496
1497 if (run_plugin_auth(mysql, scramble_data, scramble_len,
1498 scramble_plugin, db))
1499 goto error;
1500
1501 if (mysql->client_flag & CLIENT_COMPRESS32)
1502 net->compress= 1;
1503
1504 /* last part: select default db */
1505 if (!(mysql->server_capabilities & CLIENT_CONNECT_WITH_DB8) &&
1506 (db && !mysql->db))
1507 {
1508 if (mysql_select_db(mysql, db))
1509 {
1510 my_set_error(mysql, CR_SERVER_LOST2013, SQLSTATE_UNKNOWN,
1511 ER(CR_SERVER_LOST_EXTENDED)client_errors[(2055)-2000],
1512 "Setting intital database",
1513 errno(*__errno_location ()));
1514 goto error;
1515 }
1516 }
1517
1518 if (mysql->options.init_command)
1519 {
1520 char **begin= (char **)mysql->options.init_command->buffer;
1521 char **end= begin + mysql->options.init_command->elements;
1522
1523 /* Avoid reconnect in mysql_real_connect */
1524 my_bool save_reconnect= mysql->options.reconnect;
1525 mysql->options.reconnect= 0;
1526
1527 for (;begin < end; begin++)
1528 {
1529 if (mysql_real_query(mysql, *begin, (unsigned long)strlen(*begin)))
1530 goto error;
1531
1532 /* check if query produced a result set */
1533 do {
1534 MYSQL_RES *res;
1535 if ((res= mysql_use_result(mysql)))
1536 mysql_free_result(res);
1537 } while (!mysql_next_result(mysql));
1538 }
1539 mysql->options.reconnect= save_reconnect;
1540 }
1541
1542 strcpy(mysql->net.sqlstate, "00000");
1543
1544 /* connection established, apply timeouts */
1545 ma_pvio_set_timeout(mysql->net.pvio, PVIO_READ_TIMEOUT, mysql->options.read_timeout);
1546 ma_pvio_set_timeout(mysql->net.pvio, PVIO_WRITE_TIMEOUT, mysql->options.write_timeout);
1547 return(mysql);
1548
1549error:
1550 /* Free alloced memory */
1551 end_server(mysql);
1552 /* only free the allocated memory, user needs to call mysql_close */
1553 mysql_close_memory(mysql);
1554 if (!(client_flag & CLIENT_REMEMBER_OPTIONS(1UL << 31)) &&
1555 !mysql->options.extension->async_context)
1556 mysql_close_options(mysql);
1557 return(0);
1558}
1559
1560struct my_hook_data {
1561 MYSQL *orig_mysql;
1562 MYSQL *new_mysql;
1563 /* This is always NULL currently, but restoring does not hurt just in case. */
1564 MARIADB_PVIO *orig_pvio;
1565};
1566/*
1567 Callback hook to make the new VIO accessible via the old MYSQL to calling
1568 application when suspending a non-blocking call during automatic reconnect.
1569*/
1570static void
1571my_suspend_hook(my_bool suspend, void *data)
1572{
1573 struct my_hook_data *hook_data= (struct my_hook_data *)data;
1574 if (suspend)
1575 {
1576 hook_data->orig_pvio= hook_data->orig_mysql->net.pvio;
1577 hook_data->orig_mysql->net.pvio= hook_data->new_mysql->net.pvio;
1578 }
1579 else
1580 hook_data->orig_mysql->net.pvio= hook_data->orig_pvio;
1581}
1582
1583my_bool STDCALL mariadb_reconnect(MYSQL *mysql)
1584{
1585 MYSQL tmp_mysql;
1586 struct my_hook_data hook_data;
1587 struct mysql_async_context *ctxt= NULL((void*)0);
1588 LIST *li_stmt= mysql->stmts;
1589
1590 /* check if connection handler is active */
1591 if (IS_CONNHDLR_ACTIVE(mysql)((mysql)->extension && (mysql)->extension->conn_hdlr
)
)
1592 {
1593 if (mysql->extension->conn_hdlr->plugin && mysql->extension->conn_hdlr->plugin->reconnect)
1594 return(mysql->extension->conn_hdlr->plugin->reconnect(mysql));
1595 }
1596
1597 if (!mysql->options.reconnect ||
17
Assuming the condition is false
20
Taking false branch
1598 (mysql->server_status & SERVER_STATUS_IN_TRANS1) || !mysql->host_info)
18
Assuming the condition is false
19
Assuming the condition is false
1599 {
1600 /* Allow reconnect next time */
1601 mysql->server_status&= ~SERVER_STATUS_IN_TRANS1;
1602 my_set_error(mysql, CR_SERVER_GONE_ERROR2006, SQLSTATE_UNKNOWN, 0);
1603 return(1);
1604 }
1605
1606 mysql_init(&tmp_mysql);
21
Calling 'mysql_init'
1607 tmp_mysql.options=mysql->options;
1608 if (mysql->extension->conn_hdlr)
1609 {
1610 tmp_mysql.extension->conn_hdlr= mysql->extension->conn_hdlr;
1611 mysql->extension->conn_hdlr= 0;
1612 }
1613
1614 /* don't reread options from configuration files */
1615 tmp_mysql.options.my_cnf_group= tmp_mysql.options.my_cnf_file= NULL((void*)0);
1616 if (IS_MYSQL_ASYNC_ACTIVE(mysql)(((mysql)->options.extension && (mysql)->options
.extension->async_context)&& (mysql)->options.extension
->async_context->active)
)
1617 {
1618 ctxt= mysql->options.extension->async_context;
1619 hook_data.orig_mysql= mysql;
1620 hook_data.new_mysql= &tmp_mysql;
1621 hook_data.orig_pvio= mysql->net.pvio;
1622 my_context_install_suspend_resume_hook(ctxt, my_suspend_hook, &hook_data);
1623 }
1624
1625 if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd,
1626 mysql->db, mysql->port, mysql->unix_socket,
1627 mysql->client_flag | CLIENT_REMEMBER_OPTIONS(1UL << 31)) ||
1628 mysql_set_character_set(&tmp_mysql, mysql->charset->csname))
1629 {
1630 if (ctxt)
1631 my_context_install_suspend_resume_hook(ctxt, NULL((void*)0), NULL((void*)0));
1632 /* don't free options (CONC-118) */
1633 memset(&tmp_mysql.options, 0, sizeof(struct st_mysql_options));
1634 my_set_error(mysql, tmp_mysql.net.last_errno,
1635 tmp_mysql.net.sqlstate,
1636 tmp_mysql.net.last_error);
1637 mysql_close(&tmp_mysql);
1638 return(1);
1639 }
1640
1641 for (;li_stmt;li_stmt= li_stmt->next)
1642 {
1643 MYSQL_STMT *stmt= (MYSQL_STMT *)li_stmt->data;
1644
1645 if (stmt->state != MYSQL_STMT_INITTED)
1646 {
1647 stmt->state= MYSQL_STMT_INITTED;
1648 SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0){ (stmt)->last_errno= (2013); strncpy((stmt)->sqlstate,
(SQLSTATE_UNKNOWN), sizeof((stmt)->sqlstate)); strncpy((stmt
)->last_error, (0) ? (0) : client_errors[((2013))-2000], sizeof
((stmt)->last_error));}
;
1649 }
1650 }
1651
1652 tmp_mysql.free_me= mysql->free_me;
1653 tmp_mysql.stmts= mysql->stmts;
1654 mysql->stmts= NULL((void*)0);
1655
1656 if (ctxt)
1657 my_context_install_suspend_resume_hook(ctxt, NULL((void*)0), NULL((void*)0));
1658 /* Don't free options, we moved them to tmp_mysql */
1659 memset(&mysql->options, 0, sizeof(mysql->options));
1660 mysql->free_me=0;
1661 mysql_close(mysql);
1662 *mysql=tmp_mysql;
1663 mysql->net.pvio->mysql= mysql;
1664 ma_net_clear(&mysql->net);
1665 mysql->affected_rows= ~(unsigned long long) 0;
1666 mysql->info= 0;
1667 return(0);
1668}
1669
1670void ma_invalidate_stmts(MYSQL *mysql, const char *function_name)
1671{
1672 if (mysql->stmts)
1673 {
1674 LIST *li_stmt= mysql->stmts;
1675
1676 for (; li_stmt; li_stmt= li_stmt->next)
1677 {
1678 MYSQL_STMT *stmt= (MYSQL_STMT *)li_stmt->data;
1679 stmt->mysql= NULL((void*)0);
1680 SET_CLIENT_STMT_ERROR(stmt, CR_STMT_CLOSED, SQLSTATE_UNKNOWN, function_name){ (stmt)->last_errno= (2056); strncpy((stmt)->sqlstate,
(SQLSTATE_UNKNOWN), sizeof((stmt)->sqlstate)); strncpy((stmt
)->last_error, (function_name) ? (function_name) : client_errors
[((2056))-2000], sizeof((stmt)->last_error));}
;
1681 }
1682 mysql->stmts= NULL((void*)0);
1683 }
1684}
1685
1686/*
1687 Legacy support of the MariaDB 5.5 version, where timeouts where only in
1688 seconds resolution. Applications that use this will be asked to set a timeout
1689 at the nearest higher whole-seconds value.
1690*/
1691unsigned int STDCALL
1692mysql_get_timeout_value(const MYSQL *mysql)
1693{
1694 unsigned int timeout= mysql->options.extension->async_context->timeout_value;
1695 /* Avoid overflow. */
1696 if (timeout > UINT_MAX(2147483647 *2U +1U) - 999)
1697 return (timeout - 1)/1000 + 1;
1698 else
1699 return (timeout+999)/1000;
1700}
1701
1702
1703unsigned int STDCALL
1704mysql_get_timeout_value_ms(const MYSQL *mysql)
1705{
1706 return mysql->options.extension->async_context->timeout_value;
1707}
1708
1709/**************************************************************************
1710** Change user and database
1711**************************************************************************/
1712
1713my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
1714 const char *passwd, const char *db)
1715{
1716 const MARIADB_CHARSET_INFO *s_cs= mysql->charset;
1717 char *s_user= mysql->user,
1718 *s_passwd= mysql->passwd,
1719 *s_db= mysql->db;
1720 int rc;
1721
1722 if (!user)
1723 user="";
1724 if (!passwd)
1725 passwd="";
1726 if (!db)
1727 db="";
1728
1729 if (mysql->options.charset_name)
1730 mysql->charset =mysql_find_charset_name(mysql->options.charset_name);
1731 else if (mysql->server_language)
1732 mysql->charset=mysql_find_charset_nr(mysql->server_language);
1733 else
1734 mysql->charset=ma_default_charset_info;
1735
1736 mysql->user= strdup(user ? user : "")(__extension__ (__builtin_constant_p (user ? user : "") &&
((size_t)(const void *)((user ? user : "") + 1) - (size_t)(const
void *)(user ? user : "") == 1) ? (((const char *) (user ? user
: ""))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1)
: ({ size_t __len = strlen (user ? user : "") + 1; char *__retval
= (char *) malloc (__len); if (__retval != ((void*)0)) __retval
= (char *) memcpy (__retval, user ? user : "", __len); __retval
; })) : __strdup (user ? user : "")))
;
1737 mysql->passwd= strdup(passwd ? passwd : "")(__extension__ (__builtin_constant_p (passwd ? passwd : "") &&
((size_t)(const void *)((passwd ? passwd : "") + 1) - (size_t
)(const void *)(passwd ? passwd : "") == 1) ? (((const char *
) (passwd ? passwd : ""))[0] == '\0' ? (char *) calloc ((size_t
) 1, (size_t) 1) : ({ size_t __len = strlen (passwd ? passwd :
"") + 1; char *__retval = (char *) malloc (__len); if (__retval
!= ((void*)0)) __retval = (char *) memcpy (__retval, passwd ?
passwd : "", __len); __retval; })) : __strdup (passwd ? passwd
: "")))
;
1738
1739 /* db will be set in run_plugin_auth */
1740 mysql->db= 0;
1741 rc= run_plugin_auth(mysql, 0, 0, 0, db);
1742
1743 /* COM_CHANGE_USER always releases prepared statements, so we need to invalidate them */
1744 ma_invalidate_stmts(mysql, "mysql_change_user()");
1745
1746 if (rc==0)
1747 {
1748 free(s_user);
1749 free(s_passwd);
1750 free(s_db);
1751
1752 if (db && !(mysql->db= strdup(db)(__extension__ (__builtin_constant_p (db) && ((size_t
)(const void *)((db) + 1) - (size_t)(const void *)(db) == 1) ?
(((const char *) (db))[0] == '\0' ? (char *) calloc ((size_t
) 1, (size_t) 1) : ({ size_t __len = strlen (db) + 1; char *__retval
= (char *) malloc (__len); if (__retval != ((void*)0)) __retval
= (char *) memcpy (__retval, db, __len); __retval; })) : __strdup
(db)))
))
1753 {
1754 SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2008); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2008))-2000], sizeof((mysql)->net.last_error)); }
;
1755 rc= 1;
1756 }
1757 } else
1758 {
1759 free(mysql->user);
1760 free(mysql->passwd);
1761 free(mysql->db);
1762
1763 mysql->user= s_user;
1764 mysql->passwd= s_passwd;
1765 mysql->db= s_db;
1766 mysql->charset= s_cs;
1767 }
1768 return(rc);
1769}
1770
1771
1772/**************************************************************************
1773** Set current database
1774**************************************************************************/
1775
1776int STDCALL
1777mysql_select_db(MYSQL *mysql, const char *db)
1778{
1779 int error;
1780
1781 if ((error=ma_simple_command(mysql, COM_INIT_DB,db,(uint) strlen(db),0,0)))
1782 return(error);
1783 free(mysql->db);
1784 mysql->db=strdup(db)(__extension__ (__builtin_constant_p (db) && ((size_t
)(const void *)((db) + 1) - (size_t)(const void *)(db) == 1) ?
(((const char *) (db))[0] == '\0' ? (char *) calloc ((size_t
) 1, (size_t) 1) : ({ size_t __len = strlen (db) + 1; char *__retval
= (char *) malloc (__len); if (__retval != ((void*)0)) __retval
= (char *) memcpy (__retval, db, __len); __retval; })) : __strdup
(db)))
;
1785 return(0);
1786}
1787
1788
1789/*************************************************************************
1790** Send a QUIT to the server and close the connection
1791** If handle is alloced by mysql connect free it.
1792*************************************************************************/
1793
1794static void mysql_close_options(MYSQL *mysql)
1795{
1796 if (mysql->options.init_command)
1797 {
1798 char **begin= (char **)mysql->options.init_command->buffer;
1799 char **end= begin + mysql->options.init_command->elements;
1800
1801 for (;begin < end; begin++)
1802 free(*begin);
1803 ma_delete_dynamic(mysql->options.init_command);
1804 free(mysql->options.init_command);
1805 }
1806 free(mysql->options.user);
1807 free(mysql->options.host);
1808 free(mysql->options.password);
1809 free(mysql->options.unix_socket);
1810 free(mysql->options.db);
1811 free(mysql->options.my_cnf_file);
1812 free(mysql->options.my_cnf_group);
1813 free(mysql->options.charset_dir);
1814 free(mysql->options.charset_name);
1815 free(mysql->options.bind_address);
1816 free(mysql->options.ssl_key);
1817 free(mysql->options.ssl_cert);
1818 free(mysql->options.ssl_ca);
1819 free(mysql->options.ssl_capath);
1820 free(mysql->options.ssl_cipher);
1821
1822 if (mysql->options.extension)
1823 {
1824 struct mysql_async_context *ctxt;
1825 if ((ctxt = mysql->options.extension->async_context))
1826 {
1827 my_context_destroy(&ctxt->async_context);
1828 free(ctxt);
1829 mysql->options.extension->async_context= 0;
1830 }
1831 free(mysql->options.extension->plugin_dir);
1832 free(mysql->options.extension->default_auth);
1833 free(mysql->options.extension->db_driver);
1834 free(mysql->options.extension->ssl_crl);
1835 free(mysql->options.extension->ssl_crlpath);
1836 free(mysql->options.extension->tls_fp);
1837 free(mysql->options.extension->tls_fp_list);
1838 free(mysql->options.extension->tls_pw);
1839 free(mysql->options.extension->tls_version);
1840 free(mysql->options.extension->url);
1841 free(mysql->options.extension->connection_handler);
1842 if(hash_inited(&mysql->options.extension->connect_attrs)((&mysql->options.extension->connect_attrs)->array
.buffer != 0)
)
1843 hash_free(&mysql->options.extension->connect_attrs);
1844 if (hash_inited(&mysql->options.extension->userdata)((&mysql->options.extension->userdata)->array.buffer
!= 0)
)
1845 hash_free(&mysql->options.extension->userdata);
1846
1847 }
1848 free(mysql->options.extension);
1849 /* clear all pointer */
1850 memset(&mysql->options, 0, sizeof(mysql->options));
1851}
1852
1853static void mysql_close_memory(MYSQL *mysql)
1854{
1855 free(mysql->host_info);
1856 free(mysql->host);
1857 free(mysql->user);
1858 free(mysql->passwd);
1859 free(mysql->db);
1860 free(mysql->unix_socket);
1861 free(mysql->server_version);
1862 mysql->host_info= mysql->host= mysql->unix_socket=
1863 mysql->server_version=mysql->user=mysql->passwd=mysql->db=0;
1864}
1865
1866void my_set_error(MYSQL *mysql,
1867 unsigned int error_nr,
1868 const char *sqlstate,
1869 const char *format,
1870 ...)
1871{
1872 va_list ap;
1873
1874 mysql->net.last_errno= error_nr;
1875 ma_strmake(mysql->net.sqlstate, sqlstate, SQLSTATE_LENGTH5);
1876 va_start(ap, format)__builtin_va_start(ap, format);
1877 vsnprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE512,
1878 format ? format : ER(error_nr)client_errors[(error_nr)-2000], ap);
1879 va_end(ap)__builtin_va_end(ap);
1880 return;
1881}
1882
1883void mysql_close_slow_part(MYSQL *mysql)
1884{
1885 if (mysql->net.pvio)
1886 {
1887 free_old_query(mysql);
1888 mysql->status=MYSQL_STATUS_READY; /* Force command */
1889 mysql->options.reconnect=0;
1890 if (mysql->net.pvio && mysql->net.buff)
1891 ma_simple_command(mysql, COM_QUIT,NullS(char *) 0,0,1,0);
1892 end_server(mysql);
1893 }
1894}
1895
1896void ma_clear_session_state(MYSQL *mysql)
1897{
1898 uint i;
1899
1900 if (!mysql || !mysql->extension)
1901 return;
1902
1903 for (i= SESSION_TRACK_BEGIN0; i <= SESSION_TRACK_ENDSESSION_TRACK_TRANSACTION_TYPE; i++)
1904 {
1905 /* we acquired memory via ma_multi_alloc, so we don't need to free data */
1906 list_free(mysql->extension->session_state[i].list, 0);
1907 }
1908 memset(mysql->extension->session_state, 0, sizeof(struct st_mariadb_session_state) * SESSION_TRACK_TYPESSESSION_TRACK_TRANSACTION_TYPE + 1);
1909}
1910
1911void STDCALL
1912mysql_close(MYSQL *mysql)
1913{
1914 if (mysql) /* Some simple safety */
1915 {
1916 if (mysql->extension && mysql->extension->conn_hdlr)
1917 {
1918 MA_CONNECTION_HANDLER *p= mysql->extension->conn_hdlr;
1919 p->plugin->close(mysql);
1920 free(p);
1921 }
1922
1923 if (mysql->methods)
1924 mysql->methods->db_close(mysql);
1925
1926 /* reset the connection in all active statements */
1927 ma_invalidate_stmts(mysql, "mysql_close()");
1928
1929 mysql_close_memory(mysql);
1930 mysql_close_options(mysql);
1931 ma_clear_session_state(mysql);
1932
1933 if (mysql->net.extension)
1934 free(mysql->net.extension);
1935
1936 mysql->host_info=mysql->user=mysql->passwd=mysql->db=0;
1937
1938 /* Clear pointers for better safety */
1939 memset((char*) &mysql->options, 0, sizeof(mysql->options));
1940
1941 if (mysql->extension)
1942 free(mysql->extension);
1943
1944 mysql->net.pvio= 0;
1945 if (mysql->free_me)
1946 free(mysql);
1947 }
1948 return;
1949}
1950
1951
1952/**************************************************************************
1953** Do a query. If query returned rows, free old rows.
1954** Read data by mysql_store_result or by repeating calls to mysql_fetch_row
1955**************************************************************************/
1956
1957int STDCALL
1958mysql_query(MYSQL *mysql, const char *query)
1959{
1960 return mysql_real_query(mysql,query, (unsigned long) strlen(query));
1961}
1962
1963/*
1964 Send the query and return so we can do something else.
1965 Needs to be followed by mysql_read_query_result() when we want to
1966 finish processing it.
1967*/
1968
1969int STDCALL
1970mysql_send_query(MYSQL* mysql, const char* query, unsigned long length)
1971{
1972 return ma_simple_command(mysql, COM_QUERY, query, length, 1,0);
1973}
1974
1975int mthd_my_read_query_result(MYSQL *mysql)
1976{
1977 uchar *pos;
1978 ulong field_count;
1979 MYSQL_DATA *fields;
1980 ulong length;
1981
1982 if (!mysql || (length = ma_net_safe_read(mysql)) == packet_error((unsigned int) -1))
1983 {
1984 return(1);
1985 }
1986 free_old_query(mysql); /* Free old result */
1987get_info:
1988 pos=(uchar*) mysql->net.read_pos;
1989 if ((field_count= net_field_length(&pos)) == 0)
1990 {
1991 size_t item_len;
1992 mysql->affected_rows= net_field_length_ll(&pos);
1993 mysql->insert_id= net_field_length_ll(&pos);
1994 mysql->server_status=uint2korr(pos)(uint16) (((uint16) ((uchar) (pos)[0])) + ((uint16) ((uchar) (
pos)[1]) << 8))
;
1995 pos+=2;
1996 mysql->warning_count=uint2korr(pos)(uint16) (((uint16) ((uchar) (pos)[0])) + ((uint16) ((uchar) (
pos)[1]) << 8))
;
1997 pos+=2;
1998 if (pos < mysql->net.read_pos+length)
1999 {
2000 if ((item_len= net_field_length(&pos)))
2001 mysql->info=(char*) pos;
2002
2003 /* check if server supports session tracking */
2004 if (mysql->server_capabilities & CLIENT_SESSION_TRACKING(1UL << 23))
2005 {
2006 ma_clear_session_state(mysql);
2007 pos+= item_len;
2008
2009 if (mysql->server_status & SERVER_SESSION_STATE_CHANGED16384)
2010 {
2011 int i;
2012 if (pos < mysql->net.read_pos + length)
2013 {
2014 LIST *session_item;
2015 MYSQL_LEX_STRING *str= NULL((void*)0);
2016 enum enum_session_state_type si_type;
2017 uchar *old_pos= pos;
2018 size_t item_len= net_field_length(&pos); /* length for all items */
2019
2020 /* length was already set, so make sure that info will be zero terminated */
2021 if (mysql->info)
2022 *old_pos= 0;
2023
2024 while (item_len > 0)
2025 {
2026 size_t plen;
2027 char *data;
2028 old_pos= pos;
2029 si_type= (enum enum_session_state_type)net_field_length(&pos);
2030 switch(si_type) {
2031 case SESSION_TRACK_SCHEMA:
2032 case SESSION_TRACK_STATE_CHANGE:
2033 case SESSION_TRACK_TRANSACTION_CHARACTERISTICS:
2034 case SESSION_TRACK_SYSTEM_VARIABLES:
2035 net_field_length(&pos); /* ignore total length, item length will follow next */
2036 plen= net_field_length(&pos);
2037 if (!ma_multi_malloc(0,
2038 &session_item, sizeof(LIST),
2039 &str, sizeof(MYSQL_LEX_STRING),
2040 &data, plen,
2041 NULL((void*)0)))
2042 {
2043 SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2008); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2008))-2000], sizeof((mysql)->net.last_error)); }
;
2044 return -1;
2045 }
2046 str->length= plen;
2047 str->str= data;
2048 memcpy(str->str, (char *)pos, plen);
2049 pos+= plen;
2050 session_item->data= str;
2051 mysql->extension->session_state[si_type].list= list_add(mysql->extension->session_state[si_type].list, session_item);
2052
2053 /* in case schema has changed, we have to update mysql->db */
2054 if (si_type == SESSION_TRACK_SCHEMA)
2055 {
2056 free(mysql->db);
2057 mysql->db= malloc(plen + 1);
2058 memcpy(mysql->db, str->str, plen);
2059 mysql->db[plen]= 0;
2060 }
2061 else if (si_type == SESSION_TRACK_SYSTEM_VARIABLES)
2062 {
2063 my_bool set_charset= 0;
2064 /* make sure that we update charset in case it has changed */
2065 if (!strncmp(str->str, "character_set_client", str->length)(__extension__ (__builtin_constant_p (str->length) &&
((__builtin_constant_p (str->str) && strlen (str->
str) < ((size_t) (str->length))) || (__builtin_constant_p
("character_set_client") && strlen ("character_set_client"
) < ((size_t) (str->length)))) ? __extension__ ({ size_t
__s1_len, __s2_len; (__builtin_constant_p (str->str) &&
__builtin_constant_p ("character_set_client") && (__s1_len
= __builtin_strlen (str->str), __s2_len = __builtin_strlen
("character_set_client"), (!((size_t)(const void *)((str->
str) + 1) - (size_t)(const void *)(str->str) == 1) || __s1_len
>= 4) && (!((size_t)(const void *)(("character_set_client"
) + 1) - (size_t)(const void *)("character_set_client") == 1)
|| __s2_len >= 4)) ? __builtin_strcmp (str->str, "character_set_client"
) : (__builtin_constant_p (str->str) && ((size_t)(
const void *)((str->str) + 1) - (size_t)(const void *)(str
->str) == 1) && (__s1_len = __builtin_strlen (str->
str), __s1_len < 4) ? (__builtin_constant_p ("character_set_client"
) && ((size_t)(const void *)(("character_set_client")
+ 1) - (size_t)(const void *)("character_set_client") == 1) ?
__builtin_strcmp (str->str, "character_set_client") : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ("character_set_client"); int __result = (((const unsigned
char *) (const char *) (str->str))[0] - __s2[0]); if (__s1_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) (str->str))[1] - __s2[1]); if (__s1_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) (str->str))[2] - __s2[2]); if (__s1_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) (str->str))[3] - __s2[3]); } } __result
; }))) : (__builtin_constant_p ("character_set_client") &&
((size_t)(const void *)(("character_set_client") + 1) - (size_t
)(const void *)("character_set_client") == 1) && (__s2_len
= __builtin_strlen ("character_set_client"), __s2_len < 4
) ? (__builtin_constant_p (str->str) && ((size_t)(
const void *)((str->str) + 1) - (size_t)(const void *)(str
->str) == 1) ? __builtin_strcmp (str->str, "character_set_client"
) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (str->str); int __result = (((const
unsigned char *) (const char *) ("character_set_client"))[0]
- __s2[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) ("character_set_client"
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("character_set_client"
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("character_set_client"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (str
->str, "character_set_client")))); }) : strncmp (str->str
, "character_set_client", str->length)))
)
2066 set_charset= 1;
2067 plen= net_field_length(&pos);
2068 if (!ma_multi_malloc(0,
2069 &session_item, sizeof(LIST),
2070 &str, sizeof(MYSQL_LEX_STRING),
2071 &data, plen,
2072 NULL((void*)0)))
2073 {
2074 SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2008); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2008))-2000], sizeof((mysql)->net.last_error)); }
;
2075 return -1;
2076 }
2077 str->length= plen;
2078 str->str= data;
2079 memcpy(str->str, (char *)pos, plen);
2080 pos+= plen;
2081 session_item->data= str;
2082 mysql->extension->session_state[si_type].list= list_add(mysql->extension->session_state[si_type].list, session_item);
2083 if (set_charset &&
2084 strncmp(mysql->charset->csname, str->str, str->length)(__extension__ (__builtin_constant_p (str->length) &&
((__builtin_constant_p (mysql->charset->csname) &&
strlen (mysql->charset->csname) < ((size_t) (str->
length))) || (__builtin_constant_p (str->str) && strlen
(str->str) < ((size_t) (str->length)))) ? __extension__
({ size_t __s1_len, __s2_len; (__builtin_constant_p (mysql->
charset->csname) && __builtin_constant_p (str->
str) && (__s1_len = __builtin_strlen (mysql->charset
->csname), __s2_len = __builtin_strlen (str->str), (!((
size_t)(const void *)((mysql->charset->csname) + 1) - (
size_t)(const void *)(mysql->charset->csname) == 1) || __s1_len
>= 4) && (!((size_t)(const void *)((str->str) +
1) - (size_t)(const void *)(str->str) == 1) || __s2_len >=
4)) ? __builtin_strcmp (mysql->charset->csname, str->
str) : (__builtin_constant_p (mysql->charset->csname) &&
((size_t)(const void *)((mysql->charset->csname) + 1) -
(size_t)(const void *)(mysql->charset->csname) == 1) &&
(__s1_len = __builtin_strlen (mysql->charset->csname),
__s1_len < 4) ? (__builtin_constant_p (str->str) &&
((size_t)(const void *)((str->str) + 1) - (size_t)(const void
*)(str->str) == 1) ? __builtin_strcmp (mysql->charset->
csname, str->str) : (__extension__ ({ const unsigned char *
__s2 = (const unsigned char *) (const char *) (str->str); int
__result = (((const unsigned char *) (const char *) (mysql->
charset->csname))[0] - __s2[0]); if (__s1_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (mysql->charset->csname))[1] - __s2[1]); if (__s1_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) (mysql->charset->csname))[2] - __s2
[2]); if (__s1_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) (mysql->charset->
csname))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
(str->str) && ((size_t)(const void *)((str->str
) + 1) - (size_t)(const void *)(str->str) == 1) &&
(__s2_len = __builtin_strlen (str->str), __s2_len < 4)
? (__builtin_constant_p (mysql->charset->csname) &&
((size_t)(const void *)((mysql->charset->csname) + 1) -
(size_t)(const void *)(mysql->charset->csname) == 1) ?
__builtin_strcmp (mysql->charset->csname, str->str)
: (- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (mysql->charset->csname); int __result
= (((const unsigned char *) (const char *) (str->str))[0]
- __s2[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) (str->str))[1]
- __s2[1]); if (__s2_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) (str->str))[2]
- __s2[2]); if (__s2_len > 2 && __result == 0) __result
= (((const unsigned char *) (const char *) (str->str))[3]
- __s2[3]); } } __result; })))) : __builtin_strcmp (mysql->
charset->csname, str->str)))); }) : strncmp (mysql->
charset->csname, str->str, str->length)))
!= 0)
2085 {
2086 char cs_name[64];
2087 MARIADB_CHARSET_INFO *cs_info;
2088 memcpy(cs_name, str->str, str->length);
2089 cs_name[str->length]= 0;
2090 if ((cs_info = (MARIADB_CHARSET_INFO *)mysql_find_charset_name(cs_name)))
2091 mysql->charset= cs_info;
2092 }
2093 }
2094 break;
2095 default:
2096 /* not supported yet */
2097 plen= net_field_length(&pos);
2098 pos+= plen;
2099 break;
2100 }
2101 item_len-= (pos - old_pos);
2102 }
2103 }
2104 for (i= SESSION_TRACK_BEGIN0; i <= SESSION_TRACK_ENDSESSION_TRACK_TRANSACTION_TYPE; i++)
2105 {
2106 mysql->extension->session_state[i].list= list_reverse(mysql->extension->session_state[i].list);
2107 mysql->extension->session_state[i].current= mysql->extension->session_state[i].list;
2108 }
2109 }
2110 }
2111 }
2112 return(0);
2113 }
2114 if (field_count == NULL_LENGTH((unsigned long) ~0)) /* LOAD DATA LOCAL INFILE */
2115 {
2116 int error=mysql_handle_local_infile(mysql, (char *)pos);
2117
2118 if ((length=ma_net_safe_read(mysql)) == packet_error((unsigned int) -1) || error)
2119 return(-1);
2120 goto get_info; /* Get info packet */
2121 }
2122 if (!(mysql->server_status & SERVER_STATUS_AUTOCOMMIT2))
2123 mysql->server_status|= SERVER_STATUS_IN_TRANS1;
2124
2125 mysql->extra_info= net_field_length_ll(&pos); /* Maybe number of rec */
2126 if (!(fields=mysql->methods->db_read_rows(mysql,(MYSQL_FIELD*) 0,8)))
2127 return(-1);
2128 if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc,
2129 (uint) field_count,1,
2130 (my_bool) test(mysql->server_capabilities &((mysql->server_capabilities & 4) ? 1 : 0)
2131 CLIENT_LONG_FLAG)((mysql->server_capabilities & 4) ? 1 : 0))))
2132 return(-1);
2133 mysql->status=MYSQL_STATUS_GET_RESULT;
2134 mysql->field_count=field_count;
2135 return(0);
2136}
2137
2138int STDCALL mysql_session_track_get_next(MYSQL *mysql, enum enum_session_state_type type,
2139 const char **data, size_t *length)
2140{
2141 MYSQL_LEX_STRING *str;
2142 if (!mysql->extension->session_state[type].current)
2143 return 1;
2144
2145 str= (MYSQL_LEX_STRING *)mysql->extension->session_state[type].current->data;
2146 mysql->extension->session_state[type].current= mysql->extension->session_state[type].current->next;
2147
2148 *data= str->str ? str->str : NULL((void*)0);
2149 *length= str->str ? str->length : 0;
2150 return 0;
2151}
2152
2153int STDCALL mysql_session_track_get_first(MYSQL *mysql, enum enum_session_state_type type,
2154 const char **data, size_t *length)
2155{
2156 mysql->extension->session_state[type].current= mysql->extension->session_state[type].list;
2157 return mysql_session_track_get_next(mysql, type, data, length);
2158}
2159
2160my_bool STDCALL
2161mysql_read_query_result(MYSQL *mysql)
2162{
2163 return test(mysql->methods->db_read_query_result(mysql))((mysql->methods->db_read_query_result(mysql)) ? 1 : 0) ? 1 : 0;
2164}
2165
2166int STDCALL
2167mysql_real_query(MYSQL *mysql, const char *query, unsigned long length)
2168{
2169 my_bool skip_result= OPT_EXT_VAL(mysql, multi_command)((mysql)->options.extension && (mysql)->options
.extension->multi_command) ? (mysql)->options.extension
->multi_command : 0
;
2170
2171 if (length == (unsigned long)-1)
2172 length= strlen(query);
2173
2174 free_old_query(mysql);
2175
2176 if (ma_simple_command(mysql, COM_QUERY,query,length,1,0))
2177 return(-1);
2178 if (!skip_result)
2179 return(mysql->methods->db_read_query_result(mysql));
2180 return(0);
2181}
2182
2183/**************************************************************************
2184** Alloc result struct for buffered results. All rows are read to buffer.
2185** mysql_data_seek may be used.
2186**************************************************************************/
2187
2188MYSQL_RES * STDCALL
2189mysql_store_result(MYSQL *mysql)
2190{
2191 MYSQL_RES *result;
2192
2193 if (!mysql->fields)
2194 return(0);
2195 if (mysql->status != MYSQL_STATUS_GET_RESULT)
2196 {
2197 SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2014); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2014))-2000], sizeof((mysql)->net.last_error)); }
;
2198 return(0);
2199 }
2200 mysql->status=MYSQL_STATUS_READY; /* server is ready */
2201 if (!(result=(MYSQL_RES*) calloc(1, sizeof(MYSQL_RES)+
2202 sizeof(ulong)*mysql->field_count)))
2203 {
2204 SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2008); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2008))-2000], sizeof((mysql)->net.last_error)); }
;
2205 return(0);
2206 }
2207 result->eof=1; /* Marker for buffered */
2208 result->lengths=(ulong*) (result+1);
2209 if (!(result->data=mysql->methods->db_read_rows(mysql,mysql->fields,mysql->field_count)))
2210 {
2211 free(result);
2212 return(0);
2213 }
2214 mysql->affected_rows= result->row_count= result->data->rows;
2215 result->data_cursor= result->data->data;
2216 result->fields= mysql->fields;
2217 result->field_alloc= mysql->field_alloc;
2218 result->field_count= mysql->field_count;
2219 result->current_field=0;
2220 result->current_row=0; /* Must do a fetch first */
2221 mysql->fields=0; /* fields is now in result */
2222 return(result); /* Data fetched */
2223}
2224
2225
2226/**************************************************************************
2227** Alloc struct for use with unbuffered reads. Data is fetched by domand
2228** when calling to mysql_fetch_row.
2229** mysql_data_seek is a noop.
2230**
2231** No other queries may be specified with the same MYSQL handle.
2232** There shouldn't be much processing per row because mysql server shouldn't
2233** have to wait for the client (and will not wait more than 30 sec/packet).
2234**************************************************************************/
2235
2236MYSQL_RES * STDCALL
2237mysql_use_result(MYSQL *mysql)
2238{
2239 MYSQL_RES *result;
2240
2241 if (!mysql->fields)
2242 return(0);
2243 if (mysql->status != MYSQL_STATUS_GET_RESULT)
2244 {
2245 SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2014); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2014))-2000], sizeof((mysql)->net.last_error)); }
;
2246 return(0);
2247 }
2248 if (!(result=(MYSQL_RES*) calloc(1, sizeof(*result)+
2249 sizeof(ulong)*mysql->field_count)))
2250 return(0);
2251 result->lengths=(ulong*) (result+1);
2252 if (!(result->row=(MYSQL_ROW)
2253 malloc(sizeof(result->row[0])*(mysql->field_count+1))))
2254 { /* Ptrs: to one row */
2255 free(result);
2256 return(0);
2257 }
2258 result->fields= mysql->fields;
2259 result->field_alloc= mysql->field_alloc;
2260 result->field_count= mysql->field_count;
2261 result->current_field=0;
2262 result->handle= mysql;
2263 result->current_row= 0;
2264 mysql->fields=0; /* fields is now in result */
2265 mysql->status=MYSQL_STATUS_USE_RESULT;
2266 return(result); /* Data is read to be fetched */
2267}
2268
2269/**************************************************************************
2270** Return next field of the query results
2271**************************************************************************/
2272MYSQL_FIELD * STDCALL
2273mysql_fetch_field(MYSQL_RES *result)
2274{
2275 if (result->current_field >= result->field_count)
2276 return(NULL((void*)0));
2277 return &result->fields[result->current_field++];
2278}
2279
2280/**************************************************************************
2281** Return next row of the query results
2282**************************************************************************/
2283MYSQL_ROW STDCALL
2284mysql_fetch_row(MYSQL_RES *res)
2285{
2286 if (!res)
2287 return 0;
2288 if (res->handle)
2289 if (res->handle->status != MYSQL_STATUS_USE_RESULT &&
2290 res->handle->status != MYSQL_STATUS_GET_RESULT)
2291 return 0;
2292 if (!res->data)
2293 { /* Unbufferred fetch */
2294 if (!res->eof)
2295 {
2296 if (!(res->handle->methods->db_read_one_row(res->handle,res->field_count,res->row, res->lengths)))
2297 {
2298 res->row_count++;
2299 return(res->current_row=res->row);
2300 }
2301 res->eof=1;
2302 res->handle->status=MYSQL_STATUS_READY;
2303 /* Don't clear handle in mysql_free_results */
2304 res->handle=0;
2305 }
2306 return((MYSQL_ROW) NULL((void*)0));
2307 }
2308 {
2309 MYSQL_ROW tmp;
2310 if (!res->data_cursor)
2311 {
2312 return(res->current_row=(MYSQL_ROW) NULL((void*)0));
2313 }
2314 tmp = res->data_cursor->data;
2315 res->data_cursor = res->data_cursor->next;
2316 return(res->current_row=tmp);
2317 }
2318}
2319
2320/**************************************************************************
2321** Get column lengths of the current row
2322** If one uses mysql_use_result, res->lengths contains the length information,
2323** else the lengths are calculated from the offset between pointers.
2324**************************************************************************/
2325
2326ulong * STDCALL
2327mysql_fetch_lengths(MYSQL_RES *res)
2328{
2329 ulong *lengths,*prev_length;
2330 char *start;
2331 MYSQL_ROW column,end;
2332
2333 if (!(column=res->current_row))
2334 return 0; /* Something is wrong */
2335 if (res->data)
2336 {
2337 start=0;
2338 prev_length=0; /* Keep gcc happy */
2339 lengths=res->lengths;
2340 for (end=column+res->field_count+1 ; column != end ; column++,lengths++)
2341 {
2342 if (!*column)
2343 {
2344 *lengths=0; /* Null */
2345 continue;
2346 }
2347 if (start) /* Found end of prev string */
2348 *prev_length= (uint) (*column-start-1);
2349 start= *column;
2350 prev_length=lengths;
2351 }
2352 }
2353 return res->lengths;
2354}
2355
2356/**************************************************************************
2357** Move to a specific row and column
2358**************************************************************************/
2359
2360void STDCALL
2361mysql_data_seek(MYSQL_RES *result, unsigned long long row)
2362{
2363 MYSQL_ROWS *tmp=0;
2364 if (result->data)
2365 for (tmp=result->data->data; row-- && tmp ; tmp = tmp->next) ;
2366 result->current_row=0;
2367 result->data_cursor = tmp;
2368}
2369
2370/*************************************************************************
2371** put the row or field cursor one a position one got from mysql_row_tell()
2372** This doesn't restore any data. The next mysql_fetch_row or
2373** mysql_fetch_field will return the next row or field after the last used
2374*************************************************************************/
2375
2376MYSQL_ROW_OFFSET STDCALL
2377mysql_row_seek(MYSQL_RES *result, MYSQL_ROW_OFFSET row)
2378{
2379 MYSQL_ROW_OFFSET return_value=result->data_cursor;
2380 result->current_row= 0;
2381 result->data_cursor= row;
2382 return return_value;
2383}
2384
2385
2386MYSQL_FIELD_OFFSET STDCALL
2387mysql_field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET field_offset)
2388{
2389 MYSQL_FIELD_OFFSET return_value=result->current_field;
2390 result->current_field=field_offset;
2391 return return_value;
2392}
2393
2394/*****************************************************************************
2395** List all databases
2396*****************************************************************************/
2397
2398MYSQL_RES * STDCALL
2399mysql_list_dbs(MYSQL *mysql, const char *wild)
2400{
2401 char buff[255];
2402 snprintf(buff, 255, "SHOW DATABASES LIKE '%s'", wild ? wild : "%")__builtin___snprintf_chk (buff, 255, 2 - 1, __builtin_object_size
(buff, 2 > 1), "SHOW DATABASES LIKE '%s'", wild ? wild : "%"
)
;
2403 if (mysql_query(mysql,buff))
2404 return(0);
2405 return (mysql_store_result(mysql));
2406}
2407
2408
2409/*****************************************************************************
2410** List all tables in a database
2411** If wild is given then only the tables matching wild are returned
2412*****************************************************************************/
2413
2414MYSQL_RES * STDCALL
2415mysql_list_tables(MYSQL *mysql, const char *wild)
2416{
2417 char buff[255];
2418
2419 snprintf(buff, 255, "SHOW TABLES LIKE '%s'", wild ? wild : "%")__builtin___snprintf_chk (buff, 255, 2 - 1, __builtin_object_size
(buff, 2 > 1), "SHOW TABLES LIKE '%s'", wild ? wild : "%"
)
;
2420 if (mysql_query(mysql,buff))
2421 return(0);
2422 return (mysql_store_result(mysql));
2423}
2424
2425
2426/**************************************************************************
2427** List all fields in a table
2428** If wild is given then only the fields matching wild are returned
2429** Instead of this use query:
2430** show fields in 'table' like "wild"
2431**************************************************************************/
2432
2433MYSQL_RES * STDCALL
2434mysql_list_fields(MYSQL *mysql, const char *table, const char *wild)
2435{
2436 MYSQL_RES *result;
2437 MYSQL_DATA *query;
2438 char buff[255];
2439 int length= 0;
2440
2441 LINT_INIT(query);
2442
2443 length= snprintf(buff, 128, "%s%c%s", table, '\0', wild ? wild : "")__builtin___snprintf_chk (buff, 128, 2 - 1, __builtin_object_size
(buff, 2 > 1), "%s%c%s", table, '\0', wild ? wild : "")
;
2444
2445 if (ma_simple_command(mysql, COM_FIELD_LIST,buff,length,1,0) ||
2446 !(query = mysql->methods->db_read_rows(mysql,(MYSQL_FIELD*) 0,8)))
2447 return(NULL((void*)0));
2448
2449 free_old_query(mysql);
2450 if (!(result = (MYSQL_RES *) calloc(1, sizeof(MYSQL_RES))))
2451 {
2452 free_rows(query);
2453 return(NULL((void*)0));
2454 }
2455 result->field_alloc=mysql->field_alloc;
2456 mysql->fields=0;
2457 result->field_count = (uint) query->rows;
2458 result->fields= unpack_fields(query,&result->field_alloc,
2459 result->field_count,1,
2460 (my_bool) test(mysql->server_capabilities &((mysql->server_capabilities & 4) ? 1 : 0)
2461 CLIENT_LONG_FLAG)((mysql->server_capabilities & 4) ? 1 : 0));
2462 result->eof=1;
2463 return(result);
2464}
2465
2466/* List all running processes (threads) in server */
2467
2468MYSQL_RES * STDCALL
2469mysql_list_processes(MYSQL *mysql)
2470{
2471 MYSQL_DATA *fields;
2472 uint field_count;
2473 uchar *pos;
2474
2475 LINT_INIT(fields);
2476 if (ma_simple_command(mysql, COM_PROCESS_INFO,0,0,0,0))
2477 return(0);
2478 free_old_query(mysql);
2479 pos=(uchar*) mysql->net.read_pos;
2480 field_count=(uint) net_field_length(&pos);
2481 if (!(fields = mysql->methods->db_read_rows(mysql,(MYSQL_FIELD*) 0,5)))
2482 return(NULL((void*)0));
2483 if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc,field_count,0,
2484 (my_bool) test(mysql->server_capabilities &((mysql->server_capabilities & 4) ? 1 : 0)
2485 CLIENT_LONG_FLAG)((mysql->server_capabilities & 4) ? 1 : 0))))
2486 return(0);
2487 mysql->status=MYSQL_STATUS_GET_RESULT;
2488 mysql->field_count=field_count;
2489 return(mysql_store_result(mysql));
2490}
2491
2492/* In 5.0 this version became an additional parameter shutdown_level */
2493int STDCALL
2494mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level)
2495{
2496 uchar s_level[2];
2497 s_level[0]= (uchar)shutdown_level;
2498 return(ma_simple_command(mysql, COM_SHUTDOWN, (char *)s_level, 1, 0, 0));
2499}
2500
2501int STDCALL
2502mysql_refresh(MYSQL *mysql,uint options)
2503{
2504 uchar bits[1];
2505 bits[0]= (uchar) options;
2506 return(ma_simple_command(mysql, COM_REFRESH,(char*) bits,1,0,0));
2507}
2508
2509int STDCALL
2510mysql_kill(MYSQL *mysql,ulong pid)
2511{
2512 char buff[12];
2513 int4store(buff,pid)do { *((char *)(buff))=(char) ((pid)); *(((char *)(buff))+1)=
(char) (((pid) >> 8)); *(((char *)(buff))+2)=(char) (((
pid) >> 16)); *(((char *)(buff))+3)=(char) (((pid) >>
24)); } while(0)
;
2514 /* if we kill our own thread, reading the response packet will fail */
2515 return(ma_simple_command(mysql, COM_PROCESS_KILL,buff,4,0,0));
2516}
2517
2518
2519int STDCALL
2520mysql_dump_debug_info(MYSQL *mysql)
2521{
2522 return(ma_simple_command(mysql, COM_DEBUG,0,0,0,0));
2523}
2524
2525char * STDCALL
2526mysql_stat(MYSQL *mysql)
2527{
2528 if (ma_simple_command(mysql, COM_STATISTICS,0,0,0,0))
2529 return mysql->net.last_error;
2530 mysql->net.read_pos[mysql->packet_length]=0; /* End of stat string */
2531 if (!mysql->net.read_pos[0])
2532 {
2533 SET_CLIENT_ERROR(mysql, CR_WRONG_HOST_INFO , SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2009); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2009))-2000], sizeof((mysql)->net.last_error)); }
;
2534 return mysql->net.last_error;
2535 }
2536 return((char*) mysql->net.read_pos);
2537}
2538
2539int STDCALL
2540mysql_ping(MYSQL *mysql)
2541{
2542 int rc;
2543 rc= ma_simple_command(mysql, COM_PING,0,0,0,0);
2544
2545 /* if connection was terminated and reconnect is true, try again */
2546 if (rc!=0 && mysql->options.reconnect)
2547 rc= ma_simple_command(mysql, COM_PING,0,0,0,0);
2548 return rc;
2549}
2550
2551char * STDCALL
2552mysql_get_server_info(MYSQL *mysql)
2553{
2554 return((char*) mysql->server_version);
2555}
2556
2557static size_t mariadb_server_version_id(MYSQL *mysql)
2558{
2559 size_t major, minor, patch;
2560 char *p;
2561
2562 if (!(p = mysql->server_version)) {
2563 return 0;
2564 }
2565
2566 major = strtol(p, &p, 10);
2567 p += 1; /* consume the dot */
2568 minor = strtol(p, &p, 10);
2569 p += 1; /* consume the dot */
2570 patch = strtol(p, &p, 10);
2571
2572 return (major * 10000L + (unsigned long)(minor * 100L + patch));
2573}
2574
2575unsigned long STDCALL mysql_get_server_version(MYSQL *mysql)
2576{
2577 return (unsigned long)mariadb_server_version_id(mysql);
2578}
2579
2580char * STDCALL
2581mysql_get_host_info(MYSQL *mysql)
2582{
2583 return(mysql->host_info);
2584}
2585
2586uint STDCALL
2587mysql_get_proto_info(MYSQL *mysql)
2588{
2589 return (mysql->protocol_version);
2590}
2591
2592const char * STDCALL
2593mysql_get_client_info(void)
2594{
2595 return (char*) MARIADB_CLIENT_VERSION_STR"10.3.8";
2596}
2597
2598static size_t get_store_length(size_t length)
2599{
2600 if (length < (size_t) L64(251)251LL)
2601 return 1;
2602 if (length < (size_t) L64(65536)65536LL)
2603 return 2;
2604 if (length < (size_t) L64(16777216)16777216LL)
2605 return 3;
2606 return 9;
2607}
2608
2609uchar *ma_get_hash_keyval(const uchar *hash_entry,
2610 unsigned int *length,
2611 my_bool not_used __attribute__((unused)))
2612{
2613 /* Hash entry has the following format:
2614 Offset: 0 key (\0 terminated)
2615 key_length + 1 value (\0 terminated)
2616 */
2617 uchar *p= (uchar *)hash_entry;
2618 size_t len= strlen((char *)p);
2619 *length= (unsigned int)len;
2620 return p;
2621}
2622
2623void ma_hash_free(void *p)
2624{
2625 free(p);
2626}
2627
2628int STDCALL
2629mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...)
2630{
2631 va_list ap;
2632 void *arg1;
2633 size_t stacksize;
2634 struct mysql_async_context *ctxt;
2635
2636 va_start(ap, option)__builtin_va_start(ap, option);
2637
2638 arg1= va_arg(ap, void *)__builtin_va_arg(ap, void *);
2639
2640 switch (option) {
2641 case MYSQL_OPT_CONNECT_TIMEOUT:
2642 mysql->options.connect_timeout= *(uint*) arg1;
2643 break;
2644 case MYSQL_OPT_COMPRESS:
2645 mysql->options.compress= 1; /* Remember for connect */
2646 mysql->options.client_flag|= CLIENT_COMPRESS32;
2647 break;
2648 case MYSQL_OPT_NAMED_PIPE:
2649 mysql->options.named_pipe=1; /* Force named pipe */
2650 break;
2651 case MYSQL_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/
2652 if (!arg1 || test(*(my_bool*) arg1)((*(my_bool*) arg1) ? 1 : 0))
2653 mysql->options.client_flag|= CLIENT_LOCAL_FILES128;
2654 else
2655 mysql->options.client_flag&= ~CLIENT_LOCAL_FILES128;
2656 break;
2657 case MYSQL_INIT_COMMAND:
2658 options_add_initcommand(&mysql->options, (char *)arg1);
2659 break;
2660 case MYSQL_READ_DEFAULT_FILE:
2661 OPT_SET_VALUE_STR(&mysql->options, my_cnf_file, (char *)arg1)free((&mysql->options)->my_cnf_file); if(((char *)arg1
)) (&mysql->options)->my_cnf_file= (__extension__ (
__builtin_constant_p ((char *)((char *)arg1)) && ((size_t
)(const void *)(((char *)((char *)arg1)) + 1) - (size_t)(const
void *)((char *)((char *)arg1)) == 1) ? (((const char *) ((char
*)((char *)arg1)))[0] == '\0' ? (char *) calloc ((size_t) 1,
(size_t) 1) : ({ size_t __len = strlen ((char *)((char *)arg1
)) + 1; char *__retval = (char *) malloc (__len); if (__retval
!= ((void*)0)) __retval = (char *) memcpy (__retval, (char *
)((char *)arg1), __len); __retval; })) : __strdup ((char *)((
char *)arg1)))); else (&mysql->options)->my_cnf_file
= ((void*)0)
;
2662 break;
2663 case MYSQL_READ_DEFAULT_GROUP:
2664 if (!arg1 || !((char *)arg1)[0])
2665 {
2666#if defined(__APPLE__) || defined(__FreeBSD__)
2667 const char * appname = getprogname();
2668#elif defined(_GNU_SOURCE1)
2669 const char * appname = program_invocation_short_name;
2670#elif defined(WIN32)
2671 char appname[FN_REFLEN512]= "";
2672
2673 if (GetModuleFileName(NULL((void*)0), appname, FN_REFLEN512))
2674 {
2675 PathStripPath(appname);
2676 PathRemoveExtension(appname);
2677 }
2678#else
2679 const char * appname = "";
2680#endif
2681 OPT_SET_VALUE_STR(&mysql->options, my_cnf_group, appname)free((&mysql->options)->my_cnf_group); if((appname)
) (&mysql->options)->my_cnf_group= (__extension__ (
__builtin_constant_p ((char *)(appname)) && ((size_t)
(const void *)(((char *)(appname)) + 1) - (size_t)(const void
*)((char *)(appname)) == 1) ? (((const char *) ((char *)(appname
)))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : (
{ size_t __len = strlen ((char *)(appname)) + 1; char *__retval
= (char *) malloc (__len); if (__retval != ((void*)0)) __retval
= (char *) memcpy (__retval, (char *)(appname), __len); __retval
; })) : __strdup ((char *)(appname)))); else (&mysql->
options)->my_cnf_group= ((void*)0)
;
2682 break;
2683 }
2684 OPT_SET_VALUE_STR(&mysql->options, my_cnf_group, (char *)arg1)free((&mysql->options)->my_cnf_group); if(((char *)
arg1)) (&mysql->options)->my_cnf_group= (__extension__
(__builtin_constant_p ((char *)((char *)arg1)) && ((
size_t)(const void *)(((char *)((char *)arg1)) + 1) - (size_t
)(const void *)((char *)((char *)arg1)) == 1) ? (((const char
*) ((char *)((char *)arg1)))[0] == '\0' ? (char *) calloc ((
size_t) 1, (size_t) 1) : ({ size_t __len = strlen ((char *)((
char *)arg1)) + 1; char *__retval = (char *) malloc (__len); if
(__retval != ((void*)0)) __retval = (char *) memcpy (__retval
, (char *)((char *)arg1), __len); __retval; })) : __strdup ((
char *)((char *)arg1)))); else (&mysql->options)->my_cnf_group
= ((void*)0)
;
2685 break;
2686 case MYSQL_SET_CHARSET_DIR:
2687 OPT_SET_VALUE_STR(&mysql->options, charset_dir, arg1)free((&mysql->options)->charset_dir); if((arg1)) (&
mysql->options)->charset_dir= (__extension__ (__builtin_constant_p
((char *)(arg1)) && ((size_t)(const void *)(((char *
)(arg1)) + 1) - (size_t)(const void *)((char *)(arg1)) == 1) ?
(((const char *) ((char *)(arg1)))[0] == '\0' ? (char *) calloc
((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ((char *
)(arg1)) + 1; char *__retval = (char *) malloc (__len); if (__retval
!= ((void*)0)) __retval = (char *) memcpy (__retval, (char *
)(arg1), __len); __retval; })) : __strdup ((char *)(arg1))));
else (&mysql->options)->charset_dir= ((void*)0)
;
2688 break;
2689 case MYSQL_SET_CHARSET_NAME:
2690 OPT_SET_VALUE_STR(&mysql->options, charset_name, arg1)free((&mysql->options)->charset_name); if((arg1)) (
&mysql->options)->charset_name= (__extension__ (__builtin_constant_p
((char *)(arg1)) && ((size_t)(const void *)(((char *
)(arg1)) + 1) - (size_t)(const void *)((char *)(arg1)) == 1) ?
(((const char *) ((char *)(arg1)))[0] == '\0' ? (char *) calloc
((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ((char *
)(arg1)) + 1; char *__retval = (char *) malloc (__len); if (__retval
!= ((void*)0)) __retval = (char *) memcpy (__retval, (char *
)(arg1), __len); __retval; })) : __strdup ((char *)(arg1))));
else (&mysql->options)->charset_name= ((void*)0)
;
2691 break;
2692 case MYSQL_OPT_RECONNECT:
2693 mysql->options.reconnect= *(my_bool *)arg1;
2694 break;
2695 case MYSQL_OPT_PROTOCOL:
2696 mysql->options.protocol= *((uint *)arg1);
2697 break;
2698#ifdef _WIN32
2699 case MYSQL_SHARED_MEMORY_BASE_NAME:
2700 OPT_SET_VALUE_STR(&mysql->options, shared_memory_base_name, arg1)free((&mysql->options)->shared_memory_base_name); if
((arg1)) (&mysql->options)->shared_memory_base_name
= (__extension__ (__builtin_constant_p ((char *)(arg1)) &&
((size_t)(const void *)(((char *)(arg1)) + 1) - (size_t)(const
void *)((char *)(arg1)) == 1) ? (((const char *) ((char *)(arg1
)))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : (
{ size_t __len = strlen ((char *)(arg1)) + 1; char *__retval =
(char *) malloc (__len); if (__retval != ((void*)0)) __retval
= (char *) memcpy (__retval, (char *)(arg1), __len); __retval
; })) : __strdup ((char *)(arg1)))); else (&mysql->options
)->shared_memory_base_name= ((void*)0)
;
2701 break;
2702#endif
2703 case MYSQL_OPT_READ_TIMEOUT:
2704 mysql->options.read_timeout= *(uint *)arg1;
2705 break;
2706 case MYSQL_OPT_WRITE_TIMEOUT:
2707 mysql->options.write_timeout= *(uint *)arg1;
2708 break;
2709 case MYSQL_REPORT_DATA_TRUNCATION:
2710 mysql->options.report_data_truncation= *(my_bool *)arg1;
2711 break;
2712 case MYSQL_PROGRESS_CALLBACK:
2713 CHECK_OPT_EXTENSION_SET(&mysql->options)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension));
;
2714 if (mysql->options.extension)
2715 mysql->options.extension->report_progress=
2716 (void (*)(const MYSQL *, uint, uint, double, const char *, uint)) arg1;
2717 break;
2718 case MYSQL_SERVER_PUBLIC_KEY:
2719 OPT_SET_EXTENDED_VALUE_STR(&mysql->options, server_public_key, (char *)arg1)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension)); free((
gptr)(&mysql->options)->extension->server_public_key
); if(((char *)arg1)) (&mysql->options)->extension->
server_public_key= (__extension__ (__builtin_constant_p ((char
*)((char *)arg1)) && ((size_t)(const void *)(((char *
)((char *)arg1)) + 1) - (size_t)(const void *)((char *)((char
*)arg1)) == 1) ? (((const char *) ((char *)((char *)arg1)))[
0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t
__len = strlen ((char *)((char *)arg1)) + 1; char *__retval =
(char *) malloc (__len); if (__retval != ((void*)0)) __retval
= (char *) memcpy (__retval, (char *)((char *)arg1), __len);
__retval; })) : __strdup ((char *)((char *)arg1)))); else (&
mysql->options)->extension->server_public_key= ((void
*)0)
;
2720 break;
2721 case MYSQL_PLUGIN_DIR:
2722 OPT_SET_EXTENDED_VALUE_STR(&mysql->options, plugin_dir, (char *)arg1)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension)); free((
gptr)(&mysql->options)->extension->plugin_dir); if
(((char *)arg1)) (&mysql->options)->extension->plugin_dir
= (__extension__ (__builtin_constant_p ((char *)((char *)arg1
)) && ((size_t)(const void *)(((char *)((char *)arg1)
) + 1) - (size_t)(const void *)((char *)((char *)arg1)) == 1)
? (((const char *) ((char *)((char *)arg1)))[0] == '\0' ? (char
*) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen
((char *)((char *)arg1)) + 1; char *__retval = (char *) malloc
(__len); if (__retval != ((void*)0)) __retval = (char *) memcpy
(__retval, (char *)((char *)arg1), __len); __retval; })) : __strdup
((char *)((char *)arg1)))); else (&mysql->options)->
extension->plugin_dir= ((void*)0)
;
2723 break;
2724 case MYSQL_DEFAULT_AUTH:
2725 OPT_SET_EXTENDED_VALUE_STR(&mysql->options, default_auth, (char *)arg1)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension)); free((
gptr)(&mysql->options)->extension->default_auth)
; if(((char *)arg1)) (&mysql->options)->extension->
default_auth= (__extension__ (__builtin_constant_p ((char *)(
(char *)arg1)) && ((size_t)(const void *)(((char *)((
char *)arg1)) + 1) - (size_t)(const void *)((char *)((char *)
arg1)) == 1) ? (((const char *) ((char *)((char *)arg1)))[0] ==
'\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len
= strlen ((char *)((char *)arg1)) + 1; char *__retval = (char
*) malloc (__len); if (__retval != ((void*)0)) __retval = (char
*) memcpy (__retval, (char *)((char *)arg1), __len); __retval
; })) : __strdup ((char *)((char *)arg1)))); else (&mysql
->options)->extension->default_auth= ((void*)0)
;
2726 break;
2727 case MYSQL_OPT_NONBLOCK:
2728 if (mysql->options.extension &&
2729 (ctxt = mysql->options.extension->async_context) != 0)
2730 {
2731 /*
2732 We must not allow changing the stack size while a non-blocking call is
2733 suspended (as the stack is then in use).
2734 */
2735 if (ctxt->suspended)
2736 goto end;
2737 my_context_destroy(&ctxt->async_context);
2738 free(ctxt);
2739 }
2740 if (!(ctxt= (struct mysql_async_context *)
2741 calloc(1, sizeof(*ctxt))))
2742 {
2743 SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2008); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2008))-2000], sizeof((mysql)->net.last_error)); }
;
2744 goto end;
2745 }
2746 stacksize= 0;
2747 if (arg1)
2748 stacksize= *(const size_t *)arg1;
2749 if (!stacksize)
2750 stacksize= ASYNC_CONTEXT_DEFAULT_STACK_SIZE(4096*15);
2751 if (my_context_init(&ctxt->async_context, stacksize))
2752 {
2753 free(ctxt);
2754 goto end;
2755 }
2756 if (!mysql->options.extension)
2757 if(!(mysql->options.extension= (struct st_mysql_options_extension *)
2758 calloc(1, sizeof(struct st_mysql_options_extension))))
2759 {
2760 SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2008); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2008))-2000], sizeof((mysql)->net.last_error)); }
;
2761 goto end;
2762 }
2763 mysql->options.extension->async_context= ctxt;
2764 break;
2765 case MYSQL_OPT_MAX_ALLOWED_PACKET:
2766 if (mysql)
2767 mysql->options.max_allowed_packet= (unsigned long)(*(size_t *)arg1);
2768 else
2769 max_allowed_packet= (unsigned long)(*(size_t *)arg1);
2770 break;
2771 case MYSQL_OPT_NET_BUFFER_LENGTH:
2772 net_buffer_length= (unsigned long)(*(size_t *)arg1);
2773 break;
2774 case MYSQL_OPT_SSL_ENFORCE:
2775 mysql->options.use_ssl= (*(my_bool *)arg1);
2776 break;
2777 case MYSQL_OPT_SSL_VERIFY_SERVER_CERT:
2778 if (*(my_bool *)arg1)
2779 mysql->options.client_flag |= CLIENT_SSL_VERIFY_SERVER_CERT(1UL << 30);
2780 else
2781 mysql->options.client_flag &= ~CLIENT_SSL_VERIFY_SERVER_CERT(1UL << 30);
2782 break;
2783 case MYSQL_OPT_SSL_KEY:
2784 OPT_SET_VALUE_STR(&mysql->options, ssl_key, (char *)arg1)free((&mysql->options)->ssl_key); if(((char *)arg1)
) (&mysql->options)->ssl_key= (__extension__ (__builtin_constant_p
((char *)((char *)arg1)) && ((size_t)(const void *)(
((char *)((char *)arg1)) + 1) - (size_t)(const void *)((char *
)((char *)arg1)) == 1) ? (((const char *) ((char *)((char *)arg1
)))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : (
{ size_t __len = strlen ((char *)((char *)arg1)) + 1; char *__retval
= (char *) malloc (__len); if (__retval != ((void*)0)) __retval
= (char *) memcpy (__retval, (char *)((char *)arg1), __len);
__retval; })) : __strdup ((char *)((char *)arg1)))); else (&
mysql->options)->ssl_key= ((void*)0)
;
2785 break;
2786 case MYSQL_OPT_SSL_CERT:
2787 OPT_SET_VALUE_STR(&mysql->options, ssl_cert, (char *)arg1)free((&mysql->options)->ssl_cert); if(((char *)arg1
)) (&mysql->options)->ssl_cert= (__extension__ (__builtin_constant_p
((char *)((char *)arg1)) && ((size_t)(const void *)(
((char *)((char *)arg1)) + 1) - (size_t)(const void *)((char *
)((char *)arg1)) == 1) ? (((const char *) ((char *)((char *)arg1
)))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : (
{ size_t __len = strlen ((char *)((char *)arg1)) + 1; char *__retval
= (char *) malloc (__len); if (__retval != ((void*)0)) __retval
= (char *) memcpy (__retval, (char *)((char *)arg1), __len);
__retval; })) : __strdup ((char *)((char *)arg1)))); else (&
mysql->options)->ssl_cert= ((void*)0)
;
2788 break;
2789 case MYSQL_OPT_SSL_CA:
2790 OPT_SET_VALUE_STR(&mysql->options, ssl_ca, (char *)arg1)free((&mysql->options)->ssl_ca); if(((char *)arg1))
(&mysql->options)->ssl_ca= (__extension__ (__builtin_constant_p
((char *)((char *)arg1)) && ((size_t)(const void *)(
((char *)((char *)arg1)) + 1) - (size_t)(const void *)((char *
)((char *)arg1)) == 1) ? (((const char *) ((char *)((char *)arg1
)))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : (
{ size_t __len = strlen ((char *)((char *)arg1)) + 1; char *__retval
= (char *) malloc (__len); if (__retval != ((void*)0)) __retval
= (char *) memcpy (__retval, (char *)((char *)arg1), __len);
__retval; })) : __strdup ((char *)((char *)arg1)))); else (&
mysql->options)->ssl_ca= ((void*)0)
;
2791 break;
2792 case MYSQL_OPT_SSL_CAPATH:
2793 OPT_SET_VALUE_STR(&mysql->options, ssl_capath, (char *)arg1)free((&mysql->options)->ssl_capath); if(((char *)arg1
)) (&mysql->options)->ssl_capath= (__extension__ (__builtin_constant_p
((char *)((char *)arg1)) && ((size_t)(const void *)(
((char *)((char *)arg1)) + 1) - (size_t)(const void *)((char *
)((char *)arg1)) == 1) ? (((const char *) ((char *)((char *)arg1
)))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : (
{ size_t __len = strlen ((char *)((char *)arg1)) + 1; char *__retval
= (char *) malloc (__len); if (__retval != ((void*)0)) __retval
= (char *) memcpy (__retval, (char *)((char *)arg1), __len);
__retval; })) : __strdup ((char *)((char *)arg1)))); else (&
mysql->options)->ssl_capath= ((void*)0)
;
2794 break;
2795 case MYSQL_OPT_SSL_CIPHER:
2796 OPT_SET_VALUE_STR(&mysql->options, ssl_cipher, (char *)arg1)free((&mysql->options)->ssl_cipher); if(((char *)arg1
)) (&mysql->options)->ssl_cipher= (__extension__ (__builtin_constant_p
((char *)((char *)arg1)) && ((size_t)(const void *)(
((char *)((char *)arg1)) + 1) - (size_t)(const void *)((char *
)((char *)arg1)) == 1) ? (((const char *) ((char *)((char *)arg1
)))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : (
{ size_t __len = strlen ((char *)((char *)arg1)) + 1; char *__retval
= (char *) malloc (__len); if (__retval != ((void*)0)) __retval
= (char *) memcpy (__retval, (char *)((char *)arg1), __len);
__retval; })) : __strdup ((char *)((char *)arg1)))); else (&
mysql->options)->ssl_cipher= ((void*)0)
;
2797 break;
2798 case MYSQL_OPT_SSL_CRL:
2799 OPT_SET_EXTENDED_VALUE_STR(&mysql->options, ssl_crl, (char *)arg1)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension)); free((
gptr)(&mysql->options)->extension->ssl_crl); if(
((char *)arg1)) (&mysql->options)->extension->ssl_crl
= (__extension__ (__builtin_constant_p ((char *)((char *)arg1
)) && ((size_t)(const void *)(((char *)((char *)arg1)
) + 1) - (size_t)(const void *)((char *)((char *)arg1)) == 1)
? (((const char *) ((char *)((char *)arg1)))[0] == '\0' ? (char
*) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen
((char *)((char *)arg1)) + 1; char *__retval = (char *) malloc
(__len); if (__retval != ((void*)0)) __retval = (char *) memcpy
(__retval, (char *)((char *)arg1), __len); __retval; })) : __strdup
((char *)((char *)arg1)))); else (&mysql->options)->
extension->ssl_crl= ((void*)0)
;
2800 break;
2801 case MYSQL_OPT_SSL_CRLPATH:
2802 OPT_SET_EXTENDED_VALUE_STR(&mysql->options, ssl_crlpath, (char *)arg1)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension)); free((
gptr)(&mysql->options)->extension->ssl_crlpath);
if(((char *)arg1)) (&mysql->options)->extension->
ssl_crlpath= (__extension__ (__builtin_constant_p ((char *)((
char *)arg1)) && ((size_t)(const void *)(((char *)((char
*)arg1)) + 1) - (size_t)(const void *)((char *)((char *)arg1
)) == 1) ? (((const char *) ((char *)((char *)arg1)))[0] == '\0'
? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len
= strlen ((char *)((char *)arg1)) + 1; char *__retval = (char
*) malloc (__len); if (__retval != ((void*)0)) __retval = (char
*) memcpy (__retval, (char *)((char *)arg1), __len); __retval
; })) : __strdup ((char *)((char *)arg1)))); else (&mysql
->options)->extension->ssl_crlpath= ((void*)0)
;
2803 break;
2804 case MYSQL_OPT_CONNECT_ATTR_DELETE:
2805 {
2806 uchar *h;
2807 CHECK_OPT_EXTENSION_SET(&mysql->options)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension));
;
2808 if (hash_inited(&mysql->options.extension->connect_attrs)((&mysql->options.extension->connect_attrs)->array
.buffer != 0)
&&
2809 (h= (uchar *)hash_search(&mysql->options.extension->connect_attrs, (uchar *)arg1,
2810 arg1 ? (uint)strlen((char *)arg1) : 0)))
2811 {
2812 uchar *p= h;
2813 size_t key_len= strlen((char *)p);
2814 mysql->options.extension->connect_attrs_len-= key_len + get_store_length(key_len);
2815 p+= key_len + 1;
2816 key_len= strlen((char *)p);
2817 mysql->options.extension->connect_attrs_len-= key_len + get_store_length(key_len);
2818 hash_delete(&mysql->options.extension->connect_attrs, h);
2819 }
2820
2821 }
2822 break;
2823 case MYSQL_OPT_CONNECT_ATTR_RESET:
2824 CHECK_OPT_EXTENSION_SET(&mysql->options)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension));
;
2825 if (hash_inited(&mysql->options.extension->connect_attrs)((&mysql->options.extension->connect_attrs)->array
.buffer != 0)
)
2826 {
2827 hash_free(&mysql->options.extension->connect_attrs);
2828 mysql->options.extension->connect_attrs_len= 0;
2829 }
2830 break;
2831 case MARIADB_OPT_CONNECTION_HANDLER:
2832 OPT_SET_EXTENDED_VALUE_STR(&mysql->options, connection_handler, (char *)arg1)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension)); free((
gptr)(&mysql->options)->extension->connection_handler
); if(((char *)arg1)) (&mysql->options)->extension->
connection_handler= (__extension__ (__builtin_constant_p ((char
*)((char *)arg1)) && ((size_t)(const void *)(((char *
)((char *)arg1)) + 1) - (size_t)(const void *)((char *)((char
*)arg1)) == 1) ? (((const char *) ((char *)((char *)arg1)))[
0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t
__len = strlen ((char *)((char *)arg1)) + 1; char *__retval =
(char *) malloc (__len); if (__retval != ((void*)0)) __retval
= (char *) memcpy (__retval, (char *)((char *)arg1), __len);
__retval; })) : __strdup ((char *)((char *)arg1)))); else (&
mysql->options)->extension->connection_handler= ((void
*)0)
;
2833 break;
2834 case MARIADB_OPT_PORT:
2835 OPT_SET_VALUE_INT(&mysql->options, port, *((uint *)arg1))(&mysql->options)->port= (*((uint *)arg1));
2836 break;
2837 case MARIADB_OPT_UNIXSOCKET:
2838 OPT_SET_VALUE_STR(&mysql->options, unix_socket, arg1)free((&mysql->options)->unix_socket); if((arg1)) (&
mysql->options)->unix_socket= (__extension__ (__builtin_constant_p
((char *)(arg1)) && ((size_t)(const void *)(((char *
)(arg1)) + 1) - (size_t)(const void *)((char *)(arg1)) == 1) ?
(((const char *) ((char *)(arg1)))[0] == '\0' ? (char *) calloc
((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ((char *
)(arg1)) + 1; char *__retval = (char *) malloc (__len); if (__retval
!= ((void*)0)) __retval = (char *) memcpy (__retval, (char *
)(arg1), __len); __retval; })) : __strdup ((char *)(arg1))));
else (&mysql->options)->unix_socket= ((void*)0)
;
2839 break;
2840 case MARIADB_OPT_USER:
2841 OPT_SET_VALUE_STR(&mysql->options, user, arg1)free((&mysql->options)->user); if((arg1)) (&mysql
->options)->user= (__extension__ (__builtin_constant_p (
(char *)(arg1)) && ((size_t)(const void *)(((char *)(
arg1)) + 1) - (size_t)(const void *)((char *)(arg1)) == 1) ? (
((const char *) ((char *)(arg1)))[0] == '\0' ? (char *) calloc
((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ((char *
)(arg1)) + 1; char *__retval = (char *) malloc (__len); if (__retval
!= ((void*)0)) __retval = (char *) memcpy (__retval, (char *
)(arg1), __len); __retval; })) : __strdup ((char *)(arg1))));
else (&mysql->options)->user= ((void*)0)
;
2842 break;
2843 case MARIADB_OPT_HOST:
2844 OPT_SET_VALUE_STR(&mysql->options, host, arg1)free((&mysql->options)->host); if((arg1)) (&mysql
->options)->host= (__extension__ (__builtin_constant_p (
(char *)(arg1)) && ((size_t)(const void *)(((char *)(
arg1)) + 1) - (size_t)(const void *)((char *)(arg1)) == 1) ? (
((const char *) ((char *)(arg1)))[0] == '\0' ? (char *) calloc
((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ((char *
)(arg1)) + 1; char *__retval = (char *) malloc (__len); if (__retval
!= ((void*)0)) __retval = (char *) memcpy (__retval, (char *
)(arg1), __len); __retval; })) : __strdup ((char *)(arg1))));
else (&mysql->options)->host= ((void*)0)
;
2845 break;
2846 case MARIADB_OPT_SCHEMA:
2847 OPT_SET_VALUE_STR(&mysql->options, db, arg1)free((&mysql->options)->db); if((arg1)) (&mysql
->options)->db= (__extension__ (__builtin_constant_p ((
char *)(arg1)) && ((size_t)(const void *)(((char *)(arg1
)) + 1) - (size_t)(const void *)((char *)(arg1)) == 1) ? (((const
char *) ((char *)(arg1)))[0] == '\0' ? (char *) calloc ((size_t
) 1, (size_t) 1) : ({ size_t __len = strlen ((char *)(arg1)) +
1; char *__retval = (char *) malloc (__len); if (__retval !=
((void*)0)) __retval = (char *) memcpy (__retval, (char *)(arg1
), __len); __retval; })) : __strdup ((char *)(arg1)))); else (
&mysql->options)->db= ((void*)0)
;
2848 break;
2849 case MARIADB_OPT_DEBUG:
2850 break;
2851 case MARIADB_OPT_FOUND_ROWS:
2852 mysql->options.client_flag|= CLIENT_FOUND_ROWS2;
2853 break;
2854 case MARIADB_OPT_INTERACTIVE:
2855 mysql->options.client_flag|= CLIENT_INTERACTIVE1024;
2856 break;
2857 case MARIADB_OPT_MULTI_RESULTS:
2858 mysql->options.client_flag|= CLIENT_MULTI_RESULTS(1UL << 17);
2859 break;
2860 case MARIADB_OPT_MULTI_STATEMENTS:
2861 mysql->options.client_flag|= CLIENT_MULTI_STATEMENTS(1UL << 16) | CLIENT_MULTI_RESULTS(1UL << 17);
2862 break;
2863 case MARIADB_OPT_PASSWORD:
2864 OPT_SET_VALUE_STR(&mysql->options, password, arg1)free((&mysql->options)->password); if((arg1)) (&
mysql->options)->password= (__extension__ (__builtin_constant_p
((char *)(arg1)) && ((size_t)(const void *)(((char *
)(arg1)) + 1) - (size_t)(const void *)((char *)(arg1)) == 1) ?
(((const char *) ((char *)(arg1)))[0] == '\0' ? (char *) calloc
((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ((char *
)(arg1)) + 1; char *__retval = (char *) malloc (__len); if (__retval
!= ((void*)0)) __retval = (char *) memcpy (__retval, (char *
)(arg1), __len); __retval; })) : __strdup ((char *)(arg1))));
else (&mysql->options)->password= ((void*)0)
;
2865 break;
2866 case MARIADB_OPT_USERDATA:
2867 {
2868 void *data= va_arg(ap, void *)__builtin_va_arg(ap, void *);
2869 uchar *buffer, *p;
2870 char *key= (char *)arg1;
2871
2872 if (!key || !data)
2873 {
2874 SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2034); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2034))-2000], sizeof((mysql)->net.last_error)); }
;
2875 goto end;
2876 }
2877
2878 CHECK_OPT_EXTENSION_SET(&mysql->options)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension));
;
2879 if (!hash_inited(&mysql->options.extension->userdata)((&mysql->options.extension->userdata)->array.buffer
!= 0)
)
2880 {
2881 if (_hash_init(&mysql->options.extension->userdata,
2882 0, 0, 0, ma_get_hash_keyval, ma_hash_free, 0))
2883 {
2884 SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2008); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2008))-2000], sizeof((mysql)->net.last_error)); }
;
2885 goto end;
2886 }
2887 }
2888 /* check if key is already in buffer */
2889 p= (uchar *)hash_search(&mysql->options.extension->userdata,
2890 (uchar *)key,
2891 (uint)strlen(key));
2892 if (p)
2893 {
2894 p+= strlen(key) + 1;
2895 memcpy(p, &data, sizeof(void *));
2896 break;
2897 }
2898
2899 if (!(buffer= (uchar *)malloc(strlen(key) + 1 + sizeof(void *))))
2900 {
2901 SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2008); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2008))-2000], sizeof((mysql)->net.last_error)); }
;
2902 goto end;
2903 }
2904
2905 p= buffer;
2906 strcpy((char *)p, key);
2907 p+= strlen(key) + 1;
2908 memcpy(p, &data, sizeof(void *));
2909
2910 if (hash_insert(&mysql->options.extension->userdata, buffer))
2911 {
2912 free(buffer);
2913 SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2034); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2034))-2000], sizeof((mysql)->net.last_error)); }
;
2914 goto end;
2915 }
2916 }
2917 break;
2918 case MYSQL_OPT_CONNECT_ATTR_ADD:
2919 {
2920 uchar *buffer;
2921 void *arg2= va_arg(ap, void *)__builtin_va_arg(ap, void *);
2922 size_t key_len= arg1 ? strlen((char *)arg1) : 0,
2923 value_len= arg2 ? strlen((char *)arg2) : 0;
2924 size_t storage_len= key_len + value_len +
2925 get_store_length(key_len) +
2926 get_store_length(value_len);
2927
2928 /* since we store terminating zero character in hash, we need
2929 * to increase lengths */
2930 key_len++;
2931 value_len++;
2932
2933 CHECK_OPT_EXTENSION_SET(&mysql->options)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension));
;
2934 if (!key_len ||
2935 storage_len + mysql->options.extension->connect_attrs_len > 0xFFFF)
2936 {
2937 SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2034); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2034))-2000], sizeof((mysql)->net.last_error)); }
;
2938 goto end;
2939 }
2940
2941 if (!hash_inited(&mysql->options.extension->connect_attrs)((&mysql->options.extension->connect_attrs)->array
.buffer != 0)
)
2942 {
2943 if (_hash_init(&mysql->options.extension->connect_attrs,
2944 0, 0, 0, ma_get_hash_keyval, ma_hash_free, 0))
2945 {
2946 SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2008); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2008))-2000], sizeof((mysql)->net.last_error)); }
;
2947 goto end;
2948 }
2949 }
2950 if ((buffer= (uchar *)malloc(key_len + value_len)))
2951 {
2952 uchar *p= buffer;
2953 strcpy((char *)p, arg1);
2954 p+= (strlen(arg1) + 1);
2955 if (arg2)
2956 strcpy((char *)p, arg2);
2957
2958 if (hash_insert(&mysql->options.extension->connect_attrs, buffer))
2959 {
2960 free(buffer);
2961 SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2034); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2034))-2000], sizeof((mysql)->net.last_error)); }
;
2962 goto end;
2963 }
2964 mysql->options.extension->connect_attrs_len+= storage_len;
2965 }
2966 else
2967 {
2968 SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2008); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2008))-2000], sizeof((mysql)->net.last_error)); }
;
2969 goto end;
2970 }
2971 }
2972 break;
2973 case MYSQL_ENABLE_CLEARTEXT_PLUGIN:
2974 break;
2975 case MYSQL_SECURE_AUTH:
2976 mysql->options.secure_auth= *(my_bool *)arg1;
2977 break;
2978 case MYSQL_OPT_BIND:
2979 OPT_SET_VALUE_STR(&mysql->options, bind_address, arg1)free((&mysql->options)->bind_address); if((arg1)) (
&mysql->options)->bind_address= (__extension__ (__builtin_constant_p
((char *)(arg1)) && ((size_t)(const void *)(((char *
)(arg1)) + 1) - (size_t)(const void *)((char *)(arg1)) == 1) ?
(((const char *) ((char *)(arg1)))[0] == '\0' ? (char *) calloc
((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ((char *
)(arg1)) + 1; char *__retval = (char *) malloc (__len); if (__retval
!= ((void*)0)) __retval = (char *) memcpy (__retval, (char *
)(arg1), __len); __retval; })) : __strdup ((char *)(arg1))));
else (&mysql->options)->bind_address= ((void*)0)
;
2980 break;
2981 case MARIADB_OPT_TLS_CIPHER_STRENGTH:
2982 OPT_SET_EXTENDED_VALUE_INT(&mysql->options, tls_cipher_strength, *((unsigned int *)arg1))if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension)); (&
mysql->options)->extension->tls_cipher_strength= (*(
(unsigned int *)arg1))
;
2983 break;
2984 case MARIADB_OPT_SSL_FP:
2985 case MARIADB_OPT_TLS_PEER_FP:
2986 OPT_SET_EXTENDED_VALUE_STR(&mysql->options, tls_fp, (char *)arg1)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension)); free((
gptr)(&mysql->options)->extension->tls_fp); if((
(char *)arg1)) (&mysql->options)->extension->tls_fp
= (__extension__ (__builtin_constant_p ((char *)((char *)arg1
)) && ((size_t)(const void *)(((char *)((char *)arg1)
) + 1) - (size_t)(const void *)((char *)((char *)arg1)) == 1)
? (((const char *) ((char *)((char *)arg1)))[0] == '\0' ? (char
*) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen
((char *)((char *)arg1)) + 1; char *__retval = (char *) malloc
(__len); if (__retval != ((void*)0)) __retval = (char *) memcpy
(__retval, (char *)((char *)arg1), __len); __retval; })) : __strdup
((char *)((char *)arg1)))); else (&mysql->options)->
extension->tls_fp= ((void*)0)
;
2987 mysql->options.use_ssl= 1;
2988 break;
2989 case MARIADB_OPT_SSL_FP_LIST:
2990 case MARIADB_OPT_TLS_PEER_FP_LIST:
2991 OPT_SET_EXTENDED_VALUE_STR(&mysql->options, tls_fp_list, (char *)arg1)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension)); free((
gptr)(&mysql->options)->extension->tls_fp_list);
if(((char *)arg1)) (&mysql->options)->extension->
tls_fp_list= (__extension__ (__builtin_constant_p ((char *)((
char *)arg1)) && ((size_t)(const void *)(((char *)((char
*)arg1)) + 1) - (size_t)(const void *)((char *)((char *)arg1
)) == 1) ? (((const char *) ((char *)((char *)arg1)))[0] == '\0'
? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len
= strlen ((char *)((char *)arg1)) + 1; char *__retval = (char
*) malloc (__len); if (__retval != ((void*)0)) __retval = (char
*) memcpy (__retval, (char *)((char *)arg1), __len); __retval
; })) : __strdup ((char *)((char *)arg1)))); else (&mysql
->options)->extension->tls_fp_list= ((void*)0)
;
2992 mysql->options.use_ssl= 1;
2993 break;
2994 case MARIADB_OPT_TLS_PASSPHRASE:
2995 OPT_SET_EXTENDED_VALUE_STR(&mysql->options, tls_pw, (char *)arg1)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension)); free((
gptr)(&mysql->options)->extension->tls_pw); if((
(char *)arg1)) (&mysql->options)->extension->tls_pw
= (__extension__ (__builtin_constant_p ((char *)((char *)arg1
)) && ((size_t)(const void *)(((char *)((char *)arg1)
) + 1) - (size_t)(const void *)((char *)((char *)arg1)) == 1)
? (((const char *) ((char *)((char *)arg1)))[0] == '\0' ? (char
*) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen
((char *)((char *)arg1)) + 1; char *__retval = (char *) malloc
(__len); if (__retval != ((void*)0)) __retval = (char *) memcpy
(__retval, (char *)((char *)arg1), __len); __retval; })) : __strdup
((char *)((char *)arg1)))); else (&mysql->options)->
extension->tls_pw= ((void*)0)
;
2996 break;
2997 case MARIADB_OPT_CONNECTION_READ_ONLY:
2998 OPT_SET_EXTENDED_VALUE_INT(&mysql->options, read_only, *(my_bool *)arg1)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension)); (&
mysql->options)->extension->read_only= (*(my_bool *)
arg1)
;
2999 break;
3000 case MARIADB_OPT_PROXY_HEADER:
3001 {
3002 size_t arg2 = va_arg(ap, size_t)__builtin_va_arg(ap, size_t);
3003 OPT_SET_EXTENDED_VALUE(&mysql->options, proxy_header, (char *)arg1)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension)); (&
mysql->options)->extension->proxy_header= ((char *)arg1
)
;
3004 OPT_SET_EXTENDED_VALUE(&mysql->options, proxy_header_len, arg2)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension)); (&
mysql->options)->extension->proxy_header_len= (arg2)
;
3005 }
3006 break;
3007 case MARIADB_OPT_TLS_VERSION:
3008 case MYSQL_OPT_TLS_VERSION:
3009 OPT_SET_EXTENDED_VALUE_STR(&mysql->options, tls_version, (char *)arg1)if (!(&mysql->options)->extension) (&mysql->
options)->extension= (struct st_mysql_options_extension *)
calloc(1, sizeof(struct st_mysql_options_extension)); free((
gptr)(&mysql->options)->extension->tls_version);
if(((char *)arg1)) (&mysql->options)->extension->
tls_version= (__extension__ (__builtin_constant_p ((char *)((
char *)arg1)) && ((size_t)(const void *)(((char *)((char
*)arg1)) + 1) - (size_t)(const void *)((char *)((char *)arg1
)) == 1) ? (((const char *) ((char *)((char *)arg1)))[0] == '\0'
? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len
= strlen ((char *)((char *)arg1)) + 1; char *__retval = (char
*) malloc (__len); if (__retval != ((void*)0)) __retval = (char
*) memcpy (__retval, (char *)((char *)arg1), __len); __retval
; })) : __strdup ((char *)((char *)arg1)))); else (&mysql
->options)->extension->tls_version= ((void*)0)
;
3010 break;
3011 default:
3012 va_end(ap)__builtin_va_end(ap);
3013 return(-1);
3014 }
3015 va_end(ap)__builtin_va_end(ap);
3016 return(0);
3017end:
3018 va_end(ap)__builtin_va_end(ap);
3019 return(1);
3020}
3021
3022int STDCALL
3023mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...)
3024{
3025 va_list ap;
3026
3027 va_start(ap, arg)__builtin_va_start(ap, arg);
3028
3029 switch(option) {
3030 case MYSQL_OPT_CONNECT_TIMEOUT:
3031 *((uint *)arg)= mysql->options.connect_timeout;
3032 break;
3033 case MYSQL_OPT_COMPRESS:
3034 *((my_bool *)arg)= mysql->options.compress;
3035 break;
3036 case MYSQL_OPT_NAMED_PIPE:
3037 *((my_bool *)arg)= mysql->options.named_pipe;
3038 break;
3039 case MYSQL_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/
3040 *((uint *)arg)= test(mysql->options.client_flag & CLIENT_LOCAL_FILES)((mysql->options.client_flag & 128) ? 1 : 0);
3041 break;
3042 case MYSQL_INIT_COMMAND:
3043 /* mysql_get_optionsv(mysql, MYSQL_INIT_COMMAND, commands, elements) */
3044 {
3045 unsigned int *elements;
3046 if (arg)
3047 *((char **)arg)= mysql->options.init_command ? mysql->options.init_command->buffer : NULL((void*)0);
3048 if ((elements= va_arg(ap, unsigned int *)__builtin_va_arg(ap, unsigned int *)))
3049 *elements= mysql->options.init_command ? mysql->options.init_command->elements : 0;
3050 }
3051 break;
3052 case MYSQL_READ_DEFAULT_FILE:
3053 *((char **)arg)= mysql->options.my_cnf_file;
3054 break;
3055 case MYSQL_READ_DEFAULT_GROUP:
3056 *((char **)arg)= mysql->options.my_cnf_group;
3057 break;
3058 case MYSQL_SET_CHARSET_DIR:
3059 /* not supported in this version. Since all character sets
3060 are internally available, we don't throw an error */
3061 *((char **)arg)= NULL((void*)0);
3062 break;
3063 case MYSQL_SET_CHARSET_NAME:
3064 if (mysql->charset)
3065 *((const char **)arg)= mysql->charset->csname;
3066 else
3067 *((char **)arg)= mysql->options.charset_name;
3068 break;
3069 case MYSQL_OPT_RECONNECT:
3070 *((my_bool *)arg)= mysql->options.reconnect;
3071 break;
3072 case MYSQL_OPT_PROTOCOL:
3073 *((uint *)arg)= mysql->options.protocol;
3074 break;
3075 case MYSQL_OPT_READ_TIMEOUT:
3076 *((uint *)arg)= mysql->options.read_timeout;
3077 break;
3078 case MYSQL_OPT_WRITE_TIMEOUT:
3079 *((uint *)arg)= mysql->options.write_timeout;
3080 break;
3081 case MYSQL_REPORT_DATA_TRUNCATION:
3082 *((my_bool *)arg)= mysql->options.report_data_truncation;
3083 break;
3084 case MYSQL_PROGRESS_CALLBACK:
3085 *((void (**)(const MYSQL *, uint, uint, double, const char *, uint))arg)=
3086 mysql->options.extension ? mysql->options.extension->report_progress : NULL((void*)0);
3087 break;
3088 case MYSQL_SERVER_PUBLIC_KEY:
3089 *((char **)arg)= mysql->options.extension ?
3090 mysql->options.extension->server_public_key : NULL((void*)0);
3091 break;
3092 case MYSQL_PLUGIN_DIR:
3093 *((char **)arg)= mysql->options.extension ? mysql->options.extension->plugin_dir : NULL((void*)0);
3094 break;
3095 case MYSQL_DEFAULT_AUTH:
3096 *((char **)arg)= mysql->options.extension ? mysql->options.extension->default_auth : NULL((void*)0);
3097 break;
3098 case MYSQL_OPT_NONBLOCK:
3099 *((my_bool *)arg)= test(mysql->options.extension && mysql->options.extension->async_context)((mysql->options.extension && mysql->options.extension
->async_context) ? 1 : 0)
;
3100 break;
3101 case MYSQL_OPT_SSL_ENFORCE:
3102 *((my_bool *)arg)= mysql->options.use_ssl;
3103 break;
3104 case MYSQL_OPT_SSL_VERIFY_SERVER_CERT:
3105 *((my_bool *)arg)= test(mysql->options.client_flag & CLIENT_SSL_VERIFY_SERVER_CERT)((mysql->options.client_flag & (1UL << 30)) ? 1 :
0)
;
3106 break;
3107 case MYSQL_OPT_SSL_KEY:
3108 *((char **)arg)= mysql->options.ssl_key;
3109 break;
3110 case MYSQL_OPT_SSL_CERT:
3111 *((char **)arg)= mysql->options.ssl_cert;
3112 break;
3113 case MYSQL_OPT_SSL_CA:
3114 *((char **)arg)= mysql->options.ssl_ca;
3115 break;
3116 case MYSQL_OPT_SSL_CAPATH:
3117 *((char **)arg)= mysql->options.ssl_capath;
3118 break;
3119 case MYSQL_OPT_SSL_CIPHER:
3120 *((char **)arg)= mysql->options.ssl_cipher;
3121 break;
3122 case MYSQL_OPT_SSL_CRL:
3123 *((char **)arg)= mysql->options.extension ? mysql->options.ssl_cipher : NULL((void*)0);
3124 break;
3125 case MYSQL_OPT_SSL_CRLPATH:
3126 *((char **)arg)= mysql->options.extension ? mysql->options.extension->ssl_crlpath : NULL((void*)0);
3127 break;
3128 case MYSQL_OPT_CONNECT_ATTRS:
3129 /* mysql_get_optionsv(mysql, MYSQL_OPT_CONNECT_ATTRS, keys, vals, elements) */
3130 {
3131 unsigned int i, *elements;
3132 char **key= NULL((void*)0);
3133 void *arg1;
3134 char **val= NULL((void*)0);
3135
3136 if (arg)
3137 key= *(char ***)arg;
3138
3139 arg1= va_arg(ap, char **)__builtin_va_arg(ap, char **);
3140 if (arg1)
3141 val= *(char ***)arg1;
3142
3143 if (!(elements= va_arg(ap, unsigned int *)__builtin_va_arg(ap, unsigned int *)))
3144 goto error;
3145
3146 if (!elements)
3147 goto error;
3148
3149 *elements= 0;
3150
3151 if (!mysql->options.extension ||
3152 !hash_inited(&mysql->options.extension->connect_attrs)((&mysql->options.extension->connect_attrs)->array
.buffer != 0)
)
3153 break;
3154
3155 *elements= mysql->options.extension->connect_attrs.records;
3156
3157 if (val || key)
3158 {
3159 for (i=0; i < *elements; i++)
3160 {
3161 uchar *p= hash_element(&mysql->options.extension->connect_attrs, i);
3162 if (key)
3163 key[i]= (char *)p;
3164 p+= strlen((char *)p) + 1;
3165 if (val)
3166 val[i]= (char *)p;
3167 }
3168 }
3169 }
3170 break;
3171 case MYSQL_OPT_MAX_ALLOWED_PACKET:
3172 *((unsigned long *)arg)= (mysql) ? mysql->options.max_allowed_packet :
3173 max_allowed_packet;
3174 break;
3175 case MYSQL_OPT_NET_BUFFER_LENGTH:
3176 *((unsigned long *)arg)= net_buffer_length;
3177 break;
3178 case MYSQL_SECURE_AUTH:
3179 *((my_bool *)arg)= mysql->options.secure_auth;
3180 break;
3181 case MYSQL_OPT_BIND:
3182 *((char **)arg)= mysql->options.bind_address;
3183 break;
3184 case MARIADB_OPT_TLS_CIPHER_STRENGTH:
3185 *((unsigned int *)arg) = mysql->options.extension ? mysql->options.extension->tls_cipher_strength : 0;
3186 break;
3187 case MARIADB_OPT_SSL_FP:
3188 case MARIADB_OPT_TLS_PEER_FP:
3189 *((char **)arg)= mysql->options.extension ? mysql->options.extension->tls_fp : NULL((void*)0);
3190 break;
3191 case MARIADB_OPT_SSL_FP_LIST:
3192 case MARIADB_OPT_TLS_PEER_FP_LIST:
3193 *((char **)arg)= mysql->options.extension ? mysql->options.extension->tls_fp_list : NULL((void*)0);
3194 break;
3195 case MARIADB_OPT_TLS_PASSPHRASE:
3196 *((char **)arg)= mysql->options.extension ? mysql->options.extension->tls_pw : NULL((void*)0);
3197 break;
3198 case MARIADB_OPT_CONNECTION_READ_ONLY:
3199 *((my_bool *)arg)= mysql->options.extension ? mysql->options.extension->read_only : 0;
3200 break;
3201 case MARIADB_OPT_USERDATA:
3202 /* nysql_get_optionv(mysql, MARIADB_OPT_USERDATA, key, value) */
3203 {
3204 uchar *p;
3205 void *data= va_arg(ap, void *)__builtin_va_arg(ap, void *);
3206 char *key= (char *)arg;
3207 if (key && data && mysql->options.extension && hash_inited(&mysql->options.extension->userdata)((&mysql->options.extension->userdata)->array.buffer
!= 0)
&&
3208 (p= (uchar *)hash_search(&mysql->options.extension->userdata, (uchar *)key,
3209 (uint)strlen((char *)key))))
3210 {
3211 p+= strlen(key) + 1;
3212 *((void **)data)= *((void **)p);
3213 break;
3214 }
3215 if (data)
3216 *((void **)data)= NULL((void*)0);
3217 }
3218 break;
3219 case MARIADB_OPT_CONNECTION_HANDLER:
3220 *((char **)arg)= mysql->options.extension ? mysql->options.extension->connection_handler : NULL((void*)0);
3221 break;
3222 default:
3223 va_end(ap)__builtin_va_end(ap);
3224 return(-1);
3225 }
3226 va_end(ap)__builtin_va_end(ap);
3227 return(0);
3228error:
3229 va_end(ap)__builtin_va_end(ap);
3230 return(-1);
3231}
3232
3233int STDCALL mysql_get_option(MYSQL *mysql, enum mysql_option option, void *arg)
3234{
3235 return mysql_get_optionv(mysql, option, arg);
3236}
3237
3238int STDCALL
3239mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg)
3240{
3241 return mysql_optionsv(mysql, option, arg);
3242}
3243
3244int STDCALL
3245mysql_options4(MYSQL *mysql,enum mysql_option option, const void *arg1, const void *arg2)
3246{
3247 return mysql_optionsv(mysql, option, arg1, arg2);
3248}
3249/****************************************************************************
3250** Functions to get information from the MySQL structure
3251** These are functions to make shared libraries more usable.
3252****************************************************************************/
3253
3254/* MYSQL_RES */
3255my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res)
3256{
3257 return res->row_count;
3258}
3259
3260unsigned int STDCALL mysql_num_fields(MYSQL_RES *res)
3261{
3262 return res->field_count;
3263}
3264
3265/* deprecated */
3266my_bool STDCALL mysql_eof(MYSQL_RES *res)
3267{
3268 return res->eof;
3269}
3270
3271MYSQL_FIELD * STDCALL mysql_fetch_field_direct(MYSQL_RES *res,uint fieldnr)
3272{
3273 return &(res)->fields[fieldnr];
3274}
3275
3276MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res)
3277{
3278 return (res)->fields;
3279}
3280
3281MYSQL_ROWS * STDCALL mysql_row_tell(MYSQL_RES *res)
3282{
3283 return res->data_cursor;
3284}
3285
3286uint STDCALL mysql_field_tell(MYSQL_RES *res)
3287{
3288 return (res)->current_field;
3289}
3290
3291/* MYSQL */
3292
3293unsigned int STDCALL mysql_field_count(MYSQL *mysql)
3294{
3295 return mysql->field_count;
3296}
3297
3298my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql)
3299{
3300 return (mysql)->affected_rows;
3301}
3302
3303my_bool STDCALL mysql_autocommit(MYSQL *mysql, my_bool mode)
3304{
3305 return((my_bool) mysql_real_query(mysql, (mode) ? "SET autocommit=1" :
3306 "SET autocommit=0", 16));
3307}
3308
3309my_bool STDCALL mysql_commit(MYSQL *mysql)
3310{
3311 return((my_bool)mysql_real_query(mysql, "COMMIT", (unsigned long) sizeof("COMMIT")));
3312}
3313
3314my_bool STDCALL mysql_rollback(MYSQL *mysql)
3315{
3316 return((my_bool)mysql_real_query(mysql, "ROLLBACK", (unsigned long)sizeof("ROLLBACK")));
3317}
3318
3319my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql)
3320{
3321 return (mysql)->insert_id;
3322}
3323
3324uint STDCALL mysql_errno(MYSQL *mysql)
3325{
3326 return mysql ? mysql->net.last_errno : 0;
3327}
3328
3329const char * STDCALL mysql_error(MYSQL *mysql)
3330{
3331 return mysql ? (mysql)->net.last_error : (char *)"";
3332}
3333
3334const char *STDCALL mysql_info(MYSQL *mysql)
3335{
3336 return (mysql)->info;
3337}
3338
3339my_bool STDCALL mysql_more_results(MYSQL *mysql)
3340{
3341 return(test(mysql->server_status & SERVER_MORE_RESULTS_EXIST)((mysql->server_status & 8) ? 1 : 0));
3342}
3343
3344int STDCALL mysql_next_result(MYSQL *mysql)
3345{
3346
3347 /* make sure communication is not blocking */
3348 if (mysql->status != MYSQL_STATUS_READY)
3349 {
3350 SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0){ (mysql)->net.last_errno= (2014); strncpy((mysql)->net
.sqlstate, (SQLSTATE_UNKNOWN), sizeof((mysql)->net.sqlstate
)); strncpy((mysql)->net.last_error, (0) ? (0) : client_errors
[((2014))-2000], sizeof((mysql)->net.last_error)); }
;
3351 return(1);
3352 }
3353
3354 /* clear error, and mysql status variables */
3355 CLEAR_CLIENT_ERROR(mysql){ (mysql)->net.last_errno= 0; strcpy((mysql)->net.sqlstate
, "00000"); (mysql)->net.last_error[0]= '\0'; }
;
3356 mysql->affected_rows = (ulonglong) ~0;
3357
3358 if (mysql->server_status & SERVER_MORE_RESULTS_EXIST8)
3359 {
3360 return(mysql->methods->db_read_query_result(mysql));
3361 }
3362
3363 return(-1);
3364}
3365
3366ulong STDCALL mysql_thread_id(MYSQL *mysql)
3367{
3368 return (mysql)->thread_id;
3369}
3370
3371const char * STDCALL mysql_character_set_name(MYSQL *mysql)
3372{
3373 return mysql->charset->csname;
3374}
3375
3376
3377uint STDCALL mysql_thread_safe(void)
3378{
3379#ifdef THREAD1
3380 return 1;
3381#else
3382 return 0;
3383#endif
3384}
3385
3386/****************************************************************************
3387** Some support functions
3388****************************************************************************/
3389
3390/*
3391** Add escape characters to a string (blob?) to make it suitable for a insert
3392** to should at least have place for length*2+1 chars
3393** Returns the length of the to string
3394*/
3395
3396ulong STDCALL
3397mysql_escape_string(char *to,const char *from, ulong length)
3398{
3399 return (ulong)mysql_cset_escape_slashes(ma_default_charset_info, to, from, length);
3400}
3401
3402ulong STDCALL
3403mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
3404 ulong length)
3405{
3406 if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES512)
3407 return (ulong)mysql_cset_escape_quotes(mysql->charset, to, from, length);
3408 else
3409 return (ulong)mysql_cset_escape_slashes(mysql->charset, to, from, length);
3410}
3411
3412static void mariadb_get_charset_info(MYSQL *mysql, MY_CHARSET_INFO *cs)
3413{
3414 if (!cs)
3415 return;
3416
3417 cs->number= mysql->charset->nr;
3418 cs->csname= mysql->charset->csname;
3419 cs->name= mysql->charset->name;
3420 cs->state= 0;
3421 cs->comment= NULL((void*)0);
3422 cs->dir= NULL((void*)0);
3423 cs->mbminlen= mysql->charset->char_minlen;
3424 cs->mbmaxlen= mysql->charset->char_maxlen;
3425
3426 return;
3427}
3428
3429void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs)
3430{
3431 mariadb_get_charset_info(mysql, cs);
3432}
3433
3434int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname)
3435{
3436 const MARIADB_CHARSET_INFO *cs;
3437
3438 if (!csname)
3439 goto error;
3440
3441 if ((cs= mysql_find_charset_name(csname)))
3442 {
3443 char buff[64];
3444
3445 snprintf(buff, 63, "SET NAMES %s", cs->csname)__builtin___snprintf_chk (buff, 63, 2 - 1, __builtin_object_size
(buff, 2 > 1), "SET NAMES %s", cs->csname)
;
3446 if (!mysql_real_query(mysql, buff, (unsigned long)strlen(buff)))
3447 {
3448 mysql->charset= cs;
3449 return(0);
3450 }
3451 }
3452
3453error:
3454 my_set_error(mysql, CR_CANT_READ_CHARSET2019, SQLSTATE_UNKNOWN,
3455 0, csname, "compiled_in");
3456 return(mysql->net.last_errno);
3457}
3458
3459unsigned int STDCALL mysql_warning_count(MYSQL *mysql)
3460{
3461 return mysql->warning_count;
3462}
3463
3464const char * STDCALL mysql_sqlstate(MYSQL *mysql)
3465{
3466 return mysql->net.sqlstate;
3467}
3468
3469#ifndef _WIN32
3470#include <signal.h>
3471static void ignore_sigpipe()
3472{
3473 signal(SIGPIPE13, SIG_IGN((__sighandler_t) 1));
3474}
3475#else
3476#define ignore_sigpipe()
3477#endif
3478
3479#ifdef _WIN32
3480static int mysql_once_init()
3481#else
3482static void mysql_once_init()
3483#endif
3484{
3485 ma_init(); /* Will init threads */
3486 init_client_errs();
3487 get_default_configuration_dirs();
3488 if (mysql_client_plugin_init())
3489 {
3490#ifdef _WIN32
3491 return 1;
3492#else
3493 return;
3494#endif
3495 }
3496 if (!mysql_port)
3497 {
3498 struct servent *serv_ptr;
3499 char *env;
3500
3501 mysql_port = MARIADB_PORT3306;
3502 if ((serv_ptr = getservbyname("mysql", "tcp")))
3503 mysql_port = (uint)ntohs((ushort)serv_ptr->s_port)(__extension__ ({ unsigned short int __bsx = (unsigned short int
) ((ushort)serv_ptr->s_port); ((unsigned short int)((((__bsx
) >> 8) & 0xffu) | (((__bsx) & 0xffu) << 8
))); }))
;
3504 if ((env = getenv("MYSQL_TCP_PORT")))
3505 mysql_port =(uint)atoi(env);
3506 }
3507 if (!mysql_unix_port)
3508 {
3509 char *env;
3510#ifdef _WIN32
3511 mysql_unix_port = (char*)MARIADB_NAMEDPIPE;
3512#else
3513 mysql_unix_port = (char*)MARIADB_UNIX_ADDR"/tmp/mysql.sock";
3514#endif
3515 if ((env = getenv("MYSQL_UNIX_PORT")) ||
3516 (env = getenv("MARIADB_UNIX_PORT")))
3517 mysql_unix_port = env;
3518 }
3519 if (!mysql_ps_subsystem_initialized)
3520 mysql_init_ps_subsystem();
3521#ifdef HAVE_TLS1
3522 ma_tls_start(0, 0);
3523#endif
3524 ignore_sigpipe();
3525 mysql_client_init = 1;
3526#ifdef _WIN32
3527 return 0;
3528#endif
3529}
3530
3531#ifdef _WIN32
3532BOOL CALLBACK win_init_once(
3533 PINIT_ONCE InitOnce,
3534 PVOID Parameter,
3535 PVOID *lpContext)
3536{
3537 return !mysql_once_init();
3538 return TRUE(1);
3539}
3540#endif
3541
3542int STDCALL mysql_server_init(int argc __attribute__((unused)),
3543 char **argv __attribute__((unused)),
3544 char **groups __attribute__((unused)))
3545{
3546#ifdef _WIN32
3547 static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
3548 BOOL ret = InitOnceExecuteOnce(&init_once, win_init_once, NULL((void*)0), NULL((void*)0));
3549 return ret? 0: 1;
3550#else
3551 static pthread_once_t init_once = PTHREAD_ONCE_INIT0;
3552 return pthread_once(&init_once, mysql_once_init);
3553#endif
3554}
3555
3556void STDCALL mysql_server_end(void)
3557{
3558 if (!mysql_client_init)
3559 return;
3560
3561 release_configuration_dirs();
3562 mysql_client_plugin_deinit();
3563
3564 list_free(pvio_callback, 0);
3565 if (ma_init_done)
3566 ma_end(0);
3567#ifdef HAVE_TLS1
3568 ma_pvio_tls_end();
3569#endif
3570 mysql_client_init= 0;
3571 ma_init_done= 0;
3572}
3573
3574my_bool STDCALL mysql_thread_init(void)
3575{
3576 return 0;
3577}
3578
3579void STDCALL mysql_thread_end(void)
3580{
3581}
3582
3583int STDCALL mysql_set_server_option(MYSQL *mysql,
3584 enum enum_mysql_set_option option)
3585{
3586 char buffer[2];
3587 int2store(buffer, (uint)option)do { uint def_temp= (uint) ((uint)option) ; *((uchar*) (buffer
))= (uchar)(def_temp); *((uchar*) (buffer)+1)=(uchar)((def_temp
>> 8)); } while(0)
;
3588 return(ma_simple_command(mysql, COM_SET_OPTION, buffer, sizeof(buffer), 0, 0));
3589}
3590
3591ulong STDCALL mysql_get_client_version(void)
3592{
3593 return MARIADB_VERSION_ID100308;
3594}
3595
3596ulong STDCALL mysql_hex_string(char *to, const char *from, unsigned long len)
3597{
3598 char *start= to;
3599 char hexdigits[]= "0123456789ABCDEF";
3600
3601 while (len--)
3602 {
3603 *to++= hexdigits[((unsigned char)*from) >> 4];
3604 *to++= hexdigits[((unsigned char)*from) & 0x0F];
3605 from++;
3606 }
3607 *to= 0;
3608 return (ulong)(to - start);
3609}
3610
3611my_bool STDCALL mariadb_connection(MYSQL *mysql)
3612{
3613 return (strstr(mysql->server_version, "MariaDB") ||
3614 strstr(mysql->server_version, "-maria-"));
3615}
3616
3617const char * STDCALL
3618mysql_get_server_name(MYSQL *mysql)
3619{
3620 if (mysql->options.extension &&
3621 mysql->options.extension->db_driver != NULL((void*)0))
3622 return mysql->options.extension->db_driver->name;
3623 return mariadb_connection(mysql) ? "MariaDB" : "MySQL";
3624}
3625
3626static my_socket mariadb_get_socket(MYSQL *mysql)
3627{
3628 my_socket sock= INVALID_SOCKET-1;
3629 if (mysql->net.pvio)
3630 {
3631 ma_pvio_get_handle(mysql->net.pvio, &sock);
3632
3633 }
3634 /* if an asynchronous connect is in progress, we need to obtain
3635 pvio handle from async_context until the connection was
3636 successfully established.
3637 */
3638 else if (mysql->options.extension && mysql->options.extension->async_context &&
3639 mysql->options.extension->async_context->pvio)
3640 {
3641 ma_pvio_get_handle(mysql->options.extension->async_context->pvio, &sock);
3642 }
3643 return sock;
3644}
3645
3646my_socket STDCALL
3647mysql_get_socket(MYSQL *mysql)
3648{
3649 return mariadb_get_socket(mysql);
3650}
3651
3652MARIADB_CHARSET_INFO * STDCALL mariadb_get_charset_by_name(const char *csname)
3653{
3654 return (MARIADB_CHARSET_INFO *)mysql_find_charset_name(csname);
3655}
3656
3657MARIADB_CHARSET_INFO * STDCALL mariadb_get_charset_by_nr(unsigned int csnr)
3658{
3659 return (MARIADB_CHARSET_INFO *)mysql_find_charset_nr(csnr);
3660}
3661
3662my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void *arg, ...)
3663{
3664 va_list ap;
3665
3666 va_start(ap, arg)__builtin_va_start(ap, arg);
3667
3668 switch(value) {
3669 case MARIADB_MAX_ALLOWED_PACKET:
3670 *((size_t *)arg)= (size_t)max_allowed_packet;
3671 break;
3672 case MARIADB_NET_BUFFER_LENGTH:
3673 *((size_t *)arg)= (size_t)net_buffer_length;
3674 break;
3675 case MARIADB_CONNECTION_ERROR_ID:
3676 if (!mysql)
3677 goto error;
3678 *((unsigned int *)arg)= mysql->net.last_errno;
3679 break;
3680 case MARIADB_CONNECTION_ERROR:
3681 if (!mysql)
3682 goto error;
3683 *((char **)arg)= mysql->net.last_error;
3684 break;
3685 case MARIADB_CONNECTION_SQLSTATE:
3686 if (!mysql)
3687 goto error;
3688 *((char **)arg)= mysql->net.sqlstate;
3689 break;
3690 case MARIADB_CONNECTION_TLS_VERSION:
3691 #ifdef HAVE_TLS1
3692 if (mysql && mysql->net.pvio && mysql->net.pvio->ctls)
3693 *((char **)arg)= (char *)ma_pvio_tls_get_protocol_version(mysql->net.pvio->ctls);
3694 else
3695 #endif
3696 goto error;
3697 break;
3698 case MARIADB_CONNECTION_TLS_VERSION_ID:
3699 #ifdef HAVE_TLS1
3700 if (mysql && mysql->net.pvio && mysql->net.pvio->ctls)
3701 *((unsigned int *)arg)= ma_pvio_tls_get_protocol_version_id(mysql->net.pvio->ctls);
3702 else
3703 #endif
3704 goto error;
3705 break;
3706 case MARIADB_TLS_LIBRARY:
3707#ifdef HAVE_TLS1
3708 *((const char **)arg)= tls_library_version;
3709#else
3710 *((char **)arg)= "Off";
3711#endif
3712 break;
3713 case MARIADB_CLIENT_VERSION:
3714 *((const char **)arg)= MARIADB_CLIENT_VERSION_STR"10.3.8";
3715 break;
3716 case MARIADB_CLIENT_VERSION_ID:
3717 *((size_t *)arg)= MARIADB_VERSION_ID100308;
3718 break;
3719 case MARIADB_CONNECTION_SERVER_VERSION:
3720 if (mysql)
3721 *((char **)arg)= mysql->server_version;
3722 else
3723 goto error;
3724 break;
3725 case MARIADB_CONNECTION_SERVER_TYPE:
3726 if (mysql)
3727 *((const char **)arg)= mariadb_connection(mysql) ? "MariaDB" : "MySQL";
3728 else
3729 goto error;
3730 break;
3731 case MARIADB_CONNECTION_SERVER_VERSION_ID:
3732 if (mysql)
3733 *((size_t *)arg)= mariadb_server_version_id(mysql);
3734 else
3735 goto error;
3736 break;
3737 case MARIADB_CONNECTION_PROTOCOL_VERSION_ID:
3738 if (mysql)
3739 *((unsigned int *)arg)= mysql->protocol_version;
3740 else
3741 goto error;
3742 break;
3743 case MARIADB_CONNECTION_MARIADB_CHARSET_INFO:
3744 if (mysql)
3745 mariadb_get_charset_info(mysql, (MY_CHARSET_INFO *)arg);
3746 else
3747 goto error;
3748 break;
3749 case MARIADB_CONNECTION_SOCKET:
3750 if (mysql)
3751 *((my_socket *)arg)= mariadb_get_socket(mysql);
3752 else
3753 goto error;
3754 break;
3755 case MARIADB_CONNECTION_TYPE:
3756 if (mysql && mysql->net.pvio)
3757 *((int *)arg)= (int)mysql->net.pvio->type;
3758 else
3759 goto error;
3760 break;
3761 case MARIADB_CONNECTION_ASYNC_TIMEOUT_MS:
3762 if (mysql && mysql->options.extension && mysql->options.extension->async_context)
3763 *((unsigned int *)arg)= mysql->options.extension->async_context->timeout_value;
3764 break;
3765 case MARIADB_CONNECTION_ASYNC_TIMEOUT:
3766 if (mysql && mysql->options.extension && mysql->options.extension->async_context)
3767 {
3768 unsigned int timeout= mysql->options.extension->async_context->timeout_value;
3769 if (timeout > UINT_MAX(2147483647 *2U +1U) - 999)
3770 *((unsigned int *)arg)= (timeout - 1)/1000 + 1;
3771 else
3772 *((unsigned int *)arg)= (timeout+999)/1000;
3773 }
3774 break;
3775 case MARIADB_CHARSET_NAME:
3776 {
3777 char *name;
3778 name= va_arg(ap, char *)__builtin_va_arg(ap, char *);
3779 if (name)
3780 *((MARIADB_CHARSET_INFO **)arg)= (MARIADB_CHARSET_INFO *)mysql_find_charset_name(name);
3781 else
3782 goto error;
3783 }
3784 break;
3785 case MARIADB_CHARSET_ID:
3786 {
3787 unsigned int nr;
3788 nr= va_arg(ap, unsigned int)__builtin_va_arg(ap, unsigned int);
3789 *((MARIADB_CHARSET_INFO **)arg)= (MARIADB_CHARSET_INFO *)mysql_find_charset_nr(nr);
3790 }
3791 break;
3792 case MARIADB_CONNECTION_SSL_CIPHER:
3793 #ifdef HAVE_TLS1
3794 if (mysql && mysql->net.pvio && mysql->net.pvio->ctls)
3795 *((char **)arg)= (char *)ma_pvio_tls_cipher(mysql->net.pvio->ctls);
3796 else
3797 #endif
3798 goto error;
3799 break;
3800 case MARIADB_CLIENT_ERRORS:
3801 *((char ***)arg)= (char **)client_errors;
3802 break;
3803 case MARIADB_CONNECTION_INFO:
3804 if (mysql)
3805 *((char **)arg)= (char *)mysql->info;
3806 else
3807 goto error;
3808 break;
3809 case MARIADB_CONNECTION_PVIO_TYPE:
3810 if (mysql && mysql->net.pvio)
3811 *((unsigned int *)arg)= (unsigned int)mysql->net.pvio->type;
3812 else
3813 goto error;
3814 break;
3815 case MARIADB_CONNECTION_SCHEMA:
3816 if (mysql)
3817 *((char **)arg)= mysql->db;
3818 else
3819 goto error;
3820 break;
3821 case MARIADB_CONNECTION_USER:
3822 if (mysql)
3823 *((char **)arg)= mysql->user;
3824 else
3825 goto error;
3826 break;
3827 case MARIADB_CONNECTION_PORT:
3828 if (mysql)
3829 *((unsigned int *)arg)= mysql->port;
3830 else
3831 goto error;
3832 break;
3833 case MARIADB_CONNECTION_UNIX_SOCKET:
3834 if (mysql)
3835 *((char **)arg)= mysql->unix_socket;
3836 else
3837 goto error;
3838 break;
3839 case MARIADB_CONNECTION_HOST:
3840 if (mysql)
3841 *((char **)arg)= mysql->host;
3842 else
3843 goto error;
3844 break;
3845 case MARIADB_CONNECTION_SERVER_STATUS:
3846 if (mysql)
3847 *((unsigned int *)arg)= mysql->server_status;
3848 else
3849 goto error;
3850 break;
3851 case MARIADB_CONNECTION_SERVER_CAPABILITIES:
3852 if (mysql)
3853 *((unsigned long *)arg)= mysql->server_capabilities;
3854 else
3855 goto error;
3856 break;
3857 case MARIADB_CONNECTION_EXTENDED_SERVER_CAPABILITIES:
3858 if (mysql)
3859 *((unsigned long *)arg)= mysql->extension->mariadb_server_capabilities;
3860 else
3861 goto error;
3862 break;
3863 case MARIADB_CONNECTION_CLIENT_CAPABILITIES:
3864 if (mysql)
3865 *((unsigned long *)arg)= mysql->client_flag;
3866 else
3867 goto error;
3868 break;
3869 default:
3870 va_end(ap)__builtin_va_end(ap);
3871 return(-1);
3872 }
3873 va_end(ap)__builtin_va_end(ap);
3874 return(0);
3875error:
3876 va_end(ap)__builtin_va_end(ap);
3877 return(-1);
3878}
3879
3880my_bool STDCALL mariadb_get_info(MYSQL *mysql, enum mariadb_value value, void *arg)
3881{
3882 return mariadb_get_infov(mysql, value, arg);
3883}
3884
3885/*
3886 Immediately aborts connection, making all subsequent read/write operations fail.
3887 Does not invalidate memory used for mysql structure, nor closes any communication
3888 channels - mysql_close is still needed.
3889 Useful to break long query, in situation sending KILL is not possible.
3890*/
3891int STDCALL mariadb_cancel(MYSQL *mysql)
3892{
3893 if (!mysql || !mysql->net.pvio || !mysql->net.pvio->methods || !mysql->net.pvio->methods->shutdown)
3894 {
3895 return 1;
3896 }
3897 else
3898 {
3899 MARIADB_PVIO *pvio = mysql->net.pvio;
3900 return pvio->methods->shutdown(pvio);
3901 }
3902}
3903
3904/* compatibility functions for MariaDB */
3905void STDCALL
3906mysql_debug(const char *debug __attribute__((unused)))
3907{
3908 return;
3909}
3910
3911/********************************************************************
3912 mysql_net_ functions - low-level API to MySQL protocol
3913*********************************************************************/
3914ulong STDCALL mysql_net_read_packet(MYSQL *mysql)
3915{
3916 return ma_net_safe_read(mysql);
3917}
3918
3919ulong STDCALL mysql_net_field_length(uchar **packet)
3920{
3921 return net_field_length(packet);
3922}
3923
3924my_bool STDCALL mysql_embedded(void)
3925{
3926#ifdef EMBEDDED_LIBRARY
3927 return 1;
3928#else
3929 return 0;
3930#endif
3931}
3932
3933MYSQL_PARAMETERS *STDCALL
3934mysql_get_parameters(void)
3935{
3936 return &mariadb_internal_parameters;
3937}
3938
3939int STDCALL mysql_reset_connection(MYSQL *mysql)
3940{
3941 int rc;
3942
3943 /* check if connection handler is active */
3944 if (IS_CONNHDLR_ACTIVE(mysql)((mysql)->extension && (mysql)->extension->conn_hdlr
)
)
3945 {
3946 if (mysql->extension->conn_hdlr->plugin && mysql->extension->conn_hdlr->plugin->reset)
3947 return(mysql->extension->conn_hdlr->plugin->reset(mysql));
3948 }
3949
3950 /* skip result sets */
3951 if (mysql->status == MYSQL_STATUS_USE_RESULT ||
3952 mysql->status == MYSQL_STATUS_GET_RESULT ||
3953 mysql->status & SERVER_MORE_RESULTS_EXIST8)
3954 {
3955 mthd_my_skip_result(mysql);
3956 mysql->status= MYSQL_STATUS_READY;
3957 }
3958
3959 rc= ma_simple_command(mysql, COM_RESET_CONNECTION, 0, 0, 0, 0);
3960 if (rc && mysql->options.reconnect)
3961 {
3962 /* There is no big sense in resetting but we need reconnect */
3963 rc= ma_simple_command(mysql, COM_RESET_CONNECTION,0,0,0,0);
3964 }
3965 if (rc)
3966 return 1;
3967
3968 /* reset the connection in all active statements */
3969 ma_invalidate_stmts(mysql, "mysql_reset_connection()");
3970 free_old_query(mysql);
3971 mysql->status= MYSQL_STATUS_READY;
3972 mysql->affected_rows= ~(my_ulonglong)0;
3973 mysql->insert_id= 0;
3974 return 0;
3975}
3976
3977#undef STDCALL
3978/* API functions for usage in dynamic plugins */
3979struct st_mariadb_api MARIADB_API=
3980{
3981 mysql_num_rows,
3982 mysql_num_fields,
3983 mysql_eof,
3984 mysql_fetch_field_direct,
3985 mysql_fetch_fields,
3986 mysql_row_tell,
3987 mysql_field_tell,
3988 mysql_field_count,
3989 mysql_more_results,
3990 mysql_next_result,
3991 mysql_affected_rows,
3992 mysql_autocommit,
3993 mysql_commit,
3994 mysql_rollback,
3995 mysql_insert_id,
3996 mysql_errno,
3997 mysql_error,
3998 mysql_info,
3999 mysql_thread_id,
4000 mysql_character_set_name,
4001 mysql_get_character_set_info,
4002 mysql_set_character_set,
4003 mariadb_get_infov,
4004 mariadb_get_info,
4005 mysql_init,
4006 mysql_ssl_set,
4007 mysql_get_ssl_cipher,
4008 mysql_change_user,
4009 mysql_real_connect,
4010 mysql_close,
4011 mysql_select_db,
4012 mysql_query,
4013 mysql_send_query,
4014 mysql_read_query_result,
4015 mysql_real_query,
4016 mysql_shutdown,
4017 mysql_dump_debug_info,
4018 mysql_refresh,
4019 mysql_kill,
4020 mysql_ping,
4021 mysql_stat,
4022 mysql_get_server_info,
4023 mysql_get_server_version,
4024 mysql_get_host_info,
4025 mysql_get_proto_info,
4026 mysql_list_dbs,
4027 mysql_list_tables,
4028 mysql_list_fields,
4029 mysql_list_processes,
4030 mysql_store_result,
4031 mysql_use_result,
4032 mysql_options,
4033 mysql_free_result,
4034 mysql_data_seek,
4035 mysql_row_seek,
4036 mysql_field_seek,
4037 mysql_fetch_row,
4038 mysql_fetch_lengths,
4039 mysql_fetch_field,
4040 mysql_escape_string,
4041 mysql_real_escape_string,
4042 mysql_thread_safe,
4043 mysql_warning_count,
4044 mysql_sqlstate,
4045 mysql_server_init,
4046 mysql_server_end,
4047 mysql_thread_end,
4048 mysql_thread_init,
4049 mysql_set_server_option,
4050 mysql_get_client_info,
4051 mysql_get_client_version,
4052 mariadb_connection,
4053 mysql_get_server_name,
4054 mariadb_get_charset_by_name,
4055 mariadb_get_charset_by_nr,
4056 mariadb_convert_string,
4057 mysql_optionsv,
4058 mysql_get_optionv,
4059 mysql_get_option,
4060 mysql_hex_string,
4061 mysql_get_socket,
4062 mysql_get_timeout_value,
4063 mysql_get_timeout_value_ms,
4064 mariadb_reconnect,
4065 mysql_stmt_init,
4066 mysql_stmt_prepare,
4067 mysql_stmt_execute,
4068 mysql_stmt_fetch,
4069 mysql_stmt_fetch_column,
4070 mysql_stmt_store_result,
4071 mysql_stmt_param_count,
4072 mysql_stmt_attr_set,
4073 mysql_stmt_attr_get,
4074 mysql_stmt_bind_param,
4075 mysql_stmt_bind_result,
4076 mysql_stmt_close,
4077 mysql_stmt_reset,
4078 mysql_stmt_free_result,
4079 mysql_stmt_send_long_data,
4080 mysql_stmt_result_metadata,
4081 mysql_stmt_param_metadata,
4082 mysql_stmt_errno,
4083 mysql_stmt_error,
4084 mysql_stmt_sqlstate,
4085 mysql_stmt_row_seek,
4086 mysql_stmt_row_tell,
4087 mysql_stmt_data_seek,
4088 mysql_stmt_num_rows,
4089 mysql_stmt_affected_rows,
4090 mysql_stmt_insert_id,
4091 mysql_stmt_field_count,
4092 mysql_stmt_next_result,
4093 mysql_stmt_more_results,
4094 mariadb_stmt_execute_direct,
4095 mysql_reset_connection
4096};
4097
4098/*
4099 * Default methods for a connection. These methods are
4100 * stored in mysql->methods and can be overwritten by
4101 * a plugin, e.g. for using another database
4102 */
4103struct st_mariadb_methods MARIADB_DEFAULT_METHODS = {
4104 /* open a connection */
4105 mthd_my_real_connect,
4106 /* close connection */
4107 mysql_close_slow_part,
4108 /* send command to server */
4109 mthd_my_send_cmd,
4110 /* skip result set */
4111 mthd_my_skip_result,
4112 /* read response packet */
4113 mthd_my_read_query_result,
4114 /* read all rows from a result set */
4115 mthd_my_read_rows,
4116 /* read one/next row */
4117 mthd_my_read_one_row,
4118 /* check if datatype is supported */
4119 mthd_supported_buffer_type,
4120 /* read response packet from prepare */
4121 mthd_stmt_read_prepare_response,
4122 /* read response from stmt execute */
4123 mthd_my_read_query_result,
4124 /* get result set metadata for a prepared statement */
4125 mthd_stmt_get_result_metadata,
4126 /* get param metadata for a prepared statement */
4127 mthd_stmt_get_param_metadata,
4128 /* read all rows (buffered) */
4129 mthd_stmt_read_all_rows,
4130 /* fetch one row (unbuffered) */
4131 mthd_stmt_fetch_row,
4132 /* store values in bind buffer */
4133 mthd_stmt_fetch_to_bind,
4134 /* skip unbuffered stmt result */
4135 mthd_stmt_flush_unbuffered,
4136 /* set error */
4137 my_set_error,
4138 /* invalidate statements */
4139 ma_invalidate_stmts,
4140 &MARIADB_API
4141};