Typos and coding style.

master
MelwareDE 12 years ago
parent 5076ada4c7
commit 01d9dbfa34
  1. 8
      README.mwi
  2. 2
      capi.conf
  3. 294
      chan_capi.c

@ -6,7 +6,7 @@
| Control MWI indicators (MWI Server) |
+-------------------------------------------------------------------+
Using Asterisk 1.6 or newer it iss possible to provide information about state of user
Using Asterisk 1.6 or newer it is possible to provide information about state of user
mailbox to ISDN phone.
Dependent on the state of mailbox this is possible to send MWI Activate or MWI deactivate
request to activate or to deactivate Message Waiting Indicator on the phone.
@ -25,7 +25,7 @@ Where:
controlling user number - Number where mailbox can be accessed (often same as mailbox)
controlling user provided number - Password, used by PBX to check permissions
Additiona configuration parameters depends on type of PBX used and on the PBX installation:
Additional configuration parameters depends on type of PBX used and on the PBX installation:
mwifacptynrtype - type of MWI facility party number, 0 - unknown (default), 1 - public
mwifacptynrton - MWI facility party number type of number and numbering plan identification
(coding as for byte 0 of the calling party number). This byte is only valid
@ -44,14 +44,14 @@ Example:
controller=1
mwimailbox=12345:12345:221122@other,12347:12348,12349
activates monitoring of therr mailboxes: 12345@other, 12347@default and 12349@default and sending
activates monitoring of the mailboxes: 12345@other, 12347@default and 12349@default and sending
of MWI requests using CAPI controller 1.
+-------------------------------------------------------------------+
| Direct control MWI indicators (MWI Server) |
+-------------------------------------------------------------------+
This iss possible to send MWI Activate and MWI deactivate messages
This is possible to send MWI Activate and MWI deactivate messages
directly from dialplan using capicommand(mwi, ...).
This can be necessary if testing the system, if voice mailbox is managed
by other software (not by asterisk) or to verify MWI parameters.

@ -87,7 +87,7 @@ devices=2 ;number of concurrent calls (B-Channels) on this controller
; (coding as for byte 1 of the calling party number).
; This byte is only valid if byte mwifacptynrtype contains the value 1
;mwibasicservice=1;MWI basic Service, coded in accordance with ETS 300 196 [D.5]
;mwiinvocation=2 ;MWI invocation mode, 0 - deffered, 1 - immediate, 2 - combined,
;mwiinvocation=2 ;MWI invocation mode, 0 - deferred, 1 - immediate, 2 - combined,
; 65535 - suppres invocation code
;mwimailbox=12345 ;',' separated list of mailboxes for MWI in format:
; mailbox[:controlling user number[:controlling user provided number]][@context]

