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

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/main/features.c: Loading...
trunk/apps/app_directed_pickup.c
Diff Revision 6 Diff Revision 7
[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->_state == AST_STATE_RINGING || chan->_state == AST_STATE_RING || chan->_state == AST_STATE_DOWN))
103
	if (!chan->pbx && !chan->masq && (chan->_state == AST_STATE_RINGING || chan->_state == AST_STATE_RING || chan->_state == AST_STATE_DOWN))
104
		return 1;
104
		return 1;
105
	else
105
	else
106
		return 0;
106
		return 0;
107
}
107
}
108

    
   
108

   
[+20] [20] 56 lines
[+20] [+] static int pickup_by_channel(struct ast_channel *chan, char *pickup)
165
	}
165
	}
166

    
   
166

   
167
	/* 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 */
168
	if (chan != target) {
168
	if (chan != target) {
169
		res = ast_do_pickup(chan, target);
169
		res = ast_do_pickup(chan, target);
170
	} else {
170
	}
171
		ast_channel_unlock(target);
171
	ast_channel_unlock(target);
172
		target = ast_channel_unref(target);
172
	target = ast_channel_unref(target);
173
	}

   
174

    
   
173

   
175
	return res;
174
	return res;
176
}
175
}
177

    
   
176

   
178
/* Attempt to pick up specified extension with context */
177
/* Attempt to pick up specified extension with context */
[+20] [20] 8 lines
[+20] [+] static int pickup_by_exten(struct ast_channel *chan, const char *exten, const char *context)
187
	}
186
	}
188

    
   
187

   
189
	while ((target = ast_channel_iterator_next(iter))) {
188
	while ((target = ast_channel_iterator_next(iter))) {
190
		ast_channel_lock(target);
189
		ast_channel_lock(target);
191
		if ((chan != target) && can_pickup(target)) {
190
		if ((chan != target) && can_pickup(target)) {

    
   
191
			ast_log(LOG_NOTICE,"%s pickup by %s\n", target->name, chan->name);
192
			break;
192
			break;
193
		}
193
		}
194
		ast_channel_unlock(target);
194
		ast_channel_unlock(target);
195
		target = ast_channel_unref(target);
195
		target = ast_channel_unref(target);
196
	}
196
	}
197

    
   
197

   
198
	ast_channel_iterator_destroy(iter);
198
	ast_channel_iterator_destroy(iter);
199

    
   
199

   
200
	if (target) {
200
	if (target) {
201
		res = ast_do_pickup(chan, target);
201
		res = ast_do_pickup(chan, target);

    
   
202
		ast_channel_unlock(target);

    
   
203
		target = ast_channel_unref(target);
202
	}
204
	}
203

    
   
205

   
204
	return res;
206
	return res;
205
}
207
}
206

    
   
