adsi.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2012, Digium, Inc.
  5. *
  6. * Mark Michelson <mmichelson@digium.com>
  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. /*! \file
  19. * \brief ADSI Support (built upon Caller*ID)
  20. */
  21. #include "asterisk.h"
  22. #include "asterisk/adsi.h"
  23. #include "asterisk/lock.h"
  24. static const struct adsi_funcs *installed_funcs;
  25. static const int current_adsi_version = AST_ADSI_VERSION;
  26. AST_RWLOCK_DEFINE_STATIC(func_lock);
  27. int ast_adsi_begin_download(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version)
  28. {
  29. int res = 0;
  30. ast_rwlock_rdlock(&func_lock);
  31. if (installed_funcs && installed_funcs->begin_download) {
  32. res = installed_funcs->begin_download(chan, service, fdn, sec, version);
  33. }
  34. ast_rwlock_unlock(&func_lock);
  35. return res;
  36. }
  37. int ast_adsi_end_download(struct ast_channel *chan)
  38. {
  39. int res = 0;
  40. ast_rwlock_rdlock(&func_lock);
  41. if (installed_funcs && installed_funcs->end_download) {
  42. res = installed_funcs->end_download(chan);
  43. }
  44. ast_rwlock_unlock(&func_lock);
  45. return res;
  46. }
  47. int ast_adsi_channel_restore(struct ast_channel *chan)
  48. {
  49. int res = 0;
  50. ast_rwlock_rdlock(&func_lock);
  51. if (installed_funcs && installed_funcs->channel_restore) {
  52. res = installed_funcs->channel_restore(chan);
  53. }
  54. ast_rwlock_unlock(&func_lock);
  55. return res;
  56. }
  57. int ast_adsi_print(struct ast_channel *chan, char **lines, int *align, int voice)
  58. {
  59. int res = 0;
  60. ast_rwlock_rdlock(&func_lock);
  61. if (installed_funcs && installed_funcs->print) {
  62. res = installed_funcs->print(chan, lines, align, voice);
  63. }
  64. ast_rwlock_unlock(&func_lock);
  65. return res;
  66. }
  67. int ast_adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data)
  68. {
  69. int res = 0;
  70. ast_rwlock_rdlock(&func_lock);
  71. if (installed_funcs && installed_funcs->load_session) {
  72. res = installed_funcs->load_session(chan, app, ver, data);
  73. }
  74. ast_rwlock_unlock(&func_lock);
  75. return res;
  76. }
  77. int ast_adsi_unload_session(struct ast_channel *chan)
  78. {
  79. int res = 0;
  80. ast_rwlock_rdlock(&func_lock);
  81. if (installed_funcs && installed_funcs->unload_session) {
  82. res = installed_funcs->unload_session(chan);
  83. }
  84. ast_rwlock_unlock(&func_lock);
  85. return res;
  86. }
  87. int ast_adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype)
  88. {
  89. int res = 0;
  90. ast_rwlock_rdlock(&func_lock);
  91. if (installed_funcs && installed_funcs->transmit_message) {
  92. res = installed_funcs->transmit_message(chan, msg, msglen, msgtype);
  93. }
  94. ast_rwlock_unlock(&func_lock);
  95. return res;
  96. }
  97. int ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait)
  98. {
  99. int res = 0;
  100. ast_rwlock_rdlock(&func_lock);
  101. if (installed_funcs && installed_funcs->transmit_message_full) {
  102. res = installed_funcs->transmit_message_full(chan, msg, msglen, msgtype, dowait);
  103. }
  104. ast_rwlock_unlock(&func_lock);
  105. return res;
  106. }
  107. int ast_adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *buf, int maxlen)
  108. {
  109. int res = 0;
  110. ast_rwlock_rdlock(&func_lock);
  111. if (installed_funcs && installed_funcs->read_encoded_dtmf) {
  112. res = installed_funcs->read_encoded_dtmf(chan, buf, maxlen);
  113. }
  114. ast_rwlock_unlock(&func_lock);
  115. return res;
  116. }
  117. int ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver)
  118. {
  119. int res = 0;
  120. ast_rwlock_rdlock(&func_lock);
  121. if (installed_funcs && installed_funcs->connect_session) {
  122. res = installed_funcs->connect_session(buf, fdn, ver);
  123. }
  124. ast_rwlock_unlock(&func_lock);
  125. return res;
  126. }
  127. int ast_adsi_query_cpeid(unsigned char *buf)
  128. {
  129. int res = 0;
  130. ast_rwlock_rdlock(&func_lock);
  131. if (installed_funcs && installed_funcs->query_cpeid) {
  132. res = installed_funcs->query_cpeid(buf);
  133. }
  134. ast_rwlock_unlock(&func_lock);
  135. return res;
  136. }
  137. int ast_adsi_query_cpeinfo(unsigned char *buf)
  138. {
  139. int res = 0;
  140. ast_rwlock_rdlock(&func_lock);
  141. if (installed_funcs && installed_funcs->query_cpeinfo) {
  142. res = installed_funcs->query_cpeinfo(buf);
  143. }
  144. ast_rwlock_unlock(&func_lock);
  145. return res;
  146. }
  147. int ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice)
  148. {
  149. int res = 0;
  150. ast_rwlock_rdlock(&func_lock);
  151. if (installed_funcs && installed_funcs->get_cpeid) {
  152. res = installed_funcs->get_cpeid(chan, cpeid, voice);
  153. }
  154. ast_rwlock_unlock(&func_lock);
  155. return res;
  156. }
  157. int ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
  158. {
  159. int res = 0;
  160. ast_rwlock_rdlock(&func_lock);
  161. if (installed_funcs && installed_funcs->get_cpeinfo) {
  162. res = installed_funcs->get_cpeinfo(chan, width, height, buttons, voice);
  163. }
  164. ast_rwlock_unlock(&func_lock);
  165. return res;
  166. }
  167. int ast_adsi_download_connect(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver)
  168. {
  169. int res = 0;
  170. ast_rwlock_rdlock(&func_lock);
  171. if (installed_funcs && installed_funcs->download_connect) {
  172. res = installed_funcs->download_connect(buf, service, fdn, sec, ver);
  173. }
  174. ast_rwlock_unlock(&func_lock);
  175. return res;
  176. }
  177. int ast_adsi_disconnect_session(unsigned char *buf)
  178. {
  179. int res = 0;
  180. ast_rwlock_rdlock(&func_lock);
  181. if (installed_funcs && installed_funcs->disconnect_session) {
  182. res = installed_funcs->disconnect_session(buf);
  183. }
  184. ast_rwlock_unlock(&func_lock);
  185. return res;
  186. }
  187. int ast_adsi_download_disconnect(unsigned char *buf)
  188. {
  189. int res = 0;
  190. ast_rwlock_rdlock(&func_lock);
  191. if (installed_funcs && installed_funcs->download_disconnect) {
  192. res = installed_funcs->download_disconnect(buf);
  193. }
  194. ast_rwlock_unlock(&func_lock);
  195. return res;
  196. }
  197. int ast_adsi_data_mode(unsigned char *buf)
  198. {
  199. int res = 0;
  200. ast_rwlock_rdlock(&func_lock);
  201. if (installed_funcs && installed_funcs->data_mode) {
  202. res = installed_funcs->data_mode(buf);
  203. }
  204. ast_rwlock_unlock(&func_lock);
  205. return res;
  206. }
  207. int ast_adsi_clear_soft_keys(unsigned char *buf)
  208. {
  209. int res = 0;
  210. ast_rwlock_rdlock(&func_lock);
  211. if (installed_funcs && installed_funcs->clear_soft_keys) {
  212. res = installed_funcs->clear_soft_keys(buf);
  213. }
  214. ast_rwlock_unlock(&func_lock);
  215. return res;
  216. }
  217. int ast_adsi_clear_screen(unsigned char *buf)
  218. {
  219. int res = 0;
  220. ast_rwlock_rdlock(&func_lock);
  221. if (installed_funcs && installed_funcs->clear_screen) {
  222. res = installed_funcs->clear_screen(buf);
  223. }
  224. ast_rwlock_unlock(&func_lock);
  225. return res;
  226. }
  227. int ast_adsi_voice_mode(unsigned char *buf, int when)
  228. {
  229. int res = 0;
  230. ast_rwlock_rdlock(&func_lock);
  231. if (installed_funcs && installed_funcs->voice_mode) {
  232. res = installed_funcs->voice_mode(buf, when);
  233. }
  234. ast_rwlock_unlock(&func_lock);
  235. return res;
  236. }
  237. int ast_adsi_available(struct ast_channel *chan)
  238. {
  239. int res = 0;
  240. ast_rwlock_rdlock(&func_lock);
  241. if (installed_funcs && installed_funcs->available) {
  242. res = installed_funcs->available(chan);
  243. }
  244. ast_rwlock_unlock(&func_lock);
  245. return res;
  246. }
  247. int ast_adsi_display(unsigned char *buf, int page, int line, int just, int wrap, char *col1, char *col2)
  248. {
  249. int res = 0;
  250. ast_rwlock_rdlock(&func_lock);
  251. if (installed_funcs && installed_funcs->display) {
  252. res = installed_funcs->display(buf, page, line, just, wrap, col1, col2);
  253. }
  254. ast_rwlock_unlock(&func_lock);
  255. return res;
  256. }
  257. int ast_adsi_set_line(unsigned char *buf, int page, int line)
  258. {
  259. int res = 0;
  260. ast_rwlock_rdlock(&func_lock);
  261. if (installed_funcs && installed_funcs->set_line) {
  262. res = installed_funcs->set_line(buf, page, line);
  263. }
  264. ast_rwlock_unlock(&func_lock);
  265. return res;
  266. }
  267. int ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data)
  268. {
  269. int res = 0;
  270. ast_rwlock_rdlock(&func_lock);
  271. if (installed_funcs && installed_funcs->load_soft_key) {
  272. res = installed_funcs->load_soft_key(buf, key, llabel, slabel, ret, data);
  273. }
  274. ast_rwlock_unlock(&func_lock);
  275. return res;
  276. }
  277. int ast_adsi_set_keys(unsigned char *buf, unsigned char *keys)
  278. {
  279. int res = 0;
  280. ast_rwlock_rdlock(&func_lock);
  281. if (installed_funcs && installed_funcs->set_keys) {
  282. res = installed_funcs->set_keys(buf, keys);
  283. }
  284. ast_rwlock_unlock(&func_lock);
  285. return res;
  286. }
  287. int ast_adsi_input_control(unsigned char *buf, int page, int line, int display, int format, int just)
  288. {
  289. int res = 0;
  290. ast_rwlock_rdlock(&func_lock);
  291. if (installed_funcs && installed_funcs->input_control) {
  292. res = installed_funcs->input_control(buf, page, line, display, format, just);
  293. }
  294. ast_rwlock_unlock(&func_lock);
  295. return res;
  296. }
  297. int ast_adsi_input_format(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2)
  298. {
  299. int res = 0;
  300. ast_rwlock_rdlock(&func_lock);
  301. if (installed_funcs && installed_funcs->input_format) {
  302. res = installed_funcs->input_format(buf, num, dir, wrap, format1, format2);
  303. }
  304. ast_rwlock_unlock(&func_lock);
  305. return res;
  306. }
  307. void ast_adsi_install_funcs(const struct adsi_funcs *funcs)
  308. {
  309. if (funcs && funcs->version < current_adsi_version) {
  310. ast_log(LOG_WARNING, "Cannot install ADSI function pointers due to version mismatch."
  311. "Ours: %d, Theirs: %u\n", current_adsi_version, funcs->version);
  312. return;
  313. }
  314. ast_rwlock_wrlock(&func_lock);
  315. installed_funcs = funcs;
  316. ast_rwlock_unlock(&func_lock);
  317. }