Index: channels/chan_skinny.c =================================================================== --- channels/chan_skinny.c (revision 169321) +++ channels/chan_skinny.c (working copy) @@ -1321,6 +1321,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", @@ -1851,6 +1852,7 @@ l->instance = instance; set_callforwards(l, NULL, 0); register_exten(l); + has_voicemail(l); ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Skinny/%s@%s", l->name, d->name); } --instance; @@ -2503,65 +2505,64 @@ 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_skinny will get the MWI from the - * event cache instead of checking the mailbox directly. */ + struct skinny_line *l = userdata; + struct skinny_device *d = l->device; + 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(d, STIMULUS_VOICEMAIL, l->instance, l->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_ON); + transmit_lamp_indication(d, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_ON); + } else { + transmit_lamp_indication(d, STIMULUS_VOICEMAIL, l->instance, l->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_OFF); + transmit_lamp_indication(d, 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) { int new_msgs; - struct ast_event *event; - char *mbox, *context; + int dev_msgs = 0; + struct skinny_line *l2; + struct skinny_device *d = l->device; - context = mbox = ast_strdupa(l->mailbox); - strsep(&context, "@"); - if (ast_strlen_zero(context)) - context = "default"; + new_msgs = ast_app_has_voicemail(l->mailbox, NULL); - event = ast_event_get_cached(AST_EVENT_MWI, - AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mbox, - AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context, - AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS, - AST_EVENT_IE_END); + if (new_msgs) { + transmit_lamp_indication(d, STIMULUS_VOICEMAIL, l->instance, l->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_ON); + } else { + transmit_lamp_indication(d, STIMULUS_VOICEMAIL, l->instance, SKINNY_LAMP_OFF); + } - 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); + /* find out wether the device lamp should be on or off */ + AST_LIST_TRAVERSE(&d->lines, l2, list) { + if (ast_app_has_voicemail(l2->mailbox, NULL)) { + dev_msgs++; + } + } - return new_msgs; + if (dev_msgs) { + transmit_lamp_indication(d, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_ON); + } else { + transmit_lamp_indication(d, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_OFF); + } + + ast_verb(3, "Skinny has_voicemail found %d new messages\n", 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 */ - AST_LIST_TRAVERSE(&d->lines, l, list) { - if (has_voicemail(l)) { - if (skinnydebug) - ast_verb(1, "Checking for voicemail Skinny %s@%s\n", l->name, d->name); - if (skinnydebug) - ast_verb(1, "Skinny %s@%s has voicemail!\n", l->name, d->name); - transmit_lamp_indication(d, STIMULUS_VOICEMAIL, l->instance, l->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_ON); - device_lamp++; - } else { - transmit_lamp_indication(d, 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(d, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_ON); - else - transmit_lamp_indication(d, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_OFF); } /* I do not believe skinny can deal with video. @@ -6599,7 +6600,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,