Clone of PhatAC @ https://github.com/floaterxk/PhatAC

sql_common.h 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #ifndef SQL_COMMON_INCLUDED
  2. #define SQL_COMMON_INCLUDED
  3. /* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; version 2 of the License.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  14. #define SQL_COMMON_INCLUDED
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <mysql.h>
  19. #include <hash.h>
  20. extern const char *unknown_sqlstate;
  21. extern const char *cant_connect_sqlstate;
  22. extern const char *not_error_sqlstate;
  23. /*
  24. Free all memory allocated in MYSQL handle except the
  25. current options.
  26. */
  27. void mysql_close_free(MYSQL *mysql);
  28. /*
  29. Clear connection options stored in MYSQL handle and
  30. free memory used by them.
  31. */
  32. void mysql_close_free_options(MYSQL *mysql);
  33. /**
  34. The structure is used to hold the state change information
  35. received from the server. LIST functions are used for manipulation
  36. of the members of the structure.
  37. */
  38. typedef struct st_session_track_info_node {
  39. /** head_node->data is a LEX_STRING which contains the variable name. */
  40. LIST *head_node;
  41. LIST *current_node;
  42. } STATE_INFO_NODE;
  43. /**
  44. Store the change info received from the server in an array of linked lists
  45. with STATE_INFO_NODE elements (one per state type).
  46. */
  47. typedef struct st_session_track_info {
  48. /** Array of STATE_NODE_INFO elements (one per state type). */
  49. struct st_session_track_info_node info_list[SESSION_TRACK_END + 1];
  50. } STATE_INFO;
  51. /*
  52. Access to MYSQL::extension member.
  53. Note: functions mysql_extension_{init,free}() are defined
  54. in client.c.
  55. */
  56. struct st_mysql_trace_info;
  57. typedef struct st_mysql_extension {
  58. struct st_mysql_trace_info *trace_data;
  59. struct st_session_track_info state_change;
  60. } MYSQL_EXTENSION;
  61. /* "Constructor/destructor" for MYSQL extension structure. */
  62. struct st_mysql_extension* mysql_extension_init(struct st_mysql*);
  63. void mysql_extension_free(struct st_mysql_extension*);
  64. /*
  65. Note: Allocated extension structure is freed in mysql_close_free()
  66. called by mysql_close().
  67. */
  68. #define MYSQL_EXTENSION_PTR(H) \
  69. ( \
  70. (struct st_mysql_extension*) \
  71. ( (H)->extension ? \
  72. (H)->extension : ((H)->extension= mysql_extension_init(H)) \
  73. ) \
  74. )
  75. struct st_mysql_options_extention {
  76. char *plugin_dir;
  77. char *default_auth;
  78. char *ssl_crl; /* PEM CRL file */
  79. char *ssl_crlpath; /* PEM directory of CRL-s? */
  80. HASH connection_attributes;
  81. char *server_public_key_path;
  82. size_t connection_attributes_length;
  83. my_bool enable_cleartext_plugin;
  84. my_bool unused0; /* Former ssl_enforce */
  85. char *tls_version; /* TLS version option */
  86. long ssl_ctx_flags; /* SSL ctx options flag */
  87. unsigned int ssl_mode;
  88. };
  89. typedef struct st_mysql_methods
  90. {
  91. my_bool (*read_query_result)(MYSQL *mysql);
  92. my_bool (*advanced_command)(MYSQL *mysql,
  93. enum enum_server_command command,
  94. const unsigned char *header,
  95. size_t header_length,
  96. const unsigned char *arg,
  97. size_t arg_length,
  98. my_bool skip_check,
  99. MYSQL_STMT *stmt);
  100. MYSQL_DATA *(*read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
  101. unsigned int fields);
  102. MYSQL_RES * (*use_result)(MYSQL *mysql);
  103. void (*fetch_lengths)(unsigned long *to,
  104. MYSQL_ROW column, unsigned int field_count);
  105. void (*flush_use_result)(MYSQL *mysql, my_bool flush_all_results);
  106. int (*read_change_user_result)(MYSQL *mysql);
  107. #if !defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY)
  108. MYSQL_FIELD * (*list_fields)(MYSQL *mysql);
  109. my_bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
  110. int (*stmt_execute)(MYSQL_STMT *stmt);
  111. int (*read_binary_rows)(MYSQL_STMT *stmt);
  112. int (*unbuffered_fetch)(MYSQL *mysql, char **row);
  113. void (*free_embedded_thd)(MYSQL *mysql);
  114. const char *(*read_statistics)(MYSQL *mysql);
  115. my_bool (*next_result)(MYSQL *mysql);
  116. int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
  117. void (*free_rows)(MYSQL_DATA *cur);
  118. #endif
  119. } MYSQL_METHODS;
  120. #define simple_command(mysql, command, arg, length, skip_check) \
  121. ((mysql)->methods \
  122. ? (*(mysql)->methods->advanced_command)(mysql, command, 0, \
  123. 0, arg, length, skip_check, NULL) \
  124. : (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), 1))
  125. #define stmt_command(mysql, command, arg, length, stmt) \
  126. ((mysql)->methods \
  127. ? (*(mysql)->methods->advanced_command)(mysql, command, 0, \
  128. 0, arg, length, 1, stmt) \
  129. : (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), 1))
  130. extern CHARSET_INFO *default_client_charset_info;
  131. MYSQL_FIELD *unpack_fields(MYSQL *mysql, MYSQL_ROWS *data,MEM_ROOT *alloc,
  132. uint fields, my_bool default_value,
  133. uint server_capabilities);
  134. MYSQL_FIELD * cli_read_metadata_ex(MYSQL *mysql, MEM_ROOT *alloc,
  135. unsigned long field_count,
  136. unsigned int fields);
  137. MYSQL_FIELD * cli_read_metadata(MYSQL *mysql, unsigned long field_count,
  138. unsigned int fields);
  139. void free_rows(MYSQL_DATA *cur);
  140. void free_old_query(MYSQL *mysql);
  141. void end_server(MYSQL *mysql);
  142. my_bool mysql_reconnect(MYSQL *mysql);
  143. void mysql_read_default_options(struct st_mysql_options *options,
  144. const char *filename,const char *group);
  145. my_bool
  146. cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
  147. const unsigned char *header, size_t header_length,
  148. const unsigned char *arg, size_t arg_length,
  149. my_bool skip_check, MYSQL_STMT *stmt);
  150. unsigned long cli_safe_read(MYSQL *mysql, my_bool *is_data_packet);
  151. unsigned long cli_safe_read_with_ok(MYSQL *mysql, my_bool parse_ok,
  152. my_bool *is_data_packet);
  153. void net_clear_error(NET *net);
  154. void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net);
  155. void set_stmt_error(MYSQL_STMT *stmt, int errcode, const char *sqlstate,
  156. const char *err);
  157. void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate);
  158. void set_mysql_extended_error(MYSQL *mysql, int errcode, const char *sqlstate,
  159. const char *format, ...);
  160. /* client side of the pluggable authentication */
  161. struct st_plugin_vio_info;
  162. void mpvio_info(Vio *vio, struct st_plugin_vio_info *info);
  163. int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
  164. const char *data_plugin, const char *db);
  165. int mysql_client_plugin_init();
  166. void mysql_client_plugin_deinit();
  167. struct st_mysql_client_plugin;
  168. extern struct st_mysql_client_plugin *mysql_client_builtins[];
  169. uchar * send_client_connect_attrs(MYSQL *mysql, uchar *buf);
  170. extern my_bool libmysql_cleartext_plugin_enabled;
  171. void read_ok_ex(MYSQL *mysql, unsigned long len);
  172. #ifdef __cplusplus
  173. }
  174. #endif
  175. #define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41)
  176. #endif /* SQL_COMMON_INCLUDED */