Review Board 1.7.16


Fix directed group pickup feature code *8 with pickupsounds enabled , deadlock and segfault, affects 1.8.0 and trunk

Review Request #1185 - Created April 17, 2011 and submitted

Alec Davis
trunk
18654
Reviewers
asterisk-dev
rmudgett
Asterisk
Since 1.8, the new pickupsound and pickupfailsound in features.conf cause many issues.

1). chan_sip:handle_request_invite() shouldn't be playing out the fail/success audio, as it has 'netlock' locked.
2). dialplan applications for directed_pickups shouldn't beep.
3). feature code for directed pickup should beep on success/failure if configured.

Moved app_directed:pickup_do() to features:ast_do_pickup().

Functions below, all now use the new ast_do_pickup()
app_directed_pickup.c:
   pickup_by_channel()
   pickup_by_exten()
   pickup_by_mark()
   pickup_by_part()
features.c:
   ast_pickup_call()

Created a sip_pickup() thread to handle the pickup and playout the audio, spawned from handle_request_invite.
pickup using *8 feature code, with pickup sounds enabled/disabled

exten => 71,1,Pickup()           ; any ringing extension in same pickupgroup 
exten => 72,1,Pickup(85@phones)  ; dahdi extension
exten => 73,1,Pickup(823@phones) ; sip extension

Changes between revision 7 and 13

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

  1. trunk/apps/app_directed_pickup.c: Loading...
  2. trunk/channels/chan_sip.c: Loading...
  3. trunk/include/asterisk/features.h: Loading...
  4. trunk/main/features.c: Loading...
  5. trunk/res/res_features.exports.in: Loading...
trunk/apps/app_directed_pickup.c
Diff Revision 7 Diff Revision 13
[20] 97 lines
[+20] [+] static const char app[] = "Pickup";
98
/*! \todo This application should return a result code, like PICKUPRESULT */
98
/*! \todo This application should return a result code, like PICKUPRESULT */
99

    
   
99

   
100
/* Helper function that determines whether a channel is capable of being picked up */
100
/* Helper function that determines whether a channel is capable of being picked up */
101
static int can_pickup(struct ast_channel *chan)
101
static int can_pickup(struct ast_channel *chan)
102
{
102
{
103
	if (!chan->pbx && !chan->masq && (chan->_state == AST_STATE_RINGING || chan->_state == AST_STATE_RING || chan->_state == AST_STATE_DOWN))
103
	if (!chan->pbx && !chan->masq &&

    
   
104
		!ast_test_flag(chan, AST_FLAG_ZOMBIE) &&

    
   
105
		(chan->_state == AST_STATE_RINGING ||

    
   
106
		 chan->_state == AST_STATE_RING ||

    
   
107
		 chan->_state == AST_STATE_DOWN)) {
104
		return 1;
108
		return 1;
105
	else
109
	}
106
		return 0;
110
	return 0;
107
}
111
}
108

    
   
112

   
109
struct pickup_by_name_args {
113
struct pickup_by_name_args {
110
	const char *name;
114
	const char *name;
[+20] [20] 75 lines
[+20] [+] static int pickup_by_exten(struct ast_channel *chan, const char *exten, const char *context)
186
	}
190
	}
187

    
   
191

   
188
	while ((target = ast_channel_iterator_next(iter))) {
192
	while ((target = ast_channel_iterator_next(iter))) {
189
		ast_channel_lock(target);
193
		ast_channel_lock(target);
190
		if ((chan != target) && can_pickup(target)) {
194
		if ((chan != target) && can_pickup(target)) {
191
			ast_log(LOG_NOTICE,"%s pickup by %s\n", target->name, chan->name);
195
			ast_log(LOG_NOTICE, "%s pickup by %s\n", target->name, chan->name);
192
			break;
196
			break;
193
		}
197
		}
194
		ast_channel_unlock(target);
198
		ast_channel_unlock(target);
195
		target = ast_channel_unref(target);
199
		target = ast_channel_unref(target);
196
	}
200
	}
[+20] [20] 43 lines
[+20] [+] static int pickup_by_mark(struct ast_channel *chan, const char *mark)
240
	} else {
244
	} else {
241
		ast_log(LOG_WARNING, "target has gone, or not ringing anymore for %s\n", chan->name);
245
		ast_log(LOG_WARNING, "target has gone, or not ringing anymore for %s\n", chan->name);
242
	}
246
	}
243
	ast_channel_unlock(target);
247
	ast_channel_unlock(target);
244
	target = ast_channel_unref(target);
248
	target = ast_channel_unref(target);
