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.

Changes between revision 1 and 2

1 2 3 4
1 2 3 4

  1. branches/11/main/devicestate.c: Loading...
branches/11/main/devicestate.c
Diff Revision 1 Diff Revision 2
[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
	const char *cachestr;

   
713

    
   
712

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

    
   
716

   
[+20] [20] 7 lines
[+20] static void devstate_change_collector_cb(const struct ast_event *event, void *data)
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;
729

    
   
728

   
730
	cachestr = ast_event_get_ie_str(event, AST_EVENT_IE_CACHABLE);
729
	if ((cachable_str = ast_event_get_ie_str(event, AST_EVENT_IE_CACHABLE))) {
731
	if (!ast_strlen_zero(cachestr)) {
730
		sscanf(cachable_str, "%30u", &cachable);
732
		if (sscanf(cachestr, "%u", &cachable) == 1) {

   
733
			switch (cachable) {

   
734
			case AST_DEVSTATE_NOT_CACHABLE:

   
735
			case AST_DEVSTATE_CACHABLE:

   
736
				break;

   
737
			default:

   
738
				cachable = AST_DEVSTATE_CACHABLE;

   
739
			}

   
740
		}

   
741
	}
731
	}
742
	sc->cachable = cachable;
732
	sc->cachable = cachable;
743

    
   
733

   
744
	ast_mutex_lock(&devstate_collector.lock);
734
	ast_mutex_lock(&devstate_collector.lock);
745
	AST_LIST_INSERT_TAIL(&devstate_collector.devstate_change_q, sc, entry);
735
	AST_LIST_INSERT_TAIL(&devstate_collector.devstate_change_q, sc, entry);
[+20] [20] 79 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.