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 1 and 6

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 1 Diff Revision 6
[20] 94 lines
[+20] [+] ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
95

    
   
95

   
96
static const char app[] = "Pickup";
96
static const char app[] = "Pickup";
97
static const char app2[] = "PickupChan";
97
static const char app2[] = "PickupChan";
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
/* Perform actual pickup between two channels */

   
101
static int pickup_do(struct ast_channel *chan, struct ast_channel *target)

   
102
{

   
103
	return ast_do_pickup(chan, target);

   
104
}

   
105

    
   

   
106
/* 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 */
107
static int can_pickup(struct ast_channel *chan)
101
static int can_pickup(struct ast_channel *chan)
108
{
102
{
109
	if (!chan->pbx && (chan->_state == AST_STATE_RINGING || chan->_state == AST_STATE_RING || chan->_state == AST_STATE_DOWN))
103
	if (!chan->pbx && (chan->_state == AST_STATE_RINGING || chan->_state == AST_STATE_RING || chan->_state == AST_STATE_DOWN))
110
		return 1;
104
		return 1;
[+20] [20] 59 lines
[+20] [+] static int pickup_by_channel(struct ast_channel *chan, char *pickup)
170
		return -1;
164
		return -1;
171
	}
165
	}
172

    
   
166

   
173
	/* Just check that we are not picking up the SAME as target */
167
	/* Just check that we are not picking up the SAME as target */
174
	if (chan != target) {
168
	if (chan != target) {
175
		res = pickup_do(chan, target);
169
		res = ast_do_pickup(chan, target);
176
	}
170
	} else {
177

    
   

   
178
	ast_channel_unlock(target);
171
		ast_channel_unlock(target);
179
	target = ast_channel_unref(target);
172
		target = ast_channel_unref(target);

    
   
173
	}
180

    
   
174

   
181
	return res;
175
	return res;
182
}
176
}
183

    
   
177

   
184
/* Attempt to pick up specified extension with context */
178
/* Attempt to pick up specified extension with context */
[+20] [20] 17 lines
[+20] [+] static int pickup_by_exten(struct ast_channel *chan, const char *exten, const char *context)
202
	}
196
	}
203

    
   
197

   
204
	ast_channel_iterator_destroy(iter);
198
	ast_channel_iterator_destroy(iter);
205

    
   
199

   
206
	if (target) {
200
	if (target) {
207
		res = pickup_do(chan, target);
201
		res = ast_do_pickup(chan, target);
208
		ast_channel_unlock(target);

   
209
		target = ast_channel_unref(target);

   
210
	}
202
	}
211

    
   
203

   
212
	return res;
204
	return res;
213
}
205
}
214

    
   
206

   
[+20] [20] 21 lines
[+20] [+] static int pickup_by_mark(struct ast_channel *chan, const char *mark)
236
	struct ast_channel *target;
228
	struct ast_channel *target;
237
	int res = -1;
229
	int res = -1;
238

    
   
230

   
239
	if ((target = ast_channel_callback(find_by_mark, NULL, (char *) mark, 0))) {
231
	if ((target = ast_channel_callback(find_by_mark, NULL, (char *) mark, 0))) {
240
		ast_channel_lock(target);
232
		ast_channel_lock(target);
241
		res = pickup_do(chan, target);
233
		if (!target->masq && can_pickup(target)) {

    
   
234
			res = ast_do_pickup(chan, target);

    
   
235
		} else {

    
   
236
			ast_log(LOG_WARNING, "target has gone, or not ringing anymore for %s\n", chan->name);
242
		ast_channel_unlock(target);
237
			ast_channel_unlock(target);
243
		target = ast_channel_unref(target);
238
			target = ast_channel_unref(target);
244
	}
239
		}

    
   
240
	}
245

    
   
241

   
246
	return res;
242
	return res;
247
}
243
}
248

    
   
244

   

    
   
245
static int find_channel_by_group(void *obj, void *arg, void *data, int flags)

    
   
