Review Board 1.7.16


Fix Distributed Device State broken at sites using res_xmpp or res_jabber where Secuity Advisory AST-2012-015 is inplace.

Review Request #2452 - Created April 14, 2013 and submitted

Alec Davis
1.8 to trunk
ASTERISK-21429
Reviewers
asterisk-dev
Asterisk
The site that doesn't update it's devicestates from the remotesite is the site with ASR-2012-015 inplace.

This fixes the scenario where one site doesn't send the IE cachable=1 in the XMPP/Jabber message, to a newer system that expects to see it.

If the IE 'cachable' isn't present we need to default to AST_DEVSTATE_CACHABLE.
 Assigning the cachable variable directly from ast_event_get_ie_uint is wrong, if the IE 'cachable' isn't found ast_event_get_ie_uint() will return 0, 0 = AST_DEVSTATE_NOT_CACHABLE

We need to read the 'cachable' IE into a string first, allowing us to check that it exists, if it doesn't exist then default to cachable=AST_DEVSTATE_CACHABLE.
 If the 'cachable' IE does exist, then convert to a uint, validate value and go with it.


Caused by:
https://issues.asterisk.org/jira/browse/ASTERISK-20175
Yes, change device state, at either site, and it's reflected in the other. One site is prior to ASTERISK-21075.

Tested both sites at r385594, and states correct at both sites.

Diff revision 2

This is not the most recent revision of the diff. The latest diff is revision 4. See what's changed.

1 2 3 4
1 2 3 4

  1. branches/11/main/devicestate.c: Loading...
branches/11/main/devicestate.c
Revision 378321 New Change
[20] 702 lines
[+20] [+] static void *run_devstate_collector(void *data)
703
}
703
}
704

    
   
704

   
705
static void devstate_change_collector_cb(const struct ast_event *event, void *data)
705
static void devstate_change_collector_cb(const struct ast_event *event, void *data)
706
{
706
{
707
	struct devstate_change *sc;
707
	struct devstate_change *sc;
708
	const char *device;
708
	const char *device, *cachable_str;
709
	const struct ast_eid *eid;
709
	const struct ast_eid *eid;
710
	uint32_t state;
710
	uint32_t state;
711
	enum ast_devstate_cache cachable = AST_DEVSTATE_CACHABLE;
711
	enum ast_devstate_cache cachable = AST_DEVSTATE_CACHABLE;
712

    
   
712

   
713
	device = ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE);
713
	device = ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE);
714
	eid = ast_event_get_ie_raw(event, AST_EVENT_IE_EID);
714
	eid = ast_event_get_ie_raw(event, AST_EVENT_IE_EID);
715
	state = ast_event_get_ie_uint(event, AST_EVENT_IE_STATE);
715
	state = ast_event_get_ie_uint(event, AST_EVENT_IE_STATE);
716
	cachable = ast_event_get_ie_uint(event, AST_EVENT_IE_CACHABLE);

   
717

    
   
716

   
718
	if (ast_strlen_zero(device) || !eid) {
717
	if (ast_strlen_zero(device) || !eid) {
719
		ast_log(LOG_ERROR, "Invalid device state change event received\n");
718
		ast_log(LOG_ERROR, "Invalid device state change event received\n");
720
		return;
719
		return;
721
	}
720
	}
722

    
   
721

   
723
	if (!(sc = ast_calloc(1, sizeof(*sc) + strlen(device))))
722
	if (!(sc = ast_calloc(1, sizeof(*sc) + strlen(device))))
724
		return;
723
		return;
725

    
   
724

   
726
	strcpy(sc->device, device);
725
	strcpy(sc->device, device);
727
	sc->eid = *eid;
726
	sc->eid = *eid;
728
	sc->state = state;
727
	sc->state = state;

    
   
728

   

    
   
729
	if ((cachable_str = ast_event_get_ie_str(event, AST_EVENT_IE_CACHABLE))) {

    
   
730
		sscanf(cachable_str, "%30u", &cachable);

    
   
731
	}
729
	sc->cachable = cachable;
732
	sc->cachable = cachable;
730

    
   
733

   
731
	ast_mutex_lock(&devstate_collector.lock);
734
	ast_mutex_lock(&devstate_collector.lock);
732
	AST_LIST_INSERT_TAIL(&devstate_collector.devstate_change_q, sc, entry);
735
	AST_LIST_INSERT_TAIL(&devstate_collector.devstate_change_q, sc, entry);
733
	ast_cond_signal(&devstate_collector.cond);
736
	ast_cond_signal(&devstate_collector.cond);
[+20] [20] 78 lines
  1. branches/11/main/devicestate.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.