@ -217,35 +217,39 @@ static int pbx_capi_indicate(struct ast_channel *c, int condition, const void *d
#else
static int pbx_capi_indicate(struct ast_channel *c, int condition);
#endif
static struct capi_pvt* get_active_plci (struct ast_channel *c);
static void clear_channel_fax_loop (struct ast_channel *c, struct capi_pvt *i);
static struct ast_channel* capidev_acquire_locks_from_thread_context (struct capi_pvt *i);
static void pbx_capi_add_diva_protocol_independent_extension (struct capi_pvt *i,
unsigned char *facilityarray,
struct ast_channel *c,
const char* variable);
static unsigned char* pbx_capi_build_facility_number (unsigned char mwifacptynrtype,
unsigned char mwifacptynrton,
unsigned char mwifacptynrpres,
const char* number);
static void pbx_capi_register_mwi (struct cc_capi_controller *controller);
static void pbx_capi_refresh_mwi (struct cc_capi_controller *controller);
static int pbx_capi_xmit_mwi (struct cc_capi_controller *controller,
unsigned short basicService,
unsigned int numberOfMessages,
unsigned short messageStatus,
unsigned short messageReference,
unsigned short invocationMode,
const unsigned char* receivingUserNumber,
const unsigned char* controllingUserNumber,
const unsigned char* controllingUserProvidedNumber,
const unsigned char* timeX208);
static struct capi_pvt* get_active_plci(struct ast_channel *c);
static void clear_channel_fax_loop(struct ast_channel *c, struct capi_pvt *i);
static struct ast_channel* capidev_acquire_locks_from_thread_context(struct capi_pvt *i);
static void pbx_capi_add_diva_protocol_independent_extension(
struct capi_pvt *i,
unsigned char *facilityarray,
struct ast_channel *c,
const char* variable);
static unsigned char* pbx_capi_build_facility_number(
unsigned char mwifacptynrtype,
unsigned char mwifacptynrton,
unsigned char mwifacptynrpres,
const char* number);
static void pbx_capi_register_mwi(struct cc_capi_controller *controller);
static void pbx_capi_refresh_mwi(struct cc_capi_controller *controller);
static int pbx_capi_xmit_mwi(
struct cc_capi_controller *controller,
unsigned short basicService,
unsigned int numberOfMessages,
unsigned short messageStatus,
unsigned short messageReference,
unsigned short invocationMode,
const unsigned char* receivingUserNumber,
const unsigned char* controllingUserNumber,
const unsigned char* controllingUserProvidedNumber,
const unsigned char* timeX208);
static int pbx_capi_mwi(struct ast_channel *c, char *info);
static int pbx_capi_xmit_mwi_deactivate (struct cc_capi_controller *controller,
unsigned short basicService,
unsigned short invocationMode,
const unsigned char* receivingUserNumber,
const unsigned char* controllingUserNumber);
static int pbx_capi_xmit_mwi_deactivate(
struct cc_capi_controller *controller,
unsigned short basicService,
unsigned short invocationMode,
const unsigned char* receivingUserNumber,
const unsigned char* controllingUserNumber);
static void pbx_capi_unregister_mwi(struct cc_capi_controller *controller);
static void pbx_capi_cleanup_mwi(struct cc_capi_controller *controller);
@ -253,7 +257,7 @@ static void pbx_capi_cleanup_mwi(struct cc_capi_controller *controller);
MWI command parameters
*/
typedef enum _mwiAddSubscribtionParams {
mwiAddSubscribtionController = 1,
mwiAddSubscribtionController = 1,
mwiAddSubscribtionReceivingUserNumber_TypeOfFacilityPartyNumber,
mwiAddSubscribtionReceivingUserNumber_TypeOfNumberAndNumberingPlan,
mwiAddSubscribtionReceivingUserNumber_PresentationAndScreening,
@ -270,7 +274,7 @@ typedef enum _mwiAddSubscribtionParams {
} mwiAddSubscribtionParams_t;
typedef enum _mwiRemoveSubscribtionParam {
mwiRemoveSubscribtionController = 1,
mwiRemoveSubscribtionController = 1,
mwiRemoveSubscribtionReceivingUserNumber,
mwiRemoveSubscribtionMax
} mwiRemoveSubscribtionParam_t;
@ -7823,49 +7827,49 @@ int mkif(struct cc_capi_conf *conf)
/*
Init MWI subscriptions
*/
if (mwiController != 0 && conf->mwimailbox != 0) {
*/
if ((mwiController != 0) && (conf->mwimailbox != 0)) {
char* mailboxList = conf->mwimailbox;
char* mailboxMember;
while ((mailboxMember = strsep (&mailboxList, ",")) != 0) {
/*
Mailbox format: extension[:extension1[:extension2]][@context]
*/
*/
char* mailboxNumbers = strsep(&mailboxMember, "@");
const char* mailboxContext = (mailboxMember != 0) ? mailboxMember : "default";
const char* mailboxNumber = strsep (&mailboxNumbers, ":");
const char* controllingUserNumber = strsep (&mailboxNumbers, ":");
const char* controllingUserProvidedNumber = mailboxNumbers;
if (mailboxNumber != 0 && *mailboxNumber != 0) {
cc_capi_mwi_mailbox_t* mwiSubscribtion = ast_malloc (sizeof(*mwiSubscribtion));
if ((mailboxNumber != 0) && (*mailboxNumber != 0)) {
cc_capi_mwi_mailbox_t* mwiSubscribtion = ast_malloc(sizeof(*mwiSubscribtion));
if (mwiSubscribtion != 0) {
mwiSubscribtion->mailboxNumber = pbx_capi_build_facility_number (conf->mwifacptynrtype, conf->mwifacptynrton, conf->mwifacptynrpres, mailboxNumber);
mwiSubscribtion->mailboxNumber = pbx_capi_build_facility_number(conf->mwifacptynrtype, conf->mwifacptynrton, conf->mwifacptynrpres, mailboxNumber);
mwiSubscribtion->mailboxContext = ast_strdup(mailboxContext);
mwiSubscribtion->controllingUserNumber = pbx_capi_build_facility_number (conf->mwifacptynrtype, conf->mwifacptynrton, conf->mwifacptynrpres, controllingUserNumber);
mwiSubscribtion->controllingUserProvidedNumber = pbx_capi_build_facility_number (conf->mwifacptynrtype, conf->mwifacptynrton, conf->mwifacptynrpres, controllingUserProvidedNumber);
mwiSubscribtion->controllingUserNumber = pbx_capi_build_facility_number(conf->mwifacptynrtype, conf->mwifacptynrton, conf->mwifacptynrpres, controllingUserNumber);
mwiSubscribtion->controllingUserProvidedNumber = pbx_capi_build_facility_number(conf->mwifacptynrtype, conf->mwifacptynrton, conf->mwifacptynrpres, controllingUserProvidedNumber);
mwiSubscribtion->controller = mwiController;
mwiSubscribtion->mwiSubscribtion = 0;
mwiSubscribtion->basicService = conf->mwibasicservice;
mwiSubscribtion->invocationMode = conf->mwiinvocation;
if (mwiSubscribtion->mailboxNumber == 0 || mwiSubscribtion->mailboxContext == 0 ||
(mwiSubscribtion->controllingUserNumber == 0 && controllingUserNumber != 0) ||
(mwiSubscribtion->controllingUserProvidedNumber == 0 && controllingUserProvidedNumber != 0)) {
ast_free (mwiSubscribtion->mailboxNumber);
ast_free (mwiSubscribtion->mailboxContext);
ast_free (mwiSubscribtion->controllingUserNumber);
ast_free (mwiSubscribtion->controllingUserProvidedNumber);
ast_free (mwiSubscribtion);
if ((mwiSubscribtion->mailboxNumber == 0) || (mwiSubscribtion->mailboxContext == 0) ||
((mwiSubscribtion->controllingUserNumber == 0) && (controllingUserNumber != 0)) ||
((mwiSubscribtion->controllingUserProvidedNumber == 0) && (controllingUserProvidedNumber != 0))) {
ast_free(mwiSubscribtion->mailboxNumber);
ast_free(mwiSubscribtion->mailboxContext);
ast_free(mwiSubscribtion->controllingUserNumber);
ast_free(mwiSubscribtion->controllingUserProvidedNumber);
ast_free(mwiSubscribtion);
} else {
cc_verbose (4, 0, "CAPI%d add MWI subscribtion for '%s@%s' user '%s' control '%s'\n",
mwiSubscribtion->controller->controller,
mwiSubscribtion->mailboxNumber+4,
mwiSubscribtion->mailboxNumber + 4,
mwiSubscribtion->mailboxContext,
mwiSubscribtion->controllingUserNumber != 0 ? (char*)mwiSubscribtion->controllingUserNumber+4 : "",
mwiSubscribtion->controllingUserProvidedNumber != 0 ? (char*)mwiSubscribtion->controllingUserProvidedNumber+4 : "");
(mwiSubscribtion->controllingUserNumber != 0) ? (char*)mwiSubscribtion->controllingUserNumber+4 : "",
(mwiSubscribtion->controllingUserProvidedNumber != 0) ? (char*)mwiSubscribtion->controllingUserProvidedNumber+4 : "");
memset (&mwiSubscribtion->link, 0x00, sizeof(mwiSubscribtion->link));
memset(&mwiSubscribtion->link, 0x00, sizeof(mwiSubscribtion->link));
AST_LIST_INSERT_TAIL(&mwiController->mwiSubscribtions, mwiSubscribtion, link);
}
}
@ -7876,7 +7880,12 @@ int mkif(struct cc_capi_conf *conf)
return 0;
}
static unsigned char* pbx_capi_build_facility_number (unsigned char mwifacptynrtype, unsigned char mwifacptynrton, unsigned char mwifacptynrpres, const char* number) {
static unsigned char* pbx_capi_build_facility_number(
unsigned char mwifacptynrtype,
unsigned char mwifacptynrton,
unsigned char mwifacptynrpres,
const char* number)
{
unsigned char* fnr = 0;
if (number != 0) {
@ -8635,8 +8644,8 @@ static int cc_post_init_capi(void)
/*
Register MWI mailboxes and refresh MWI info
*/
pbx_capi_register_mwi (capi_controllers[controller]);
pbx_capi_refresh_mwi (capi_controllers[controller]);
pbx_capi_register_mwi(capi_controllers[controller]);
pbx_capi_refresh_mwi(capi_controllers[controller]);
}
} else {
cc_log(LOG_NOTICE, "Unused contr%d\n",controller);
@ -8975,17 +8984,17 @@ static int capi_eval_config(struct ast_config *cfg)
#endif
if (conf_interface(&conf, ast_variable_browse(cfg, cat))) {
ast_free (conf.mwimailbox);
ast_free(conf.mwimailbox);
cc_log(LOG_ERROR, "Error interface config.\n");
return -1;
}
if (mkif(&conf)) {
ast_free (conf.mwimailbox);
ast_free(conf.mwimailbox);
cc_log(LOG_ERROR,"Error creating interface list\n");
return -1;
}
ast_free (conf.mwimailbox);
ast_free(conf.mwimailbox);
}
return 0;
}
@ -9042,7 +9051,7 @@ int unload_module(void)
for (controller = 1; controller <= CAPI_MAX_CONTROLLERS; controller++) {
if (capi_controllers[controller]) {
pbx_capi_cleanup_mwi (capi_controllers[controller]);
pbx_capi_cleanup_mwi(capi_controllers[controller]);
ast_free(capi_controllers[controller]);
}
}
@ -9265,62 +9274,63 @@ static unsigned char* time2X208 (time_t t) {
}
#if defined(CC_AST_HAS_EVENT_MWI)
static void pbx_capi_mwi_event (const struct ast_event *event, void *userdata) {
static void pbx_capi_mwi_event(const struct ast_event *event, void *userdata)
{
cc_capi_mwi_mailbox_t* mwiSubscribtion = userdata;
/* const char *mbox_context; */
const char *mbox_number;
int num_messages, num_old_messages;
/* const char *mbox_context; */
const char *mbox_number;
int num_messages, num_old_messages;
unsigned char* t;
int ret;
mbox_number = ast_event_get_ie_str(event, AST_EVENT_IE_MAILBOX);
if (ast_strlen_zero(mbox_number)) {
return;
}
/*
mbox_context = ast_event_get_ie_str(event, AST_EVENT_IE_CONTEXT);
if (ast_strlen_zero(mbox_context)) {
return;
}
*/
mbox_number = ast_event_get_ie_str(event, AST_EVENT_IE_MAILBOX);
if (ast_strlen_zero(mbox_number)) {
return;
}
num_messages = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
num_old_messages = ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS);
/*
mbox_context = ast_event_get_ie_str(event, AST_EVENT_IE_CONTEXT);
if (ast_strlen_zero(mbox_context)) {
return;
}
*/
num_messages = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
num_old_messages = ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS);
t = time2X208 (time(NULL));
cc_verbose (4, 0, "CAPI%d MWI event for '%s@%s' %d messages\n",
mwiSubscribtion->controller->controller,
mwiSubscribtion->mailboxNumber+4,
mwiSubscribtion->mailboxContext,
num_messages);
if (num_messages != 0 || num_old_messages != 0) {
ret = pbx_capi_xmit_mwi (mwiSubscribtion->controller,
mwiSubscribtion->basicService,
num_messages,
0,
0,
mwiSubscribtion->invocationMode,
mwiSubscribtion->mailboxNumber,
mwiSubscribtion->controllingUserNumber,
mwiSubscribtion->controllingUserProvidedNumber,
t);
mwiSubscribtion->controller->controller,
mwiSubscribtion->mailboxNumber+4,
mwiSubscribtion->mailboxContext,
num_messages);
if ((num_messages != 0) || (num_old_messages != 0)) {
ret = pbx_capi_xmit_mwi(mwiSubscribtion->controller,
mwiSubscribtion->basicService,
num_messages,
0,
0,
mwiSubscribtion->invocationMode,
mwiSubscribtion->mailboxNumber,
mwiSubscribtion->controllingUserNumber,
mwiSubscribtion->controllingUserProvidedNumber,
t);
} else {
ret = pbx_capi_xmit_mwi_deactivate (mwiSubscribtion->controller,
mwiSubscribtion->basicService,
mwiSubscribtion->invocationMode,
mwiSubscribtion->mailboxNumber,
mwiSubscribtion->controllingUserNumber);
ret = pbx_capi_xmit_mwi_deactivate(mwiSubscribtion->controller,
mwiSubscribtion->basicService,
mwiSubscribtion->invocationMode,
mwiSubscribtion->mailboxNumber,
mwiSubscribtion->controllingUserNumber);
}
ast_free (t);
ast_free(t);
}
#endif
static void pbx_capi_register_mwi (struct cc_capi_controller *controller) {
static void pbx_capi_register_mwi(struct cc_capi_controller *controller)
{
cc_capi_mwi_mailbox_t* mwiSubscribtion;
AST_LIST_TRAVERSE(&controller->mwiSubscribtions, mwiSubscribtion, link) {
@ -9343,18 +9353,19 @@ static void pbx_capi_register_mwi (struct cc_capi_controller *controller) {
}
}
static void pbx_capi_refresh_mwi (struct cc_capi_controller *controller) {
static void pbx_capi_refresh_mwi(struct cc_capi_controller *controller)
{
cc_capi_mwi_mailbox_t* mwiSubscribtion;
AST_LIST_TRAVERSE(&controller->mwiSubscribtions, mwiSubscribtion, link) {
if (mwiSubscribtion->mwiSubscribtion != 0) {
#if defined(CC_AST_HAS_EVENT_MWI)
struct ast_event *event = ast_event_get_cached(AST_EVENT_MWI,
AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, &mwiSubscribtion->mailboxNumber[4],
AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, mwiSubscribtion->mailboxContext,
AST_EVENT_IE_END);
AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, &mwiSubscribtion->mailboxNumber[4],
AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, mwiSubscribtion->mailboxContext,
AST_EVENT_IE_END);
if (event != 0) {
pbx_capi_mwi_event (event, mwiSubscribtion);
pbx_capi_mwi_event(event, mwiSubscribtion);
ast_event_destroy(event);
}
#endif
@ -9362,7 +9373,8 @@ static void pbx_capi_refresh_mwi (struct cc_capi_controller *controller) {
}
}
static void pbx_capi_unregister_mwi(struct cc_capi_controller *controller) {
static void pbx_capi_unregister_mwi(struct cc_capi_controller *controller)
{
cc_capi_mwi_mailbox_t* mwiSubscribtion;
AST_LIST_TRAVERSE(&controller->mwiSubscribtions, mwiSubscribtion, link) {
@ -9375,7 +9387,8 @@ static void pbx_capi_unregister_mwi(struct cc_capi_controller *controller) {
}
}
static void pbx_capi_cleanup_mwi(struct cc_capi_controller *controller) {
static void pbx_capi_cleanup_mwi(struct cc_capi_controller *controller)
{
cc_capi_mwi_mailbox_t* mwiSubscribtion;
pbx_capi_unregister_mwi(controller);
@ -9389,54 +9402,57 @@ static void pbx_capi_cleanup_mwi(struct cc_capi_controller *controller) {
}
}
static int pbx_capi_xmit_mwi (struct cc_capi_controller *controller,
unsigned short basicService,
unsigned int numberOfMessages,
unsigned short messageStatus,
unsigned short messageReference,
unsigned short invocationMode,
const unsigned char* receivingUserNumber,
const unsigned char* controllingUserNumber,
const unsigned char* controllingUserProvidedNumber,
const unsigned char* timeX208)
static int pbx_capi_xmit_mwi(
struct cc_capi_controller *controller,
unsigned short basicService,
unsigned int numberOfMessages,
unsigned short messageStatus,
unsigned short messageReference,
unsigned short invocationMode,
const unsigned char* receivingUserNumber,
const unsigned char* controllingUserNumber,
const unsigned char* controllingUserProvidedNumber,
const unsigned char* timeX208)
{
MESSAGE_EXCHANGE_ERROR error;
_cword messageNumber = get_capi_MessageNumber();
error = capi_sendf(NULL, 0, CAPI_FACILITY_REQ, controller->controller, messageNumber,
"w(w(wdwwwssssd))",
0x0003, /* Suppl. Service */
0x0013, /* MWI Activate */
basicService, /* Basic Service */
numberOfMessages, /* Number of messages */
messageStatus, /* Added messages */
messageReference, /* Message reference */
invocationMode, /* Invocation mode */
receivingUserNumber, /* Receiving user number */
controllingUserNumber, /* Controlling user number */
controllingUserProvidedNumber, /* Controlling user provided number */
timeX208, /* time */
messageNumber);
"w(w(wdwwwssssd))",
0x0003, /* Suppl. Service */
0x0013, /* MWI Activate */
basicService, /* Basic Service */
numberOfMessages, /* Number of messages */
messageStatus, /* Added messages */
messageReference, /* Message reference */
invocationMode, /* Invocation mode */
receivingUserNumber, /* Receiving user number */
controllingUserNumber, /* Controlling user number */
controllingUserProvidedNumber, /* Controlling user provided number */
timeX208, /* time */
messageNumber);
return ((error == CapiNoError) ? 0 : -1);
}
static int pbx_capi_xmit_mwi_deactivate (struct cc_capi_controller *controller,
unsigned short basicService,
unsigned short invocationMode,
const unsigned char* receivingUserNumber,
const unsigned char* controllingUserNumber) {
static int pbx_capi_xmit_mwi_deactivate(
struct cc_capi_controller *controller,
unsigned short basicService,
unsigned short invocationMode,
const unsigned char* receivingUserNumber,
const unsigned char* controllingUserNumber)
{
MESSAGE_EXCHANGE_ERROR error;
_cword messageNumber = get_capi_MessageNumber();
error = capi_sendf(NULL, 0, CAPI_FACILITY_REQ, controller->controller, messageNumber,
"w(w(wwss))",
0x0003, /* Suppl. Service */
0x0014, /* MWI Activate */
basicService, /* Basic Service */
invocationMode, /* Invocation mode */
receivingUserNumber, /* Receiving user number */
controllingUserNumber /* Controlling user number */);
"w(w(wwss))",
0x0003, /* Suppl. Service */
0x0014, /* MWI Activate */
basicService, /* Basic Service */
invocationMode, /* Invocation mode */
receivingUserNumber, /* Receiving user number */
controllingUserNumber /* Controlling user number */);
return ((error == CapiNoError) ? 0 : -1);
}

Loading…
Cancel
Save