246
{

    
   
247
	struct ast_channel *chan = obj;

    
   
248
	struct ast_channel *c = data;

    
   
249

   

    
   
250
	ast_channel_lock(chan);

    
   
251
	int i = (c != chan) &&

    
   
252
		(chan->pickupgroup & c->callgroup) &&

    
   
253
		!c->masq && can_pickup(chan);

    
   
254

   

    
   
255
	ast_channel_unlock(chan);

    
   
256
	return i ? CMP_MATCH | CMP_STOP : 0;

    
   
257
}

    
   
258

   

    
   
259
static int pickup_by_group(struct ast_channel *chan)

    
   
260
{

    
   
261
	struct ast_channel *target;

    
   
262
	int res = -1;

    
   
263
	if ((target = ast_channel_callback(find_channel_by_group, NULL, chan, 0))) {

    
   
264
		ast_log(LOG_NOTICE, "%s, pickup attempt by %s\n", target->name, chan->name);

    
   
265
		ast_channel_lock(target);

    
   
266
		if (!target->masq && can_pickup(target)) {

    
   
267
			res = ast_do_pickup(chan, target);

    
   
268
		} else {

    
   
269
			ast_log(LOG_WARNING, "target has gone, or not ringing anymore for %s\n", chan->name);
Moved from 208

    
   
270
			ast_channel_unlock(target);
Moved from 209

    
   
271
			target = ast_channel_unref(target);

    
   
272
		}

    
   
273
	}

    
   
274
	return res;

    
   
275
}

    
   
276

   
249
/* application entry point for Pickup() */
277
/* application entry point for Pickup() */
250
static int pickup_exec(struct ast_channel *chan, const char *data)
278
static int pickup_exec(struct ast_channel *chan, const char *data)
251
{
279
{
252
	int res = 0;
280
	int res = 0;
253
	char *tmp = ast_strdupa(data);
281
	char *tmp = ast_strdupa(data);
254
	char *exten = NULL, *context = NULL;
282
	char *exten = NULL, *context = NULL;
255

    
   
283

   
256
	if (ast_strlen_zero(data)) {
284
	if (ast_strlen_zero(data)) {
257
		res = ast_pickup_call(chan);
285
		res = pickup_by_group(chan);
258
		return res;
286
		return res;
259
	}
287
	}
260
	
288
	
261
	/* Parse extension (and context if there) */
289
	/* Parse extension (and context if there) */
262
	while (!ast_strlen_zero(tmp) && (exten = strsep(&tmp, "&"))) {
290
	while (!ast_strlen_zero(tmp) && (exten = strsep(&tmp, "&"))) {
[+20] [20] 35 lines
[+20] [+] static int pickup_by_part(struct ast_channel *chan, const char *part)
298
	struct ast_channel *target;
326
	struct ast_channel *target;
299
	int res = -1;
327
	int res = -1;
300

    
   
328

   
301
	if ((target = ast_channel_callback(find_by_part, NULL, (char *) part, 0))) {
329
	if ((target = ast_channel_callback(find_by_part, NULL, (char *) part, 0))) {
302
		ast_channel_lock(target);
330
		ast_channel_lock(target);
303
		res = pickup_do(chan, target);
331
		if (!target->masq && can_pickup(target)) {

    
   
332
			res = ast_do_pickup(chan, target);

    
   
333
		} else {

    
   
334
			ast_log(LOG_WARNING, "target has gone, or not ringing anymore for %s\n", chan->name);
304
		ast_channel_unlock(target);
335
			ast_channel_unlock(target);
305
		target = ast_channel_unref(target);
336
			target = ast_channel_unref(target);
306
	}
337
		}

    
   
338
	}
307

    
   
339

   
308
	return res;
340
	return res;
309
}
341
}
310

    
   
342

   
311
/* application entry point for PickupChan() */
343
/* application entry point for PickupChan() */
[+20] [20] 61 lines
trunk/channels/chan_sip.c
Diff Revision 1 Diff Revision 6
 
trunk/include/asterisk/features.h
Diff Revision 1 Diff Revision 6
 
trunk/main/features.c
Diff Revision 1 Diff Revision 6
 
trunk/res/res_features.exports.in
Diff Revision 1 Diff Revision 6
 
  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.