Asterisk - The Open Source Telephony Project  18.5.0
adsi.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2012, Digium, Inc.
5  *
6  * Mark Michelson <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  * \brief ADSI Support (built upon Caller*ID)
21  */
22 
23 #include "asterisk.h"
24 
25 #include "asterisk/adsi.h"
26 #include "asterisk/lock.h"
27 
28 static const struct adsi_funcs *installed_funcs;
31 
32 int ast_adsi_begin_download(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version)
33 {
34  int res = 0;
36  if (installed_funcs && installed_funcs->begin_download) {
37  res = installed_funcs->begin_download(chan, service, fdn, sec, version);
38  }
40  return res;
41 }
42 
44 {
45  int res = 0;
47  if (installed_funcs && installed_funcs->end_download) {
48  res = installed_funcs->end_download(chan);
49  }
51  return res;
52 }
53 
55 {
56  int res = 0;
58  if (installed_funcs && installed_funcs->channel_restore) {
59  res = installed_funcs->channel_restore(chan);
60  }
62  return res;
63 }
64 
65 int ast_adsi_print(struct ast_channel *chan, char **lines, int *align, int voice)
66 {
67  int res = 0;
69  if (installed_funcs && installed_funcs->print) {
70  res = installed_funcs->print(chan, lines, align, voice);
71  }
73  return res;
74 }
75 
76 int ast_adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data)
77 {
78  int res = 0;
80  if (installed_funcs && installed_funcs->load_session) {
81  res = installed_funcs->load_session(chan, app, ver, data);
82  }
84  return res;
85 }
86 
88 {
89  int res = 0;
91  if (installed_funcs && installed_funcs->unload_session) {
92  res = installed_funcs->unload_session(chan);
93  }
95  return res;
96 }
97 
98 int ast_adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype)
99 {
100  int res = 0;
102  if (installed_funcs && installed_funcs->transmit_message) {
103  res = installed_funcs->transmit_message(chan, msg, msglen, msgtype);
104  }
106  return res;
107 }
108 
109 int ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait)
110 {
111  int res = 0;
113  if (installed_funcs && installed_funcs->transmit_message_full) {
114  res = installed_funcs->transmit_message_full(chan, msg, msglen, msgtype, dowait);
115  }
117  return res;
118 }
119 
120 int ast_adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *buf, int maxlen)
121 {
122  int res = 0;
124  if (installed_funcs && installed_funcs->read_encoded_dtmf) {
125  res = installed_funcs->read_encoded_dtmf(chan, buf, maxlen);
126  }
128  return res;
129 }
130 
131 int ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver)
132 {
133  int res = 0;
135  if (installed_funcs && installed_funcs->connect_session) {
136  res = installed_funcs->connect_session(buf, fdn, ver);
137  }
139  return res;
140 }
141 
142 int ast_adsi_query_cpeid(unsigned char *buf)
143 {
144  int res = 0;
146  if (installed_funcs && installed_funcs->query_cpeid) {
147  res = installed_funcs->query_cpeid(buf);
148  }
150  return res;
151 }
152 
153 int ast_adsi_query_cpeinfo(unsigned char *buf)
154 {
155  int res = 0;
157  if (installed_funcs && installed_funcs->query_cpeinfo) {
158  res = installed_funcs->query_cpeinfo(buf);
159  }
161  return res;
162 }
163 
164 int ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice)
165 {
166  int res = 0;
168  if (installed_funcs && installed_funcs->get_cpeid) {
169  res = installed_funcs->get_cpeid(chan, cpeid, voice);
170  }
172  return res;
173 }
174 
175 int ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
176 {
177  int res = 0;
179  if (installed_funcs && installed_funcs->get_cpeinfo) {
180  res = installed_funcs->get_cpeinfo(chan, width, height, buttons, voice);
181  }
183  return res;
184 }
185 
186 int ast_adsi_download_connect(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver)
187 {
188  int res = 0;
190  if (installed_funcs && installed_funcs->download_connect) {
191  res = installed_funcs->download_connect(buf, service, fdn, sec, ver);
192  }
194  return res;
195 }
196 
197 int ast_adsi_disconnect_session(unsigned char *buf)
198 {
199  int res = 0;
201  if (installed_funcs && installed_funcs->disconnect_session) {
202  res = installed_funcs->disconnect_session(buf);
203  }
205  return res;
206 }
207 
209 {
210  int res = 0;
212  if (installed_funcs && installed_funcs->download_disconnect) {
213  res = installed_funcs->download_disconnect(buf);
214  }
216  return res;
217 }
218 
219 int ast_adsi_data_mode(unsigned char *buf)
220 {
221  int res = 0;
223  if (installed_funcs && installed_funcs->data_mode) {
224  res = installed_funcs->data_mode(buf);
225  }
227  return res;
228 }
229 
230 int ast_adsi_clear_soft_keys(unsigned char *buf)
231 {
232  int res = 0;
234  if (installed_funcs && installed_funcs->clear_soft_keys) {
235  res = installed_funcs->clear_soft_keys(buf);
236  }
238  return res;
239 }
240 
241 int ast_adsi_clear_screen(unsigned char *buf)
242 {
243  int res = 0;
245  if (installed_funcs && installed_funcs->clear_screen) {
246  res = installed_funcs->clear_screen(buf);
247  }
249  return res;
250 }
251 
252 int ast_adsi_voice_mode(unsigned char *buf, int when)
253 {
254  int res = 0;
256  if (installed_funcs && installed_funcs->voice_mode) {
257  res = installed_funcs->voice_mode(buf, when);
258  }
260  return res;
261 }
262 
264 {
265  int res = 0;
267  if (installed_funcs && installed_funcs->available) {
268  res = installed_funcs->available(chan);
269  }
271  return res;
272 }
273 
274 int ast_adsi_display(unsigned char *buf, int page, int line, int just, int wrap, char *col1, char *col2)
275 {
276  int res = 0;
278  if (installed_funcs && installed_funcs->display) {
279  res = installed_funcs->display(buf, page, line, just, wrap, col1, col2);
280  }
282  return res;
283 }
284 
285 int ast_adsi_set_line(unsigned char *buf, int page, int line)
286 {
287  int res = 0;
289  if (installed_funcs && installed_funcs->set_line) {
290  res = installed_funcs->set_line(buf, page, line);
291  }
293  return res;
294 }
295 
296 int ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data)
297 {
298  int res = 0;
300  if (installed_funcs && installed_funcs->load_soft_key) {
301  res = installed_funcs->load_soft_key(buf, key, llabel, slabel, ret, data);
302  }
304  return res;
305 }
306 
307 int ast_adsi_set_keys(unsigned char *buf, unsigned char *keys)
308 {
309  int res = 0;
311  if (installed_funcs && installed_funcs->set_keys) {
312  res = installed_funcs->set_keys(buf, keys);
313  }
315  return res;
316 }
317 
318 int ast_adsi_input_control(unsigned char *buf, int page, int line, int display, int format, int just)
319 {
320  int res = 0;
322  if (installed_funcs && installed_funcs->input_control) {
323  res = installed_funcs->input_control(buf, page, line, display, format, just);
324  }
326  return res;
327 }
328 
329 int ast_adsi_input_format(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2)
330 {
331  int res = 0;
333  if (installed_funcs && installed_funcs->input_format) {
334  res = installed_funcs->input_format(buf, num, dir, wrap, format1, format2);
335  }
337  return res;
338 }
339 
340 void ast_adsi_install_funcs(const struct adsi_funcs *funcs)
341 {
342  if (funcs && funcs->version < current_adsi_version) {
343  ast_log(LOG_WARNING, "Cannot install ADSI function pointers due to version mismatch."
344  "Ours: %d, Theirs: %u\n", current_adsi_version, funcs->version);
345  return;
346  }
347 
349  installed_funcs = funcs;
351 }
int(* voice_mode)(unsigned char *buf, int when)
Definition: adsi.h:367
#define ast_rwlock_rdlock(a)
Definition: lock.h:233
Main Channel structure associated with a channel.
int(* available)(struct ast_channel *chan)
Definition: adsi.h:368
Asterisk locking-related definitions:
int(* unload_session)(struct ast_channel *chan)
Definition: adsi.h:352
Asterisk main include file. File version handling, generic pbx functions.
void ast_adsi_install_funcs(const struct adsi_funcs *funcs)
Definition: adsi.c:340
#define AST_RWLOCK_DEFINE_STATIC(rwlock)
Definition: lock.h:541
int(* query_cpeinfo)(unsigned char *buf)
Definition: adsi.h:358
int(* download_connect)(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver)
Definition: adsi.h:361
int ast_adsi_print(struct ast_channel *chan, char **lines, int *align, int voice)
Display some stuff on the screen.
Definition: adsi.c:65
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
int(* input_format)(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2)
Definition: adsi.h:374
static const int current_adsi_version
Definition: adsi.c:29
#define LOG_WARNING
Definition: logger.h:274
int(* transmit_message)(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype)
Definition: adsi.h:353
int ast_adsi_end_download(struct ast_channel *chan)
Definition: adsi.c:43
int(* end_download)(struct ast_channel *chan)
Definition: adsi.h:348
int ast_adsi_unload_session(struct ast_channel *chan)
Definition: adsi.c:87
int ast_adsi_download_disconnect(unsigned char *buf)
Disconnects (and hopefully saves) a downloaded script.
Definition: adsi.c:208
enum ast_cc_service_type service
Definition: chan_sip.c:949
int(* data_mode)(unsigned char *buf)
Definition: adsi.h:364
int(* display)(unsigned char *buf, int page, int line, int just, int wrap, char *col1, char *col2)
Definition: adsi.h:369
int ast_adsi_query_cpeid(unsigned char *buf)
Definition: adsi.c:142
int ast_adsi_set_line(unsigned char *buf, int page, int line)
Sets the current line and page.
Definition: adsi.c:285
ADSI Support (built upon Caller*ID)
#define ast_rwlock_unlock(a)
Definition: lock.h:232
int(* disconnect_session)(unsigned char *buf)
Definition: adsi.h:362
int ast_adsi_query_cpeinfo(unsigned char *buf)
Definition: adsi.c:153
int ast_adsi_available(struct ast_channel *chan)
Returns non-zero if Channel does or might support ADSI.
Definition: adsi.c:263
int ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice)
Definition: adsi.c:164
static ast_rwlock_t func_lock
Definition: adsi.c:30
int(* print)(struct ast_channel *chan, char **lines, int *align, int voice)
Definition: adsi.h:350
#define AST_ADSI_VERSION
Definition: adsi.h:123
int ast_adsi_disconnect_session(unsigned char *buf)
Disconnects a running session.
Definition: adsi.c:197
#define ast_log
Definition: astobj2.c:42
int ast_adsi_display(unsigned char *buf, int page, int line, int just, int wrap, char *col1, char *col2)
Loads a line of info into the display.
Definition: adsi.c:274
int ast_adsi_input_format(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2)
Set input format.
Definition: adsi.c:329
int ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
Definition: adsi.c:175
int(* begin_download)(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version)
Definition: adsi.h:347
int(* channel_restore)(struct ast_channel *chan)
Definition: adsi.h:349
int(* query_cpeid)(unsigned char *buf)
Definition: adsi.h:357
int ast_adsi_voice_mode(unsigned char *buf, int when)
Puts CPE in voice mode.
Definition: adsi.c:252
int ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver)
Connects an ADSI Display Session.
Definition: adsi.c:131
int ast_adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype)
Definition: adsi.c:98
int(* input_control)(unsigned char *buf, int page, int line, int display, int format, int just)
Definition: adsi.h:373
int(* get_cpeid)(struct ast_channel *chan, unsigned char *cpeid, int voice)
Definition: adsi.h:359
int ast_adsi_input_control(unsigned char *buf, int page, int line, int display, int format, int just)
Set input information.
Definition: adsi.c:318
unsigned int version
Definition: adsi.h:346
int(* get_cpeinfo)(struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
Definition: adsi.h:360
static char version[AST_MAX_EXTENSION]
Definition: chan_ooh323.c:391
int(* clear_screen)(unsigned char *buf)
Definition: adsi.h:366
int ast_adsi_data_mode(unsigned char *buf)
Puts CPE in data mode.
Definition: adsi.c:219
int ast_adsi_channel_restore(struct ast_channel *chan)
Definition: adsi.c:54
int(* clear_soft_keys)(unsigned char *buf)
Definition: adsi.h:365
int ast_adsi_download_connect(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver)
Begin an ADSI script download.
Definition: adsi.c:186
static const struct adsi_funcs * installed_funcs
Definition: adsi.c:28
int ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data)
Creates "load soft key" parameters.
Definition: adsi.c:296
#define ast_rwlock_wrlock(a)
Definition: lock.h:234
int ast_adsi_clear_soft_keys(unsigned char *buf)
Definition: adsi.c:230
int(* connect_session)(unsigned char *buf, unsigned char *fdn, int ver)
Definition: adsi.h:356
int(* set_keys)(unsigned char *buf, unsigned char *keys)
Definition: adsi.h:372
int ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait)
Definition: adsi.c:109
int ast_adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data)
Check if scripts for a given app are already loaded. Version may be -1, if any version is okay...
Definition: adsi.c:76
int ast_adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *buf, int maxlen)
Definition: adsi.c:120
int(* set_line)(unsigned char *buf, int page, int line)
Definition: adsi.h:370
int(* download_disconnect)(unsigned char *buf)
Definition: adsi.h:363
int(* load_session)(struct ast_channel *chan, unsigned char *app, int ver, int data)
Definition: adsi.h:351
int(* load_soft_key)(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data)
Definition: adsi.h:371
int(* read_encoded_dtmf)(struct ast_channel *chan, unsigned char *buf, int maxlen)
Definition: adsi.h:355
int(* transmit_message_full)(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait)
Definition: adsi.h:354
static const char app[]
Definition: app_mysql.c:62
int ast_adsi_begin_download(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version)
Definition: adsi.c:32
int ast_adsi_clear_screen(unsigned char *buf)
Definition: adsi.c:241
static snd_pcm_format_t format
Definition: chan_alsa.c:102
int ast_adsi_set_keys(unsigned char *buf, unsigned char *keys)
Set which soft keys should be displayed.
Definition: adsi.c:307