mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-23 12:42:02 +00:00
FS-10801: [core] Add a database interface to the FreeSWITCH Core.
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
* Contributor(s):
|
||||
*
|
||||
* Anthony Minessale II <anthm@freeswitch.org>
|
||||
* Andrey Volk <andywolk@gmail.com>
|
||||
*
|
||||
*
|
||||
* switch_core.h -- Core Library Private Data (not to be installed into the system)
|
||||
@@ -334,6 +335,8 @@ extern struct switch_session_manager session_manager;
|
||||
|
||||
|
||||
|
||||
switch_status_t switch_core_sqldb_init(const char **err);
|
||||
void switch_core_sqldb_destroy();
|
||||
switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_t manage);
|
||||
void switch_core_sqldb_stop(void);
|
||||
void switch_core_session_init(switch_memory_pool_t *pool);
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
* Luke Dashjr <luke@openmethods.com> (OpenMethods, LLC)
|
||||
* Joseph Sullivan <jossulli@amazon.com>
|
||||
* Emmanuel Schmidbauer <eschmidbauer@gmail.com>
|
||||
* Andrey Volk <andywolk@gmail.com>
|
||||
*
|
||||
* switch_core.h -- Core Library
|
||||
*
|
||||
@@ -2474,13 +2475,15 @@ typedef enum {
|
||||
typedef enum {
|
||||
SCDB_TYPE_CORE_DB,
|
||||
SCDB_TYPE_ODBC,
|
||||
SCDB_TYPE_PGSQL
|
||||
SCDB_TYPE_PGSQL,
|
||||
SCDB_TYPE_DATABASE_INTERFACE
|
||||
} switch_cache_db_handle_type_t;
|
||||
|
||||
typedef union {
|
||||
switch_core_db_t *core_db_dbh;
|
||||
switch_odbc_handle_t *odbc_dbh;
|
||||
switch_pgsql_handle_t *pgsql_dbh;
|
||||
switch_database_interface_handle_t *database_interface_dbh;
|
||||
} switch_cache_db_native_handle_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -2497,10 +2500,18 @@ typedef struct {
|
||||
char *dsn;
|
||||
} switch_cache_db_pgsql_options_t;
|
||||
|
||||
typedef struct {
|
||||
char *dsn;
|
||||
char prefix[16];
|
||||
switch_database_interface_t *database_interface;
|
||||
switch_bool_t make_module_no_unloadable;
|
||||
} switch_cache_db_database_interface_options_t;
|
||||
|
||||
typedef union {
|
||||
switch_cache_db_core_db_options_t core_db_options;
|
||||
switch_cache_db_odbc_options_t odbc_options;
|
||||
switch_cache_db_pgsql_options_t pgsql_options;
|
||||
switch_cache_db_database_interface_options_t database_interface_options;
|
||||
} switch_cache_db_connection_options_t;
|
||||
|
||||
struct switch_cache_db_handle;
|
||||
@@ -2511,6 +2522,11 @@ static inline const char *switch_cache_db_type_name(switch_cache_db_handle_type_
|
||||
const char *type_str = "INVALID";
|
||||
|
||||
switch (type) {
|
||||
case SCDB_TYPE_DATABASE_INTERFACE:
|
||||
{
|
||||
type_str = "DATABASE_INTERFACE";
|
||||
}
|
||||
break;
|
||||
case SCDB_TYPE_PGSQL:
|
||||
{
|
||||
type_str = "PGSQL";
|
||||
@@ -2559,6 +2575,8 @@ SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_h
|
||||
const char *file, const char *func, int line);
|
||||
#define switch_cache_db_get_db_handle(_a, _b, _c) _switch_cache_db_get_db_handle(_a, _b, _c, __FILE__, __SWITCH_FUNC__, __LINE__)
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle_dsn_ex(switch_cache_db_handle_t **dbh, const char *dsn, switch_bool_t make_module_no_unloadable,
|
||||
const char *file, const char *func, int line);
|
||||
SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle_dsn(switch_cache_db_handle_t **dbh, const char *dsn,
|
||||
const char *file, const char *func, int line);
|
||||
#define switch_cache_db_get_db_handle_dsn(_a, _b) _switch_cache_db_get_db_handle_dsn(_a, _b, __FILE__, __SWITCH_FUNC__, __LINE__)
|
||||
@@ -2643,6 +2661,13 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans_full(sw
|
||||
const char *inner_post_trans_execute);
|
||||
#define switch_cache_db_persistant_execute_trans(_d, _s, _r) switch_cache_db_persistant_execute_trans_full(_d, _s, _r, NULL, NULL, NULL, NULL)
|
||||
|
||||
SWITCH_DECLARE(void) switch_cache_db_database_interface_flush_handles(switch_database_interface_t *database_interface);
|
||||
|
||||
/*!
|
||||
\brief Returns error if no suitable database interface found to serve core db dsn.
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_check_core_db_dsn();
|
||||
|
||||
SWITCH_DECLARE(void) switch_core_set_signal_handlers(void);
|
||||
SWITCH_DECLARE(uint32_t) switch_core_debug_level(void);
|
||||
SWITCH_DECLARE(int32_t) switch_core_sps(void);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
* Contributor(s):
|
||||
*
|
||||
* Anthony Minessale II <anthm@freeswitch.org>
|
||||
* Andrey Volk <andywolk@gmail.com>
|
||||
*
|
||||
*
|
||||
* switch_loadable_module.h -- Loadable Modules
|
||||
@@ -51,6 +52,14 @@ SWITCH_BEGIN_EXTERN_C
|
||||
\ingroup core1
|
||||
\{
|
||||
*/
|
||||
|
||||
/*! \brief List of loadable module types */
|
||||
typedef enum {
|
||||
SWITCH_LOADABLE_MODULE_TYPE_PRELOAD,
|
||||
SWITCH_LOADABLE_MODULE_TYPE_COMMON,
|
||||
SWITCH_LOADABLE_MODULE_TYPE_POSTLOAD
|
||||
} switch_loadable_module_type_t;
|
||||
|
||||
/*! \brief The abstraction of a loadable module */
|
||||
struct switch_loadable_module_interface {
|
||||
/*! the name of the module */
|
||||
@@ -87,6 +96,8 @@ SWITCH_BEGIN_EXTERN_C
|
||||
switch_management_interface_t *management_interface;
|
||||
/*! the table of limit interfaces the module has implemented */
|
||||
switch_limit_interface_t *limit_interface;
|
||||
/*! the table of database interfaces the module has implemented */
|
||||
switch_database_interface_t *database_interface;
|
||||
switch_thread_rwlock_t *rwlock;
|
||||
int refs;
|
||||
switch_memory_pool_t *pool;
|
||||
@@ -205,6 +216,13 @@ SWITCH_DECLARE(switch_json_api_interface_t *) switch_loadable_module_get_json_ap
|
||||
*/
|
||||
SWITCH_DECLARE(switch_file_interface_t *) switch_loadable_module_get_file_interface(const char *name, const char *modname);
|
||||
|
||||
/*!
|
||||
\brief Retrieve the database interface by it's registered name
|
||||
\param name the name of the dsn prefix
|
||||
\return the desired database format interface
|
||||
*/
|
||||
SWITCH_DECLARE(switch_database_interface_t *) switch_loadable_module_get_database_interface(const char *name, const char *modname);
|
||||
|
||||
/*!
|
||||
\brief Retrieve the speech interface by it's registered name
|
||||
\param name the name of the speech interface
|
||||
@@ -311,6 +329,13 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_load_module(const char *d
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_loadable_module_exists(const char *mod);
|
||||
|
||||
/*!
|
||||
\brief Protect module from beeing unloaded
|
||||
\param mod the module name
|
||||
\return the status
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_loadable_module_protect(const char *mod);
|
||||
|
||||
/*!
|
||||
\brief Unoad a module
|
||||
\param dir the directory where the module resides
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
*
|
||||
* Anthony Minessale II <anthm@freeswitch.org>
|
||||
* Luke Dashjr <luke@openmethods.com> (OpenMethods, LLC)
|
||||
* Andrey Volk <andywolk@gmail.com>
|
||||
*
|
||||
*
|
||||
* switch_module_interfaces.h -- Module Interface Definitions
|
||||
@@ -614,6 +615,38 @@ struct switch_directory_handle {
|
||||
void *private_info;
|
||||
};
|
||||
|
||||
/*! \brief Abstract interface to a database module */
|
||||
struct switch_database_interface {
|
||||
/*! the name of the interface */
|
||||
const char *interface_name;
|
||||
switch_status_t(*handle_new)(char *dsn, switch_database_interface_handle_t **dih);
|
||||
switch_status_t(*handle_destroy)(switch_database_interface_handle_t **dih);
|
||||
switch_status_t(*flush)(switch_database_interface_handle_t *dih);
|
||||
switch_status_t(*exec_detailed)(const char *file, const char *func, int line,
|
||||
switch_database_interface_handle_t *dih, const char *sql, char **err);
|
||||
switch_status_t(*exec_string)(switch_database_interface_handle_t *dih, const char *sql, char *resbuf, size_t len, char **err);
|
||||
switch_status_t(*sql_set_auto_commit_attr)(switch_database_interface_handle_t *dih, switch_bool_t on);
|
||||
switch_status_t(*commit)(switch_database_interface_handle_t *dih);
|
||||
switch_status_t(*rollback)(switch_database_interface_handle_t *dih);
|
||||
switch_status_t(*callback_exec_detailed)(const char *file, const char *func, int line,
|
||||
switch_database_interface_handle_t *dih, const char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err);
|
||||
switch_status_t(*affected_rows)(switch_database_interface_handle_t *dih, int *affected_rows);
|
||||
|
||||
/*! list of supported dsn prefixes */
|
||||
char **prefixes;
|
||||
switch_thread_rwlock_t *rwlock;
|
||||
int refs;
|
||||
switch_mutex_t *reflock;
|
||||
switch_loadable_module_interface_t *parent;
|
||||
struct switch_database_interface *next;
|
||||
};
|
||||
|
||||
/*! an abstract representation of a database interface. */
|
||||
struct switch_database_interface_handle {
|
||||
switch_cache_db_database_interface_options_t connection_options;
|
||||
void *handle;
|
||||
};
|
||||
|
||||
struct switch_audio_codec_settings {
|
||||
int unused;
|
||||
};
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
* Joseph Sullivan <jossulli@amazon.com>
|
||||
* Raymond Chandler <intralanman@freeswitch.org>
|
||||
* Emmanuel Schmidbauer <e.schmidbauer@gmail.com>
|
||||
* Andrey Volk <andywolk@gmail.com>
|
||||
*
|
||||
* switch_types.h -- Data Types
|
||||
*
|
||||
@@ -400,6 +401,7 @@ typedef enum {
|
||||
SWITCH_LIMIT_INTERFACE,
|
||||
SWITCH_CHAT_APPLICATION_INTERFACE,
|
||||
SWITCH_JSON_API_INTERFACE,
|
||||
SWITCH_DATABASE_INTERFACE,
|
||||
} switch_module_interface_name_t;
|
||||
|
||||
typedef enum {
|
||||
@@ -2290,6 +2292,7 @@ typedef struct switch_codec_fmtp switch_codec_fmtp_t;
|
||||
typedef struct switch_odbc_handle switch_odbc_handle_t;
|
||||
typedef struct switch_pgsql_handle switch_pgsql_handle_t;
|
||||
typedef struct switch_pgsql_result switch_pgsql_result_t;
|
||||
typedef struct switch_database_interface_handle switch_database_interface_handle_t;
|
||||
|
||||
typedef struct switch_io_routines switch_io_routines_t;
|
||||
typedef struct switch_speech_handle switch_speech_handle_t;
|
||||
@@ -2313,6 +2316,7 @@ typedef struct switch_management_interface switch_management_interface_t;
|
||||
typedef struct switch_core_port_allocator switch_core_port_allocator_t;
|
||||
typedef struct switch_media_bug switch_media_bug_t;
|
||||
typedef struct switch_limit_interface switch_limit_interface_t;
|
||||
typedef struct switch_database_interface switch_database_interface_t;
|
||||
|
||||
typedef void (*hashtable_destructor_t)(void *ptr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user