--- channels/chan_skinny.c-orig 2008-10-31 16:49:17.000000000 -0700 +++ channels/chan_skinny.c 2008-10-31 20:59:27.000000000 -0700 @@ -1275,6 +1275,7 @@ static int skinny_senddigit_begin(struct ast_channel *ast, char digit); static int skinny_senddigit_end(struct ast_channel *ast, char digit, unsigned int duration); static int handle_time_date_req_message(struct skinny_req *req, struct skinnysession *s); +static void has_voicemail(struct skinny_line *l); static const struct ast_channel_tech skinny_tech = { .type = "Skinny", @@ -1783,6 +1784,7 @@ } for (l = d->lines; l; l = l->next) { register_exten(l); + has_voicemail(l); ast_device_state_changed("Skinny/%s@%s", l->name, d->name); } break; @@ -2240,65 +2242,53 @@ static void mwi_event_cb(const struct ast_event *event, void *userdata) { - /* This module does not handle MWI in an event-based manner. However, it - * subscribes to MWI for each mailbox that is configured so that the core - * knows that we care about it. Then, chan_zap will get the MWI from the - * event cache instead of checking the mailbox directly. */ + struct skinny_line *l = userdata; + struct skinny_device *d = l->parent; + struct skinnysession *s = d->session; + int new_msgs = 0; + + if (s) { + if (event) + new_msgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS); + + if (new_msgs) { + transmit_lamp_indication(s, STIMULUS_VOICEMAIL, l->instance, l->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_ON); + transmit_lamp_indication(s, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_ON); + } else { + transmit_lamp_indication(s, STIMULUS_VOICEMAIL, l->instance, l->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_OFF); + transmit_lamp_indication(s, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_OFF); + } + + ast_verb(3, "Skinny mwi_event_cb found %d new messages\n", new_msgs); + + } } -static int has_voicemail(struct skinny_line *l) +static void has_voicemail(struct skinny_line *l) { + struct skinny_device *d = l->parent; + struct skinnysession *s = d->session; int new_msgs; - struct ast_event *event; - char *mailbox, *context; - context = mailbox = ast_strdupa(l->mailbox); - strsep(&context, "@"); - if (ast_strlen_zero(context)) - context = "default"; - - event = ast_event_get_cached(AST_EVENT_MWI, - AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox, - AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context, - AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS, - AST_EVENT_IE_END); - - if (event) { - new_msgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS); - ast_event_destroy(event); - } else - new_msgs = ast_app_has_voicemail(l->mailbox, NULL); + new_msgs = ast_app_has_voicemail(l->mailbox, NULL); + + if (new_msgs) { + transmit_lamp_indication(s, STIMULUS_VOICEMAIL, l->instance, l->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_ON); + transmit_lamp_indication(s, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_ON); + } else { + transmit_lamp_indication(s, STIMULUS_VOICEMAIL, l->instance, l->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_OFF); + transmit_lamp_indication(s, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_OFF); + } + + ast_verb(3, "Skinny has_voicemail found %d new messages\n", new_msgs); - return new_msgs; } static void do_housekeeping(struct skinnysession *s) { - int device_lamp = 0; - struct skinny_device *d = s->device; - struct skinny_line *l; - /* Update time on device */ handle_time_date_req_message(NULL, s); - /* Set MWI on individual lines */ - for (l = d->lines; l; l = l->next) { - if (has_voicemail(l)) { - if (skinnydebug) - ast_debug(1, "Checking for voicemail Skinny %s@%s\n", l->name, d->name); - if (skinnydebug) - ast_debug(1, "Skinny %s@%s has voicemail!\n", l->name, d->name); - transmit_lamp_indication(s, STIMULUS_VOICEMAIL, l->instance, l->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_ON); - device_lamp++; - } else { - transmit_lamp_indication(s, STIMULUS_VOICEMAIL, l->instance, SKINNY_LAMP_OFF); - } - } - /* If at least one line has VM, turn the device level lamp on */ - if (device_lamp) - transmit_lamp_indication(s, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_ON); - else - transmit_lamp_indication(s, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_OFF); } /* I do not believe skinny can deal with video. @@ -3121,7 +3111,7 @@ strsep(&cfg_context, "@"); if (ast_strlen_zero(cfg_context)) cfg_context = "default"; - l->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, NULL, + l->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, l, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, cfg_mailbox, AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, cfg_context, AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,