~davewalker/ubuntu/maverick/asterisk/lp_705014

« back to all changes in this revision

Viewing changes to channels/chan_local.c

  • Committer: Bazaar Package Importer
  • Author(s): Kilian Krause
  • Date: 2005-03-09 22:09:05 UTC
  • mto: (1.2.1 upstream) (8.2.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20050309220905-9afy6hcpw96xbr6j
Tags: upstream-1.0.6
ImportĀ upstreamĀ versionĀ 1.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 */
13
13
 
14
14
#include <stdio.h>
15
 
#include <pthread.h>
16
15
#include <string.h>
17
16
#include <asterisk/lock.h>
18
17
#include <asterisk/channel.h>
49
48
static int capability = -1;
50
49
 
51
50
static int usecnt =0;
52
 
static ast_mutex_t usecnt_lock = AST_MUTEX_INITIALIZER;
 
51
AST_MUTEX_DEFINE_STATIC(usecnt_lock);
53
52
 
54
53
#define IS_OUTBOUND(a,b) (a == b->chan ? 1 : 0)
55
54
 
56
55
/* Protect the interface list (of sip_pvt's) */
57
 
static ast_mutex_t locallock = AST_MUTEX_INITIALIZER;
 
56
AST_MUTEX_DEFINE_STATIC(locallock);
58
57
 
59
58
static struct local_pvt {
60
59
        ast_mutex_t lock;                               /* Channel private lock */
87
86
                /* We had a glare on the hangup.  Forget all this business,
88
87
                return and destroy p.  */
89
88
                ast_mutex_unlock(&p->lock);
 
89
                ast_mutex_destroy(&p->lock);
90
90
                free(p);
91
91
                return -1;
92
92
        }
112
112
                ast_mutex_lock(&p->lock);
113
113
                goto retrylock;
114
114
        }
115
 
        ast_queue_frame(other, f, 0);
 
115
        ast_queue_frame(other, f);
116
116
        ast_mutex_unlock(&other->lock);
117
117
        p->glaredetect = 0;
118
118
        return 0;