208

   
[+20] [20] 19 lines
[+20] [+] static int find_by_mark(void *obj, void *arg, void *data, int flags)
226
static int pickup_by_mark(struct ast_channel *chan, const char *mark)
228
static int pickup_by_mark(struct ast_channel *chan, const char *mark)
227
{
229
{
228
	struct ast_channel *target;
230
	struct ast_channel *target;
229
	int res = -1;
231
	int res = -1;
230

    
   
232

   
231
	if ((target = ast_channel_callback(find_by_mark, NULL, (char *) mark, 0))) {
233
	if (!(target = ast_channel_callback(find_by_mark, NULL, (char *) mark, 0))) {

    
   
234
		return res;

    
   
235
	}

    
   
236

   
232
		ast_channel_lock(target);
237
	ast_channel_lock(target);
233
		if (!target->masq && can_pickup(target)) {
238
	if (can_pickup(target)) {
234
			res = ast_do_pickup(chan, target);
239
		res = ast_do_pickup(chan, target);
235
		} else {
240
	} else {
236
			ast_log(LOG_WARNING, "target has gone, or not ringing anymore for %s\n", chan->name);
241
		ast_log(LOG_WARNING, "target has gone, or not ringing anymore for %s\n", chan->name);

    
   
242
	}
237
			ast_channel_unlock(target);
243
	ast_channel_unlock(target);
238
			target = ast_channel_unref(target);
244
	target = ast_channel_unref(target);
239
		}
245
	
240
	}

   
241

    
   

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

    
   
248

   
245
static int find_channel_by_group(void *obj, void *arg, void *data, int flags)
249
static int find_channel_by_group(void *obj, void *arg, void *data, int flags)
246
{
250
{
247
	struct ast_channel *chan = obj;
251
	struct ast_channel *chan = obj;
248
	struct ast_channel *c = data;
252
	struct ast_channel *c = data;
249

    
   
253

   
250
	ast_channel_lock(chan);
254
	ast_channel_lock(chan);
251
	int i = (c != chan) &&
255
	int i = (c != chan) &&
252
		(chan->pickupgroup & c->callgroup) &&
256
		(chan->pickupgroup & c->callgroup) &&
253
		!c->masq && can_pickup(chan);
257
		can_pickup(chan);
254

    
   
258

   
255
	ast_channel_unlock(chan);
259
	ast_channel_unlock(chan);
256
	return i ? CMP_MATCH | CMP_STOP : 0;
260
	return i ? CMP_MATCH | CMP_STOP : 0;
257
}
261
}
258

    
   
262

   
259
static int pickup_by_group(struct ast_channel *chan)
263
static int pickup_by_group(struct ast_channel *chan)
260
{
264
{
261
	struct ast_channel *target;
265
	struct ast_channel *target;
262
	int res = -1;
266
	int res = -1;
263
	if ((target = ast_channel_callback(find_channel_by_group, NULL, chan, 0))) {
267

   

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

    
   
269
		return res;

    
   
270
	}

    
   
271
	
264
		ast_log(LOG_NOTICE, "%s, pickup attempt by %s\n", target->name, chan->name);
272
	ast_log(LOG_NOTICE, "%s, pickup attempt by %s\n", target->name, chan->name);
265
		ast_channel_lock(target);
273
	ast_channel_lock(target);
266
		if (!target->masq && can_pickup(target)) {
274
	if (can_pickup(target)) {
267
			res = ast_do_pickup(chan, target);
275
		res = ast_do_pickup(chan, target);
268
		} else {
276
	} else {
269
			ast_log(LOG_WARNING, "target has gone, or not ringing anymore for %s\n", chan->name);
277
		ast_log(LOG_WARNING, "target has gone, or not ringing anymore for %s\n", chan->name);

    
   
278
	}
270
			ast_channel_unlock(target);
279
	ast_channel_unlock(target);
271
			target = ast_channel_unref(target);
280
	target = ast_channel_unref(target);
272
		}
281
	
273
	}

   
274
	return res;
282
	return res;
275
}
283
}
276

    
   
284

   
277
/* application entry point for Pickup() */
285
/* application entry point for Pickup() */
278
static int pickup_exec(struct ast_channel *chan, const char *data)
286
static int pickup_exec(struct ast_channel *chan, const char *data)
[+20] [20] 47 lines
[+20] [+] static int pickup_by_part(struct ast_channel *chan, const char *part)
326
	struct ast_channel *target;
334
	struct ast_channel *target;
327
	int res = -1;
335
	int res = -1;
328

    
   
336

   
329
	if ((target = ast_channel_callback(find_by_part, NULL, (char *) part, 0))) {
337
	if ((target = ast_channel_callback(find_by_part, NULL, (char *) part, 0))) {
330
		ast_channel_lock(target);
338
		ast_channel_lock(target);
331
		if (!target->masq && can_pickup(target)) {
339
		if (can_pickup(target)) {
332
			res = ast_do_pickup(chan, target);
340
			res = ast_do_pickup(chan, target);
333
		} else {
341
		} else {
334
			ast_log(LOG_WARNING, "target has gone, or not ringing anymore for %s\n", chan->name);
342
			ast_log(LOG_WARNING, "target has gone, or not ringing anymore for %s\n", chan->name);

    
   
343
		}
335
			ast_channel_unlock(target);
344
		ast_channel_unlock(target);
336
			target = ast_channel_unref(target);
345
		target = ast_channel_unref(target);
337
		}
346
	}
338
	}

   
339

    
   
347

   
340
	return res;
348
	return res;
341
}
349
}
342

    
   
350

   
343
/* application entry point for PickupChan() */
351
/* application entry point for PickupChan() */
[+20] [20] 61 lines
trunk/main/features.c
Diff Revision 6 Diff Revision 7
 
  1. trunk/apps/app_directed_pickup.c: Loading...
  2. trunk/main/features.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.