Skip to content

Commit 0b415ac

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

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
@@ -1425,6 +1425,7 @@ struct newsqlheader {
14251425
int length;
14261426
};
14271427

1428+
#ifdef CDB2API_TEST
14281429
void cdb2_set_min_retries(int min_retries)
14291430
{
14301431
if (min_retries > 0) {
@@ -1438,6 +1439,7 @@ void cdb2_set_max_retries(int max_retries)
14381439
MAX_RETRIES = max_retries;
14391440
}
14401441
}
1442+
#endif
14411443

14421444
void cdb2_hndl_set_min_retries(cdb2_hndl_tp *hndl, int min_retries)
14431445
{
@@ -6838,6 +6840,7 @@ const char *cdb2_column_name(cdb2_hndl_tp *hndl, int col)
68386840
return ret;
68396841
}
68406842

6843+
#ifdef CDB2API_TEST
68416844
int cdb2_snapshot_file(cdb2_hndl_tp *hndl, int *snapshot_file,
68426845
int *snapshot_offset)
68436846
{
@@ -6851,18 +6854,14 @@ int cdb2_snapshot_file(cdb2_hndl_tp *hndl, int *snapshot_file,
68516854
(*snapshot_offset) = hndl->snapshot_offset;
68526855
return 0;
68536856
}
6854-
6855-
void cdb2_getinfo(cdb2_hndl_tp *hndl, int *intrans, int *hasql)
6856-
{
6857-
(*intrans) = hndl->in_trans;
6858-
(*hasql) = hndl->is_hasql;
6859-
}
6857+
#endif
68606858

68616859
void cdb2_set_debug_trace(cdb2_hndl_tp *hndl)
68626860
{
68636861
hndl->debug_trace = 1;
68646862
}
68656863

6864+
#ifdef CDB2API_TEST
68666865
void cdb2_dump_ports(cdb2_hndl_tp *hndl, FILE *out)
68676866
{
68686867
int i;
@@ -6896,6 +6895,7 @@ const char *cdb2_cnonce(cdb2_hndl_tp *hndl)
68966895

68976896
return hndl->cnonce.str;
68986897
}
6898+
#endif
68996899

69006900
const char *cdb2_errstr(cdb2_hndl_tp *hndl)
69016901
{

cdb2api/cdb2api.h

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ typedef struct cdb2_effects_type effects_tp;
212212
void cdb2_set_comdb2db_config(const char *cfg_file);
213213
void cdb2_set_comdb2db_info(const char *cfg_info);
214214
void cdb2_set_identity(cdb2_hndl_tp *hndl, const void *identity);
215-
int cdb2_get_comdb2db(char **comdb2db_name, char **comdb2db_class);
216215

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

@@ -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,23 +240,19 @@ 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-
260250
int cdb2_push_context(cdb2_hndl_tp *hndl, const char *msg);
261251
int cdb2_pop_context(cdb2_hndl_tp *hndl);
262252
int cdb2_clear_contexts(cdb2_hndl_tp *hndl);
263253

264-
int cdb2_init_ssl(int init_libssl, int init_libcrypto);
265-
int cdb2_is_ssl_encrypted(cdb2_hndl_tp *hndl);
266-
267254
int cdb2_clear_ack(cdb2_hndl_tp *hndl);
268255

269-
char *cdb2_string_escape(cdb2_hndl_tp *hndl, const char *str);
270-
271256
// on success, `*value` points to dynamically allocated memory
272257
// that must be freed by the caller.
273258
int cdb2_get_property(cdb2_hndl_tp *hndl, const char *key, char **value);
@@ -338,6 +323,10 @@ int cdb2_register_retry_callback(cdb2_hndl_tp *hndl, RETRY_CALLBACK f);
338323
void cdb2_identity_create();
339324
void cdb2_identity_destroy(int is_task_exit);
340325
int cdb2_identity_valid();
326+
int cdb2_init_ssl(int init_libssl, int init_libcrypto);
327+
int cdb2_is_ssl_encrypted(cdb2_hndl_tp *hndl);
328+
329+
char *cdb2_string_escape(cdb2_hndl_tp *hndl, const char *str);
341330

342331
struct cdb2_identity {
343332
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)