121
121
static int local_answer(struct ast_channel *ast)
122
122
{
123
123
        struct local_pvt *p = ast->pvt->pvt;
124
 
        int isoutbound = IS_OUTBOUND(ast, p);
 
124
        int isoutbound;
125
125
        int res = -1;
126
126
        ast_mutex_lock(&p->lock);
 
127
        isoutbound = IS_OUTBOUND(ast, p);
127
128
        if (isoutbound) {
128
129
                /* Pass along answer since somebody answered us */
129
130
                struct ast_frame answer = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
174
175
{
175
176
        struct local_pvt *p = ast->pvt->pvt;
176
177
        int res = -1;
177
 
        int isoutbound = IS_OUTBOUND(ast, p);
 
178
        int isoutbound;
178
179
 
179
180
 
180
181
        /* Just queue for delivery to the other side */
181
182
        ast_mutex_lock(&p->lock);
 
183
        isoutbound = IS_OUTBOUND(ast, p);
182
184
        res = local_queue_frame(p, isoutbound, f, ast);
183
185
        check_bridge(p, isoutbound);
184
186
        ast_mutex_unlock(&p->lock);
207
209
        struct local_pvt *p = ast->pvt->pvt;
208
210
        int res = -1;
209
211
        struct ast_frame f = { AST_FRAME_CONTROL, };
210
 
        int isoutbound = IS_OUTBOUND(ast, p);
 
212
        int isoutbound;
211
213
        /* Queue up a frame representing the indication as a control frame */
212
214
        ast_mutex_lock(&p->lock);
 
215
        isoutbound = IS_OUTBOUND(ast, p);
213
216
        f.subclass = condition;
214
217
        res = local_queue_frame(p, isoutbound, &f, ast);
215
218
        ast_mutex_unlock(&p->lock);
221
224
        struct local_pvt *p = ast->pvt->pvt;
222
225
        int res = -1;
223
226
        struct ast_frame f = { AST_FRAME_DTMF, };
224
 
        int isoutbound = IS_OUTBOUND(ast, p);
 
227
        int isoutbound;
225
228
        ast_mutex_lock(&p->lock);
 
229
        isoutbound = IS_OUTBOUND(ast, p);
226
230
        f.subclass = digit;
227
231
        res = local_queue_frame(p, isoutbound, &f, ast);
228
232
        ast_mutex_unlock(&p->lock);
239
243
                p->chan->callerid = strdup(p->owner->callerid);
240
244
        else
241
245
                p->chan->callerid = NULL;
 
246
        if (p->owner->rdnis)
 
247
                p->chan->rdnis = strdup(p->owner->rdnis);
 
248
        else
 
249
                p->chan->rdnis = NULL;
242
250
        if (p->owner->ani)
243
251
                p->chan->ani = strdup(p->owner->ani);
244
252
        else
245
253
                p->chan->ani = NULL;
 
254
        strncpy(p->chan->language, p->owner->language, sizeof(p->chan->language) - 1);
 
255
        strncpy(p->chan->accountcode, p->owner->accountcode, sizeof(p->chan->accountcode) - 1);
 
256
        p->chan->cdrflags = p->owner->cdrflags;
 
257
        
246
258
        p->launchedpbx = 1;
247
259
        /* Start switch on sub channel */
248
260
        res = ast_pbx_start(p->chan);
262
274
                                prev->next = cur->next;
263
275
                        else
264
276
                                locals = cur->next;
 
277
                        ast_mutex_destroy(cur);
265
278
                        free(cur);
266
279
                        break;
267
280
                }
277
290
static int local_hangup(struct ast_channel *ast)
278
291
{
279
292
        struct local_pvt *p = ast->pvt->pvt;
280
 
        int isoutbound = IS_OUTBOUND(ast, p);
 
293
        int isoutbound;
281
294
        struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP };
282
295
        struct local_pvt *cur, *prev=NULL;
283
296
        struct ast_channel *ochan = NULL;
284
297
        int glaredetect;
285
298
        ast_mutex_lock(&p->lock);
 
299
        isoutbound = IS_OUTBOUND(ast, p);
286
300
        if (isoutbound) {
287
301
                p->chan = NULL;
288
302
                p->launchedpbx = 0;
290
304
                p->owner = NULL;
291
305
        ast->pvt->pvt = NULL;
292
306
        
 
307
        ast_mutex_lock(&usecnt_lock);
 
308
        usecnt--;
 
309
        ast_mutex_unlock(&usecnt_lock);
 
310
        
293
311
        if (!p->owner && !p->chan) {
294
312
                /* Okay, done with the private part now, too. */
295
313
                glaredetect = p->glaredetect;
314
332
                }
315
333
                ast_mutex_unlock(&locallock);
316
334
                /* And destroy */
317
 
                if (!glaredetect)
 
335
                if (!glaredetect) {
 
336
                        ast_mutex_destroy(&p->lock);
318
337
                        free(p);
 
338
                }
319
339
                return 0;
320
340
        }
321
341
        if (p->chan && !p->launchedpbx)
355
375
                        strncpy(tmp->context, "default", sizeof(tmp->context) - 1);
356
376
                tmp->reqformat = format;
357
377
                if (!ast_exists_extension(NULL, tmp->context, tmp->exten, 1, NULL)) {
358
 
                        ast_log(LOG_NOTICE, "No such extension/context %s@%s creating local channel\n", tmp->context, tmp->exten);
 
378
                        ast_log(LOG_NOTICE, "No such extension/context %s@%s creating local channel\n", tmp->exten, tmp->context);
 
379
                        ast_mutex_destroy(&tmp->lock);
359
380
                        free(tmp);
360
381
                        tmp = NULL;
361
382
                } else {
424
445
                p->chan = tmp2;
425
446
                ast_mutex_lock(&usecnt_lock);
426
447
                usecnt++;
 
448
                usecnt++;
427
449
                ast_mutex_unlock(&usecnt_lock);
428
450
                ast_update_use_count();
429
451
                strncpy(tmp->context, p->context, sizeof(tmp->context)-1);
451
473
{
452
474
        struct local_pvt *p;
453
475
 
454
 
        if (argc != 2)
 
476
        if (argc != 3)
455
477
                return RESULT_SHOWUSAGE;
456
478
        ast_mutex_lock(&locallock);
457
479
        p = locals;
468
490
}
469
491
 
470
492
static char show_locals_usage[] = 
471
 
"Usage: show locals\n"
472
 
"       Provides summary information on locals.\n";
 
493
"Usage: local show channels\n"
 
494
"       Provides summary information on local channels.\n";
473
495
 
474
496
static struct ast_cli_entry cli_show_locals = {
475
 
        { "show", "locals", NULL }, locals_show, 
 
497
        { "local", "show", "channels", NULL }, locals_show, 
476
498
        "Show status of local channels", show_locals_usage, NULL };
477
499
 
478
500
int load_module()