| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 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; |
| 29 |
static const int current_adsi_version = AST_ADSI_VERSION; |
| 30 |
AST_RWLOCK_DEFINE_STATIC(func_lock); |
| 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; |
| 35 |
ast_rwlock_rdlock(&func_lock); |
| 36 |
if (installed_funcs && installed_funcs->begin_download) { |
| 37 |
res = installed_funcs->begin_download(chan, service, fdn, sec, version); |
| 38 |
} |
| 39 |
ast_rwlock_unlock(&func_lock); |
| 40 |
return res; |
| 41 |
} |
| 42 |
|
| 43 |
int ast_adsi_end_download(struct ast_channel *chan) |
| 44 |
{ |
| 45 |
int res = 0; |
| 46 |
ast_rwlock_rdlock(&func_lock); |
| 47 |
if (installed_funcs && installed_funcs->end_download) { |
| 48 |
res = installed_funcs->end_download(chan); |
| 49 |
} |
| 50 |
ast_rwlock_unlock(&func_lock); |
| 51 |
return res; |
| 52 |
} |
| 53 |
|
| 54 |
int ast_adsi_channel_restore(struct ast_channel *chan) |
| 55 |
{ |
| 56 |
int res = 0; |
| 57 |
ast_rwlock_rdlock(&func_lock); |
| 58 |
if (installed_funcs && installed_funcs->channel_restore) { |
| 59 |
res = installed_funcs->channel_restore(chan); |
| 60 |
} |
| 61 |
ast_rwlock_unlock(&func_lock); |
| 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; |
| 68 |
ast_rwlock_rdlock(&func_lock); |
| 69 |
if (installed_funcs && installed_funcs->print) { |
| 70 |
res = installed_funcs->print(chan, lines, align, voice); |
| 71 |
} |
| 72 |
ast_rwlock_unlock(&func_lock); |
| 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; |
| 79 |
ast_rwlock_rdlock(&func_lock); |
| 80 |
if (installed_funcs && installed_funcs->load_session) { |
| 81 |
res = installed_funcs->load_session(chan, app, ver, data); |
| 82 |
} |
| 83 |
ast_rwlock_unlock(&func_lock); |
| 84 |
return res; |
| 85 |
} |
| 86 |
|
| 87 |
int ast_adsi_unload_session(struct ast_channel *chan) |
| 88 |
{ |
| 89 |
int res = 0; |
| 90 |
ast_rwlock_rdlock(&func_lock); |
| 91 |
if (installed_funcs && installed_funcs->unload_session) { |
| 92 |
res = installed_funcs->unload_session(chan); |
| 93 |
} |
| 94 |
ast_rwlock_unlock(&func_lock); |
| 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; |
| 101 |
ast_rwlock_rdlock(&func_lock); |
| 102 |
if (installed_funcs && installed_funcs->transmit_message) { |
| 103 |
res = installed_funcs->transmit_message(chan, msg, msglen, msgtype); |
| 104 |
} |
| 105 |
ast_rwlock_unlock(&func_lock); |
| 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; |
| 112 |
ast_rwlock_rdlock(&func_lock); |
| 113 |
if (installed_funcs && installed_funcs->transmit_message_full) { |
| 114 |
res = installed_funcs->transmit_message_full(chan, msg, msglen, msgtype, dowait); |
| 115 |
} |
| 116 |
ast_rwlock_unlock(&func_lock); |
| 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; |
| 123 |
ast_rwlock_rdlock(&func_lock); |
| 124 |
if (installed_funcs && installed_funcs->read_encoded_dtmf) { |
| 125 |
res = installed_funcs->read_encoded_dtmf(chan, buf, maxlen); |
| 126 |
} |
| 127 |
ast_rwlock_unlock(&func_lock); |
| 128 |
return res; |
| 129 |
} |
| 130 |
|
| 131 |
int ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver) |
| 132 |
{ |
| 133 |
int res = 0; |
| 134 |
ast_rwlock_rdlock(&func_lock); |
| 135 |
if (installed_funcs && installed_funcs->connect_session) { |
| 136 |
res = installed_funcs->connect_session(buf, fdn, ver); |
| 137 |
} |
| 138 |
ast_rwlock_unlock(&func_lock); |
| 139 |
return res; |
| 140 |
} |
| 141 |
|
| 142 |
int ast_adsi_query_cpeid(unsigned char *buf) |
| 143 |
{ |
| 144 |
int res = 0; |
| 145 |
ast_rwlock_rdlock(&func_lock); |
| 146 |
if (installed_funcs && installed_funcs->query_cpeid) { |
| 147 |
res = installed_funcs->query_cpeid(buf); |
| 148 |
} |
| 149 |
ast_rwlock_unlock(&func_lock); |
| 150 |
return res; |
| 151 |
} |
| 152 |
|
| 153 |
int ast_adsi_query_cpeinfo(unsigned char *buf) |
| 154 |
{ |
| 155 |
int res = 0; |
| 156 |
ast_rwlock_rdlock(&func_lock); |
| 157 |
if (installed_funcs && installed_funcs->query_cpeinfo) { |
| 158 |
res = installed_funcs->query_cpeinfo(buf); |
| 159 |
} |
| 160 |
ast_rwlock_unlock(&func_lock); |
| 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; |
| 167 |
ast_rwlock_rdlock(&func_lock); |
| 168 |
if (installed_funcs && installed_funcs->get_cpeid) { |
| 169 |
res = installed_funcs->get_cpeid(chan, cpeid, voice); |
| 170 |
} |
| 171 |
ast_rwlock_unlock(&func_lock); |
| 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; |
| 178 |
ast_rwlock_rdlock(&func_lock); |
| 179 |
if (installed_funcs && installed_funcs->get_cpeinfo) { |
| 180 |
res = installed_funcs->get_cpeinfo(chan, width, height, buttons, voice); |
| 181 |
} |
| 182 |
ast_rwlock_unlock(&func_lock); |
| 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; |
| 189 |
ast_rwlock_rdlock(&func_lock); |
| 190 |
if (installed_funcs && installed_funcs->download_connect) { |
| 191 |
res = installed_funcs->download_connect(buf, service, fdn, sec, ver); |
| 192 |
} |
| 193 |
ast_rwlock_unlock(&func_lock); |
| 194 |
return res; |
| 195 |
} |
| 196 |
|
| 197 |
int ast_adsi_disconnect_session(unsigned char *buf) |
| 198 |
{ |
| 199 |
int res = 0; |
| 200 |
ast_rwlock_rdlock(&func_lock); |
| 201 |
if (installed_funcs && installed_funcs->disconnect_session) { |
| 202 |
res = installed_funcs->disconnect_session(buf); |
| 203 |
} |
| 204 |
ast_rwlock_unlock(&func_lock); |
| 205 |
return res; |
| 206 |
} |
| 207 |
|
| 208 |
int ast_adsi_download_disconnect(unsigned char *buf) |
| 209 |
{ |
| 210 |
int res = 0; |
| 211 |
ast_rwlock_rdlock(&func_lock); |
| 212 |
if (installed_funcs && installed_funcs->download_disconnect) { |
| 213 |
res = installed_funcs->download_disconnect(buf); |
| 214 |
} |
| 215 |
ast_rwlock_unlock(&func_lock); |
| 216 |
return res; |
| 217 |
} |
| 218 |
|
| 219 |
int ast_adsi_data_mode(unsigned char *buf) |
| 220 |
{ |
| 221 |
int res = 0; |
| 222 |
ast_rwlock_rdlock(&func_lock); |
| 223 |
if (installed_funcs && installed_funcs->data_mode) { |
| 224 |
res = installed_funcs->data_mode(buf); |
| 225 |
} |
| 226 |
ast_rwlock_unlock(&func_lock); |
| 227 |
return res; |
| 228 |
} |
| 229 |
|
| 230 |
int ast_adsi_clear_soft_keys(unsigned char *buf) |
| 231 |
{ |
| 232 |
int res = 0; |
| 233 |
ast_rwlock_rdlock(&func_lock); |
| 234 |
if (installed_funcs && installed_funcs->clear_soft_keys) { |
| 235 |
res = installed_funcs->clear_soft_keys(buf); |
| 236 |
} |
| 237 |
ast_rwlock_unlock(&func_lock); |
| 238 |
return res; |
| 239 |
} |
| 240 |
|
| 241 |
int ast_adsi_clear_screen(unsigned char *buf) |
| 242 |
{ |
| 243 |
int res = 0; |
| 244 |
ast_rwlock_rdlock(&func_lock); |
| 245 |
if (installed_funcs && installed_funcs->clear_screen) { |
| 246 |
res = installed_funcs->clear_screen(buf); |
| 247 |
} |
| 248 |
ast_rwlock_unlock(&func_lock); |
| 249 |
return res; |
| 250 |
} |
| 251 |
|
| 252 |
int ast_adsi_voice_mode(unsigned char *buf, int when) |
| 253 |
{ |
| 254 |
int res = 0; |
| 255 |
ast_rwlock_rdlock(&func_lock); |
| 256 |
if (installed_funcs && installed_funcs->voice_mode) { |
| 257 |
res = installed_funcs->voice_mode(buf, when); |
| 258 |
} |
| 259 |
ast_rwlock_unlock(&func_lock); |
| 260 |
return res; |
| 261 |
} |
| 262 |
|
| 263 |
int ast_adsi_available(struct ast_channel *chan) |
| 264 |
{ |
| 265 |
int res = 0; |
| 266 |
ast_rwlock_rdlock(&func_lock); |
| 267 |
if (installed_funcs && installed_funcs->available) { |
| 268 |
res = installed_funcs->available(chan); |
| 269 |
} |
| 270 |
ast_rwlock_unlock(&func_lock); |
| 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; |
| 277 |
ast_rwlock_rdlock(&func_lock); |
| 278 |
if (installed_funcs && installed_funcs->display) { |
| 279 |
res = installed_funcs->display(buf, page, line, just, wrap, col1, col2); |
| 280 |
} |
| 281 |
ast_rwlock_unlock(&func_lock); |
| 282 |
return res; |
| 283 |
} |
| 284 |
|
| 285 |
int ast_adsi_set_line(unsigned char *buf, int page, int line) |
| 286 |
{ |
| 287 |
int res = 0; |
| 288 |
ast_rwlock_rdlock(&func_lock); |
| 289 |
if (installed_funcs && installed_funcs->set_line) { |
| 290 |
res = installed_funcs->set_line(buf, page, line); |
| 291 |
} |
| 292 |
ast_rwlock_unlock(&func_lock); |
| 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; |
| 299 |
ast_rwlock_rdlock(&func_lock); |
| 300 |
if (installed_funcs && installed_funcs->load_soft_key) { |
| 301 |
res = installed_funcs->load_soft_key(buf, key, llabel, slabel, ret, data); |
| 302 |
} |
| 303 |
ast_rwlock_unlock(&func_lock); |
| 304 |
return res; |
| 305 |
} |
| 306 |
|
| 307 |
int ast_adsi_set_keys(unsigned char *buf, unsigned char *keys) |
| 308 |
{ |
| 309 |
int res = 0; |
| 310 |
ast_rwlock_rdlock(&func_lock); |
| 311 |
if (installed_funcs && installed_funcs->set_keys) { |
| 312 |
res = installed_funcs->set_keys(buf, keys); |
| 313 |
} |
| 314 |
ast_rwlock_unlock(&func_lock); |
| 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; |
| 321 |
ast_rwlock_rdlock(&func_lock); |
| 322 |
if (installed_funcs && installed_funcs->input_control) { |
| 323 |
res = installed_funcs->input_control(buf, page, line, display, format, just); |
| 324 |
} |
| 325 |
ast_rwlock_unlock(&func_lock); |
| 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; |
| 332 |
ast_rwlock_rdlock(&func_lock); |
| 333 |
if (installed_funcs && installed_funcs->input_format) { |
| 334 |
res = installed_funcs->input_format(buf, num, dir, wrap, format1, format2); |
| 335 |
} |
| 336 |
ast_rwlock_unlock(&func_lock); |
| 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 |
|
| 348 |
ast_rwlock_wrlock(&func_lock); |
| 349 |
installed_funcs = funcs; |
| 350 |
ast_rwlock_unlock(&func_lock); |
| 351 |
} |