1 /* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License, version 2.0, 5 as published by the Free Software Foundation. 6 7 This program is also distributed with certain software (including 8 but not limited to OpenSSL) that is licensed under separate terms, 9 as designated in a particular file or component or in included license 10 documentation. The authors of MySQL hereby grant you an additional 11 permission to link the program and your derivative works with the 12 separately licensed software that they have included with MySQL. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License, version 2.0, for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software Foundation, 21 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ 22 23 #ifndef XA_H_INCLUDED 24 #define XA_H_INCLUDED 25 26 #include <string.h> 27 #include <sys/types.h> 28 29 #include "mysqld.h" 30 #include "m_string.h" 31 #include "my_dbug.h" 32 #include "my_global.h" 33 #include "sql_cmd.h" // Sql_cmd 34 35 typedef ulonglong my_xid; // this line is the same as in log_event.h 36 #define XIDDATASIZE 128 37 #define MYSQL_XID_PREFIX "MySQLXid" 38 #define MYSQL_XID_PREFIX_LEN 8 39 #define MYSQL_XID_OFFSET (MYSQL_XID_PREFIX_LEN+sizeof(server_id)) 40 #define MYSQL_XID_GTRID_LEN (MYSQL_XID_OFFSET+sizeof(my_xid)) 41 42 /** 43 struct xid_t is binary compatible with the XID structure as 44 in the X/Open CAE Specification, Distributed Transaction Processing: 45 The XA Specification, X/Open Company Ltd., 1991. 46 http://www.opengroup.org/bookstore/catalog/c193.htm 47 48 @see MYSQL_XID in mysql/plugin.h 49 */ 50 struct xid_t { 51 long formatID; 52 long gtrid_length; 53 long bqual_length; 54 char data[XIDDATASIZE]; // not \0-terminated ! 55 xid_txid_t56 xid_t() {} /* Remove gcc warning */ eqxid_t57 bool eq(struct xid_t *xid) 58 { return eq(xid->gtrid_length, xid->bqual_length, xid->data); } eqxid_t59 bool eq(long g, long b, const char *d) 60 { return g == gtrid_length && b == bqual_length && !memcmp(d, data, g+b); } setxid_t61 void set(struct xid_t *xid) 62 { memcpy(this, xid, xid->length()); } setxid_t63 void set(long f, const char *g, long gl, const char *b, long bl) 64 { 65 formatID= f; 66 memcpy(data, g, gtrid_length= gl); 67 memcpy(data+gl, b, bqual_length= bl); 68 } setxid_t69 void set(ulonglong xid) 70 { 71 my_xid tmp; 72 formatID= 1; 73 set(MYSQL_XID_PREFIX_LEN, 0, MYSQL_XID_PREFIX); 74 memcpy(data+MYSQL_XID_PREFIX_LEN, &server_id, sizeof(server_id)); 75 tmp= xid; 76 memcpy(data+MYSQL_XID_OFFSET, &tmp, sizeof(tmp)); 77 gtrid_length=MYSQL_XID_GTRID_LEN; 78 } setxid_t79 void set(long g, long b, const char *d) 80 { 81 formatID= 1; 82 gtrid_length= g; 83 bqual_length= b; 84 memcpy(data, d, g+b); 85 } is_nullxid_t86 bool is_null() { return formatID == -1; } nullxid_t87 void null() { formatID= -1; } quick_get_my_xidxid_t88 my_xid quick_get_my_xid() 89 { 90 my_xid tmp; 91 memcpy(&tmp, data+MYSQL_XID_OFFSET, sizeof(tmp)); 92 return tmp; 93 } get_my_xidxid_t94 my_xid get_my_xid() 95 { 96 return gtrid_length == MYSQL_XID_GTRID_LEN && bqual_length == 0 && 97 !memcmp(data, MYSQL_XID_PREFIX, MYSQL_XID_PREFIX_LEN) ? 98 quick_get_my_xid() : 0; 99 } lengthxid_t100 uint length() 101 { 102 return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+ 103 gtrid_length+bqual_length; 104 } keyxid_t105 uchar *key() 106 { 107 return (uchar *)>rid_length; 108 } key_lengthxid_t109 uint key_length() 110 { 111 return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length; 112 } 113 }; 114 typedef struct xid_t XID; 115 #endif 116