Skip to content

Commit 1fb77c6

Browse files
committed
Only allow some functions internally/for testing
Signed-off-by: Salil Chandra <schandra107@bloomberg.net>
1 parent 20ee63c commit 1fb77c6

24 files changed

Lines changed: 116 additions & 33 deletions

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ endif()
1717

1818
option(COMDB2_TEST "Turn ON to compile with testing features" OFF)
1919
if(COMDB2_TEST)
20-
add_definitions(-DCOMDB2_TEST)
20+
add_definitions(-DCOMDB2_TEST)
21+
add_definitions(-DCDB2API_TEST)
2122
endif()
2223

2324
option(WITH_TINFO "Turn ON on platforms where tinfo library is required for cdb2sql" OFF)

cdb2api/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ include_directories(
2828
add_definitions(-DDISABLE_HOSTADDR_CACHE)
2929
add_definitions(-DSBUF2_SERVER=0)
3030

31-
if (COMDB2_TEST)
32-
add_definitions(-DCDB2API_TEST)
33-
endif()
34-
3531
if (COMDB2_BBCMAKE)
3632
include(${EXTRA_PLUGINS}/cdb2api/cdb2api.cmake)
3733
add_library(opencdb2api STATIC ${src})

cdb2api/cdb2api.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,7 @@ struct newsqlheader {
14211421
int length;
14221422
};
14231423

1424+
#ifdef CDB2API_TEST
14241425
void cdb2_set_min_retries(int min_retries)
14251426
{
14261427
if (min_retries > 0) {
@@ -1434,6 +1435,7 @@ void cdb2_set_max_retries(int max_retries)
14341435
MAX_RETRIES = max_retries;
14351436
}
14361437
}
1438+
#endif
14371439

14381440
void cdb2_hndl_set_min_retries(cdb2_hndl_tp *hndl, int min_retries)
14391441
{
@@ -6817,6 +6819,7 @@ const char *cdb2_column_name(cdb2_hndl_tp *hndl, int col)
68176819
return ret;
68186820
}
68196821

6822+
#ifdef CDB2API_TEST
68206823
int cdb2_snapshot_file(cdb2_hndl_tp *hndl, int *snapshot_file,
68216824
int *snapshot_offset)
68226825
{
@@ -6830,18 +6833,14 @@ int cdb2_snapshot_file(cdb2_hndl_tp *hndl, int *snapshot_file,
68306833
(*snapshot_offset) = hndl->snapshot_offset;
68316834
return 0;
68326835
}
6833-
6834-
void cdb2_getinfo(cdb2_hndl_tp *hndl, int *intrans, int *hasql)
6835-
{
6836-
(*intrans) = hndl->in_trans;
6837-
(*hasql) = hndl->is_hasql;
6838-
}
6836+
#endif
68396837

68406838
void cdb2_set_debug_trace(cdb2_hndl_tp *hndl)
68416839
{
68426840
hndl->debug_trace = 1;
68436841
}
68446842

6843+
#ifdef CDB2API_TEST
68456844
void cdb2_dump_ports(cdb2_hndl_tp *hndl, FILE *out)
68466845
{
68476846
int i;
@@ -6875,6 +6874,7 @@ const char *cdb2_cnonce(cdb2_hndl_tp *hndl)
68756874

68766875
return hndl->cnonce.str;
68776876
}
6877+
#endif
68786878

68796879
const char *cdb2_errstr(cdb2_hndl_tp *hndl)
68806880
{

cdb2api/cdb2api.h

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ void cdb2_set_comdb2db_config(char *cfg_file);
213213
void cdb2_set_comdb2db_info(char *cfg_info);
214214
void cdb2_set_sockpool(const char *sp_path);
215215
void cdb2_set_identity(cdb2_hndl_tp *hndl, const void *identity);
216-
int cdb2_get_comdb2db(char **comdb2db_name, char **comdb2db_class);
217216

218217
int cdb2_open(cdb2_hndl_tp **hndl, const char *dbname, const char *type, int flags);
219218

@@ -232,16 +231,6 @@ int cdb2_column_type(cdb2_hndl_tp *hndl, int col);
232231
int cdb2_column_size(cdb2_hndl_tp *hndl, int col);
233232
void *cdb2_column_value(cdb2_hndl_tp *hndl, int col);
234233
const char *cdb2_errstr(cdb2_hndl_tp *hndl);
235-
const char *cdb2_cnonce(cdb2_hndl_tp *hndl);
236-
void cdb2_set_debug_trace(cdb2_hndl_tp *hndl);
237-
void cdb2_dump_ports(cdb2_hndl_tp *hndl, FILE *out);
238-
void cdb2_cluster_info(cdb2_hndl_tp *hndl, char **cluster, int *ports, int max, int *count);
239-
int cdb2_snapshot_file(cdb2_hndl_tp *hndl, int *file, int *offset);
240-
void cdb2_getinfo(cdb2_hndl_tp *hndl, int *intrans, int *hasql);
241-
void cdb2_set_max_retries(int max_retries);
242-
void cdb2_set_min_retries(int min_retries);
243-
void cdb2_hndl_set_max_retries(cdb2_hndl_tp *hndl, int max_retries);
244-
void cdb2_hndl_set_min_retries(cdb2_hndl_tp *hndl, int min_retries);
245234

246235
int cdb2_bind_param(cdb2_hndl_tp *hndl, const char *name, int type,
247236
const void *varaddr, int length);
@@ -251,19 +240,15 @@ int cdb2_bind_array(cdb2_hndl_tp *, const char *, cdb2_coltype, const void *, si
251240
int cdb2_bind_array_index(cdb2_hndl_tp *, int, cdb2_coltype, const void *, size_t, size_t);
252241
int cdb2_clearbindings(cdb2_hndl_tp *hndl);
253242

243+
/* SOCKPOOL CLIENT APIS */
244+
void cdb2_enable_sockpool();
245+
void cdb2_disable_sockpool();
246+
254247
const char *cdb2_dbname(cdb2_hndl_tp *hndl);
255248
const char *cdb2_host(cdb2_hndl_tp *hndl);
256249

257-
void cdb2_enable_sockpool(void);
258-
void cdb2_disable_sockpool(void);
259-
260-
int cdb2_init_ssl(int init_libssl, int init_libcrypto);
261-
int cdb2_is_ssl_encrypted(cdb2_hndl_tp *hndl);
262-
263250
int cdb2_clear_ack(cdb2_hndl_tp *hndl);
264251

265-
char *cdb2_string_escape(cdb2_hndl_tp *hndl, const char *str);
266-
267252
// on success, `*value` points to dynamically allocated memory
268253
// that must be freed by the caller.
269254
int cdb2_get_property(cdb2_hndl_tp *hndl, const char *key, char **value);
@@ -334,6 +319,10 @@ int cdb2_register_retry_callback(cdb2_hndl_tp *hndl, RETRY_CALLBACK f);
334319
void cdb2_identity_create();
335320
void cdb2_identity_destroy(int is_task_exit);
336321
int cdb2_identity_valid();
322+
int cdb2_init_ssl(int init_libssl, int init_libcrypto);
323+
int cdb2_is_ssl_encrypted(cdb2_hndl_tp *hndl);
324+
325+
char *cdb2_string_escape(cdb2_hndl_tp *hndl, const char *str);
337326

338327
struct cdb2_identity {
339328
void (*resetIdentity_start)();

cdb2api/cdb2api_int.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#include <sbuf2.h>
2626
#include "cdb2api.h"
2727

28+
#if defined __cplusplus
29+
extern "C" {
30+
#endif
31+
2832
SBUF2 *cdb2_socket_pool_get(cdb2_hndl_tp *hndl, const char *typestr, int dbnum, int *port, int *was_from_local_cache);
2933
// use this one for fastsql since client_sbuf and server_sbuf are different
3034
int cdb2_socket_pool_get_fd(cdb2_hndl_tp *hndl, const char *typestr, int dbnum, int *port);
@@ -38,6 +42,13 @@ int cdb2_read_line(char *line, int maxlen, SBUF2 *s, const char *buf, int *chrno
3842

3943
void cdb2_setIdentityBlob(cdb2_hndl_tp *hndl, void *id);
4044

45+
void cdb2_hndl_set_max_retries(cdb2_hndl_tp *hndl, int max_retries);
46+
void cdb2_hndl_set_min_retries(cdb2_hndl_tp *hndl, int min_retries);
47+
48+
int cdb2_get_comdb2db(char **comdb2db_name, char **comdb2db_class);
49+
50+
void cdb2_set_debug_trace(cdb2_hndl_tp *hndl);
51+
4152
#ifndef WITH_DL_LIBS
4253
#define WITH_DL_LIBS 0
4354
#endif
@@ -47,4 +58,8 @@ void cdb2_set_install_libs(void (*ptr)(const char *));
4758
void cdb2_set_uninstall_libs(void (*ptr)(const char *));
4859
#endif
4960

61+
#if defined __cplusplus
62+
}
63+
#endif
64+
5065
#endif

cdb2api/cdb2api_test.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ struct cdb2_hndl;
8282
const char *get_default_cluster(void);
8383
const char *get_default_cluster_hndl(struct cdb2_hndl *);
8484

85+
void cdb2_set_max_retries(int max_retries);
86+
void cdb2_set_min_retries(int min_retries);
87+
88+
void cdb2_cluster_info(cdb2_hndl_tp *hndl, char **cluster, int *ports, int max, int *count);
89+
const char *cdb2_cnonce(cdb2_hndl_tp *hndl);
90+
int cdb2_snapshot_file(cdb2_hndl_tp *hndl, int *file, int *offset);
91+
void cdb2_dump_ports(cdb2_hndl_tp *hndl, FILE *out);
92+
8593
#if defined __cplusplus
8694
}
8795
#endif /* __cplusplus */

db/machcache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <string.h>
2020
#include <sys_wrap.h>
2121
#include <cdb2api.h>
22+
#include <cdb2api_int.h>
2223
#include <machcache.h>
2324

2425
struct class_machs {

db/phys_rep.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "phys_rep.h"
1818
#include <cdb2api.h>
19+
#include <cdb2api_int.h>
1920
#include <stdio.h>
2021
#include <stdlib.h>
2122
#include <time.h>

db/reverse_conn.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "cdb2_constants.h"
2626
#include "comdb2.h"
2727
#include "cdb2api.h"
28+
#include "cdb2api_int.h"
2829
#include "list.h"
2930
#include "logmsg.h"
3031
#include "net_int.h"

db/sqllogfill.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
#include <sqllogfill.h>
1717
#include <cdb2api.h>
18+
#include <cdb2api_int.h>
1819
#include <sys_wrap.h>
1920
#include <parse_lsn.h>
2021
#include <unistd.h>

0 commit comments

Comments
 (0)