Initial framework for directory interface modules (ldap etc)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@575 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
dbd2d43a0e
commit
95fbe70503
|
@ -818,6 +818,60 @@ SWITCH_DECLARE(switch_status) switch_core_speech_feed_tts(switch_speech_handle *
|
|||
SWITCH_DECLARE(switch_status) switch_core_speech_close(switch_speech_handle *sh, unsigned int *flags);
|
||||
///\}
|
||||
|
||||
|
||||
///\defgroup dir Directory Service Functions
|
||||
///\ingroup core1
|
||||
///\{
|
||||
/*!
|
||||
\brief Open a directory handle
|
||||
\param dh a direcotry handle to use
|
||||
\param module_name the directory module to use
|
||||
\param source the source of the db (ip, hostname, path etc)
|
||||
\param dsn the username or designation of the lookup
|
||||
\param passwd the password
|
||||
\param pool the pool to use (NULL for new pool)
|
||||
\return SWITCH_STATUS_SUCCESS if the handle is opened
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status) switch_core_directory_open(switch_directory_handle *dh,
|
||||
char *module_name,
|
||||
char *source,
|
||||
char *dsn,
|
||||
char *passwd,
|
||||
switch_memory_pool *pool);
|
||||
|
||||
/*!
|
||||
\brief Query a directory handle
|
||||
\param dh a direcotry handle to use
|
||||
\param query a string of filters or query data
|
||||
\return SWITCH_STATUS_SUCCESS if the query is successful
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status) switch_core_directory_query(switch_directory_handle *dh, char *query);
|
||||
|
||||
/*!
|
||||
\brief Obtain the next record in a lookup
|
||||
\param dh a direcotry handle to use
|
||||
\return SWITCH_STATUS_SUCCESS if another record exists
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status) switch_core_directory_next(switch_directory_handle *dh);
|
||||
|
||||
/*!
|
||||
\brief Obtain the next name/value pair in the current record
|
||||
\param dh a direcotry handle to use
|
||||
\param var a pointer to pointer of the name to fill in
|
||||
\param val a pointer to poinbter of the value to fill in
|
||||
\return SWITCH_STATUS_SUCCESS if an item exists
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status) switch_core_directory_next_pair(switch_directory_handle *dh, char **var, char **val);
|
||||
|
||||
/*!
|
||||
\brief Close an open directory handle
|
||||
\param dh a direcotry handle to close
|
||||
\return SWITCH_STATUS_SUCCESS if handle was closed
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status) switch_core_directory_close(switch_directory_handle *dh);
|
||||
///\}
|
||||
|
||||
|
||||
///\defgroup misc Misc
|
||||
///\ingroup core1
|
||||
///\{
|
||||
|
|
|
@ -73,6 +73,8 @@ struct switch_loadable_module_interface {
|
|||
const switch_file_interface *file_interface;
|
||||
/*! the table of speech interfaces the module has implmented */
|
||||
const switch_speech_interface *speech_interface;
|
||||
/*! the table of directory interfaces the module has implmented */
|
||||
const switch_directory_interface *directory_interface;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
@ -142,6 +144,13 @@ SWITCH_DECLARE(switch_file_interface *) switch_loadable_module_get_file_interfac
|
|||
*/
|
||||
SWITCH_DECLARE(switch_speech_interface *) switch_loadable_module_get_speech_interface(char *name);
|
||||
|
||||
/*!
|
||||
\brief Retrieve the directory interface by it's registered name
|
||||
\param name the name of the directory interface
|
||||
\return the desired directory interface
|
||||
*/
|
||||
SWITCH_DECLARE(switch_directory_interface *) switch_loadable_module_get_directory_interface(char *name);
|
||||
|
||||
|
||||
/*!
|
||||
\brief Retrieve the list of loaded codecs into an array
|
||||
|
|
|
@ -320,6 +320,39 @@ struct switch_speech_handle {
|
|||
};
|
||||
|
||||
|
||||
|
||||
/*! \brief Abstract interface to a directory module */
|
||||
struct switch_directory_interface {
|
||||
/*! the name of the interface */
|
||||
const char *interface_name;
|
||||
/*! function to open the directory interface */
|
||||
switch_status (*directory_open)(switch_directory_handle *dh, char *source, char *dsn, char *passwd);
|
||||
/*! function to close the directory interface */
|
||||
switch_status (*directory_close)(switch_directory_handle *dh);
|
||||
/*! function to query the directory interface */
|
||||
switch_status (*directory_query)(switch_directory_handle *dh, char *query);
|
||||
/*! function to advance to the next record */
|
||||
switch_status (*directory_next)(switch_directory_handle *dh);
|
||||
/*! function to advance to the next name/value pair in the current record */
|
||||
switch_status (*directory_next_pair)(switch_directory_handle *dh, char **var, char **val);
|
||||
|
||||
const struct switch_directory_interface *next;
|
||||
};
|
||||
|
||||
/*! an abstract representation of a directory interface. */
|
||||
struct switch_directory_handle {
|
||||
/*! the interface of the module that implemented the current directory interface */
|
||||
const struct switch_directory_interface *directory_interface;
|
||||
/*! flags to control behaviour */
|
||||
unsigned int flags;
|
||||
|
||||
/*! the handle's memory pool */
|
||||
switch_memory_pool *memory_pool;
|
||||
/*! private data for the format module to store handle specific info */
|
||||
void *private;
|
||||
};
|
||||
|
||||
|
||||
/* nobody has more setting than speex so we will let them set the standard */
|
||||
/*! \brief Various codec settings (currently only relevant to speex) */
|
||||
struct switch_codec_settings {
|
||||
|
|
|
@ -241,6 +241,19 @@ typedef enum {
|
|||
|
||||
} switch_speech_flag;
|
||||
|
||||
|
||||
/*!
|
||||
\enum switch_directory_flag
|
||||
\brief Directory Handle related flags
|
||||
<pre>
|
||||
SWITCH_DIRECTORY_FLAG_FREE_POOL = (1 << 0) - Free interface's pool on destruction.
|
||||
</pre>
|
||||
*/
|
||||
typedef enum {
|
||||
SWITCH_DIRECTORY_FLAG_FREE_POOL = (1 << 0),
|
||||
|
||||
} switch_directory_flag;
|
||||
|
||||
/*!
|
||||
\enum switch_codec_type
|
||||
\brief Codec types
|
||||
|
@ -380,6 +393,8 @@ typedef struct switch_codec_settings switch_codec_settings;
|
|||
typedef struct switch_config switch_config;
|
||||
typedef struct switch_speech_handle switch_speech_handle;
|
||||
typedef struct switch_speech_interface switch_speech_interface;
|
||||
typedef struct switch_directory_handle switch_directory_handle;
|
||||
typedef struct switch_directory_interface switch_directory_interface;
|
||||
typedef void (*switch_application_function)(switch_core_session *, char *);
|
||||
typedef void (*switch_event_callback_t)(switch_event *);
|
||||
typedef switch_caller_extension *(*switch_dialplan_hunt_function)(switch_core_session *);
|
||||
|
|
|
@ -444,6 +444,52 @@ SWITCH_DECLARE(switch_status) switch_core_file_close(switch_file_handle *fh)
|
|||
return fh->file_interface->file_close(fh);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status) switch_core_directory_open(switch_directory_handle *dh,
|
||||
char *module_name,
|
||||
char *source,
|
||||
char *dsn,
|
||||
char *passwd,
|
||||
switch_memory_pool *pool)
|
||||
{
|
||||
switch_status status;
|
||||
|
||||
if (!(dh->directory_interface = switch_loadable_module_get_directory_interface(module_name))) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "invalid directory module [%s]!\n", module_name);
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
|
||||
if (pool) {
|
||||
dh->memory_pool = pool;
|
||||
} else {
|
||||
if ((status = switch_core_new_memory_pool(&dh->memory_pool)) != SWITCH_STATUS_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
switch_set_flag(dh, SWITCH_DIRECTORY_FLAG_FREE_POOL);
|
||||
}
|
||||
|
||||
return dh->directory_interface->directory_open(dh, source, dsn, passwd);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status) switch_core_directory_query(switch_directory_handle *dh, char *query)
|
||||
{
|
||||
return dh->directory_interface->directory_query(dh, query);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status) switch_core_directory_next(switch_directory_handle *dh)
|
||||
{
|
||||
return dh->directory_interface->directory_next(dh);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status) switch_core_directory_next_pair(switch_directory_handle *dh, char **var, char **val)
|
||||
{
|
||||
return dh->directory_interface->directory_next_pair(dh, var, val);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status) switch_core_directory_close(switch_directory_handle *dh)
|
||||
{
|
||||
return dh->directory_interface->directory_close(dh);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status) switch_core_speech_open(switch_speech_handle *sh,
|
||||
char *module_name,
|
||||
unsigned int flags,
|
||||
|
|
|
@ -63,6 +63,7 @@ struct switch_loadable_module_container {
|
|||
switch_hash *api_hash;
|
||||
switch_hash *file_hash;
|
||||
switch_hash *speech_hash;
|
||||
switch_hash *directory_hash;
|
||||
switch_memory_pool *pool;
|
||||
};
|
||||
|
||||
|
@ -220,6 +221,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
|
|||
switch_core_hash_init(&loadable_modules.api_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.file_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.speech_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.directory_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.dialplan_hash, loadable_modules.pool);
|
||||
|
||||
while (apr_dir_read(&finfo, finfo_flags, module_dir_handle) == APR_SUCCESS) {
|
||||
|
@ -331,6 +333,15 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
|
|||
switch_core_hash_insert(loadable_modules.speech_hash, (char *) ptr->interface_name, (void *) ptr);
|
||||
}
|
||||
}
|
||||
|
||||
if (new_module->interface->directory_interface) {
|
||||
const switch_directory_interface *ptr;
|
||||
|
||||
for (ptr = new_module->interface->directory_interface; ptr; ptr = ptr->next) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Directory interface '%s'\n", ptr->interface_name);
|
||||
switch_core_hash_insert(loadable_modules.directory_hash, (char *) ptr->interface_name, (void *) ptr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -400,6 +411,11 @@ SWITCH_DECLARE(switch_speech_interface *) switch_loadable_module_get_speech_inte
|
|||
return switch_core_hash_find(loadable_modules.speech_hash, name);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_directory_interface *) switch_loadable_module_get_directory_interface(char *name)
|
||||
{
|
||||
return switch_core_hash_find(loadable_modules.directory_hash, name);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int) switch_loadable_module_get_codecs(switch_memory_pool *pool, switch_codec_interface **array,
|
||||
int arraylen)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue