Remove the old stub files, preferring the optional_api method.

(closes issue #17475)
 Reported by: tilghman
 
Review: https://reviewboard.asterisk.org/r/695/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@276490 65c4cc65-6c06-0410-ace0-fbb531ad65f3
certified/1.8.6
Tilghman Lesher 15 years ago
parent 8e7d01d484
commit 832d1296c6

@ -24,6 +24,8 @@
#define _ASTERISK_ADSI_H #define _ASTERISK_ADSI_H
#include "asterisk/callerid.h" #include "asterisk/callerid.h"
#include "asterisk/optional_api.h"
/*! \name ADSI parameters */ /*! \name ADSI parameters */
/*@{ */ /*@{ */
@ -121,44 +123,35 @@
/*@} */ /*@} */
/*! Perform Asterisk ADSI initialization (for channel drivers that want AST_OPTIONAL_API(int, ast_adsi_begin_download, (struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version), { return 0; });
* to support ADSI when the handset is first lifted)
* \param chan Channel to initialize for ADSI (if supported)
*
* \retval 0 on success (or adsi unavailable.
* \retval -1 on hangup.
*/
extern int (*ast_adsi_channel_init)(struct ast_channel *chan);
extern int (*ast_adsi_begin_download)(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version); AST_OPTIONAL_API(int, ast_adsi_end_download, (struct ast_channel *chan), { return 0; });
extern int (*ast_adsi_end_download)(struct ast_channel *chan); /*! Restore ADSI initialization (for applications that play with ADSI
* and want to restore it to normal. If you touch "INFO" then you
/*! Restore ADSI initialization (for applications that play with ADSI * have to use the ast_adsi_channel_init again instead.
* and want to restore it to normal. If you touch "INFO" then you
* have to use the ast_adsi_channel_init again instead.
* \param chan Channel to restore * \param chan Channel to restore
* *
* \retval 0 on success (or adsi unavailable) * \retval 0 on success (or adsi unavailable)
* \retval -1 on hangup * \retval -1 on hangup
*/ */
extern int (*ast_adsi_channel_restore)(struct ast_channel *chan); AST_OPTIONAL_API(int, ast_adsi_channel_restore, (struct ast_channel *chan), { return 0; });
/*! /*!
* \brief Display some stuff on the screen * \brief Display some stuff on the screen
* \param chan Channel to display on * \param chan Channel to display on
* \param lines NULL-terminated list of things to print (no more than 4 recommended) * \param lines NULL-terminated list of things to print (no more than 4 recommended)
* \param align list of alignments to use (ADSI_JUST_LEFT, ADSI_JUST_RIGHT, ADSI_JUST_CEN, etc..) * \param align list of alignments to use (ADSI_JUST_LEFT, ADSI_JUST_RIGHT, ADSI_JUST_CEN, etc..)
* \param voice whether to jump into voice mode when finished * \param voice whether to jump into voice mode when finished
* *
* \retval 0 on success (or adsi unavailable) * \retval 0 on success (or adsi unavailable)
* \retval -1 on hangup * \retval -1 on hangup
*/ */
extern int (*ast_adsi_print)(struct ast_channel *chan, char **lines, int *align, int voice); AST_OPTIONAL_API(int, ast_adsi_print, (struct ast_channel *chan, char **lines, int *align, int voice), { return 0; });
/*! /*!
* \brief Check if scripts for a given app are already loaded. * \brief Check if scripts for a given app are already loaded.
* Version may be -1, if any version is okay, or 0-255 for a specific version. * Version may be -1, if any version is okay, or 0-255 for a specific version.
* \param chan Channel to test for loaded app * \param chan Channel to test for loaded app
* \param app Four character app name (must be unique to your application) * \param app Four character app name (must be unique to your application)
* \param ver optional version number * \param ver optional version number
@ -168,22 +161,21 @@ extern int (*ast_adsi_print)(struct ast_channel *chan, char **lines, int *align,
* \retval -1 on hangup * \retval -1 on hangup
* \retval 1 if script already loaded. * \retval 1 if script already loaded.
*/ */
extern int (*ast_adsi_load_session)(struct ast_channel *chan, unsigned char *app, int ver, int data); AST_OPTIONAL_API(int, ast_adsi_load_session, (struct ast_channel *chan, unsigned char *app, int ver, int data), { return 0; });
extern int (*ast_adsi_unload_session)(struct ast_channel *chan); AST_OPTIONAL_API(int, ast_adsi_unload_session, (struct ast_channel *chan), { return 0; });
/* ADSI Layer 2 transmission functions */ /* ADSI Layer 2 transmission functions */
extern int (*ast_adsi_transmit_messages)(struct ast_channel *chan, unsigned char **msg, int *msglen, int *msgtype); AST_OPTIONAL_API(int, ast_adsi_transmit_message, (struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype), { return 0; });
extern int (*ast_adsi_transmit_message)(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype); AST_OPTIONAL_API(int, ast_adsi_transmit_message_full, (struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait), { return 0; });
extern int (*ast_adsi_transmit_message_full)(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait); /*! Read some encoded DTMF data.
/*! Read some encoded DTMF data.
* Returns number of bytes received * Returns number of bytes received
*/ */
extern int (*ast_adsi_read_encoded_dtmf)(struct ast_channel *chan, unsigned char *buf, int maxlen); AST_OPTIONAL_API(int, ast_adsi_read_encoded_dtmf, (struct ast_channel *chan, unsigned char *buf, int maxlen), { return 0; });
/* ADSI Layer 3 creation functions */ /* ADSI Layer 3 creation functions */
/*! /*!
* \brief Connects an ADSI Display Session * \brief Connects an ADSI Display Session
* \param buf Character buffer to create parameter in (must have at least 256 free) * \param buf Character buffer to create parameter in (must have at least 256 free)
* \param fdn Optional 4 byte Feature Download Number (for loading soft keys) * \param fdn Optional 4 byte Feature Download Number (for loading soft keys)
* \param ver Optional version number (0-255, or -1 to omit) * \param ver Optional version number (0-255, or -1 to omit)
@ -192,25 +184,25 @@ extern int (*ast_adsi_read_encoded_dtmf)(struct ast_channel *chan, unsigned char
* \retval -1 on error. * \retval -1 on error.
*/ */
extern int (*ast_adsi_connect_session)(unsigned char *buf, unsigned char *fdn, int ver); AST_OPTIONAL_API(int, ast_adsi_connect_session, (unsigned char *buf, unsigned char *fdn, int ver), { return 0; });
/*! Build Query CPE ID of equipment. /*! Build Query CPE ID of equipment.
* Returns number of bytes added to message * Returns number of bytes added to message
*/ */
extern int (*ast_adsi_query_cpeid)(unsigned char *buf); AST_OPTIONAL_API(int, ast_adsi_query_cpeid, (unsigned char *buf), { return 0; });
extern int (*ast_adsi_query_cpeinfo)(unsigned char *buf); AST_OPTIONAL_API(int, ast_adsi_query_cpeinfo, (unsigned char *buf), { return 0; });
/*! Get CPE ID from an attached ADSI compatible CPE. /*! Get CPE ID from an attached ADSI compatible CPE.
* Returns 1 on success, storing 4 bytes of CPE ID at buf * Returns 1 on success, storing 4 bytes of CPE ID at buf
* or -1 on hangup, or 0 if there was no hangup but it failed to find the * or -1 on hangup, or 0 if there was no hangup but it failed to find the
* device ID. Returns to voice mode if "voice" is non-zero. * device ID. Returns to voice mode if "voice" is non-zero.
*/ */
extern int (*ast_adsi_get_cpeid)(struct ast_channel *chan, unsigned char *cpeid, int voice); AST_OPTIONAL_API(int, ast_adsi_get_cpeid, (struct ast_channel *chan, unsigned char *cpeid, int voice), { return 0; });
extern int (*ast_adsi_get_cpeinfo)(struct ast_channel *chan, int *width, int *height, int *buttons, int voice); AST_OPTIONAL_API(int, ast_adsi_get_cpeinfo, (struct ast_channel *chan, int *width, int *height, int *buttons, int voice), { return 0; });
/*! /*!
* \brief Begin an ADSI script download * \brief Begin an ADSI script download
* \param buf Character buffer to create parameter in (must have at least 256 free) * \param buf Character buffer to create parameter in (must have at least 256 free)
* \param service a 1-18 byte name of the feature * \param service a 1-18 byte name of the feature
* \param fdn 4 byte Feature Download Number (for loading soft keys) * \param fdn 4 byte Feature Download Number (for loading soft keys)
@ -221,38 +213,38 @@ extern int (*ast_adsi_get_cpeinfo)(struct ast_channel *chan, int *width, int *he
* \retval -1 on error. * \retval -1 on error.
*/ */
extern int (*ast_adsi_download_connect)(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver); AST_OPTIONAL_API(int, ast_adsi_download_connect, (unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver), { return 0; });
/*! /*!
* \brief Disconnects a running session. * \brief Disconnects a running session.
* \param buf Character buffer to create parameter in (must have at least 256 free) * \param buf Character buffer to create parameter in (must have at least 256 free)
* *
* \retval number of bytes added to buffer * \retval number of bytes added to buffer
* \retval -1 on error. * \retval -1 on error.
*/ */
extern int (*ast_adsi_disconnect_session)(unsigned char *buf); AST_OPTIONAL_API(int, ast_adsi_disconnect_session, (unsigned char *buf), { return 0; });
/*! /*!
* \brief Disconnects (and hopefully saves) a downloaded script * \brief Disconnects (and hopefully saves) a downloaded script
* \param buf Character buffer to create parameter in (must have at least 256 free) * \param buf Character buffer to create parameter in (must have at least 256 free)
* *
* \retval number of bytes added to buffer * \retval number of bytes added to buffer
* \retval -1 on error. * \retval -1 on error.
*/ */
extern int (*ast_adsi_download_disconnect)(unsigned char *buf); AST_OPTIONAL_API(int, ast_adsi_download_disconnect, (unsigned char *buf), { return 0; });
/*! /*!
* \brief Puts CPE in data mode. * \brief Puts CPE in data mode.
* \param buf Character buffer to create parameter in (must have at least 256 free) * \param buf Character buffer to create parameter in (must have at least 256 free)
* *
* \retval number of bytes added to buffer * \retval number of bytes added to buffer
* \retval -1 on error. * \retval -1 on error.
*/ */
extern int (*ast_adsi_data_mode)(unsigned char *buf); AST_OPTIONAL_API(int, ast_adsi_data_mode, (unsigned char *buf), { return 0; });
extern int (*ast_adsi_clear_soft_keys)(unsigned char *buf); AST_OPTIONAL_API(int, ast_adsi_clear_soft_keys, (unsigned char *buf), { return 0; });
extern int (*ast_adsi_clear_screen)(unsigned char *buf); AST_OPTIONAL_API(int, ast_adsi_clear_screen, (unsigned char *buf), { return 0; });
/*! /*!
* \brief Puts CPE in voice mode. * \brief Puts CPE in voice mode.
* \param buf Character buffer to create parameter in (must have at least 256 free) * \param buf Character buffer to create parameter in (must have at least 256 free)
* \param when (a time in seconds) to make the switch * \param when (a time in seconds) to make the switch
@ -260,15 +252,15 @@ extern int (*ast_adsi_clear_screen)(unsigned char *buf);
* \retval number of bytes added to buffer * \retval number of bytes added to buffer
* \retval -1 on error. * \retval -1 on error.
*/ */
extern int (*ast_adsi_voice_mode)(unsigned char *buf, int when); AST_OPTIONAL_API(int, ast_adsi_voice_mode, (unsigned char *buf, int when), { return 0; });
/*! /*!
* \brief Returns non-zero if Channel does or might support ADSI * \brief Returns non-zero if Channel does or might support ADSI
* \param chan Channel to check * \param chan Channel to check
*/ */
extern int (*ast_adsi_available)(struct ast_channel *chan); AST_OPTIONAL_API(int, ast_adsi_available, (struct ast_channel *chan), { return 0; });
/*! /*!
* \brief Loads a line of info into the display. * \brief Loads a line of info into the display.
* \param buf Character buffer to create parameter in (must have at least 256 free) * \param buf Character buffer to create parameter in (must have at least 256 free)
* \param page Page to load (ADSI_COMM_PAGE or ADSI_INFO_PAGE) * \param page Page to load (ADSI_COMM_PAGE or ADSI_INFO_PAGE)
@ -282,10 +274,10 @@ extern int (*ast_adsi_available)(struct ast_channel *chan);
* \retval -1 on error. * \retval -1 on error.
*/ */
extern int (*ast_adsi_display)(unsigned char *buf, int page, int line, int just, int wrap, char *col1, char *col2); AST_OPTIONAL_API(int, ast_adsi_display, (unsigned char *buf, int page, int line, int just, int wrap, char *col1, char *col2), { return 0; });
/*! /*!
* \brief Sets the current line and page. * \brief Sets the current line and page.
* \param buf Character buffer to create parameter in (must have at least 256 free) * \param buf Character buffer to create parameter in (must have at least 256 free)
* \param page Which page (ADSI_COMM_PAGE or ADSI_INFO_PAGE) * \param page Which page (ADSI_COMM_PAGE or ADSI_INFO_PAGE)
* \param line Line number (1-33 for info page, 1-4 for comm page) * \param line Line number (1-33 for info page, 1-4 for comm page)
@ -294,9 +286,9 @@ extern int (*ast_adsi_display)(unsigned char *buf, int page, int line, int just,
* \retval -1 on error. * \retval -1 on error.
*/ */
extern int (*ast_adsi_set_line)(unsigned char *buf, int page, int line); AST_OPTIONAL_API(int, ast_adsi_set_line, (unsigned char *buf, int page, int line), { return 0; });
/*! /*!
* \brief Creates "load soft key" parameters * \brief Creates "load soft key" parameters
* \param buf Character buffer to create parameter in (must have at least 256 free) * \param buf Character buffer to create parameter in (must have at least 256 free)
* \param key Key code from 2 to 33, for which key we are loading * \param key Key code from 2 to 33, for which key we are loading
@ -308,10 +300,10 @@ extern int (*ast_adsi_set_line)(unsigned char *buf, int page, int line);
* \retval number of bytes added to buffer * \retval number of bytes added to buffer
* \retval -1 on error. * \retval -1 on error.
*/ */
extern int (*ast_adsi_load_soft_key)(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data); AST_OPTIONAL_API(int, ast_adsi_load_soft_key, (unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data), { return 0; });
/*! /*!
* \brief Set which soft keys should be displayed * \brief Set which soft keys should be displayed
* \param buf Character buffer to create parameter in (must have at least 256 free) * \param buf Character buffer to create parameter in (must have at least 256 free)
* \param keys Array of 8 unsigned chars with the key numbers, may be OR'd with ADSI_KEY_HILITE * \param keys Array of 8 unsigned chars with the key numbers, may be OR'd with ADSI_KEY_HILITE
* But remember, the last two keys aren't real keys, they're for scrolling * But remember, the last two keys aren't real keys, they're for scrolling
@ -319,10 +311,10 @@ extern int (*ast_adsi_load_soft_key)(unsigned char *buf, int key, const char *ll
* \retval number of bytes added to buffer * \retval number of bytes added to buffer
* \retval -1 on error. * \retval -1 on error.
*/ */
extern int (*ast_adsi_set_keys)(unsigned char *buf, unsigned char *keys); AST_OPTIONAL_API(int, ast_adsi_set_keys, (unsigned char *buf, unsigned char *keys), { return 0; });
/*! /*!
* \brief Set input information * \brief Set input information
* \param buf Character buffer to create parameter in (must have at least 256 free) * \param buf Character buffer to create parameter in (must have at least 256 free)
* \param page Which page to input on (ADSI_COMM_PAGE or ADSI_INFO_PAGE) * \param page Which page to input on (ADSI_COMM_PAGE or ADSI_INFO_PAGE)
* \param line Line number to input on * \param line Line number to input on
@ -333,10 +325,10 @@ extern int (*ast_adsi_set_keys)(unsigned char *buf, unsigned char *keys);
* \retval number of bytes added to buffer * \retval number of bytes added to buffer
* \retval -1 on error. * \retval -1 on error.
*/ */
extern int (*ast_adsi_input_control)(unsigned char *buf, int page, int line, int display, int format, int just); AST_OPTIONAL_API(int, ast_adsi_input_control, (unsigned char *buf, int page, int line, int display, int format, int just), { return 0; });
/*! /*!
* \brief Set input format * \brief Set input format
* \param buf Character buffer to create parameter in (must have at least 256 free) * \param buf Character buffer to create parameter in (must have at least 256 free)
* \param num Which format we are setting * \param num Which format we are setting
* \param dir Which direction (ADSI_DIR_FROM_LEFT or ADSI_DIR_FROM_RIGHT) * \param dir Which direction (ADSI_DIR_FROM_LEFT or ADSI_DIR_FROM_RIGHT)
@ -347,7 +339,7 @@ extern int (*ast_adsi_input_control)(unsigned char *buf, int page, int line, int
* \retval number of bytes added to buffer * \retval number of bytes added to buffer
* \retval -1 on error. * \retval -1 on error.
*/ */
extern int (*ast_adsi_input_format)(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2); AST_OPTIONAL_API(int, ast_adsi_input_format, (unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2), { return 0; });
#endif /* _ASTERISK_ADSI_H */ #endif /* _ASTERISK_ADSI_H */

@ -69,8 +69,9 @@ typedef struct agi_command {
* *
* \param mod Pointer to the module_info structure for the module that is registering the command * \param mod Pointer to the module_info structure for the module that is registering the command
* \param cmd Pointer to the descriptor for the command * \param cmd Pointer to the descriptor for the command
* \return 1 on success, 0 if the command is already registered * \retval 1 on success
* * \retval 0 the command is already registered
* \retval AST_OPTIONAL_API_UNAVAILABLE the module is not loaded.
*/ */
AST_OPTIONAL_API(int, ast_agi_register, AST_OPTIONAL_API(int, ast_agi_register,
(struct ast_module *mod, agi_command *cmd), (struct ast_module *mod, agi_command *cmd),

@ -1,7 +1,7 @@
/* /*
* Asterisk -- An open source telephony toolkit. * Asterisk -- An open source telephony toolkit.
* *
* Copyright (C) 1999 - 2005, Digium, Inc. * Copyright (C) 1999 - 2010, Digium, Inc.
* *
* Mark Spencer <markster@digium.com> * Mark Spencer <markster@digium.com>
* *
@ -27,12 +27,14 @@
extern "C" { extern "C" {
#endif #endif
#include "asterisk/optional_api.h"
#define AST_KEY_PUBLIC (1 << 0) #define AST_KEY_PUBLIC (1 << 0)
#define AST_KEY_PRIVATE (1 << 1) #define AST_KEY_PRIVATE (1 << 1)
struct ast_key; struct ast_key;
/*! /*!
* \brief Retrieve a key * \brief Retrieve a key
* \param name of the key we are retrieving * \param name of the key we are retrieving
* \param int type of key (AST_KEY_PUBLIC or AST_KEY_PRIVATE) * \param int type of key (AST_KEY_PUBLIC or AST_KEY_PRIVATE)
@ -40,9 +42,9 @@ struct ast_key;
* \retval the key on success. * \retval the key on success.
* \retval NULL on failure. * \retval NULL on failure.
*/ */
extern struct ast_key *(*ast_key_get)(const char *key, int type); AST_OPTIONAL_API(struct ast_key *, ast_key_get, (const char *key, int type), { return NULL; });
/*! /*!
* \brief Check the authenticity of a message signature using a given public key * \brief Check the authenticity of a message signature using a given public key
* \param key a public key to use to verify * \param key a public key to use to verify
* \param msg the message that has been signed * \param msg the message that has been signed
@ -52,9 +54,9 @@ extern struct ast_key *(*ast_key_get)(const char *key, int type);
* \retval -1 otherwise. * \retval -1 otherwise.
* *
*/ */
extern int (*ast_check_signature)(struct ast_key *key, const char *msg, const char *sig); AST_OPTIONAL_API(int, ast_check_signature, (struct ast_key *key, const char *msg, const char *sig), { return -1; });
/*! /*!
* \brief Check the authenticity of a message signature using a given public key * \brief Check the authenticity of a message signature using a given public key
* \param key a public key to use to verify * \param key a public key to use to verify
* \param msg the message that has been signed * \param msg the message that has been signed
@ -64,7 +66,7 @@ extern int (*ast_check_signature)(struct ast_key *key, const char *msg, const ch
* \retval -1 otherwise. * \retval -1 otherwise.
* *
*/ */
extern int (*ast_check_signature_bin)(struct ast_key *key, const char *msg, int msglen, const unsigned char *sig); AST_OPTIONAL_API(int, ast_check_signature_bin, (struct ast_key *key, const char *msg, int msglen, const unsigned char *sig), { return -1; });
/*! /*!
* \brief Sign a message signature using a given private key * \brief Sign a message signature using a given private key
@ -77,7 +79,7 @@ extern int (*ast_check_signature_bin)(struct ast_key *key, const char *msg, int
* \retval -1 on failure. * \retval -1 on failure.
* *
*/ */
extern int (*ast_sign)(struct ast_key *key, char *msg, char *sig); AST_OPTIONAL_API(int, ast_sign, (struct ast_key *key, char *msg, char *sig), { return -1; });
/*! /*!
* \brief Sign a message signature using a given private key * \brief Sign a message signature using a given private key
@ -90,7 +92,7 @@ extern int (*ast_sign)(struct ast_key *key, char *msg, char *sig);
* \retval -1 on failure. * \retval -1 on failure.
* *
*/ */
extern int (*ast_sign_bin)(struct ast_key *key, const char *msg, int msglen, unsigned char *sig); AST_OPTIONAL_API(int, ast_sign_bin, (struct ast_key *key, const char *msg, int msglen, unsigned char *sig), { return -1; });
/*! /*!
* \brief Encrypt a message using a given private key * \brief Encrypt a message using a given private key
@ -104,7 +106,7 @@ extern int (*ast_sign_bin)(struct ast_key *key, const char *msg, int msglen, uns
* \retval -1 on failure. * \retval -1 on failure.
* *
*/ */
extern int (*ast_encrypt_bin)(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key); AST_OPTIONAL_API(int, ast_encrypt_bin, (unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key), { return -1; });
/*! /*!
* \brief Decrypt a message using a given private key * \brief Decrypt a message using a given private key
@ -118,7 +120,10 @@ extern int (*ast_encrypt_bin)(unsigned char *dst, const unsigned char *src, int
* \retval -1 on failure. * \retval -1 on failure.
* *
*/ */
extern int (*ast_decrypt_bin)(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key); AST_OPTIONAL_API(int, ast_decrypt_bin, (unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key), { return -1; });
AST_OPTIONAL_API(int, ast_crypto_loaded, (void), { return 0; });
#if defined(__cplusplus) || defined(c_plusplus) #if defined(__cplusplus) || defined(c_plusplus)
} }
#endif #endif

@ -80,6 +80,13 @@
* definition; this means that any consumers of the API functions so * definition; this means that any consumers of the API functions so
* defined will require that the provider of the API functions be * defined will require that the provider of the API functions be
* loaded before they can reference the symbols. * loaded before they can reference the symbols.
*
* WARNING WARNING WARNING WARNING WARNING
*
* You MUST add the AST_MODFLAG_GLOBAL_SYMBOLS to the module for which you
* are enabling optional_api functionality, or it will fail to work.
*
* WARNING WARNING WARNING WARNING WARNING
*/ */
#define __stringify_1(x) #x #define __stringify_1(x) #x
@ -174,11 +181,11 @@
#define AST_OPTIONAL_API(result, name, proto, stub) \ #define AST_OPTIONAL_API(result, name, proto, stub) \
result AST_OPTIONAL_API_NAME(name) proto; \ result AST_OPTIONAL_API_NAME(name) proto; \
__attribute__((alias(__stringify(AST_OPTIONAL_API_NAME(name))))) typeof(AST_OPTIONAL_API_NAME(name)) name; static __attribute__((alias(__stringify(AST_OPTIONAL_API_NAME(name))))) typeof(AST_OPTIONAL_API_NAME(name)) name;
#define AST_OPTIONAL_API_ATTR(result, attr, name, proto, stub) \ #define AST_OPTIONAL_API_ATTR(result, attr, name, proto, stub) \
result __attribute__((attr)) AST_OPTIONAL_API_NAME(name) proto; \ result __attribute__((attr)) AST_OPTIONAL_API_NAME(name) proto; \
__attribute__((alias(__stringify(AST_OPTIONAL_API_NAME(name))))) typeof(AST_OPTIONAL_API_NAME(name)) name; static __attribute__((alias(__stringify(AST_OPTIONAL_API_NAME(name))))) typeof(AST_OPTIONAL_API_NAME(name)) name;
#else #else

@ -92,7 +92,7 @@ ifneq ($(findstring USE_HOARD_ALLOCATOR,$(MENUSELECT_CFLAGS)),)
endif endif
ifeq ($(GNU_LD),1) ifeq ($(GNU_LD),1)
ASTLINK+=-Wl,--version-script,asterisk.exports ASTLINK+=-Wl,--version-script,asterisk.exports,--dynamic-list,asterisk.dynamics
endif endif
CHECK_SUBDIR: # do nothing, just make sure that we recurse in the subdir/ CHECK_SUBDIR: # do nothing, just make sure that we recurse in the subdir/

@ -1,77 +0,0 @@
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 1999 - 2005, Digium, Inc.
*
* Christopher L. Wade <wade.christopher@gmail.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/channel.h"
#include "asterisk/adsi.h"
#ifdef SKREP
#define build_stub(func_name,...) \
static int stub_ ## func_name(__VA_ARGS__) \
{ \
if (option_debug > 4) \
ast_log(LOG_NOTICE, "ADSI support not loaded!\n"); \
return -1; \
} \
\
int (*func_name)(__VA_ARGS__) = \
stub_ ## func_name;
#endif
#define build_stub(func_name,...) \
static int stub_##func_name(__VA_ARGS__) \
{ \
ast_debug(5, "ADSI support not loaded!\n"); \
return -1; \
} \
\
int (*func_name)(__VA_ARGS__) = \
stub_##func_name;
build_stub(ast_adsi_channel_init, struct ast_channel *chan)
build_stub(ast_adsi_begin_download, struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version)
build_stub(ast_adsi_end_download, struct ast_channel *chan)
build_stub(ast_adsi_channel_restore, struct ast_channel *chan)
build_stub(ast_adsi_print, struct ast_channel *chan, char **lines, int *align, int voice)
build_stub(ast_adsi_load_session, struct ast_channel *chan, unsigned char *app, int ver, int data)
build_stub(ast_adsi_unload_session, struct ast_channel *chan)
build_stub(ast_adsi_transmit_messages, struct ast_channel *chan, unsigned char **msg, int *msglen, int *msgtype)
build_stub(ast_adsi_transmit_message, struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype)
build_stub(ast_adsi_transmit_message_full, struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait)
build_stub(ast_adsi_read_encoded_dtmf, struct ast_channel *chan, unsigned char *buf, int maxlen)
build_stub(ast_adsi_connect_session, unsigned char *buf, unsigned char *fdn, int ver)
build_stub(ast_adsi_query_cpeid, unsigned char *buf)
build_stub(ast_adsi_query_cpeinfo, unsigned char *buf)
build_stub(ast_adsi_get_cpeid, struct ast_channel *chan, unsigned char *cpeid, int voice)
build_stub(ast_adsi_get_cpeinfo, struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
build_stub(ast_adsi_download_connect, unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver)
build_stub(ast_adsi_disconnect_session, unsigned char *buf)
build_stub(ast_adsi_download_disconnect, unsigned char *buf)
build_stub(ast_adsi_data_mode, unsigned char *buf)
build_stub(ast_adsi_clear_soft_keys, unsigned char *buf)
build_stub(ast_adsi_clear_screen, unsigned char *buf)
build_stub(ast_adsi_voice_mode, unsigned char *buf, int when)
build_stub(ast_adsi_available, struct ast_channel *chan)
build_stub(ast_adsi_display, unsigned char *buf, int page, int line, int just, int wrap, char *col1, char *col2)
build_stub(ast_adsi_set_line, unsigned char *buf, int page, int line)
build_stub(ast_adsi_load_soft_key, unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data)
build_stub(ast_adsi_set_keys, unsigned char *buf, unsigned char *keys)
build_stub(ast_adsi_input_control, unsigned char *buf, int page, int line, int display, int format, int just)
build_stub(ast_adsi_input_format, unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2)

@ -1,6 +1,14 @@
{ {
ast_agi_*; *ast_adsi_*;
ast_pktccops_*; *ast_agi_*;
ast_smdi_*; *ast_pktccops_*;
ast_monitor_*; *ast_smdi_*;
*ast_monitor_*;
*ast_key_get;
*ast_check_signature;
*ast_check_signature_bin;
*ast_sign;
*ast_sign_bin;
*ast_encrypt_bin;
*ast_decrypt_bin;
}; };

@ -1,68 +0,0 @@
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 1999 - 2005, Digium, Inc.
*
* Mark Spencer <markster@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*! \file
*
* \brief Stubs for res_crypto routines
*
* \author Mark Spencer <markster@digium.com>
*/
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/crypto.h"
#include "asterisk/logger.h"
static struct ast_key *stub_ast_key_get(const char *kname, int ktype)
{
ast_log(LOG_NOTICE, "Crypto support not loaded!\n");
return NULL;
}
#ifdef SKREP
#define build_stub(func_name,...) \
static int stub_ ## func_name(__VA_ARGS__) \
{ \
ast_log(LOG_NOTICE, "Crypto support not loaded!\n"); \
return -1; \
} \
\
int (*func_name)(__VA_ARGS__) = \
stub_ ## func_name;
#endif
#define build_stub(func_name,...) \
static int stub_##func_name(__VA_ARGS__) \
{ \
ast_log(LOG_NOTICE, "Crypto support not loaded!\n"); \
return -1; \
} \
\
int (*func_name)(__VA_ARGS__) = \
stub_##func_name;
struct ast_key *(*ast_key_get)(const char *key, int type) =
stub_ast_key_get;
build_stub(ast_check_signature, struct ast_key *key, const char *msg, const char *sig);
build_stub(ast_check_signature_bin, struct ast_key *key, const char *msg, int msglen, const unsigned char *sig);
build_stub(ast_sign, struct ast_key *key, char *msg, char *sig);
build_stub(ast_sign_bin, struct ast_key *key, const char *msg, int msglen, unsigned char *sig);
build_stub(ast_encrypt_bin, unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key);
build_stub(ast_decrypt_bin, unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key);

@ -836,7 +836,7 @@ static enum ast_module_load_result load_resource(const char *resource_name, unsi
return required ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_DECLINE; return required ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_DECLINE;
} }
if (!mod->lib && mod->info->backup_globals && mod->info->backup_globals()) { if (!mod->lib && mod->info->backup_globals()) {
ast_log(LOG_WARNING, "Module '%s' was unable to backup its global data.\n", resource_name); ast_log(LOG_WARNING, "Module '%s' was unable to backup its global data.\n", resource_name);
return required ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_DECLINE; return required ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_DECLINE;
} }

@ -20,9 +20,9 @@
/*! \file /*! \file
* *
* \brief ADSI support * \brief ADSI support
* *
* \author Mark Spencer <markster@digium.com> * \author Mark Spencer <markster@digium.com>
* *
* \note this module is required by app_voicemail and app_getcpeid * \note this module is required by app_voicemail and app_getcpeid
* \todo Move app_getcpeid into this module * \todo Move app_getcpeid into this module
@ -37,7 +37,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <time.h> #include <time.h>
#include <math.h> #include <math.h>
#include "asterisk/adsi.h"
#include "asterisk/ulaw.h" #include "asterisk/ulaw.h"
#include "asterisk/alaw.h" #include "asterisk/alaw.h"
#include "asterisk/callerid.h" #include "asterisk/callerid.h"
@ -47,6 +46,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/config.h" #include "asterisk/config.h"
#include "asterisk/file.h" #include "asterisk/file.h"
#define AST_API_MODULE
#include "asterisk/adsi.h"
#define DEFAULT_ADSI_MAX_RETRIES 3 #define DEFAULT_ADSI_MAX_RETRIES 3
#define ADSI_MAX_INTRO 20 #define ADSI_MAX_INTRO 20
@ -73,20 +75,22 @@ static int adsi_generate(unsigned char *buf, int msgtype, unsigned char *msg, in
/* Initial carrier (imaginary) */ /* Initial carrier (imaginary) */
float cr = 1.0, ci = 0.0, scont = 0.0; float cr = 1.0, ci = 0.0, scont = 0.0;
if (msglen > 255) if (msglen > 255) {
msglen = 255; msglen = 255;
}
/* If first message, Send 150ms of MARK's */ /* If first message, Send 150ms of MARK's */
if (msgnum == 1) { if (msgnum == 1) {
for (x = 0; x < 150; x++) /* was 150 */ for (x = 0; x < 150; x++) { /* was 150 */
PUT_CLID_MARKMS; PUT_CLID_MARKMS;
}
} }
/* Put message type */ /* Put message type */
PUT_CLID(msgtype); PUT_CLID(msgtype);
sum = msgtype; sum = msgtype;
/* Put message length (plus one for the message number) */ /* Put message length (plus one for the message number) */
PUT_CLID(msglen + 1); PUT_CLID(msglen + 1);
sum += msglen + 1; sum += msglen + 1;
@ -106,8 +110,9 @@ static int adsi_generate(unsigned char *buf, int msgtype, unsigned char *msg, in
#if 0 #if 0
if (last) { if (last) {
/* Put trailing marks */ /* Put trailing marks */
for (x = 0; x < 50; x++) for (x = 0; x < 50; x++) {
PUT_CLID_MARKMS; PUT_CLID_MARKMS;
}
} }
#endif #endif
return bytes; return bytes;
@ -128,10 +133,11 @@ static int adsi_careful_send(struct ast_channel *chan, unsigned char *buf, int l
amt = len; amt = len;
/* Send remainder if provided */ /* Send remainder if provided */
if (amt > *remain) if (amt > *remain) {
amt = *remain; amt = *remain;
else } else {
*remain = *remain - amt; *remain = *remain - amt;
}
outf.frametype = AST_FRAME_VOICE; outf.frametype = AST_FRAME_VOICE;
outf.subclass.codec = AST_FORMAT_ULAW; outf.subclass.codec = AST_FORMAT_ULAW;
outf.data.ptr = buf; outf.data.ptr = buf;
@ -146,32 +152,35 @@ static int adsi_careful_send(struct ast_channel *chan, unsigned char *buf, int l
len -= amt; len -= amt;
} }
while(len) { while (len) {
amt = len; amt = len;
/* If we don't get anything at all back in a second, forget /* If we don't get anything at all back in a second, forget
about it */ about it */
if (ast_waitfor(chan, 1000) < 1) if (ast_waitfor(chan, 1000) < 1) {
return -1; return -1;
}
/* Detect hangup */ /* Detect hangup */
if (!(inf = ast_read(chan))) if (!(inf = ast_read(chan))) {
return -1; return -1;
}
/* Drop any frames that are not voice */ /* Drop any frames that are not voice */
if (inf->frametype != AST_FRAME_VOICE) { if (inf->frametype != AST_FRAME_VOICE) {
ast_frfree(inf); ast_frfree(inf);
continue; continue;
} }
if (inf->subclass.codec != AST_FORMAT_ULAW) { if (inf->subclass.codec != AST_FORMAT_ULAW) {
ast_log(LOG_WARNING, "Channel not in ulaw?\n"); ast_log(LOG_WARNING, "Channel not in ulaw?\n");
ast_frfree(inf); ast_frfree(inf);
return -1; return -1;
} }
/* Send no more than they sent us */ /* Send no more than they sent us */
if (amt > inf->datalen) if (amt > inf->datalen) {
amt = inf->datalen; amt = inf->datalen;
else if (remain) } else if (remain) {
*remain = inf->datalen - amt; *remain = inf->datalen - amt;
}
outf.frametype = AST_FRAME_VOICE; outf.frametype = AST_FRAME_VOICE;
outf.subclass.codec = AST_FORMAT_ULAW; outf.subclass.codec = AST_FORMAT_ULAW;
outf.data.ptr = buf; outf.data.ptr = buf;
@ -204,23 +213,25 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms
return -1; return -1;
} }
while(retries < maxretries) { while (retries < maxretries) {
if (!(chan->adsicpe & ADSI_FLAG_DATAMODE)) { if (!(chan->adsicpe & ADSI_FLAG_DATAMODE)) {
/* Generate CAS (no SAS) */ /* Generate CAS (no SAS) */
ast_gen_cas(buf, 0, 680, AST_FORMAT_ULAW); ast_gen_cas(buf, 0, 680, AST_FORMAT_ULAW);
/* Send CAS */ /* Send CAS */
if (adsi_careful_send(chan, buf, 680, NULL)) if (adsi_careful_send(chan, buf, 680, NULL)) {
ast_log(LOG_WARNING, "Unable to send CAS\n"); ast_log(LOG_WARNING, "Unable to send CAS\n");
}
/* Wait For DTMF result */ /* Wait For DTMF result */
waittime = 500; waittime = 500;
for(;;) { for (;;) {
if (((res = ast_waitfor(chan, waittime)) < 1)) { if (((res = ast_waitfor(chan, waittime)) < 1)) {
/* Didn't get back DTMF A in time */ /* Didn't get back DTMF A in time */
ast_debug(1, "No ADSI CPE detected (%d)\n", res); ast_debug(1, "No ADSI CPE detected (%d)\n", res);
if (!chan->adsicpe) if (!chan->adsicpe) {
chan->adsicpe = AST_ADSI_UNAVAILABLE; chan->adsicpe = AST_ADSI_UNAVAILABLE;
}
errno = ENOSYS; errno = ENOSYS;
return -1; return -1;
} }
@ -232,16 +243,19 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms
if (f->frametype == AST_FRAME_DTMF) { if (f->frametype == AST_FRAME_DTMF) {
if (f->subclass.integer == 'A') { if (f->subclass.integer == 'A') {
/* Okay, this is an ADSI CPE. Note this for future reference, too */ /* Okay, this is an ADSI CPE. Note this for future reference, too */
if (!chan->adsicpe) if (!chan->adsicpe) {
chan->adsicpe = AST_ADSI_AVAILABLE; chan->adsicpe = AST_ADSI_AVAILABLE;
}
break; break;
} else { } else {
if (f->subclass.integer == 'D') if (f->subclass.integer == 'D') {
ast_debug(1, "Off-hook capable CPE only, not ADSI\n"); ast_debug(1, "Off-hook capable CPE only, not ADSI\n");
else } else {
ast_log(LOG_WARNING, "Unknown ADSI response '%c'\n", f->subclass.integer); ast_log(LOG_WARNING, "Unknown ADSI response '%c'\n", f->subclass.integer);
if (!chan->adsicpe) }
if (!chan->adsicpe) {
chan->adsicpe = AST_ADSI_UNAVAILABLE; chan->adsicpe = AST_ADSI_UNAVAILABLE;
}
errno = ENOSYS; errno = ENOSYS;
ast_frfree(f); ast_frfree(f);
return -1; return -1;
@ -266,36 +280,39 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms
return -1; return -1;
} }
ast_debug(1, "Message %d, of %d input bytes, %d output bytes\n", x + 1, msglen[x], res); ast_debug(1, "Message %d, of %d input bytes, %d output bytes\n", x + 1, msglen[x], res);
pos += res; pos += res;
x++; x++;
} }
rem = 0; rem = 0;
res = adsi_careful_send(chan, buf, pos, &rem); res = adsi_careful_send(chan, buf, pos, &rem);
if (!def) if (!def) {
ast_channel_undefer_dtmf(chan); ast_channel_undefer_dtmf(chan);
if (res) }
if (res) {
return -1; return -1;
}
ast_debug(1, "Sent total spill of %d bytes\n", pos); ast_debug(1, "Sent total spill of %d bytes\n", pos);
memset(ack, 0, sizeof(ack)); memset(ack, 0, sizeof(ack));
/* Get real result and check for hangup */ /* Get real result and check for hangup */
if ((res = ast_readstring(chan, ack, 2, 1000, 1000, "")) < 0) if ((res = ast_readstring(chan, ack, 2, 1000, 1000, "")) < 0) {
return -1; return -1;
}
if (ack[0] == 'D') { if (ack[0] == 'D') {
ast_debug(1, "Acked up to message %d\n", atoi(ack + 1)); start += atoi(ack + 1); ast_debug(1, "Acked up to message %d\n", atoi(ack + 1)); start += atoi(ack + 1);
if (start >= x) if (start >= x) {
break; break;
else { } else {
retries++; retries++;
ast_debug(1, "Retransmitting (%d), from %d\n", retries, start + 1); ast_debug(1, "Retransmitting (%d), from %d\n", retries, start + 1);
} }
} else { } else {
retries++; retries++;
ast_log(LOG_WARNING, "Unexpected response to ack: %s (retry %d)\n", ack, retries); ast_log(LOG_WARNING, "Unexpected response to ack: %s (retry %d)\n", ack, retries);
} }
} }
if (retries >= maxretries) { if (retries >= maxretries) {
ast_log(LOG_WARNING, "Maximum ADSI Retries (%d) exceeded\n", maxretries); ast_log(LOG_WARNING, "Maximum ADSI Retries (%d) exceeded\n", maxretries);
@ -303,10 +320,9 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms
return -1; return -1;
} }
return 0; return 0;
} }
static int _ast_adsi_begin_download(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version) int AST_OPTIONAL_API_NAME(ast_adsi_begin_download)(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version)
{ {
int bytes = 0; int bytes = 0;
unsigned char buf[256]; unsigned char buf[256];
@ -315,30 +331,34 @@ static int _ast_adsi_begin_download(struct ast_channel *chan, char *service, uns
/* Setup the resident soft key stuff, a piece at a time */ /* Setup the resident soft key stuff, a piece at a time */
/* Upload what scripts we can for voicemail ahead of time */ /* Upload what scripts we can for voicemail ahead of time */
bytes += ast_adsi_download_connect(buf + bytes, service, fdn, sec, version); bytes += ast_adsi_download_connect(buf + bytes, service, fdn, sec, version);
if (ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DOWNLOAD, 0)) if (ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DOWNLOAD, 0)) {
return -1; return -1;
if (ast_readstring(chan, ack, 1, 10000, 10000, "")) }
if (ast_readstring(chan, ack, 1, 10000, 10000, "")) {
return -1; return -1;
if (ack[0] == 'B') }
if (ack[0] == 'B') {
return 0; return 0;
}
ast_debug(1, "Download was denied by CPE\n"); ast_debug(1, "Download was denied by CPE\n");
return -1; return -1;
} }
static int _ast_adsi_end_download(struct ast_channel *chan) int AST_OPTIONAL_API_NAME(ast_adsi_end_download)(struct ast_channel *chan)
{ {
int bytes = 0; int bytes = 0;
unsigned char buf[256]; unsigned char buf[256];
/* Setup the resident soft key stuff, a piece at a time */ /* Setup the resident soft key stuff, a piece at a time */
/* Upload what scripts we can for voicemail ahead of time */ /* Upload what scripts we can for voicemail ahead of time */
bytes += ast_adsi_download_disconnect(buf + bytes); bytes += ast_adsi_download_disconnect(buf + bytes);
if (ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DOWNLOAD, 0)) if (ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DOWNLOAD, 0)) {
return -1; return -1;
}
return 0; return 0;
} }
static int _ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait) int AST_OPTIONAL_API_NAME(ast_adsi_transmit_message_full)(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait)
{ {
unsigned char *msgs[5] = { NULL, NULL, NULL, NULL, NULL }; unsigned char *msgs[5] = { NULL, NULL, NULL, NULL, NULL };
int msglens[5], msgtypes[5], newdatamode = (chan->adsicpe & ADSI_FLAG_DATAMODE), res, x, writeformat = chan->writeformat, readformat = chan->readformat, waitforswitch = 0; int msglens[5], msgtypes[5], newdatamode = (chan->adsicpe & ADSI_FLAG_DATAMODE), res, x, writeformat = chan->writeformat, readformat = chan->readformat, waitforswitch = 0;
@ -349,7 +369,7 @@ static int _ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned ch
waitforswitch++; waitforswitch++;
newdatamode = ADSI_FLAG_DATAMODE; newdatamode = ADSI_FLAG_DATAMODE;
} }
if (msg[x] == ADSI_SWITCH_TO_VOICE) { if (msg[x] == ADSI_SWITCH_TO_VOICE) {
ast_debug(1, "Switch to voice is sent!\n"); ast_debug(1, "Switch to voice is sent!\n");
waitforswitch++; waitforswitch++;
@ -376,8 +396,9 @@ static int _ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned ch
if (ast_set_read_format(chan, AST_FORMAT_ULAW)) { if (ast_set_read_format(chan, AST_FORMAT_ULAW)) {
ast_log(LOG_WARNING, "Unable to set read format to ULAW\n"); ast_log(LOG_WARNING, "Unable to set read format to ULAW\n");
if (writeformat) { if (writeformat) {
if (ast_set_write_format(chan, writeformat)) if (ast_set_write_format(chan, writeformat)) {
ast_log(LOG_WARNING, "Unable to restore write format to %d\n", writeformat); ast_log(LOG_WARNING, "Unable to restore write format to %d\n", writeformat);
}
} }
return -1; return -1;
} }
@ -385,26 +406,30 @@ static int _ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned ch
if (dowait) { if (dowait) {
ast_debug(1, "Wait for switch is '%d'\n", waitforswitch); ast_debug(1, "Wait for switch is '%d'\n", waitforswitch);
while (waitforswitch-- && ((res = ast_waitfordigit(chan, 1000)) > 0)) { while (waitforswitch-- && ((res = ast_waitfordigit(chan, 1000)) > 0)) {
res = 0; res = 0;
ast_debug(1, "Waiting for 'B'...\n"); ast_debug(1, "Waiting for 'B'...\n");
} }
} }
if (!res) if (!res) {
chan->adsicpe = (chan->adsicpe & ~ADSI_FLAG_DATAMODE) | newdatamode; chan->adsicpe = (chan->adsicpe & ~ADSI_FLAG_DATAMODE) | newdatamode;
}
if (writeformat) if (writeformat) {
ast_set_write_format(chan, writeformat); ast_set_write_format(chan, writeformat);
if (readformat) }
if (readformat) {
ast_set_read_format(chan, readformat); ast_set_read_format(chan, readformat);
}
if (!res) if (!res) {
res = ast_safe_sleep(chan, 100 ); res = ast_safe_sleep(chan, 100 );
}
return res; return res;
} }
static int _ast_adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype) int AST_OPTIONAL_API_NAME(ast_adsi_transmit_message)(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype)
{ {
return ast_adsi_transmit_message_full(chan, msg, msglen, msgtype, 1); return ast_adsi_transmit_message_full(chan, msg, msglen, msgtype, 1);
} }
@ -420,13 +445,14 @@ static inline int ccopy(unsigned char *dst, const unsigned char *src, int max)
return x; return x;
} }
static int _ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data) int AST_OPTIONAL_API_NAME(ast_adsi_load_soft_key)(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data)
{ {
int bytes = 0; int bytes = 0;
/* Abort if invalid key specified */ /* Abort if invalid key specified */
if ((key < 2) || (key > 33)) if ((key < 2) || (key > 33)) {
return -1; return -1;
}
buf[bytes++] = ADSI_LOAD_SOFTKEY; buf[bytes++] = ADSI_LOAD_SOFTKEY;
/* Reserve for length */ /* Reserve for length */
@ -448,8 +474,9 @@ static int _ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llab
if (ret) { if (ret) {
/* Place delimiter */ /* Place delimiter */
buf[bytes++] = 0xff; buf[bytes++] = 0xff;
if (data) if (data) {
buf[bytes++] = ADSI_SWITCH_TO_DATA2; buf[bytes++] = ADSI_SWITCH_TO_DATA2;
}
/* Carefully copy return string */ /* Carefully copy return string */
bytes += ccopy(buf + bytes, (const unsigned char *)ret, 20); bytes += ccopy(buf + bytes, (const unsigned char *)ret, 20);
@ -457,10 +484,9 @@ static int _ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llab
/* Replace parameter length */ /* Replace parameter length */
buf[1] = bytes - 2; buf[1] = bytes - 2;
return bytes; return bytes;
} }
static int _ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver) int AST_OPTIONAL_API_NAME(ast_adsi_connect_session)(unsigned char *buf, unsigned char *fdn, int ver)
{ {
int bytes = 0, x; int bytes = 0, x;
@ -471,10 +497,12 @@ static int _ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int
bytes++; bytes++;
if (fdn) { if (fdn) {
for (x = 0; x < 4; x++) for (x = 0; x < 4; x++) {
buf[bytes++] = fdn[x]; buf[bytes++] = fdn[x];
if (ver > -1) }
if (ver > -1) {
buf[bytes++] = ver & 0xff; buf[bytes++] = ver & 0xff;
}
} }
buf[1] = bytes - 2; buf[1] = bytes - 2;
@ -482,7 +510,7 @@ static int _ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int
} }
static int _ast_adsi_download_connect(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver) int AST_OPTIONAL_API_NAME(ast_adsi_download_connect)(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver)
{ {
int bytes = 0, x; int bytes = 0, x;
@ -497,12 +525,14 @@ static int _ast_adsi_download_connect(unsigned char *buf, char *service, unsign
/* Delimiter */ /* Delimiter */
buf[bytes++] = 0xff; buf[bytes++] = 0xff;
for (x = 0; x < 4; x++) for (x = 0; x < 4; x++) {
buf[bytes++] = fdn[x]; buf[bytes++] = fdn[x];
}
for (x = 0; x < 4; x++) for (x = 0; x < 4; x++) {
buf[bytes++] = sec[x]; buf[bytes++] = sec[x];
}
buf[bytes++] = ver & 0xff; buf[bytes++] = ver & 0xff;
@ -512,7 +542,7 @@ static int _ast_adsi_download_connect(unsigned char *buf, char *service, unsign
} }
static int _ast_adsi_disconnect_session(unsigned char *buf) int AST_OPTIONAL_API_NAME(ast_adsi_disconnect_session)(unsigned char *buf)
{ {
int bytes = 0; int bytes = 0;
@ -527,7 +557,7 @@ static int _ast_adsi_disconnect_session(unsigned char *buf)
} }
static int _ast_adsi_query_cpeid(unsigned char *buf) int AST_OPTIONAL_API_NAME(ast_adsi_query_cpeid)(unsigned char *buf)
{ {
int bytes = 0; int bytes = 0;
buf[bytes++] = ADSI_QUERY_CPEID; buf[bytes++] = ADSI_QUERY_CPEID;
@ -537,7 +567,7 @@ static int _ast_adsi_query_cpeid(unsigned char *buf)
return bytes; return bytes;
} }
static int _ast_adsi_query_cpeinfo(unsigned char *buf) int AST_OPTIONAL_API_NAME(ast_adsi_query_cpeinfo)(unsigned char *buf)
{ {
int bytes = 0; int bytes = 0;
buf[bytes++] = ADSI_QUERY_CONFIG; buf[bytes++] = ADSI_QUERY_CONFIG;
@ -547,27 +577,30 @@ static int _ast_adsi_query_cpeinfo(unsigned char *buf)
return bytes; return bytes;
} }
static int _ast_adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *buf, int maxlen) int AST_OPTIONAL_API_NAME(ast_adsi_read_encoded_dtmf)(struct ast_channel *chan, unsigned char *buf, int maxlen)
{ {
int bytes = 0, res, gotstar = 0, pos = 0; int bytes = 0, res, gotstar = 0, pos = 0;
unsigned char current = 0; unsigned char current = 0;
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
while(bytes <= maxlen) { while (bytes <= maxlen) {
/* Wait up to a second for a digit */ /* Wait up to a second for a digit */
if (!(res = ast_waitfordigit(chan, 1000))) if (!(res = ast_waitfordigit(chan, 1000))) {
break; break;
}
if (res == '*') { if (res == '*') {
gotstar = 1; gotstar = 1;
continue; continue;
} }
/* Ignore anything other than a digit */ /* Ignore anything other than a digit */
if ((res < '0') || (res > '9')) if ((res < '0') || (res > '9')) {
continue; continue;
}
res -= '0'; res -= '0';
if (gotstar) if (gotstar) {
res += 9; res += 9;
}
if (pos) { if (pos) {
pos = 0; pos = 0;
buf[bytes++] = (res << 4) | current; buf[bytes++] = (res << 4) | current;
@ -581,7 +614,7 @@ static int _ast_adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *
return bytes; return bytes;
} }
static int _ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice) int AST_OPTIONAL_API_NAME(ast_adsi_get_cpeid)(struct ast_channel *chan, unsigned char *cpeid, int voice)
{ {
unsigned char buf[256] = ""; unsigned char buf[256] = "";
int bytes = 0, res; int bytes = 0, res;
@ -612,7 +645,7 @@ static int _ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, i
return res; return res;
} }
static int _ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice) int AST_OPTIONAL_API_NAME(ast_adsi_get_cpeinfo)(struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
{ {
unsigned char buf[256] = ""; unsigned char buf[256] = "";
int bytes = 0, res; int bytes = 0, res;
@ -625,43 +658,49 @@ static int _ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *heig
ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
/* Get width */ /* Get width */
if ((res = ast_readstring(chan, (char *)buf, 2, 1000, 500, "")) < 0) if ((res = ast_readstring(chan, (char *) buf, 2, 1000, 500, "")) < 0) {
return res; return res;
if (strlen((char *)buf) != 2) { }
if (strlen((char *) buf) != 2) {
ast_log(LOG_WARNING, "Got %d bytes of width, expecting 2\n", res); ast_log(LOG_WARNING, "Got %d bytes of width, expecting 2\n", res);
res = 0; res = 0;
} else { } else {
res = 1; res = 1;
} }
if (width) if (width) {
*width = atoi((char *)buf); *width = atoi((char *) buf);
}
/* Get height */ /* Get height */
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
if (res) { if (res) {
if ((res = ast_readstring(chan, (char *)buf, 2, 1000, 500, "")) < 0) if ((res = ast_readstring(chan, (char *) buf, 2, 1000, 500, "")) < 0) {
return res; return res;
if (strlen((char *)buf) != 2) { }
if (strlen((char *) buf) != 2) {
ast_log(LOG_WARNING, "Got %d bytes of height, expecting 2\n", res); ast_log(LOG_WARNING, "Got %d bytes of height, expecting 2\n", res);
res = 0; res = 0;
} else { } else {
res = 1; res = 1;
} }
if (height) if (height) {
*height= atoi((char *)buf); *height = atoi((char *) buf);
}
} }
/* Get buttons */ /* Get buttons */
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
if (res) { if (res) {
if ((res = ast_readstring(chan, (char *)buf, 1, 1000, 500, "")) < 0) if ((res = ast_readstring(chan, (char *) buf, 1, 1000, 500, "")) < 0) {
return res; return res;
if (strlen((char *)buf) != 1) { }
if (strlen((char *) buf) != 1) {
ast_log(LOG_WARNING, "Got %d bytes of buttons, expecting 1\n", res); ast_log(LOG_WARNING, "Got %d bytes of buttons, expecting 1\n", res);
res = 0; res = 0;
} else { } else {
res = 1; res = 1;
} }
if (buttons) if (buttons) {
*buttons = atoi((char *)buf); *buttons = atoi((char *) buf);
}
} }
if (voice) { if (voice) {
bytes = 0; bytes = 0;
@ -673,7 +712,7 @@ static int _ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *heig
return res; return res;
} }
static int _ast_adsi_data_mode(unsigned char *buf) int AST_OPTIONAL_API_NAME(ast_adsi_data_mode)(unsigned char *buf)
{ {
int bytes = 0; int bytes = 0;
@ -688,7 +727,7 @@ static int _ast_adsi_data_mode(unsigned char *buf)
} }
static int _ast_adsi_clear_soft_keys(unsigned char *buf) int AST_OPTIONAL_API_NAME(ast_adsi_clear_soft_keys)(unsigned char *buf)
{ {
int bytes = 0; int bytes = 0;
@ -703,7 +742,7 @@ static int _ast_adsi_clear_soft_keys(unsigned char *buf)
} }
static int _ast_adsi_clear_screen(unsigned char *buf) int AST_OPTIONAL_API_NAME(ast_adsi_clear_screen)(unsigned char *buf)
{ {
int bytes = 0; int bytes = 0;
@ -718,7 +757,7 @@ static int _ast_adsi_clear_screen(unsigned char *buf)
} }
static int _ast_adsi_voice_mode(unsigned char *buf, int when) int AST_OPTIONAL_API_NAME(ast_adsi_voice_mode)(unsigned char *buf, int when)
{ {
int bytes = 0; int bytes = 0;
@ -735,16 +774,17 @@ static int _ast_adsi_voice_mode(unsigned char *buf, int when)
} }
static int _ast_adsi_available(struct ast_channel *chan) int AST_OPTIONAL_API_NAME(ast_adsi_available)(struct ast_channel *chan)
{ {
int cpe = chan->adsicpe & 0xff; int cpe = chan->adsicpe & 0xff;
if ((cpe == AST_ADSI_AVAILABLE) || if ((cpe == AST_ADSI_AVAILABLE) ||
(cpe == AST_ADSI_UNKNOWN)) (cpe == AST_ADSI_UNKNOWN)) {
return 1; return 1;
}
return 0; return 0;
} }
static int _ast_adsi_download_disconnect(unsigned char *buf) int AST_OPTIONAL_API_NAME(ast_adsi_download_disconnect)(unsigned char *buf)
{ {
int bytes = 0; int bytes = 0;
@ -759,7 +799,7 @@ static int _ast_adsi_download_disconnect(unsigned char *buf)
} }
static int _ast_adsi_display(unsigned char *buf, int page, int line, int just, int wrap, int AST_OPTIONAL_API_NAME(ast_adsi_display)(unsigned char *buf, int page, int line, int just, int wrap,
char *col1, char *col2) char *col1, char *col2)
{ {
int bytes = 0; int bytes = 0;
@ -772,11 +812,12 @@ static int _ast_adsi_display(unsigned char *buf, int page, int line, int just, i
if (line > 33) return -1; if (line > 33) return -1;
} }
if (line < 1) if (line < 1) {
return -1; return -1;
}
/* Parameter type */ /* Parameter type */
buf[bytes++] = ADSI_LOAD_VIRTUAL_DISP; buf[bytes++] = ADSI_LOAD_VIRTUAL_DISP;
/* Reserve space for size */ /* Reserve space for size */
bytes++; bytes++;
@ -794,18 +835,18 @@ static int _ast_adsi_display(unsigned char *buf, int page, int line, int just, i
/* Delimiter */ /* Delimiter */
buf[bytes++] = 0xff; buf[bytes++] = 0xff;
/* Secondary column */ /* Secondary column */
bytes += ccopy(buf + bytes, (unsigned char *)col2, 20); bytes += ccopy(buf + bytes, (unsigned char *)col2, 20);
/* Update length */ /* Update length */
buf[1] = bytes - 2; buf[1] = bytes - 2;
return bytes; return bytes;
} }
static int _ast_adsi_input_control(unsigned char *buf, int page, int line, int display, int format, int just) int AST_OPTIONAL_API_NAME(ast_adsi_input_control)(unsigned char *buf, int page, int line, int display, int format, int just)
{ {
int bytes = 0; int bytes = 0;
@ -815,39 +856,40 @@ static int _ast_adsi_input_control(unsigned char *buf, int page, int line, int d
if (line > 33) return -1; if (line > 33) return -1;
} }
if (line < 1) if (line < 1) {
return -1; return -1;
}
buf[bytes++] = ADSI_INPUT_CONTROL; buf[bytes++] = ADSI_INPUT_CONTROL;
bytes++; bytes++;
buf[bytes++] = ((page & 1) << 7) | (line & 0x3f); buf[bytes++] = ((page & 1) << 7) | (line & 0x3f);
buf[bytes++] = ((display & 1) << 7) | ((just & 0x3) << 4) | (format & 0x7); buf[bytes++] = ((display & 1) << 7) | ((just & 0x3) << 4) | (format & 0x7);
buf[1] = bytes - 2; buf[1] = bytes - 2;
return bytes; return bytes;
} }
static int _ast_adsi_input_format(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2) int AST_OPTIONAL_API_NAME(ast_adsi_input_format)(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2)
{ {
int bytes = 0; int bytes = 0;
if (!strlen((char *)format1)) if (ast_strlen_zero((char *) format1)) {
return -1; return -1;
}
buf[bytes++] = ADSI_INPUT_FORMAT; buf[bytes++] = ADSI_INPUT_FORMAT;
bytes++; bytes++;
buf[bytes++] = ((dir & 1) << 7) | ((wrap & 1) << 6) | (num & 0x7); buf[bytes++] = ((dir & 1) << 7) | ((wrap & 1) << 6) | (num & 0x7);
bytes += ccopy(buf + bytes, (unsigned char *)format1, 20); bytes += ccopy(buf + bytes, (unsigned char *) format1, 20);
buf[bytes++] = 0xff; buf[bytes++] = 0xff;
if (format2 && strlen((char *)format2)) { if (!ast_strlen_zero(format2)) {
bytes += ccopy(buf + bytes, (unsigned char *)format2, 20); bytes += ccopy(buf + bytes, (unsigned char *) format2, 20);
} }
buf[1] = bytes - 2; buf[1] = bytes - 2;
return bytes; return bytes;
} }
static int _ast_adsi_set_keys(unsigned char *buf, unsigned char *keys) int AST_OPTIONAL_API_NAME(ast_adsi_set_keys)(unsigned char *buf, unsigned char *keys)
{ {
int bytes = 0, x; int bytes = 0, x;
@ -856,13 +898,14 @@ static int _ast_adsi_set_keys(unsigned char *buf, unsigned char *keys)
/* Space for size */ /* Space for size */
bytes++; bytes++;
/* Key definitions */ /* Key definitions */
for (x = 0; x < 6; x++) for (x = 0; x < 6; x++) {
buf[bytes++] = (keys[x] & 0x3f) ? keys[x] : (keys[x] | 0x1); buf[bytes++] = (keys[x] & 0x3f) ? keys[x] : (keys[x] | 0x1);
}
buf[1] = bytes - 2; buf[1] = bytes - 2;
return bytes; return bytes;
} }
static int _ast_adsi_set_line(unsigned char *buf, int page, int line) int AST_OPTIONAL_API_NAME(ast_adsi_set_line)(unsigned char *buf, int page, int line)
{ {
int bytes = 0; int bytes = 0;
@ -874,11 +917,12 @@ static int _ast_adsi_set_line(unsigned char *buf, int page, int line)
if (line > 33) return -1; if (line > 33) return -1;
} }
if (line < 1) if (line < 1) {
return -1; return -1;
}
/* Parameter type */ /* Parameter type */
buf[bytes++] = ADSI_LINE_CONTROL; buf[bytes++] = ADSI_LINE_CONTROL;
/* Reserve space for size */ /* Reserve space for size */
bytes++; bytes++;
@ -887,13 +931,12 @@ static int _ast_adsi_set_line(unsigned char *buf, int page, int line)
buf[1] = bytes - 2; buf[1] = bytes - 2;
return bytes; return bytes;
}
};
static int total = 0; static int total = 0;
static int speeds = 0; static int speeds = 0;
static int _ast_adsi_channel_restore(struct ast_channel *chan) int AST_OPTIONAL_API_NAME(ast_adsi_channel_restore)(struct ast_channel *chan)
{ {
unsigned char dsp[256] = "", keyd[6] = ""; unsigned char dsp[256] = "", keyd[6] = "";
int bytes, x; int bytes, x;
@ -905,8 +948,9 @@ static int _ast_adsi_channel_restore(struct ast_channel *chan)
/* Prepare key setup messages */ /* Prepare key setup messages */
if (speeds) { if (speeds) {
for (x = 0; x < speeds; x++) for (x = 0; x < speeds; x++) {
keyd[x] = ADSI_SPEED_DIAL + x; keyd[x] = ADSI_SPEED_DIAL + x;
}
bytes += ast_adsi_set_keys(dsp + bytes, keyd); bytes += ast_adsi_set_keys(dsp + bytes, keyd);
} }
ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0); ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0);
@ -914,24 +958,27 @@ static int _ast_adsi_channel_restore(struct ast_channel *chan)
} }
static int _ast_adsi_print(struct ast_channel *chan, char **lines, int *alignments, int voice) int AST_OPTIONAL_API_NAME(ast_adsi_print)(struct ast_channel *chan, char **lines, int *alignments, int voice)
{ {
unsigned char buf[4096]; unsigned char buf[4096];
int bytes = 0, res, x; int bytes = 0, res, x;
for(x = 0; lines[x]; x++) for (x = 0; lines[x]; x++) {
bytes += ast_adsi_display(buf + bytes, ADSI_INFO_PAGE, x+1, alignments[x], 0, lines[x], ""); bytes += ast_adsi_display(buf + bytes, ADSI_INFO_PAGE, x+1, alignments[x], 0, lines[x], "");
}
bytes += ast_adsi_set_line(buf + bytes, ADSI_INFO_PAGE, 1); bytes += ast_adsi_set_line(buf + bytes, ADSI_INFO_PAGE, 1);
if (voice) if (voice) {
bytes += ast_adsi_voice_mode(buf + bytes, 0); bytes += ast_adsi_voice_mode(buf + bytes, 0);
}
res = ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); res = ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
if (voice) if (voice) {
/* Ignore the resulting DTMF B announcing it's in voice mode */ /* Ignore the resulting DTMF B announcing it's in voice mode */
ast_waitfordigit(chan, 1000); ast_waitfordigit(chan, 1000);
}
return res; return res;
} }
static int _ast_adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data) int AST_OPTIONAL_API_NAME(ast_adsi_load_session)(struct ast_channel *chan, unsigned char *app, int ver, int data)
{ {
unsigned char dsp[256] = ""; unsigned char dsp[256] = "";
int bytes = 0, res; int bytes = 0, res;
@ -940,15 +987,18 @@ static int _ast_adsi_load_session(struct ast_channel *chan, unsigned char *app,
/* Connect to session */ /* Connect to session */
bytes += ast_adsi_connect_session(dsp + bytes, app, ver); bytes += ast_adsi_connect_session(dsp + bytes, app, ver);
if (data) if (data) {
bytes += ast_adsi_data_mode(dsp + bytes); bytes += ast_adsi_data_mode(dsp + bytes);
}
/* Prepare key setup messages */ /* Prepare key setup messages */
if (ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0)) if (ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0)) {
return -1; return -1;
}
if (app) { if (app) {
if ((res = ast_readstring(chan, resp, 1, 1200, 1200, "")) < 0) if ((res = ast_readstring(chan, resp, 1, 1200, 1200, "")) < 0) {
return -1; return -1;
}
if (res) { if (res) {
ast_debug(1, "No response from CPE about version. Assuming not there.\n"); ast_debug(1, "No response from CPE about version. Assuming not there.\n");
return 0; return 0;
@ -967,7 +1017,7 @@ static int _ast_adsi_load_session(struct ast_channel *chan, unsigned char *app,
} }
static int _ast_adsi_unload_session(struct ast_channel *chan) int AST_OPTIONAL_API_NAME(ast_adsi_unload_session)(struct ast_channel *chan)
{ {
unsigned char dsp[256] = ""; unsigned char dsp[256] = "";
int bytes = 0; int bytes = 0;
@ -977,37 +1027,41 @@ static int _ast_adsi_unload_session(struct ast_channel *chan)
bytes += ast_adsi_voice_mode(dsp + bytes, 0); bytes += ast_adsi_voice_mode(dsp + bytes, 0);
/* Prepare key setup messages */ /* Prepare key setup messages */
if (ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0)) if (ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0)) {
return -1; return -1;
}
return 0; return 0;
} }
static int str2align(const char *s) static int str2align(const char *s)
{ {
if (!strncasecmp(s, "l", 1)) if (!strncasecmp(s, "l", 1)) {
return ADSI_JUST_LEFT; return ADSI_JUST_LEFT;
else if (!strncasecmp(s, "r", 1)) } else if (!strncasecmp(s, "r", 1)) {
return ADSI_JUST_RIGHT; return ADSI_JUST_RIGHT;
else if (!strncasecmp(s, "i", 1)) } else if (!strncasecmp(s, "i", 1)) {
return ADSI_JUST_IND; return ADSI_JUST_IND;
else } else {
return ADSI_JUST_CENT; return ADSI_JUST_CENT;
}
} }
static void init_state(void) static void init_state(void)
{ {
int x; int x;
for (x = 0; x < ADSI_MAX_INTRO; x++) for (x = 0; x < ADSI_MAX_INTRO; x++) {
aligns[x] = ADSI_JUST_CENT; aligns[x] = ADSI_JUST_CENT;
}
ast_copy_string(intro[0], "Welcome to the", sizeof(intro[0])); ast_copy_string(intro[0], "Welcome to the", sizeof(intro[0]));
ast_copy_string(intro[1], "Asterisk", sizeof(intro[1])); ast_copy_string(intro[1], "Asterisk", sizeof(intro[1]));
ast_copy_string(intro[2], "Open Source PBX", sizeof(intro[2])); ast_copy_string(intro[2], "Open Source PBX", sizeof(intro[2]));
total = 3; total = 3;
speeds = 0; speeds = 0;
for (x = 3; x < ADSI_MAX_INTRO; x++) for (x = 3; x < ADSI_MAX_INTRO; x++) {
intro[x][0] = '\0'; intro[x][0] = '\0';
}
memset(speeddial, 0, sizeof(speeddial)); memset(speeddial, 0, sizeof(speeddial));
alignment = ADSI_JUST_CENT; alignment = ADSI_JUST_CENT;
} }
@ -1026,22 +1080,24 @@ static void adsi_load(int reload)
return; return;
} }
for (v = ast_variable_browse(conf, "intro"); v; v = v->next) { for (v = ast_variable_browse(conf, "intro"); v; v = v->next) {
if (!strcasecmp(v->name, "alignment")) if (!strcasecmp(v->name, "alignment")) {
alignment = str2align(v->value); alignment = str2align(v->value);
else if (!strcasecmp(v->name, "greeting")) { } else if (!strcasecmp(v->name, "greeting")) {
if (x < ADSI_MAX_INTRO) { if (x < ADSI_MAX_INTRO) {
aligns[x] = alignment; aligns[x] = alignment;
ast_copy_string(intro[x], v->value, sizeof(intro[x])); ast_copy_string(intro[x], v->value, sizeof(intro[x]));
x++; x++;
} }
} else if (!strcasecmp(v->name, "maxretries")) { } else if (!strcasecmp(v->name, "maxretries")) {
if (atoi(v->value) > 0) if (atoi(v->value) > 0) {
maxretries = atoi(v->value); maxretries = atoi(v->value);
}
} }
} }
if (x) if (x) {
total = x; total = x;
}
x = 0; x = 0;
for (v = ast_variable_browse(conf, "speeddial"); v; v = v->next) { for (v = ast_variable_browse(conf, "speeddial"); v; v = v->next) {
char buf[3 * SPEEDDIAL_MAX_LEN]; char buf[3 * SPEEDDIAL_MAX_LEN];
@ -1049,8 +1105,9 @@ static void adsi_load(int reload)
ast_copy_string(buf, v->value, sizeof(buf)); ast_copy_string(buf, v->value, sizeof(buf));
name = strsep(&stringp, ","); name = strsep(&stringp, ",");
sname = strsep(&stringp, ","); sname = strsep(&stringp, ",");
if (!sname) if (!sname) {
sname = name; sname = name;
}
if (x < ADSI_MAX_SPEED_DIAL) { if (x < ADSI_MAX_SPEED_DIAL) {
ast_copy_string(speeddial[x][0], v->name, sizeof(speeddial[x][0])); ast_copy_string(speeddial[x][0], v->name, sizeof(speeddial[x][0]));
ast_copy_string(speeddial[x][1], name, 18); ast_copy_string(speeddial[x][1], name, 18);
@ -1058,8 +1115,9 @@ static void adsi_load(int reload)
x++; x++;
} }
} }
if (x) if (x) {
speeds = x; speeds = x;
}
ast_config_destroy(conf); ast_config_destroy(conf);
return; return;
@ -1074,36 +1132,6 @@ static int reload(void)
static int load_module(void) static int load_module(void)
{ {
adsi_load(0); adsi_load(0);
ast_adsi_begin_download = _ast_adsi_begin_download;
ast_adsi_end_download = _ast_adsi_end_download;
ast_adsi_channel_restore = _ast_adsi_channel_restore;
ast_adsi_print = _ast_adsi_print;
ast_adsi_load_session = _ast_adsi_load_session;
ast_adsi_unload_session = _ast_adsi_unload_session;
ast_adsi_transmit_message = _ast_adsi_transmit_message;
ast_adsi_transmit_message_full = _ast_adsi_transmit_message_full;
ast_adsi_read_encoded_dtmf = _ast_adsi_read_encoded_dtmf;
ast_adsi_connect_session = _ast_adsi_connect_session;
ast_adsi_query_cpeid = _ast_adsi_query_cpeid;
ast_adsi_query_cpeinfo = _ast_adsi_query_cpeinfo;
ast_adsi_get_cpeid = _ast_adsi_get_cpeid;
ast_adsi_get_cpeinfo = _ast_adsi_get_cpeinfo;
ast_adsi_download_connect = _ast_adsi_download_connect;
ast_adsi_disconnect_session = _ast_adsi_disconnect_session;
ast_adsi_download_disconnect = _ast_adsi_download_disconnect;
ast_adsi_data_mode = _ast_adsi_data_mode;
ast_adsi_clear_soft_keys = _ast_adsi_clear_soft_keys;
ast_adsi_clear_screen = _ast_adsi_clear_screen;
ast_adsi_voice_mode = _ast_adsi_voice_mode;
ast_adsi_available = _ast_adsi_available;
ast_adsi_display = _ast_adsi_display;
ast_adsi_set_line = _ast_adsi_set_line;
ast_adsi_load_soft_key = _ast_adsi_load_soft_key;
ast_adsi_set_keys = _ast_adsi_set_keys;
ast_adsi_input_control = _ast_adsi_input_control;
ast_adsi_input_format = _ast_adsi_input_format;
return AST_MODULE_LOAD_SUCCESS; return AST_MODULE_LOAD_SUCCESS;
} }
@ -1113,7 +1141,7 @@ static int unload_module(void)
return -1; return -1;
} }
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "ADSI Resource", AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "ADSI Resource",
.load = load_module, .load = load_module,
.unload = unload_module, .unload = unload_module,
.reload = reload, .reload = reload,

@ -1,33 +1,33 @@
{ {
global: global:
LINKER_SYMBOL_PREFIXast_adsi_available; LINKER_SYMBOL_PREFIX*ast_adsi_available;
LINKER_SYMBOL_PREFIXast_adsi_begin_download; LINKER_SYMBOL_PREFIX*ast_adsi_begin_download;
LINKER_SYMBOL_PREFIXast_adsi_channel_restore; LINKER_SYMBOL_PREFIX*ast_adsi_channel_restore;
LINKER_SYMBOL_PREFIXast_adsi_clear_screen; LINKER_SYMBOL_PREFIX*ast_adsi_clear_screen;
LINKER_SYMBOL_PREFIXast_adsi_clear_soft_keys; LINKER_SYMBOL_PREFIX*ast_adsi_clear_soft_keys;
LINKER_SYMBOL_PREFIXast_adsi_connect_session; LINKER_SYMBOL_PREFIX*ast_adsi_connect_session;
LINKER_SYMBOL_PREFIXast_adsi_data_mode; LINKER_SYMBOL_PREFIX*ast_adsi_data_mode;
LINKER_SYMBOL_PREFIXast_adsi_disconnect_session; LINKER_SYMBOL_PREFIX*ast_adsi_disconnect_session;
LINKER_SYMBOL_PREFIXast_adsi_display; LINKER_SYMBOL_PREFIX*ast_adsi_display;
LINKER_SYMBOL_PREFIXast_adsi_download_connect; LINKER_SYMBOL_PREFIX*ast_adsi_download_connect;
LINKER_SYMBOL_PREFIXast_adsi_download_disconnect; LINKER_SYMBOL_PREFIX*ast_adsi_download_disconnect;
LINKER_SYMBOL_PREFIXast_adsi_end_download; LINKER_SYMBOL_PREFIX*ast_adsi_end_download;
LINKER_SYMBOL_PREFIXast_adsi_get_cpeid; LINKER_SYMBOL_PREFIX*ast_adsi_get_cpeid;
LINKER_SYMBOL_PREFIXast_adsi_get_cpeinfo; LINKER_SYMBOL_PREFIX*ast_adsi_get_cpeinfo;
LINKER_SYMBOL_PREFIXast_adsi_input_control; LINKER_SYMBOL_PREFIX*ast_adsi_input_control;
LINKER_SYMBOL_PREFIXast_adsi_input_format; LINKER_SYMBOL_PREFIX*ast_adsi_input_format;
LINKER_SYMBOL_PREFIXast_adsi_load_session; LINKER_SYMBOL_PREFIX*ast_adsi_load_session;
LINKER_SYMBOL_PREFIXast_adsi_load_soft_key; LINKER_SYMBOL_PREFIX*ast_adsi_load_soft_key;
LINKER_SYMBOL_PREFIXast_adsi_print; LINKER_SYMBOL_PREFIX*ast_adsi_print;
LINKER_SYMBOL_PREFIXast_adsi_query_cpeid; LINKER_SYMBOL_PREFIX*ast_adsi_query_cpeid;
LINKER_SYMBOL_PREFIXast_adsi_query_cpeinfo; LINKER_SYMBOL_PREFIX*ast_adsi_query_cpeinfo;
LINKER_SYMBOL_PREFIXast_adsi_read_encoded_dtmf; LINKER_SYMBOL_PREFIX*ast_adsi_read_encoded_dtmf;
LINKER_SYMBOL_PREFIXast_adsi_set_keys; LINKER_SYMBOL_PREFIX*ast_adsi_set_keys;
LINKER_SYMBOL_PREFIXast_adsi_set_line; LINKER_SYMBOL_PREFIX*ast_adsi_set_line;
LINKER_SYMBOL_PREFIXast_adsi_transmit_message; LINKER_SYMBOL_PREFIX*ast_adsi_transmit_message;
LINKER_SYMBOL_PREFIXast_adsi_transmit_message_full; LINKER_SYMBOL_PREFIX*ast_adsi_transmit_message_full;
LINKER_SYMBOL_PREFIXast_adsi_unload_session; LINKER_SYMBOL_PREFIX*ast_adsi_unload_session;
LINKER_SYMBOL_PREFIXast_adsi_voice_mode; LINKER_SYMBOL_PREFIX*ast_adsi_voice_mode;
local: local:
*; *;
}; };

@ -20,7 +20,7 @@
* *
* \brief Provide Cryptographic Signature capability * \brief Provide Cryptographic Signature capability
* *
* \author Mark Spencer <markster@digium.com> * \author Mark Spencer <markster@digium.com>
* *
* \extref Uses the OpenSSL library, available at * \extref Uses the OpenSSL library, available at
* http://www.openssl.org/ * http://www.openssl.org/
@ -40,18 +40,20 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <dirent.h> #include <dirent.h>
#include "asterisk/module.h" #include "asterisk/module.h"
#include "asterisk/crypto.h"
#include "asterisk/md5.h" #include "asterisk/md5.h"
#include "asterisk/cli.h" #include "asterisk/cli.h"
#include "asterisk/io.h" #include "asterisk/io.h"
#include "asterisk/lock.h" #include "asterisk/lock.h"
#include "asterisk/utils.h" #include "asterisk/utils.h"
#define AST_API_MODULE
#include "asterisk/crypto.h"
/* /*
* Asterisk uses RSA keys with SHA-1 message digests for its * Asterisk uses RSA keys with SHA-1 message digests for its
* digital signatures. The choice of RSA is due to its higher * digital signatures. The choice of RSA is due to its higher
* throughput on verification, and the choice of SHA-1 based * throughput on verification, and the choice of SHA-1 based
* on the recently discovered collisions in MD5's compression * on the recently discovered collisions in MD5's compression
* algorithm and recommendations of avoiding MD5 in new schemes * algorithm and recommendations of avoiding MD5 in new schemes
* from various industry experts. * from various industry experts.
* *
@ -103,7 +105,7 @@ static int pw_cb(char *buf, int size, int rwflag, void *userdata)
key->infd = -2; key->infd = -2;
return -1; return -1;
} }
snprintf(prompt, sizeof(prompt), ">>>> passcode for %s key '%s': ", snprintf(prompt, sizeof(prompt), ">>>> passcode for %s key '%s': ",
key->ktype == AST_KEY_PRIVATE ? "PRIVATE" : "PUBLIC", key->name); key->ktype == AST_KEY_PRIVATE ? "PRIVATE" : "PUBLIC", key->name);
if (write(key->outfd, prompt, strlen(prompt)) < 0) { if (write(key->outfd, prompt, strlen(prompt)) < 0) {
@ -116,8 +118,9 @@ static int pw_cb(char *buf, int size, int rwflag, void *userdata)
memset(buf, 0, size); memset(buf, 0, size);
res = read(key->infd, buf, size); res = read(key->infd, buf, size);
ast_restore_tty(key->infd, tmp); ast_restore_tty(key->infd, tmp);
if (buf[strlen(buf) -1] == '\n') if (buf[strlen(buf) -1] == '\n') {
buf[strlen(buf) - 1] = '\0'; buf[strlen(buf) - 1] = '\0';
}
return strlen(buf); return strlen(buf);
} }
@ -125,15 +128,16 @@ static int pw_cb(char *buf, int size, int rwflag, void *userdata)
* \brief return the ast_key structure for name * \brief return the ast_key structure for name
* \see ast_key_get * \see ast_key_get
*/ */
static struct ast_key *__ast_key_get(const char *kname, int ktype) struct ast_key * AST_OPTIONAL_API_NAME(ast_key_get)(const char *kname, int ktype)
{ {
struct ast_key *key; struct ast_key *key;
AST_RWLIST_RDLOCK(&keys); AST_RWLIST_RDLOCK(&keys);
AST_RWLIST_TRAVERSE(&keys, key, list) { AST_RWLIST_TRAVERSE(&keys, key, list) {
if (!strcmp(kname, key->name) && if (!strcmp(kname, key->name) &&
(ktype == key->ktype)) (ktype == key->ktype)) {
break; break;
}
} }
AST_RWLIST_UNLOCK(&keys); AST_RWLIST_UNLOCK(&keys);
@ -161,12 +165,13 @@ static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd,
static int notice = 0; static int notice = 0;
/* Make sure its name is a public or private key */ /* Make sure its name is a public or private key */
if ((c = strstr(fname, ".pub")) && !strcmp(c, ".pub")) if ((c = strstr(fname, ".pub")) && !strcmp(c, ".pub")) {
ktype = AST_KEY_PUBLIC; ktype = AST_KEY_PUBLIC;
else if ((c = strstr(fname, ".key")) && !strcmp(c, ".key")) } else if ((c = strstr(fname, ".key")) && !strcmp(c, ".key")) {
ktype = AST_KEY_PRIVATE; ktype = AST_KEY_PRIVATE;
else } else {
return NULL; return NULL;
}
/* Get actual filename */ /* Get actual filename */
snprintf(ffname, sizeof(ffname), "%s/%s", dir, fname); snprintf(ffname, sizeof(ffname), "%s/%s", dir, fname);
@ -178,25 +183,27 @@ static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd,
} }
MD5Init(&md5); MD5Init(&md5);
while(!feof(f)) { while (!feof(f)) {
/* Calculate a "whatever" quality md5sum of the key */ /* Calculate a "whatever" quality md5sum of the key */
char buf[256] = ""; char buf[256] = "";
if (!fgets(buf, sizeof(buf), f)) { if (!fgets(buf, sizeof(buf), f)) {
continue; continue;
} }
if (!feof(f)) if (!feof(f)) {
MD5Update(&md5, (unsigned char *) buf, strlen(buf)); MD5Update(&md5, (unsigned char *) buf, strlen(buf));
}
} }
MD5Final(digest, &md5); MD5Final(digest, &md5);
/* Look for an existing key */ /* Look for an existing key */
AST_RWLIST_TRAVERSE(&keys, key, list) { AST_RWLIST_TRAVERSE(&keys, key, list) {
if (!strcasecmp(key->fn, ffname)) if (!strcasecmp(key->fn, ffname)) {
break; break;
}
} }
if (key) { if (key) {
/* If the MD5 sum is the same, and it isn't awaiting a passcode /* If the MD5 sum is the same, and it isn't awaiting a passcode
then this is far enough */ then this is far enough */
if (!memcmp(digest, key->digest, 16) && if (!memcmp(digest, key->digest, 16) &&
!(key->ktype & KEY_NEEDS_PASSCODE)) { !(key->ktype & KEY_NEEDS_PASSCODE)) {
@ -234,10 +241,11 @@ static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd,
/* Reset the file back to the beginning */ /* Reset the file back to the beginning */
rewind(f); rewind(f);
/* Now load the key with the right method */ /* Now load the key with the right method */
if (ktype == AST_KEY_PUBLIC) if (ktype == AST_KEY_PUBLIC) {
key->rsa = PEM_read_RSA_PUBKEY(f, NULL, pw_cb, key); key->rsa = PEM_read_RSA_PUBKEY(f, NULL, pw_cb, key);
else } else {
key->rsa = PEM_read_RSAPrivateKey(f, NULL, pw_cb, key); key->rsa = PEM_read_RSAPrivateKey(f, NULL, pw_cb, key);
}
fclose(f); fclose(f);
if (key->rsa) { if (key->rsa) {
if (RSA_size(key->rsa) == 128) { if (RSA_size(key->rsa) == 128) {
@ -246,20 +254,23 @@ static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd,
ast_verb(3, "Loaded %s key '%s'\n", key->ktype == AST_KEY_PUBLIC ? "PUBLIC" : "PRIVATE", key->name); ast_verb(3, "Loaded %s key '%s'\n", key->ktype == AST_KEY_PUBLIC ? "PUBLIC" : "PRIVATE", key->name);
ast_debug(1, "Key '%s' loaded OK\n", key->name); ast_debug(1, "Key '%s' loaded OK\n", key->name);
key->delme = 0; key->delme = 0;
} else } else {
ast_log(LOG_NOTICE, "Key '%s' is not expected size.\n", key->name); ast_log(LOG_NOTICE, "Key '%s' is not expected size.\n", key->name);
}
} else if (key->infd != -2) { } else if (key->infd != -2) {
ast_log(LOG_WARNING, "Key load %s '%s' failed\n",key->ktype == AST_KEY_PUBLIC ? "PUBLIC" : "PRIVATE", key->name); ast_log(LOG_WARNING, "Key load %s '%s' failed\n",key->ktype == AST_KEY_PUBLIC ? "PUBLIC" : "PRIVATE", key->name);
if (ofd > -1) if (ofd > -1) {
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
else } else {
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
}
} else { } else {
ast_log(LOG_NOTICE, "Key '%s' needs passcode.\n", key->name); ast_log(LOG_NOTICE, "Key '%s' needs passcode.\n", key->name);
key->ktype |= KEY_NEEDS_PASSCODE; key->ktype |= KEY_NEEDS_PASSCODE;
if (!notice) { if (!notice) {
if (!ast_opt_init_keys) if (!ast_opt_init_keys) {
ast_log(LOG_NOTICE, "Add the '-i' flag to the asterisk command line if you want to automatically initialize passcodes at launch.\n"); ast_log(LOG_NOTICE, "Add the '-i' flag to the asterisk command line if you want to automatically initialize passcodes at launch.\n");
}
notice++; notice++;
} }
/* Keep it anyway */ /* Keep it anyway */
@ -269,8 +280,9 @@ static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd,
} }
/* If this is a new key add it to the list */ /* If this is a new key add it to the list */
if (!found) if (!found) {
AST_RWLIST_INSERT_TAIL(&keys, key, list); AST_RWLIST_INSERT_TAIL(&keys, key, list);
}
return key; return key;
} }
@ -279,7 +291,7 @@ static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd,
* \brief signs outgoing message with public key * \brief signs outgoing message with public key
* \see ast_sign_bin * \see ast_sign_bin
*/ */
static int __ast_sign_bin(struct ast_key *key, const char *msg, int msglen, unsigned char *dsig) int AST_OPTIONAL_API_NAME(ast_sign_bin)(struct ast_key *key, const char *msg, int msglen, unsigned char *dsig)
{ {
unsigned char digest[20]; unsigned char digest[20];
unsigned int siglen = 128; unsigned int siglen = 128;
@ -305,14 +317,13 @@ static int __ast_sign_bin(struct ast_key *key, const char *msg, int msglen, unsi
} }
return 0; return 0;
} }
/*! /*!
* \brief decrypt a message * \brief decrypt a message
* \see ast_decrypt_bin * \see ast_decrypt_bin
*/ */
static int __ast_decrypt_bin(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key) int AST_OPTIONAL_API_NAME(ast_decrypt_bin)(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key)
{ {
int res, pos = 0; int res, pos = 0;
@ -326,10 +337,11 @@ static int __ast_decrypt_bin(unsigned char *dst, const unsigned char *src, int s
return -1; return -1;
} }
while(srclen) { while (srclen) {
/* Process chunks 128 bytes at a time */ /* Process chunks 128 bytes at a time */
if ((res = RSA_private_decrypt(128, src, dst, key->rsa, RSA_PKCS1_OAEP_PADDING)) < 0) if ((res = RSA_private_decrypt(128, src, dst, key->rsa, RSA_PKCS1_OAEP_PADDING)) < 0) {
return -1; return -1;
}
pos += res; pos += res;
src += 128; src += 128;
srclen -= 128; srclen -= 128;
@ -343,7 +355,7 @@ static int __ast_decrypt_bin(unsigned char *dst, const unsigned char *src, int s
* \brief encrypt a message * \brief encrypt a message
* \see ast_encrypt_bin * \see ast_encrypt_bin
*/ */
static int __ast_encrypt_bin(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key) int AST_OPTIONAL_API_NAME(ast_encrypt_bin)(unsigned char *dst, const unsigned char *src, int srclen, struct ast_key *key)
{ {
int res, bytes, pos = 0; int res, bytes, pos = 0;
@ -351,11 +363,12 @@ static int __ast_encrypt_bin(unsigned char *dst, const unsigned char *src, int s
ast_log(LOG_WARNING, "Cannot encrypt with a private key\n"); ast_log(LOG_WARNING, "Cannot encrypt with a private key\n");
return -1; return -1;
} }
while(srclen) { while (srclen) {
bytes = srclen; bytes = srclen;
if (bytes > 128 - 41) if (bytes > 128 - 41) {
bytes = 128 - 41; bytes = 128 - 41;
}
/* Process chunks 128-41 bytes at a time */ /* Process chunks 128-41 bytes at a time */
if ((res = RSA_public_encrypt(bytes, src, dst, key->rsa, RSA_PKCS1_OAEP_PADDING)) != 128) { if ((res = RSA_public_encrypt(bytes, src, dst, key->rsa, RSA_PKCS1_OAEP_PADDING)) != 128) {
ast_log(LOG_NOTICE, "How odd, encrypted size is %d\n", res); ast_log(LOG_NOTICE, "How odd, encrypted size is %d\n", res);
@ -373,14 +386,15 @@ static int __ast_encrypt_bin(unsigned char *dst, const unsigned char *src, int s
* \brief wrapper for __ast_sign_bin then base64 encode it * \brief wrapper for __ast_sign_bin then base64 encode it
* \see ast_sign * \see ast_sign
*/ */
static int __ast_sign(struct ast_key *key, char *msg, char *sig) int AST_OPTIONAL_API_NAME(ast_sign)(struct ast_key *key, char *msg, char *sig)
{ {
unsigned char dsig[128]; unsigned char dsig[128];
int siglen = sizeof(dsig), res; int siglen = sizeof(dsig), res;
if (!(res = ast_sign_bin(key, msg, strlen(msg), dsig))) if (!(res = ast_sign_bin(key, msg, strlen(msg), dsig))) {
/* Success -- encode (256 bytes max as documented) */ /* Success -- encode (256 bytes max as documented) */
ast_base64encode(sig, dsig, siglen, 256); ast_base64encode(sig, dsig, siglen, 256);
}
return res; return res;
} }
@ -389,7 +403,7 @@ static int __ast_sign(struct ast_key *key, char *msg, char *sig)
* \brief check signature of a message * \brief check signature of a message
* \see ast_check_signature_bin * \see ast_check_signature_bin
*/ */
static int __ast_check_signature_bin(struct ast_key *key, const char *msg, int msglen, const unsigned char *dsig) int AST_OPTIONAL_API_NAME(ast_check_signature_bin)(struct ast_key *key, const char *msg, int msglen, const unsigned char *dsig)
{ {
unsigned char digest[20]; unsigned char digest[20];
int res; int res;
@ -418,7 +432,7 @@ static int __ast_check_signature_bin(struct ast_key *key, const char *msg, int m
* \brief base64 decode then sent to __ast_check_signature_bin * \brief base64 decode then sent to __ast_check_signature_bin
* \see ast_check_signature * \see ast_check_signature
*/ */
static int __ast_check_signature(struct ast_key *key, const char *msg, const char *sig) int AST_OPTIONAL_API_NAME(ast_check_signature)(struct ast_key *key, const char *msg, const char *sig)
{ {
unsigned char dsig[128]; unsigned char dsig[128];
int res; int res;
@ -434,6 +448,11 @@ static int __ast_check_signature(struct ast_key *key, const char *msg, const cha
return res; return res;
} }
int AST_OPTIONAL_API_NAME(ast_crypto_loaded)(void)
{
return 1;
}
/*! /*!
* \brief refresh RSA keys from file * \brief refresh RSA keys from file
* \param ifd file descriptor * \param ifd file descriptor
@ -456,23 +475,26 @@ static void crypto_load(int ifd, int ofd)
/* Load new keys */ /* Load new keys */
if ((dir = opendir(ast_config_AST_KEY_DIR))) { if ((dir = opendir(ast_config_AST_KEY_DIR))) {
while((ent = readdir(dir))) { while ((ent = readdir(dir))) {
try_load_key(ast_config_AST_KEY_DIR, ent->d_name, ifd, ofd, &note); try_load_key(ast_config_AST_KEY_DIR, ent->d_name, ifd, ofd, &note);
} }
closedir(dir); closedir(dir);
} else } else {
ast_log(LOG_WARNING, "Unable to open key directory '%s'\n", ast_config_AST_KEY_DIR); ast_log(LOG_WARNING, "Unable to open key directory '%s'\n", ast_config_AST_KEY_DIR);
}
if (note) if (note) {
ast_log(LOG_NOTICE, "Please run the command 'init keys' to enter the passcodes for the keys\n"); ast_log(LOG_NOTICE, "Please run the command 'init keys' to enter the passcodes for the keys\n");
}
/* Delete any keys that are no longer present */ /* Delete any keys that are no longer present */
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&keys, key, list) { AST_RWLIST_TRAVERSE_SAFE_BEGIN(&keys, key, list) {
if (key->delme) { if (key->delme) {
ast_debug(1, "Deleting key %s type %d\n", key->name, key->ktype); ast_debug(1, "Deleting key %s type %d\n", key->name, key->ktype);
AST_RWLIST_REMOVE_CURRENT(list); AST_RWLIST_REMOVE_CURRENT(list);
if (key->rsa) if (key->rsa) {
RSA_free(key->rsa); RSA_free(key->rsa);
}
ast_free(key); ast_free(key);
} }
} }
@ -484,12 +506,13 @@ static void crypto_load(int ifd, int ofd)
static void md52sum(char *sum, unsigned char *md5) static void md52sum(char *sum, unsigned char *md5)
{ {
int x; int x;
for (x = 0; x < 16; x++) for (x = 0; x < 16; x++) {
sum += sprintf(sum, "%02x", *(md5++)); sum += sprintf(sum, "%02x", *(md5++));
}
} }
/*! /*!
* \brief show the list of RSA keys * \brief show the list of RSA keys
* \param e CLI command * \param e CLI command
* \param cmd * \param cmd
* \param a list of CLI arguments * \param a list of CLI arguments
@ -520,7 +543,7 @@ static char *handle_cli_keys_show(struct ast_cli_entry *e, int cmd, struct ast_c
AST_RWLIST_RDLOCK(&keys); AST_RWLIST_RDLOCK(&keys);
AST_RWLIST_TRAVERSE(&keys, key, list) { AST_RWLIST_TRAVERSE(&keys, key, list) {
md52sum(sum, key->digest); md52sum(sum, key->digest);
ast_cli(a->fd, FORMAT, key->name, ast_cli(a->fd, FORMAT, key->name,
(key->ktype & 0xf) == AST_KEY_PUBLIC ? "PUBLIC" : "PRIVATE", (key->ktype & 0xf) == AST_KEY_PUBLIC ? "PUBLIC" : "PRIVATE",
key->ktype & KEY_NEEDS_PASSCODE ? "[Needs Passcode]" : "[Loaded]", sum); key->ktype & KEY_NEEDS_PASSCODE ? "[Needs Passcode]" : "[Loaded]", sum);
count_keys++; count_keys++;
@ -534,10 +557,10 @@ static char *handle_cli_keys_show(struct ast_cli_entry *e, int cmd, struct ast_c
#undef FORMAT #undef FORMAT
} }
/*! /*!
* \brief initialize all RSA keys * \brief initialize all RSA keys
* \param e CLI command * \param e CLI command
* \param cmd * \param cmd
* \param a list of CLI arguments * \param a list of CLI arguments
* \return CLI_SUCCESS * \return CLI_SUCCESS
*/ */
@ -559,8 +582,9 @@ static char *handle_cli_keys_init(struct ast_cli_entry *e, int cmd, struct ast_c
return NULL; return NULL;
} }
if (a->argc != 2) if (a->argc != 2) {
return CLI_SHOWUSAGE; return CLI_SHOWUSAGE;
}
AST_RWLIST_WRLOCK(&keys); AST_RWLIST_WRLOCK(&keys);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&keys, key, list) { AST_RWLIST_TRAVERSE_SAFE_BEGIN(&keys, key, list) {
@ -586,15 +610,6 @@ static struct ast_cli_entry cli_crypto[] = {
static int crypto_init(void) static int crypto_init(void)
{ {
ast_cli_register_multiple(cli_crypto, ARRAY_LEN(cli_crypto)); ast_cli_register_multiple(cli_crypto, ARRAY_LEN(cli_crypto));
/* Install ourselves into stubs */
ast_key_get = __ast_key_get;
ast_check_signature = __ast_check_signature;
ast_check_signature_bin = __ast_check_signature_bin;
ast_sign = __ast_sign;
ast_sign_bin = __ast_sign_bin;
ast_encrypt_bin = __ast_encrypt_bin;
ast_decrypt_bin = __ast_decrypt_bin;
return 0; return 0;
} }
@ -607,10 +622,11 @@ static int reload(void)
static int load_module(void) static int load_module(void)
{ {
crypto_init(); crypto_init();
if (ast_opt_init_keys) if (ast_opt_init_keys) {
crypto_load(STDIN_FILENO, STDOUT_FILENO); crypto_load(STDIN_FILENO, STDOUT_FILENO);
else } else {
crypto_load(-1, -1); crypto_load(-1, -1);
}
return AST_MODULE_LOAD_SUCCESS; return AST_MODULE_LOAD_SUCCESS;
} }
@ -621,8 +637,8 @@ static int unload_module(void)
} }
/* needs usecount semantics defined */ /* needs usecount semantics defined */
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Cryptographic Digital Signatures", AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Cryptographic Digital Signatures",
.load = load_module, .load = load_module,
.unload = unload_module, .unload = unload_module,
.reload = reload .reload = reload,
); );

@ -0,0 +1,13 @@
{
global:
LINKER_SYMBOL_PREFIX*ast_check_signature;
LINKER_SYMBOL_PREFIX*ast_check_signature_bin;
LINKER_SYMBOL_PREFIX*ast_crypto_loaded;
LINKER_SYMBOL_PREFIX*ast_decrypt_bin;
LINKER_SYMBOL_PREFIX*ast_encrypt_bin;
LINKER_SYMBOL_PREFIX*ast_key_get;
LINKER_SYMBOL_PREFIX*ast_sign;
LINKER_SYMBOL_PREFIX*ast_sign_bin;
local:
*;
};

@ -35,6 +35,10 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$");
#include "asterisk/utils.h" #include "asterisk/utils.h"
#include "asterisk/test.h" #include "asterisk/test.h"
#include "asterisk/crypto.h"
#include "asterisk/adsi.h"
#include "asterisk/agi.h"
#include "asterisk/channel.h"
#include "asterisk/module.h" #include "asterisk/module.h"
AST_TEST_DEFINE(uri_encode_decode_test) AST_TEST_DEFINE(uri_encode_decode_test)
@ -236,6 +240,99 @@ AST_TEST_DEFINE(base64_test)
return res; return res;
} }
AST_TEST_DEFINE(crypto_loaded_test)
{
switch (cmd) {
case TEST_INIT:
info->name = "crypto_loaded_test";
info->category = "/res/crypto/";
info->summary = "Crypto loaded into memory";
info->description = "Verifies whether the crypto functions overrode the stubs";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
ast_test_status_update(test,
"address of __stub__ast_crypto_loaded is %p\n",
__stub__ast_crypto_loaded);
ast_test_status_update(test,
"address of __ref__ast_crypto_loaded is %p\n",
__ref__ast_crypto_loaded);
ast_test_status_update(test,
"pointer to ast_crypto_loaded is %p\n",
ast_crypto_loaded);
return ast_crypto_loaded() ? AST_TEST_PASS : AST_TEST_FAIL;
}
AST_TEST_DEFINE(adsi_loaded_test)
{
struct ast_channel c = { .adsicpe = AST_ADSI_AVAILABLE, };
switch (cmd) {
case TEST_INIT:
info->name = "adsi_loaded_test";
info->category = "/res/adsi/";
info->summary = "ADSI loaded into memory";
info->description = "Verifies whether the adsi functions overrode the stubs";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
return ast_adsi_available(&c) ? AST_TEST_PASS : AST_TEST_FAIL;
}
static int handle_noop(struct ast_channel *chan, AGI *agi, int arg, const char * const argv[])
{
ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
AST_TEST_DEFINE(agi_loaded_test)
{
int res = AST_TEST_PASS;
struct agi_command noop_command =
{ { "testnoop", NULL }, handle_noop, NULL, NULL, 0 };
switch (cmd) {
case TEST_INIT:
info->name = "agi_loaded_test";
info->category = "/res/agi/";
info->summary = "AGI loaded into memory";
info->description = "Verifies whether the agi functions overrode the stubs";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
ast_test_status_update(test,
"address of __stub__ast_agi_register is %p\n",
__stub__ast_agi_register);
ast_test_status_update(test,
"address of __ref__ast_agi_register is %p\n",
__ref__ast_agi_register);
ast_test_status_update(test,
"pointer to ast_agi_register is %p\n",
ast_agi_register);
if (ast_agi_register(ast_module_info->self, &noop_command) == AST_OPTIONAL_API_UNAVAILABLE) {
return AST_TEST_FAIL;
}
#ifndef HAVE_NULLSAFE_PRINTF
/* Test for condition without actually crashing Asterisk */
if (noop_command.usage == NULL) {
res = AST_TEST_FAIL;
}
if (noop_command.syntax == NULL) {
res = AST_TEST_FAIL;
}
#endif
ast_agi_unregister(ast_module_info->self, &noop_command);
return res;
}
static int unload_module(void) static int unload_module(void)
{ {
@ -243,6 +340,9 @@ static int unload_module(void)
AST_TEST_UNREGISTER(md5_test); AST_TEST_UNREGISTER(md5_test);
AST_TEST_UNREGISTER(sha1_test); AST_TEST_UNREGISTER(sha1_test);
AST_TEST_UNREGISTER(base64_test); AST_TEST_UNREGISTER(base64_test);
AST_TEST_UNREGISTER(crypto_loaded_test);
AST_TEST_UNREGISTER(adsi_loaded_test);
AST_TEST_UNREGISTER(agi_loaded_test);
return 0; return 0;
} }
@ -252,6 +352,9 @@ static int load_module(void)
AST_TEST_REGISTER(md5_test); AST_TEST_REGISTER(md5_test);
AST_TEST_REGISTER(sha1_test); AST_TEST_REGISTER(sha1_test);
AST_TEST_REGISTER(base64_test); AST_TEST_REGISTER(base64_test);
AST_TEST_REGISTER(crypto_loaded_test);
AST_TEST_REGISTER(adsi_loaded_test);
AST_TEST_REGISTER(agi_loaded_test);
return AST_MODULE_LOAD_SUCCESS; return AST_MODULE_LOAD_SUCCESS;
} }

Loading…
Cancel
Save