~ubuntu-branches/debian/squeeze/asterisk-chan-capi/squeeze

« back to all changes in this revision

Viewing changes to app_capiRETRIEVE.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings
  • Date: 2007-03-07 01:58:53 UTC
  • mfrom: (3.1.3 feisty)
  • Revision ID: james.westby@ubuntu.com-20070307015853-yw0ov095k4fx2rza
Tags: 0.7.1-1.1
* Non-maintainer upload
* Protect calls to capi_cmsg2str and use of its buffer with a mutex.
  (Closes: #411293)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * (CAPI*)
3
 
 *
4
 
 * An implementation of Common ISDN API 2.0 for Asterisk
5
 
 *
6
 
 * RETRIEVE
7
 
 *
8
 
 * Copyright (C) 2002, Junghanns.NET GmbH
9
 
 *
10
 
 * Klaus-Peter Junghanns <kapejod@ns1.jnetdns.de>
11
 
 *
12
 
 * This program is free software and may be modified and 
13
 
 * distributed under the terms of the GNU Public License.
14
 
 */
15
 
 
16
 
#include <asterisk/file.h>
17
 
#include <asterisk/logger.h>
18
 
#include <asterisk/channel.h>
19
 
#include <asterisk/channel_pvt.h>
20
 
#include <asterisk/pbx.h>
21
 
#include <asterisk/module.h>
22
 
#include <stdlib.h>
23
 
#include <unistd.h>
24
 
#include <string.h>
25
 
#include <stdlib.h>
26
 
 
27
 
#include <pthread.h>
28
 
#include <linux/capi.h>
29
 
#include <capi20.h>
30
 
#include "chan_capi_pvt.h"
31
 
#include "chan_capi_app.h"
32
 
 
33
 
 
34
 
 
35
 
static char *tdesc = "(CAPI*) RETRIEVE";
36
 
static char *app = "capiRETRIEVE";
37
 
static char *synopsis = "retrieve the call that is on hold";
38
 
 
39
 
STANDARD_LOCAL_USER;
40
 
 
41
 
LOCAL_USER_DECL;
42
 
 
43
 
static int capiRETRIEVE_exec(struct ast_channel *chan, void *data)
44
 
{
45
 
    struct ast_capi_pvt *i = chan->pvt->pvt;
46
 
    MESSAGE_EXCHANGE_ERROR Info;
47
 
    _cmsg       CMSG/*,*CMSG2*/;
48
 
    char        fac[4];
49
 
    int res=0;
50
 
    struct localuser *u;
51
 
 
52
 
    LOCAL_USER_ADD(u);
53
 
    /* Do our thing here */
54
 
 
55
 
//    if ((i->state != CAPI_STATE_ONHOLD) || (i->onholdPLCI <= 0)) {
56
 
    if (i->onholdPLCI <= 0) {
57
 
        ast_log(LOG_WARNING, "no call on hold to retrieve!\n");
58
 
        return -1;
59
 
    }
60
 
 
61
 
    fac[0] = 3; // len
62
 
    fac[1] = 0x03; // retrieve
63
 
    fac[2] = 0x00;
64
 
    fac[3] = 0; 
65
 
 
66
 
    FACILITY_REQ_HEADER(&CMSG,ast_capi_ApplID,ast_capi_MessageNumber++,0);
67
 
    FACILITY_REQ_PLCI(&CMSG) = i->onholdPLCI;
68
 
    FACILITY_REQ_FACILITYSELECTOR(&CMSG) = 0x0003; // sservices
69
 
    FACILITY_REQ_FACILITYREQUESTPARAMETER(&CMSG) = (char *)&fac;
70
 
 
71
 
    if ((Info = _capi_put_cmsg(&CMSG)) != 0) {
72
 
        ast_log(LOG_ERROR,"Error sending FACILITY_REQ\n");
73
 
        return Info;
74
 
    } else {
75
 
        i->state = CAPI_STATE_RETRIEVING;
76
 
        ast_log(LOG_NOTICE,"sent FACILITY_REQ PLCI = %#x\n",i->onholdPLCI);
77
 
    }
78
 
 
79
 
    while (i->state == CAPI_STATE_RETRIEVING) {
80
 
        usleep(10000);
81
 
    }
82
 
 
83
 
 
84
 
    // send a CONNECT_B3_REQ
85
 
    memset(&CMSG,0,sizeof(_cmsg));
86
 
    CONNECT_B3_REQ_HEADER(&CMSG, ast_capi_ApplID, ast_capi_MessageNumber++,0);
87
 
    CONNECT_B3_REQ_PLCI(&CMSG) = i->PLCI;
88
 
    if ((Info = _capi_put_cmsg(&CMSG)) != 0) {
89
 
        ast_log(LOG_ERROR,"error sending CONNECT_B3_REQ (error=%#x)\n",Info);
90
 
    } else {
91
 
        ast_log(LOG_NOTICE,"sent CONNECT_B3_REQ (PLCI=%#x)\n",i->PLCI);
92
 
    }
93
 
 
94
 
    while (i->state == CAPI_STATE_CONNECTED) {
95
 
        usleep(10000);
96
 
    }
97
 
    ast_log(LOG_NOTICE,"retrieved PLCI = %#x\n",i->PLCI);
98
 
    
99
 
    LOCAL_USER_REMOVE(u);
100
 
    return res;
101
 
}
102
 
 
103
 
int unload_module(void)
104
 
{
105
 
        STANDARD_HANGUP_LOCALUSERS;
106
 
        return ast_unregister_application(app);
107
 
}
108
 
 
109
 
int load_module(void)
110
 
{
111
 
        return ast_register_application(app, capiRETRIEVE_exec,synopsis,tdesc);
112
 
}
113
 
 
114
 
char *description(void)
115
 
{
116
 
        return tdesc;
117
 
}
118
 
 
119
 
int usecount(void)
120
 
{
121
 
        int res;
122
 
        STANDARD_USECOUNT(res);
123
 
        return res;
124
 
}
125
 
 
126
 
char *key()
127
 
{
128
 
        return ASTERISK_GPL_KEY;
129
 
}