~singpolyma/asterisk

ref: 51af79b42e4ae7d1831603633d73bf0df179720e asterisk/main/adsi.c -rw-r--r-- 9.2 KiB
51af79b4Christopher Vollick Content Created By Initiator 2: Electric Boogaloo 10 months ago
                                                                                
130ba7ae Bernhard Schmidt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/*
 * Asterisk -- An open source telephony toolkit.
 *
 * Copyright (C) 2012, Digium, Inc.
 *
 * Mark Michelson <mmichelson@digium.com>
 *
 * See http://www.asterisk.org for more information about
 * the Asterisk project. Please do not directly contact
 * any of the maintainers of this project for assistance;
 * the project provides a web site, mailing lists and IRC
 * channels for your use.
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License Version 2. See the LICENSE file
 * at the top of the source tree.
 */

/*! \file
 * \brief ADSI Support (built upon Caller*ID)
 */

#include "asterisk.h"

#include "asterisk/adsi.h"
#include "asterisk/lock.h"

static const struct adsi_funcs *installed_funcs;
static const int current_adsi_version = AST_ADSI_VERSION;
AST_RWLOCK_DEFINE_STATIC(func_lock);

int ast_adsi_begin_download(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->begin_download) {
		res = installed_funcs->begin_download(chan, service, fdn, sec, version);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_end_download(struct ast_channel *chan)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->end_download) {
		res = installed_funcs->end_download(chan);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_channel_restore(struct ast_channel *chan)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->channel_restore) {
		res = installed_funcs->channel_restore(chan);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_print(struct ast_channel *chan, char **lines, int *align, int voice)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->print) {
		res = installed_funcs->print(chan, lines, align, voice);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->load_session) {
		res = installed_funcs->load_session(chan, app, ver, data);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_unload_session(struct ast_channel *chan)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->unload_session) {
		res = installed_funcs->unload_session(chan);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->transmit_message) {
		res = installed_funcs->transmit_message(chan, msg, msglen, msgtype);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->transmit_message_full) {
		res = installed_funcs->transmit_message_full(chan, msg, msglen, msgtype, dowait);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *buf, int maxlen)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->read_encoded_dtmf) {
		res = installed_funcs->read_encoded_dtmf(chan, buf, maxlen);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->connect_session) {
		res = installed_funcs->connect_session(buf, fdn, ver);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_query_cpeid(unsigned char *buf)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->query_cpeid) {
		res = installed_funcs->query_cpeid(buf);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_query_cpeinfo(unsigned char *buf)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->query_cpeinfo) {
		res = installed_funcs->query_cpeinfo(buf);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->get_cpeid) {
		res = installed_funcs->get_cpeid(chan, cpeid, voice);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->get_cpeinfo) {
		res = installed_funcs->get_cpeinfo(chan, width, height, buttons, voice);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_download_connect(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->download_connect) {
		res = installed_funcs->download_connect(buf, service, fdn, sec, ver);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_disconnect_session(unsigned char *buf)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->disconnect_session) {
		res = installed_funcs->disconnect_session(buf);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_download_disconnect(unsigned char *buf)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->download_disconnect) {
		res = installed_funcs->download_disconnect(buf);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_data_mode(unsigned char *buf)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->data_mode) {
		res = installed_funcs->data_mode(buf);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_clear_soft_keys(unsigned char *buf)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->clear_soft_keys) {
		res = installed_funcs->clear_soft_keys(buf);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_clear_screen(unsigned char *buf)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->clear_screen) {
		res = installed_funcs->clear_screen(buf);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_voice_mode(unsigned char *buf, int when)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->voice_mode) {
		res = installed_funcs->voice_mode(buf, when);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_available(struct ast_channel *chan)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->available) {
		res = installed_funcs->available(chan);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_display(unsigned char *buf, int page, int line, int just, int wrap, char *col1, char *col2)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->display) {
		res = installed_funcs->display(buf, page, line, just, wrap, col1, col2);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_set_line(unsigned char *buf, int page, int line)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->set_line) {
		res = installed_funcs->set_line(buf, page, line);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->load_soft_key) {
		res = installed_funcs->load_soft_key(buf, key, llabel, slabel, ret, data);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_set_keys(unsigned char *buf, unsigned char *keys)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->set_keys) {
		res = installed_funcs->set_keys(buf, keys);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_input_control(unsigned char *buf, int page, int line, int display, int format, int just)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->input_control) {
		res = installed_funcs->input_control(buf, page, line, display, format, just);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

int ast_adsi_input_format(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2)
{
	int res = 0;
	ast_rwlock_rdlock(&func_lock);
	if (installed_funcs && installed_funcs->input_format) {
		res = installed_funcs->input_format(buf, num, dir, wrap, format1, format2);
	}
	ast_rwlock_unlock(&func_lock);
	return res;
}

void ast_adsi_install_funcs(const struct adsi_funcs *funcs)
{
	if (funcs && funcs->version < current_adsi_version) {
		ast_log(LOG_WARNING, "Cannot install ADSI function pointers due to version mismatch."
				"Ours: %d, Theirs: %u\n", current_adsi_version, funcs->version);
		return;
	}

	ast_rwlock_wrlock(&func_lock);
	installed_funcs = funcs;
	ast_rwlock_unlock(&func_lock);
}