CUBRID Engine  latest
cas_protocol.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * cas_protocol.h -
22  */
23 
24 #ifndef _CAS_PROTOCOL_H_
25 #define _CAS_PROTOCOL_H_
26 
27 #ifdef __cplusplus
28 extern "C"
29 {
30 #endif
31 
32 #ident "$Id$"
33 
34 #define SRV_CON_CLIENT_INFO_SIZE 10
35 #define SRV_CON_CLIENT_MAGIC_LEN 5
36 #define SRV_CON_CLIENT_MAGIC_STR "CUBRK"
37 #define SRV_CON_CLIENT_MAGIC_STR_SSL "CUBRS"
38 #define SRV_CON_MSG_IDX_CLIENT_TYPE 5
39 
40 #define IS_SSL_CLIENT(driver_info) \
41  (strncmp (driver_info, SRV_CON_CLIENT_MAGIC_STR_SSL, SRV_CON_CLIENT_MAGIC_LEN) == 0)
42 
43 /* 8th and 9th-byte (index 7 and 8) are reserved for backward compatibility.
44  * 8.4.0 patch 1 or earlier versions hold minor and patch version on them.
45  */
46 #define SRV_CON_MSG_IDX_PROTO_VERSION 6
47 #define SRV_CON_MSG_IDX_FUNCTION_FLAG 7
48 #define SRV_CON_MSG_IDX_RESERVED2 8
49 /* For backward compatibility */
50 #define SRV_CON_MSG_IDX_MAJOR_VER (SRV_CON_MSG_IDX_PROTO_VERSION)
51 #define SRV_CON_MSG_IDX_MINOR_VER (SRV_CON_MSG_IDX_FUNCTION_FLAG)
52 #define SRV_CON_MSG_IDX_PATCH_VER (SRV_CON_MSG_IDX_RESERVED2)
53 
54 #define SRV_CON_DBNAME_SIZE 32
55 #define SRV_CON_DBUSER_SIZE 32
56 #define SRV_CON_DBPASSWD_SIZE 32
57 #define SRV_CON_URL_SIZE 512
58 #define SRV_CON_DBSESS_ID_SIZE 20
59 #define SRV_CON_VER_STR_MAX_SIZE 20
60 
61 #define SRV_CON_DB_INFO_SIZE \
62  (SRV_CON_DBNAME_SIZE + SRV_CON_DBUSER_SIZE + SRV_CON_DBPASSWD_SIZE + \
63  SRV_CON_URL_SIZE + SRV_CON_DBSESS_ID_SIZE)
64 #define SRV_CON_DB_INFO_SIZE_PRIOR_8_4_0 \
65  (SRV_CON_DBNAME_SIZE + SRV_CON_DBUSER_SIZE + SRV_CON_DBPASSWD_SIZE + \
66  SRV_CON_URL_SIZE)
67 #define SRV_CON_DB_INFO_SIZE_PRIOR_8_2_0 \
68  (SRV_CON_DBNAME_SIZE + SRV_CON_DBUSER_SIZE + SRV_CON_DBPASSWD_SIZE)
69 
70  typedef enum
71  {
82 
83  typedef enum
84  {
88 
89  typedef enum
90  {
95  } CAS_INFO_TYPE;
96 
97  typedef enum
98  {
103  } CAS_CHANGE_MODE;
104 
105 #define CAS_INFO_FLAG_MASK_AUTOCOMMIT 0x01
106 #define CAS_INFO_FLAG_MASK_FORCE_OUT_TRAN 0x02
107 #define CAS_INFO_FLAG_MASK_NEW_SESSION_ID 0x04
108 
109 #define CAS_INFO_SIZE (4)
110 #define CAS_INFO_RESERVED_DEFAULT (-1)
111 
112 #define MSG_HEADER_INFO_SIZE CAS_INFO_SIZE
113 #define MSG_HEADER_MSG_SIZE ((int) sizeof(int))
114 #define MSG_HEADER_SIZE (MSG_HEADER_INFO_SIZE + MSG_HEADER_MSG_SIZE)
115 
116 #define BROKER_INFO_SIZE 8
117 #define BROKER_RENEWED_ERROR_CODE 0x80
118 #define BROKER_SUPPORT_HOLDABLE_RESULT 0x40
119 /* Do not remove or rename BROKER_RECONNECT_WHEN_SERVER_DOWN */
120 #define BROKER_RECONNECT_WHEN_SERVER_DOWN 0x20
121 
122 /* For backward compatibility */
123 #define BROKER_INFO_MAJOR_VERSION (BROKER_INFO_PROTO_VERSION)
124 #define BROKER_INFO_MINOR_VERSION (BROKER_INFO_FUNCTION_FLAG)
125 #define BROKER_INFO_PATCH_VERSION (BROKER_INFO_RESERVED2)
126 #define BROKER_INFO_RESERVED (BROKER_INFO_RESERVED3)
127 
128 #define CAS_PID_SIZE 4
129 #define SESSION_ID_SIZE 4
130 #define DRIVER_SESSION_SIZE SRV_CON_DBSESS_ID_SIZE
131 #define CAS_CONNECTION_REPLY_SIZE_PRIOR_PROTOCOL_V3 (CAS_PID_SIZE + BROKER_INFO_SIZE + SESSION_ID_SIZE)
132 #define CAS_CONNECTION_REPLY_SIZE_V3 (CAS_PID_SIZE + BROKER_INFO_SIZE + DRIVER_SESSION_SIZE)
133 #define CAS_CONNECTION_REPLY_SIZE_V4 (CAS_PID_SIZE + CAS_PID_SIZE + BROKER_INFO_SIZE + DRIVER_SESSION_SIZE)
134 #define CAS_CONNECTION_REPLY_SIZE CAS_CONNECTION_REPLY_SIZE_V4
135 
136 #define CAS_KEEP_CONNECTION_ON 1
137 
138 #define CAS_GET_QUERY_INFO_PLAN 1
139 
140 #define CAS_STATEMENT_POOLING_OFF 0
141 #define CAS_STATEMENT_POOLING_ON 1
142 
143 #define CCI_PCONNECT_OFF 0
144 #define CCI_PCONNECT_ON 1
145 
146 #define CAS_REQ_HEADER_JDBC "JDBC"
147 #define CAS_REQ_HEADER_ODBC "ODBC"
148 #define CAS_REQ_HEADER_PHP "PHP"
149 #define CAS_REQ_HEADER_OLEDB "OLEDB"
150 #define CAS_REQ_HEADER_CCI "CCI"
151 
152 #define SHARD_ID_INVALID (-1)
153 #define SHARD_ID_UNSUPPORTED (-2)
154 
155 /* db_name used by client's broker health checker */
156 #define HEALTH_CHECK_DUMMY_DB "___health_check_dummy_db___"
157 
159  {
204 
205  /* Whenever you want to introduce a new function code, you must add a corresponding function entry to
206  * server_fn_table of both CUBRID and (MySQL, Oracle). */
208 
209  /* function code list of protocol version V2 - 9.0.0.xxxx */
212  };
214 
216  {
217  PROTOCOL_V0 = 0, /* old protocol */
218  PROTOCOL_V1 = 1, /* query_timeout and query_cancel */
219  PROTOCOL_V2 = 2, /* send columns meta-data with the result for executing */
220  PROTOCOL_V3 = 3, /* session information extend with server session key */
221  PROTOCOL_V4 = 4, /* send as_index to driver */
222  PROTOCOL_V5 = 5, /* shard feature, fetch end flag */
223  PROTOCOL_V6 = 6, /* cci/cas4m support unsigned integer type */
224  PROTOCOL_V7 = 7, /* timezone types, to pin xasl entry for retry */
225  PROTOCOL_V8 = 8, /* JSON type */
226  PROTOCOL_V9 = 9, /* cas health check: get function status */
227  PROTOCOL_V10 = 10, /* Secure Broker/CAS using SSL */
229  };
231 
233  {
242  };
244 
246  {
256  };
258 
260  {
267  };
268  typedef enum t_dbms_type T_DBMS_TYPE;
269 #define IS_CONNECTED_TO_PROXY(type) \
270  ((type) == CAS_PROXY_DBMS_CUBRID \
271  || (type) == CAS_PROXY_DBMS_MYSQL \
272  || (type) == CAS_PROXY_DBMS_ORACLE)
273 
274 #define IS_VALID_CAS_FC(fc) \
275  (fc >= CAS_FC_END_TRAN && fc < CAS_FC_MAX)
276 
277 /* Current protocol version */
278 #define CAS_PROTOCOL_VERSION ((unsigned char)(CURRENT_PROTOCOL))
279 
280 /* Indicates version variable holds CAS protocol version. */
281 #define CAS_PROTO_INDICATOR (0x40)
282 
283 /* Make a version to be used in CAS. */
284 #define CAS_PROTO_MAKE_VER(VER) \
285  ((T_BROKER_VERSION) (CAS_PROTO_INDICATOR << 24 | (VER)))
286 #define CAS_PROTO_CURRENT_VER \
287  ((T_BROKER_VERSION) CAS_PROTO_MAKE_VER(CURRENT_PROTOCOL))
288 
289 #define DOES_CLIENT_MATCH_THE_PROTOCOL(CLIENT, MATCH) ((CLIENT) == CAS_PROTO_MAKE_VER((MATCH)))
290 #define DOES_CLIENT_UNDERSTAND_THE_PROTOCOL(CLIENT, REQUIRE) ((CLIENT) >= CAS_PROTO_MAKE_VER((REQUIRE)))
291 
292 /* Pack/unpack CAS protocol version to/from network. */
293 #define CAS_PROTO_VER_MASK (0x3F)
294 #define CAS_PROTO_PACK_NET_VER(VER) \
295  (char)((char)CAS_PROTO_INDICATOR | (char)(VER))
296 #define CAS_PROTO_UNPACK_NET_VER(VER) \
297  (CAS_PROTO_MAKE_VER(CAS_PROTO_VER_MASK & (char)(VER)))
298 #define CAS_PROTO_PACK_CURRENT_NET_VER \
299  CAS_PROTO_PACK_NET_VER(CURRENT_PROTOCOL)
300 
301 #define CAS_CONV_ERROR_TO_OLD(V) (V + 9000)
302 #define CAS_CONV_ERROR_TO_NEW(V) (V - 9000)
303 
304 #define CAS_MAKE_VER(MAJOR, MINOR, PATCH) \
305  ((T_BROKER_VERSION) (((MAJOR) << 16) | ((MINOR) << 8) | (PATCH)))
306 
307 #define CAS_MAKE_PROTO_VER(DRIVER_INFO) \
308  (((DRIVER_INFO)[SRV_CON_MSG_IDX_PROTO_VERSION]) & CAS_PROTO_INDICATOR) ? \
309  CAS_PROTO_UNPACK_NET_VER ((DRIVER_INFO)[SRV_CON_MSG_IDX_PROTO_VERSION]) : \
310  CAS_MAKE_VER ((DRIVER_INFO)[SRV_CON_MSG_IDX_MAJOR_VER], \
311  (DRIVER_INFO)[SRV_CON_MSG_IDX_MINOR_VER], \
312  (DRIVER_INFO)[SRV_CON_MSG_IDX_PATCH_VER])
313 
314 #define CAS_TYPE_FIRST_BYTE_PROTOCOL_MASK 0x80
315 
316 /* For backward compatibility */
317 #define CAS_VER_TO_MAJOR(VER) ((int) (((VER) >> 16) & 0xFF))
318 #define CAS_VER_TO_MINOR(VER) ((int) (((VER) >> 8) & 0xFF))
319 #define CAS_VER_TO_PATCH(VER) ((int) ((VER) & 0xFF))
320 #define CAS_PROTO_TO_VER_STR(MSG_P, VER) \
321  do { \
322  switch (VER) \
323  { \
324  case PROTOCOL_V1: \
325  *((char **) (MSG_P)) = (char *) "8.4.1"; \
326  break; \
327  case PROTOCOL_V2: \
328  *((char **) (MSG_P)) = (char *) "9.0.0"; \
329  break; \
330  case PROTOCOL_V3: \
331  *((char **) (MSG_P)) = (char *) "8.4.3"; \
332  break; \
333  case PROTOCOL_V4: \
334  *((char **) (MSG_P)) = (char *) "9.1.0"; \
335  break; \
336  default: \
337  *((char **) (MSG_P)) = (char *) ""; \
338  break; \
339  } \
340  } while (0)
341 
342  typedef int T_BROKER_VERSION;
343 
344  extern const char *cas_bi_get_broker_info (void);
345  extern char cas_bi_get_dbms_type (void);
346  extern void cas_bi_set_dbms_type (const char dbms_type);
347  extern void cas_bi_set_keep_connection (const char keep_connection);
348  extern char cas_bi_get_keep_connection (void);
349  extern void cas_bi_set_statement_pooling (const char statement_pooling);
350  extern char cas_bi_get_statement_pooling (void);
351  extern void cas_bi_set_cci_pconnect (const char cci_pconnect);
352  extern char cas_bi_get_cci_pconnect (void);
353  extern void cas_bi_set_protocol_version (const char protocol_version);
354  extern char cas_bi_get_protocol_version (void);
355  extern void cas_bi_set_renewed_error_code (const bool renewed_error_code);
356  extern bool cas_bi_get_renewed_error_code (void);
357  extern bool cas_di_understand_renewed_error_code (const char *driver_info);
358  extern void cas_bi_make_broker_info (char *broker_info, char dbms_type, char statement_pooling, char cci_pconnect);
359 #ifdef __cplusplus
360 }
361 #endif
362 
363 #endif /* _CAS_PROTOCOL_H_ */
char cas_bi_get_protocol_version(void)
Definition: cas_meta.c:130
enum t_dbms_type T_DBMS_TYPE
Definition: cas_protocol.h:268
enum t_cas_func_code T_CAS_FUNC_CODE
Definition: cas_protocol.h:213
enum t_broker_info_pos T_BROKER_INFO_POS
Definition: cas_protocol.h:243
void cas_bi_set_keep_connection(const char keep_connection)
Definition: cas_meta.c:70
bool cas_bi_get_renewed_error_code(void)
Definition: cas_meta.c:197
enum t_driver_info_pos T_DRIVER_INFO_POS
Definition: cas_protocol.h:257
void cas_bi_set_renewed_error_code(const bool renewed_error_code)
Definition: cas_meta.c:184
char cas_bi_get_statement_pooling(void)
Definition: cas_meta.c:97
bool cas_di_understand_renewed_error_code(const char *driver_info)
Definition: cas_meta.c:203
t_driver_info_pos
Definition: cas_protocol.h:245
static char broker_info[BROKER_INFO_SIZE]
Definition: cas_meta.c:34
void cas_bi_set_dbms_type(const char dbms_type)
Definition: cas_meta.c:58
t_broker_info_pos
Definition: cas_protocol.h:232
const char * cas_bi_get_broker_info(void)
Definition: cas_meta.c:52
void cas_bi_set_statement_pooling(const char statement_pooling)
Definition: cas_meta.c:82
void cas_bi_set_protocol_version(const char protocol_version)
Definition: cas_meta.c:124
enum t_cas_protocol T_CAS_PROTOCOL
Definition: cas_protocol.h:230
CAS_CHANGE_MODE
Definition: cas_protocol.h:97
t_cas_func_code
Definition: cas_protocol.h:158
CAS_INFO_TYPE
Definition: cas_protocol.h:89
char cas_bi_get_keep_connection(void)
Definition: cas_meta.c:76
int T_BROKER_VERSION
Definition: cas_protocol.h:342
void cas_bi_set_cci_pconnect(const char cci_pconnect)
Definition: cas_meta.c:103
void cas_bi_make_broker_info(char *broker_info, char dbms_type, char statement_pooling, char cci_pconnect)
Definition: cas_meta.c:214
char cas_bi_get_dbms_type(void)
Definition: cas_meta.c:64
t_dbms_type
Definition: cas_protocol.h:259
char cas_bi_get_cci_pconnect(void)
Definition: cas_meta.c:118
CAS_CLIENT_TYPE
Definition: cas_protocol.h:70
CAS_INFO_STATUS_TYPE
Definition: cas_protocol.h:83
t_cas_protocol
Definition: cas_protocol.h:215