245
	
249

   
246
	return res;
250
	return res;
247
}
251
}
248

    
   
252

   
249
static int find_channel_by_group(void *obj, void *arg, void *data, int flags)
253
static int find_channel_by_group(void *obj, void *arg, void *data, int flags)
250
{
254
{
251
	struct ast_channel *chan = obj;
255
	struct ast_channel *chan = obj;
252
	struct ast_channel *c = data;
256
	struct ast_channel *c = data;

    
   
257
	int i;
253

    
   
258

   
254
	ast_channel_lock(chan);
259
	ast_channel_lock(chan);
255
	int i = (c != chan) &&
260
	i = (c != chan) && (chan->pickupgroup & c->callgroup) &&
256
		(chan->pickupgroup & c->callgroup) &&

   
257
		can_pickup(chan);
261
		can_pickup(chan);
258

    
   
262

   
259
	ast_channel_unlock(chan);
263
	ast_channel_unlock(chan);
260
	return i ? CMP_MATCH | CMP_STOP : 0;
264
	return i ? CMP_MATCH | CMP_STOP : 0;
261
}
265
}
[+20] [20] 4 lines
[+20] [+] static int pickup_by_group(struct ast_channel *chan)
266
	int res = -1;
270
	int res = -1;
267

    
   
271

   
268
	if (!(target = ast_channel_callback(find_channel_by_group, NULL, chan, 0))) {
272
	if (!(target = ast_channel_callback(find_channel_by_group, NULL, chan, 0))) {
269
		return res;
273
		return res;
270
	}
274
	}
271
	
275

   
272
	ast_log(LOG_NOTICE, "%s, pickup attempt by %s\n", target->name, chan->name);
276
	ast_log(LOG_NOTICE, "%s, pickup attempt by %s\n", target->name, chan->name);
273
	ast_channel_lock(target);
277
	ast_channel_lock(target);
274
	if (can_pickup(target)) {
278
	if (can_pickup(target)) {
275
		res = ast_do_pickup(chan, target);
279
		res = ast_do_pickup(chan, target);
276
	} else {
280
	} else {
277
		ast_log(LOG_WARNING, "target has gone, or not ringing anymore for %s\n", chan->name);
281
		ast_log(LOG_WARNING, "target has gone, or not ringing anymore for %s\n", chan->name);
278
	}
282
	}
279
	ast_channel_unlock(target);
283
	ast_channel_unlock(target);
280
	target = ast_channel_unref(target);
284
	target = ast_channel_unref(target);
281
	
285

   
282
	return res;
286
	return res;
283
}
287
}
284

    
   
288

   
285
/* application entry point for Pickup() */
289
/* application entry point for Pickup() */
286
static int pickup_exec(struct ast_channel *chan, const char *data)
290
static int pickup_exec(struct ast_channel *chan, const char *data)
[+20] [20] 4 lines
[+20] static int pickup_by_group(struct ast_channel *chan)
291

    
   
295

   
292
	if (ast_strlen_zero(data)) {
296
	if (ast_strlen_zero(data)) {
293
		res = pickup_by_group(chan);
297
		res = pickup_by_group(chan);
294
		return res;
298
		return res;
295
	}
299
	}
296
	
300

   
297
	/* Parse extension (and context if there) */
301
	/* Parse extension (and context if there) */
298
	while (!ast_strlen_zero(tmp) && (exten = strsep(&tmp, "&"))) {
302
	while (!ast_strlen_zero(tmp) && (exten = strsep(&tmp, "&"))) {
299
		if ((context = strchr(exten, '@')))
303
		if ((context = strchr(exten, '@')))
300
			*context++ = '\0';
304
			*context++ = '\0';
301
		if (!ast_strlen_zero(context) && !strcasecmp(context, PICKUPMARK)) {
305
		if (!ast_strlen_zero(context) && !strcasecmp(context, PICKUPMARK)) {
[+20] [20] 111 lines
trunk/channels/chan_sip.c
Diff Revision 7 Diff Revision 13
 
trunk/include/asterisk/features.h
Diff Revision 7 Diff Revision 13
 
trunk/main/features.c
Diff Revision 7 Diff Revision 13
 
trunk/res/res_features.exports.in
Diff Revision 7 Diff Revision 13 - File Reverted
 
  1. trunk/apps/app_directed_pickup.c: Loading...
  2. trunk/channels/chan_sip.c: Loading...
  3. trunk/include/asterisk/features.h: Loading...
  4. trunk/main/features.c: Loading...
  5. trunk/res/res_features.exports.in: 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.