From 0a27d8bfe5fa36d8cb600b5b520f9b5c7fbf0ed6 Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Mon, 21 Aug 2006 02:11:39 +0000 Subject: merge new_loader_completion branch, including (at least): - restructured build tree and makefiles to eliminate recursion problems - support for embedded modules - support for static builds - simpler cross-compilation support - simpler module/loader interface (no exported symbols) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@40722 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- .cleancount | 2 +- Makefile | 390 +-- Makefile.moddir_rules | 75 +- Makefile.rules | 23 +- abstract_jb.c | 784 ----- acinclude.m4 | 13 + acl.c | 425 --- aescrypt.c | 317 -- aeskey.c | 469 --- aesopt.h | 1029 ------ aestab.c | 232 -- alaw.c | 101 - app.c | 1328 -------- apps/Makefile | 21 +- apps/app_adsiprog.c | 25 +- apps/app_alarmreceiver.c | 31 +- apps/app_amd.c | 31 +- apps/app_authenticate.c | 26 +- apps/app_cdr.c | 25 +- apps/app_chanisavail.c | 30 +- apps/app_channelredirect.c | 26 +- apps/app_chanspy.c | 37 +- apps/app_controlplayback.c | 25 +- apps/app_db.c | 34 +- apps/app_dial.c | 31 +- apps/app_dictate.c | 26 +- apps/app_directed_pickup.c | 24 +- apps/app_directory.c | 26 +- apps/app_disa.c | 37 +- apps/app_dumpchan.c | 25 +- apps/app_echo.c | 27 +- apps/app_exec.c | 46 +- apps/app_externalivr.c | 27 +- apps/app_festival.c | 36 +- apps/app_flash.c | 25 +- apps/app_followme.c | 47 +- apps/app_forkcdr.c | 25 +- apps/app_getcpeid.c | 25 +- apps/app_hasnewvoicemail.c | 31 +- apps/app_ices.c | 31 +- apps/app_image.c | 29 +- apps/app_ivrdemo.c | 26 +- apps/app_lookupblacklist.c | 27 +- apps/app_lookupcidname.c | 49 +- apps/app_macro.c | 45 +- apps/app_meetme.c | 63 +- apps/app_milliwatt.c | 27 +- apps/app_mixmonitor.c | 34 +- apps/app_morsecode.c | 29 +- apps/app_mp3.c | 31 +- apps/app_nbscat.c | 31 +- apps/app_osplookup.c | 93 +- apps/app_page.c | 27 +- apps/app_parkandannounce.c | 39 +- apps/app_playback.c | 35 +- apps/app_privacy.c | 36 +- apps/app_queue.c | 97 +- apps/app_random.c | 27 +- apps/app_read.c | 31 +- apps/app_readfile.c | 29 +- apps/app_realtime.c | 32 +- apps/app_record.c | 33 +- apps/app_rpt.c | 76 +- apps/app_sayunixtime.c | 27 +- apps/app_senddtmf.c | 27 +- apps/app_sendtext.c | 29 +- apps/app_setcallerid.c | 37 +- apps/app_setcdruserfield.c | 33 +- apps/app_settransfercapability.c | 27 +- apps/app_skel.c | 24 +- apps/app_sms.c | 39 +- apps/app_softhangup.c | 27 +- apps/app_speech_utils.c | 104 +- apps/app_stack.c | 33 +- apps/app_system.c | 27 +- apps/app_talkdetect.c | 27 +- apps/app_test.c | 34 +- apps/app_transfer.c | 31 +- apps/app_url.c | 31 +- apps/app_userevent.c | 28 +- apps/app_verbose.c | 36 +- apps/app_voicemail.c | 70 +- apps/app_waitforring.c | 27 +- apps/app_waitforsilence.c | 26 +- apps/app_while.c | 28 +- apps/app_zapateller.c | 29 +- apps/app_zapbarge.c | 30 +- apps/app_zapras.c | 27 +- apps/app_zapscan.c | 27 +- ast_expr2.c | 2871 ---------------- ast_expr2.fl | 405 --- ast_expr2.h | 120 - ast_expr2.y | 1045 ------ ast_expr2f.c | 3299 ------------------- asterisk.8 | 193 -- asterisk.c | 2724 ---------------- asterisk.sgml | 364 --- astmm.c | 443 --- autoservice.c | 154 - build_tools/cflags.xml | 5 + build_tools/embed_modules.xml | 18 + build_tools/menuselect-deps.in | 3 + build_tools/prep_moduledeps | 35 +- buildinfo.c | 33 - callerid.c | 1096 ------- cdr.c | 1175 ------- cdr/Makefile | 9 +- cdr/cdr_csv.c | 27 +- cdr/cdr_custom.c | 26 +- cdr/cdr_manager.c | 25 +- cdr/cdr_odbc.c | 25 +- cdr/cdr_pgsql.c | 25 +- cdr/cdr_radius.c | 16 +- cdr/cdr_sqlite.c | 25 +- cdr/cdr_tds.c | 25 +- channel.c | 4516 -------------------------- channels/Makefile | 34 +- channels/chan_agent.c | 56 +- channels/chan_alsa.c | 17 +- channels/chan_features.c | 16 +- channels/chan_h323.c | 17 +- channels/chan_iax2.c | 24 +- channels/chan_jingle.c | 25 +- channels/chan_local.c | 32 +- channels/chan_mgcp.c | 31 +- channels/chan_misdn.c | 33 +- channels/chan_nbs.c | 35 +- channels/chan_oss.c | 18 +- channels/chan_phone.c | 19 +- channels/chan_sip.c | 23 +- channels/chan_skinny.c | 23 +- channels/chan_zap.c | 24 +- channels/h323/Makefile | 1 - channels/misdn/Makefile | 25 +- channels/misdn/ie.c | 96 +- channels/misdn/isdn_lib.c | 104 +- channels/misdn/isdn_lib.h | 1 - channels/misdn/isdn_lib_intern.h | 8 +- channels/misdn/isdn_msg_parser.c | 147 +- chanvars.c | 86 - cli.c | 1386 -------- codecs/Makefile | 29 +- codecs/codec_a_mu.c | 24 +- codecs/codec_adpcm.c | 30 +- codecs/codec_alaw.c | 30 +- codecs/codec_g726.c | 37 +- codecs/codec_gsm.c | 30 +- codecs/codec_ilbc.c | 26 +- codecs/codec_lpc10.c | 31 +- codecs/codec_speex.c | 40 +- codecs/codec_ulaw.c | 35 +- codecs/codec_zap.c | 38 +- codecs/gsm/Makefile | 6 +- coef_in.h | 13 - coef_out.h | 4 - config.c | 1235 ------- configure | 6476 +++++++++++++++++++++++-------------- configure.ac | 167 +- cryptostub.c | 95 - cygwin/Makefile | 9 - cygwin/cygloader.c | 33 - db.c | 593 ---- db1-ast/Makefile | 73 - db1-ast/btree/bt_close.c | 182 -- db1-ast/btree/bt_conv.c | 221 -- db1-ast/btree/bt_debug.c | 329 -- db1-ast/btree/bt_delete.c | 657 ---- db1-ast/btree/bt_get.c | 105 - db1-ast/btree/bt_open.c | 458 --- db1-ast/btree/bt_overflow.c | 228 -- db1-ast/btree/bt_page.c | 100 - db1-ast/btree/bt_put.c | 321 -- db1-ast/btree/bt_search.c | 213 -- db1-ast/btree/bt_seq.c | 460 --- db1-ast/btree/bt_split.c | 829 ----- db1-ast/btree/bt_utils.c | 260 -- db1-ast/btree/btree.h | 391 --- db1-ast/btree/extern.h | 70 - db1-ast/db/db.c | 113 - db1-ast/hash/README | 72 - db1-ast/hash/extern.h | 65 - db1-ast/hash/hash.c | 999 ------ db1-ast/hash/hash.h | 293 -- db1-ast/hash/hash_bigkey.c | 668 ---- db1-ast/hash/hash_buf.c | 355 -- db1-ast/hash/hash_func.c | 225 -- db1-ast/hash/hash_log2.c | 56 - db1-ast/hash/hash_page.c | 944 ------ db1-ast/hash/hsearch.c | 107 - db1-ast/hash/ndbm.c | 235 -- db1-ast/hash/page.h | 92 - db1-ast/hash/search.h | 51 - db1-ast/include/circ-queue.h | 131 - db1-ast/include/compat.h | 49 - db1-ast/include/db.h | 250 -- db1-ast/include/mpool.h | 115 - db1-ast/include/ndbm.h | 79 - db1-ast/libdb.map | 11 - db1-ast/mpool/README | 7 - db1-ast/mpool/mpool.c | 498 --- db1-ast/recno/extern.h | 54 - db1-ast/recno/rec_close.c | 183 -- db1-ast/recno/rec_delete.c | 197 -- db1-ast/recno/rec_get.c | 311 -- db1-ast/recno/rec_open.c | 241 -- db1-ast/recno/rec_put.c | 280 -- db1-ast/recno/rec_search.c | 126 - db1-ast/recno/rec_seq.c | 131 - db1-ast/recno/rec_utils.c | 122 - db1-ast/recno/recno.h | 39 - devicestate.c | 383 --- dlfcn.c | 1314 -------- dns.c | 235 -- dnsmgr.c | 426 --- doc/asterisk.8 | 193 ++ doc/asterisk.sgml | 364 +++ dsp.c | 1761 ---------- ecdisa.h | 15 - editline/CHANGES | 42 - editline/INSTALL | 64 - editline/Makefile.in | 233 -- editline/PLATFORMS | 13 - editline/README | 11 - editline/TEST/test.c | 268 -- editline/chared.c | 695 ---- editline/chared.h | 159 - editline/common.c | 951 ------ editline/config.guess | 1449 --------- editline/config.h.in | 21 - editline/config.sub | 1412 -------- editline/configure | 2421 -------------- editline/configure.in | 276 -- editline/editline.3 | 646 ---- editline/editrc.5 | 491 --- editline/el.c | 509 --- editline/el.h | 145 - editline/emacs.c | 488 --- editline/hist.c | 197 -- editline/hist.h | 80 - editline/histedit.h | 197 -- editline/history.c | 875 ----- editline/install-sh | 250 -- editline/key.c | 687 ---- editline/key.h | 79 - editline/makelist | 254 -- editline/map.c | 1418 -------- editline/map.h | 79 - editline/np/fgetln.c | 88 - editline/np/strlcat.c | 75 - editline/np/strlcpy.c | 75 - editline/np/unvis.c | 322 -- editline/np/vis.c | 348 -- editline/np/vis.h | 96 - editline/parse.c | 259 -- editline/parse.h | 52 - editline/prompt.c | 174 - editline/prompt.h | 62 - editline/read.c | 555 ---- editline/read.h | 55 - editline/readline.c | 1669 ---------- editline/readline/readline.h | 118 - editline/refresh.c | 1104 ------- editline/refresh.h | 63 - editline/search.c | 649 ---- editline/search.h | 70 - editline/sig.c | 198 -- editline/sig.h | 72 - editline/sys.h | 133 - editline/term.c | 1587 --------- editline/term.h | 124 - editline/tokenizer.c | 397 --- editline/tokenizer.h | 54 - editline/tty.c | 1182 ------- editline/tty.h | 484 --- editline/vi.c | 941 ------ enum.c | 663 ---- file.c | 1167 ------- fixedjitterbuf.c | 351 -- fixedjitterbuf.h | 93 - formats/Makefile | 9 +- formats/format_g723.c | 17 +- formats/format_g726.c | 23 +- formats/format_g729.c | 17 +- formats/format_gsm.c | 17 +- formats/format_h263.c | 17 +- formats/format_h264.c | 17 +- formats/format_ilbc.c | 17 +- formats/format_jpeg.c | 20 +- formats/format_ogg_vorbis.c | 21 +- formats/format_pcm.c | 19 +- formats/format_sln.c | 17 +- formats/format_vox.c | 17 +- formats/format_wav.c | 17 +- formats/format_wav_gsm.c | 17 +- frame.c | 1369 -------- fskmodem.c | 305 -- funcs/Makefile | 9 +- funcs/func_base64.c | 18 +- funcs/func_callerid.c | 18 +- funcs/func_cdr.c | 19 +- funcs/func_channel.c | 18 +- funcs/func_curl.c | 28 +- funcs/func_cut.c | 35 +- funcs/func_db.c | 19 +- funcs/func_enum.c | 35 +- funcs/func_env.c | 20 +- funcs/func_global.c | 19 +- funcs/func_groupcount.c | 18 +- funcs/func_language.c | 19 +- funcs/func_logic.c | 19 +- funcs/func_math.c | 19 +- funcs/func_md5.c | 19 +- funcs/func_moh.c | 19 +- funcs/func_odbc.c | 24 +- funcs/func_rand.c | 28 +- funcs/func_realtime.c | 45 +- funcs/func_sha1.c | 19 +- funcs/func_strings.c | 19 +- funcs/func_timeout.c | 18 +- funcs/func_uri.c | 17 +- http.c | 698 ---- image.c | 210 -- include/asterisk.h | 8 +- include/asterisk/abstract_jb.h | 1 - include/asterisk/autoconfig.h.in | 81 +- include/asterisk/cdr.h | 6 +- include/asterisk/compiler.h | 28 +- include/asterisk/dns.h | 2 - include/asterisk/file.h | 9 +- include/asterisk/indications.h | 3 - include/asterisk/linkedlists.h | 15 +- include/asterisk/lock.h | 2 - include/asterisk/module.h | 309 +- include/asterisk/monitor.h | 2 - include/asterisk/srv.h | 2 - include/asterisk/translate.h | 13 +- include/asterisk/utils.h | 10 +- indications.c | 600 ---- io.c | 371 --- jitterbuf.c | 825 ----- jitterbuf.h | 162 - loader.c | 1015 ------ logger.c | 914 ------ main/Makefile | 138 + main/abstract_jb.c | 784 +++++ main/acl.c | 425 +++ main/aescrypt.c | 317 ++ main/aeskey.c | 469 +++ main/aesopt.h | 1029 ++++++ main/aestab.c | 232 ++ main/alaw.c | 101 + main/app.c | 1328 ++++++++ main/ast_expr2.c | 2871 ++++++++++++++++ main/ast_expr2.fl | 405 +++ main/ast_expr2.h | 120 + main/ast_expr2.y | 1045 ++++++ main/ast_expr2f.c | 3299 +++++++++++++++++++ main/asterisk.c | 2727 ++++++++++++++++ main/astmm.c | 443 +++ main/autoservice.c | 154 + main/buildinfo.c | 33 + main/callerid.c | 1096 +++++++ main/cdr.c | 1175 +++++++ main/channel.c | 4516 ++++++++++++++++++++++++++ main/chanvars.c | 86 + main/cli.c | 1390 ++++++++ main/coef_in.h | 13 + main/coef_out.h | 4 + main/config.c | 1235 +++++++ main/cryptostub.c | 95 + main/db.c | 593 ++++ main/db1-ast/Makefile | 73 + main/db1-ast/btree/bt_close.c | 182 ++ main/db1-ast/btree/bt_conv.c | 221 ++ main/db1-ast/btree/bt_debug.c | 329 ++ main/db1-ast/btree/bt_delete.c | 657 ++++ main/db1-ast/btree/bt_get.c | 105 + main/db1-ast/btree/bt_open.c | 458 +++ main/db1-ast/btree/bt_overflow.c | 228 ++ main/db1-ast/btree/bt_page.c | 100 + main/db1-ast/btree/bt_put.c | 321 ++ main/db1-ast/btree/bt_search.c | 213 ++ main/db1-ast/btree/bt_seq.c | 460 +++ main/db1-ast/btree/bt_split.c | 829 +++++ main/db1-ast/btree/bt_utils.c | 260 ++ main/db1-ast/btree/btree.h | 391 +++ main/db1-ast/btree/extern.h | 70 + main/db1-ast/db/db.c | 103 + main/db1-ast/hash/README | 72 + main/db1-ast/hash/extern.h | 65 + main/db1-ast/hash/hash.c | 999 ++++++ main/db1-ast/hash/hash.h | 293 ++ main/db1-ast/hash/hash_bigkey.c | 668 ++++ main/db1-ast/hash/hash_buf.c | 355 ++ main/db1-ast/hash/hash_func.c | 225 ++ main/db1-ast/hash/hash_log2.c | 56 + main/db1-ast/hash/hash_page.c | 944 ++++++ main/db1-ast/hash/hsearch.c | 107 + main/db1-ast/hash/ndbm.c | 235 ++ main/db1-ast/hash/page.h | 92 + main/db1-ast/hash/search.h | 51 + main/db1-ast/include/circ-queue.h | 131 + main/db1-ast/include/compat.h | 49 + main/db1-ast/include/db.h | 250 ++ main/db1-ast/include/mpool.h | 115 + main/db1-ast/include/ndbm.h | 79 + main/db1-ast/libdb.map | 11 + main/db1-ast/mpool/README | 7 + main/db1-ast/mpool/mpool.c | 498 +++ main/db1-ast/recno/extern.h | 54 + main/db1-ast/recno/rec_close.c | 183 ++ main/db1-ast/recno/rec_delete.c | 197 ++ main/db1-ast/recno/rec_get.c | 311 ++ main/db1-ast/recno/rec_open.c | 241 ++ main/db1-ast/recno/rec_put.c | 280 ++ main/db1-ast/recno/rec_search.c | 126 + main/db1-ast/recno/rec_seq.c | 131 + main/db1-ast/recno/rec_utils.c | 122 + main/db1-ast/recno/recno.h | 39 + main/devicestate.c | 383 +++ main/dlfcn.c | 1314 ++++++++ main/dns.c | 228 ++ main/dnsmgr.c | 426 +++ main/dsp.c | 1761 ++++++++++ main/ecdisa.h | 15 + main/editline/CHANGES | 42 + main/editline/INSTALL | 64 + main/editline/Makefile.in | 233 ++ main/editline/PLATFORMS | 13 + main/editline/README | 11 + main/editline/TEST/test.c | 268 ++ main/editline/chared.c | 695 ++++ main/editline/chared.h | 159 + main/editline/common.c | 951 ++++++ main/editline/config.guess | 1449 +++++++++ main/editline/config.h.in | 21 + main/editline/config.sub | 1412 ++++++++ main/editline/configure | 2421 ++++++++++++++ main/editline/configure.in | 276 ++ main/editline/editline.3 | 646 ++++ main/editline/editrc.5 | 491 +++ main/editline/el.c | 509 +++ main/editline/el.h | 145 + main/editline/emacs.c | 488 +++ main/editline/hist.c | 197 ++ main/editline/hist.h | 80 + main/editline/histedit.h | 197 ++ main/editline/history.c | 875 +++++ main/editline/install-sh | 250 ++ main/editline/key.c | 687 ++++ main/editline/key.h | 79 + main/editline/makelist | 254 ++ main/editline/map.c | 1418 ++++++++ main/editline/map.h | 79 + main/editline/np/fgetln.c | 88 + main/editline/np/strlcat.c | 75 + main/editline/np/strlcpy.c | 75 + main/editline/np/unvis.c | 322 ++ main/editline/np/vis.c | 348 ++ main/editline/np/vis.h | 96 + main/editline/parse.c | 259 ++ main/editline/parse.h | 52 + main/editline/prompt.c | 174 + main/editline/prompt.h | 62 + main/editline/read.c | 555 ++++ main/editline/read.h | 55 + main/editline/readline.c | 1669 ++++++++++ main/editline/readline/readline.h | 118 + main/editline/refresh.c | 1104 +++++++ main/editline/refresh.h | 63 + main/editline/search.c | 649 ++++ main/editline/search.h | 70 + main/editline/sig.c | 198 ++ main/editline/sig.h | 72 + main/editline/sys.h | 133 + main/editline/term.c | 1587 +++++++++ main/editline/term.h | 124 + main/editline/tokenizer.c | 397 +++ main/editline/tokenizer.h | 54 + main/editline/tty.c | 1182 +++++++ main/editline/tty.h | 484 +++ main/editline/vi.c | 941 ++++++ main/enum.c | 663 ++++ main/file.c | 1161 +++++++ main/fixedjitterbuf.c | 351 ++ main/fixedjitterbuf.h | 93 + main/frame.c | 1369 ++++++++ main/fskmodem.c | 305 ++ main/http.c | 698 ++++ main/image.c | 210 ++ main/indications.c | 600 ++++ main/io.c | 371 +++ main/jitterbuf.c | 825 +++++ main/jitterbuf.h | 162 + main/loader.c | 883 +++++ main/logger.c | 914 ++++++ main/manager.c | 2630 +++++++++++++++ main/md5.c | 267 ++ main/netsock.c | 211 ++ main/pbx.c | 5963 ++++++++++++++++++++++++++++++++++ main/plc.c | 251 ++ main/poll.c | 306 ++ main/privacy.c | 119 + main/rtp.c | 3012 +++++++++++++++++ main/say.c | 6420 ++++++++++++++++++++++++++++++++++++ main/sched.c | 399 +++ main/sha1.c | 385 +++ main/slinfactory.c | 157 + main/srv.c | 140 + main/stdtime/Makefile | 29 + main/stdtime/localtime.c | 1509 +++++++++ main/stdtime/private.h | 226 ++ main/stdtime/test.c | 21 + main/stdtime/tzfile.h | 189 ++ main/strcompat.c | 77 + main/tdd.c | 320 ++ main/term.c | 280 ++ main/translate.c | 703 ++++ main/udptl.c | 1255 +++++++ main/ulaw.c | 106 + main/utils.c | 1231 +++++++ makeopts.in | 28 +- manager.c | 2630 --------------- md5.c | 267 -- muted.c | 688 ---- netsock.c | 211 -- pbx.c | 5963 ---------------------------------- pbx/Makefile | 15 +- pbx/pbx_ael.c | 37 +- pbx/pbx_config.c | 23 +- pbx/pbx_dundi.c | 33 +- pbx/pbx_loopback.c | 19 +- pbx/pbx_realtime.c | 18 +- pbx/pbx_spool.c | 16 +- plc.c | 251 -- poll.c | 306 -- privacy.c | 119 - res/Makefile | 11 +- res/res_adsi.c | 22 +- res/res_agi.c | 27 +- res/res_clioriginate.c | 29 +- res/res_config_odbc.c | 23 +- res/res_config_pgsql.c | 28 +- res/res_convert.c | 30 +- res/res_crypto.c | 26 +- res/res_features.c | 63 +- res/res_indications.c | 22 +- res/res_jabber.c | 24 +- res/res_monitor.c | 20 +- res/res_musiconhold.c | 23 +- res/res_odbc.c | 24 +- res/res_smdi.c | 28 +- res/res_snmp.c | 22 +- res/res_speech.c | 19 +- rtp.c | 3012 ----------------- say.c | 6420 ------------------------------------ sched.c | 399 --- sha1.c | 385 --- slinfactory.c | 157 - sounds.txt | 718 ---- sounds/Makefile | 4 +- srv.c | 140 - stdtime/Makefile | 29 - stdtime/localtime.c | 1509 --------- stdtime/private.h | 226 -- stdtime/test.c | 21 - stdtime/tzfile.h | 189 -- strcompat.c | 77 - tdd.c | 320 -- term.c | 280 -- translate.c | 706 ---- udptl.c | 1255 ------- ulaw.c | 106 - utils.c | 1231 ------- utils/Makefile | 34 +- utils/ael_main.c | 4 +- utils/muted.c | 688 ++++ 577 files changed, 110057 insertions(+), 111284 deletions(-) delete mode 100644 abstract_jb.c delete mode 100644 acl.c delete mode 100644 aescrypt.c delete mode 100644 aeskey.c delete mode 100644 aesopt.h delete mode 100644 aestab.c delete mode 100644 alaw.c delete mode 100644 app.c delete mode 100644 ast_expr2.c delete mode 100644 ast_expr2.fl delete mode 100644 ast_expr2.h delete mode 100644 ast_expr2.y delete mode 100644 ast_expr2f.c delete mode 100644 asterisk.8 delete mode 100644 asterisk.c delete mode 100644 asterisk.sgml delete mode 100644 astmm.c delete mode 100644 autoservice.c create mode 100644 build_tools/embed_modules.xml delete mode 100644 buildinfo.c delete mode 100644 callerid.c delete mode 100644 cdr.c delete mode 100644 channel.c delete mode 100644 chanvars.c delete mode 100644 cli.c delete mode 100644 coef_in.h delete mode 100644 coef_out.h delete mode 100644 config.c delete mode 100644 cryptostub.c delete mode 100644 cygwin/Makefile delete mode 100644 cygwin/cygloader.c delete mode 100644 db.c delete mode 100644 db1-ast/Makefile delete mode 100644 db1-ast/btree/bt_close.c delete mode 100644 db1-ast/btree/bt_conv.c delete mode 100644 db1-ast/btree/bt_debug.c delete mode 100644 db1-ast/btree/bt_delete.c delete mode 100644 db1-ast/btree/bt_get.c delete mode 100644 db1-ast/btree/bt_open.c delete mode 100644 db1-ast/btree/bt_overflow.c delete mode 100644 db1-ast/btree/bt_page.c delete mode 100644 db1-ast/btree/bt_put.c delete mode 100644 db1-ast/btree/bt_search.c delete mode 100644 db1-ast/btree/bt_seq.c delete mode 100644 db1-ast/btree/bt_split.c delete mode 100644 db1-ast/btree/bt_utils.c delete mode 100644 db1-ast/btree/btree.h delete mode 100644 db1-ast/btree/extern.h delete mode 100644 db1-ast/db/db.c delete mode 100644 db1-ast/hash/README delete mode 100644 db1-ast/hash/extern.h delete mode 100644 db1-ast/hash/hash.c delete mode 100644 db1-ast/hash/hash.h delete mode 100644 db1-ast/hash/hash_bigkey.c delete mode 100644 db1-ast/hash/hash_buf.c delete mode 100644 db1-ast/hash/hash_func.c delete mode 100644 db1-ast/hash/hash_log2.c delete mode 100644 db1-ast/hash/hash_page.c delete mode 100644 db1-ast/hash/hsearch.c delete mode 100644 db1-ast/hash/ndbm.c delete mode 100644 db1-ast/hash/page.h delete mode 100644 db1-ast/hash/search.h delete mode 100644 db1-ast/include/circ-queue.h delete mode 100644 db1-ast/include/compat.h delete mode 100644 db1-ast/include/db.h delete mode 100644 db1-ast/include/mpool.h delete mode 100644 db1-ast/include/ndbm.h delete mode 100644 db1-ast/libdb.map delete mode 100644 db1-ast/mpool/README delete mode 100644 db1-ast/mpool/mpool.c delete mode 100644 db1-ast/recno/extern.h delete mode 100644 db1-ast/recno/rec_close.c delete mode 100644 db1-ast/recno/rec_delete.c delete mode 100644 db1-ast/recno/rec_get.c delete mode 100644 db1-ast/recno/rec_open.c delete mode 100644 db1-ast/recno/rec_put.c delete mode 100644 db1-ast/recno/rec_search.c delete mode 100644 db1-ast/recno/rec_seq.c delete mode 100644 db1-ast/recno/rec_utils.c delete mode 100644 db1-ast/recno/recno.h delete mode 100644 devicestate.c delete mode 100644 dlfcn.c delete mode 100644 dns.c delete mode 100644 dnsmgr.c create mode 100644 doc/asterisk.8 create mode 100644 doc/asterisk.sgml delete mode 100644 dsp.c delete mode 100644 ecdisa.h delete mode 100644 editline/CHANGES delete mode 100644 editline/INSTALL delete mode 100644 editline/Makefile.in delete mode 100644 editline/PLATFORMS delete mode 100644 editline/README delete mode 100644 editline/TEST/test.c delete mode 100644 editline/chared.c delete mode 100644 editline/chared.h delete mode 100644 editline/common.c delete mode 100755 editline/config.guess delete mode 100644 editline/config.h.in delete mode 100755 editline/config.sub delete mode 100755 editline/configure delete mode 100644 editline/configure.in delete mode 100644 editline/editline.3 delete mode 100644 editline/editrc.5 delete mode 100644 editline/el.c delete mode 100644 editline/el.h delete mode 100644 editline/emacs.c delete mode 100644 editline/hist.c delete mode 100644 editline/hist.h delete mode 100644 editline/histedit.h delete mode 100644 editline/history.c delete mode 100755 editline/install-sh delete mode 100644 editline/key.c delete mode 100644 editline/key.h delete mode 100644 editline/makelist delete mode 100644 editline/map.c delete mode 100644 editline/map.h delete mode 100644 editline/np/fgetln.c delete mode 100644 editline/np/strlcat.c delete mode 100644 editline/np/strlcpy.c delete mode 100644 editline/np/unvis.c delete mode 100644 editline/np/vis.c delete mode 100644 editline/np/vis.h delete mode 100644 editline/parse.c delete mode 100644 editline/parse.h delete mode 100644 editline/prompt.c delete mode 100644 editline/prompt.h delete mode 100644 editline/read.c delete mode 100644 editline/read.h delete mode 100644 editline/readline.c delete mode 100644 editline/readline/readline.h delete mode 100644 editline/refresh.c delete mode 100644 editline/refresh.h delete mode 100644 editline/search.c delete mode 100644 editline/search.h delete mode 100644 editline/sig.c delete mode 100644 editline/sig.h delete mode 100644 editline/sys.h delete mode 100644 editline/term.c delete mode 100644 editline/term.h delete mode 100644 editline/tokenizer.c delete mode 100644 editline/tokenizer.h delete mode 100644 editline/tty.c delete mode 100644 editline/tty.h delete mode 100644 editline/vi.c delete mode 100644 enum.c delete mode 100644 file.c delete mode 100644 fixedjitterbuf.c delete mode 100644 fixedjitterbuf.h delete mode 100644 frame.c delete mode 100644 fskmodem.c delete mode 100644 http.c delete mode 100644 image.c delete mode 100644 indications.c delete mode 100644 io.c delete mode 100644 jitterbuf.c delete mode 100644 jitterbuf.h delete mode 100644 loader.c delete mode 100644 logger.c create mode 100644 main/Makefile create mode 100644 main/abstract_jb.c create mode 100644 main/acl.c create mode 100644 main/aescrypt.c create mode 100644 main/aeskey.c create mode 100644 main/aesopt.h create mode 100644 main/aestab.c create mode 100644 main/alaw.c create mode 100644 main/app.c create mode 100644 main/ast_expr2.c create mode 100644 main/ast_expr2.fl create mode 100644 main/ast_expr2.h create mode 100644 main/ast_expr2.y create mode 100644 main/ast_expr2f.c create mode 100644 main/asterisk.c create mode 100644 main/astmm.c create mode 100644 main/autoservice.c create mode 100644 main/buildinfo.c create mode 100644 main/callerid.c create mode 100644 main/cdr.c create mode 100644 main/channel.c create mode 100644 main/chanvars.c create mode 100644 main/cli.c create mode 100644 main/coef_in.h create mode 100644 main/coef_out.h create mode 100644 main/config.c create mode 100644 main/cryptostub.c create mode 100644 main/db.c create mode 100644 main/db1-ast/Makefile create mode 100644 main/db1-ast/btree/bt_close.c create mode 100644 main/db1-ast/btree/bt_conv.c create mode 100644 main/db1-ast/btree/bt_debug.c create mode 100644 main/db1-ast/btree/bt_delete.c create mode 100644 main/db1-ast/btree/bt_get.c create mode 100644 main/db1-ast/btree/bt_open.c create mode 100644 main/db1-ast/btree/bt_overflow.c create mode 100644 main/db1-ast/btree/bt_page.c create mode 100644 main/db1-ast/btree/bt_put.c create mode 100644 main/db1-ast/btree/bt_search.c create mode 100644 main/db1-ast/btree/bt_seq.c create mode 100644 main/db1-ast/btree/bt_split.c create mode 100644 main/db1-ast/btree/bt_utils.c create mode 100644 main/db1-ast/btree/btree.h create mode 100644 main/db1-ast/btree/extern.h create mode 100644 main/db1-ast/db/db.c create mode 100644 main/db1-ast/hash/README create mode 100644 main/db1-ast/hash/extern.h create mode 100644 main/db1-ast/hash/hash.c create mode 100644 main/db1-ast/hash/hash.h create mode 100644 main/db1-ast/hash/hash_bigkey.c create mode 100644 main/db1-ast/hash/hash_buf.c create mode 100644 main/db1-ast/hash/hash_func.c create mode 100644 main/db1-ast/hash/hash_log2.c create mode 100644 main/db1-ast/hash/hash_page.c create mode 100644 main/db1-ast/hash/hsearch.c create mode 100644 main/db1-ast/hash/ndbm.c create mode 100644 main/db1-ast/hash/page.h create mode 100644 main/db1-ast/hash/search.h create mode 100644 main/db1-ast/include/circ-queue.h create mode 100644 main/db1-ast/include/compat.h create mode 100644 main/db1-ast/include/db.h create mode 100644 main/db1-ast/include/mpool.h create mode 100644 main/db1-ast/include/ndbm.h create mode 100644 main/db1-ast/libdb.map create mode 100644 main/db1-ast/mpool/README create mode 100644 main/db1-ast/mpool/mpool.c create mode 100644 main/db1-ast/recno/extern.h create mode 100644 main/db1-ast/recno/rec_close.c create mode 100644 main/db1-ast/recno/rec_delete.c create mode 100644 main/db1-ast/recno/rec_get.c create mode 100644 main/db1-ast/recno/rec_open.c create mode 100644 main/db1-ast/recno/rec_put.c create mode 100644 main/db1-ast/recno/rec_search.c create mode 100644 main/db1-ast/recno/rec_seq.c create mode 100644 main/db1-ast/recno/rec_utils.c create mode 100644 main/db1-ast/recno/recno.h create mode 100644 main/devicestate.c create mode 100644 main/dlfcn.c create mode 100644 main/dns.c create mode 100644 main/dnsmgr.c create mode 100644 main/dsp.c create mode 100644 main/ecdisa.h create mode 100644 main/editline/CHANGES create mode 100644 main/editline/INSTALL create mode 100644 main/editline/Makefile.in create mode 100644 main/editline/PLATFORMS create mode 100644 main/editline/README create mode 100644 main/editline/TEST/test.c create mode 100644 main/editline/chared.c create mode 100644 main/editline/chared.h create mode 100644 main/editline/common.c create mode 100755 main/editline/config.guess create mode 100644 main/editline/config.h.in create mode 100755 main/editline/config.sub create mode 100755 main/editline/configure create mode 100644 main/editline/configure.in create mode 100644 main/editline/editline.3 create mode 100644 main/editline/editrc.5 create mode 100644 main/editline/el.c create mode 100644 main/editline/el.h create mode 100644 main/editline/emacs.c create mode 100644 main/editline/hist.c create mode 100644 main/editline/hist.h create mode 100644 main/editline/histedit.h create mode 100644 main/editline/history.c create mode 100755 main/editline/install-sh create mode 100644 main/editline/key.c create mode 100644 main/editline/key.h create mode 100644 main/editline/makelist create mode 100644 main/editline/map.c create mode 100644 main/editline/map.h create mode 100644 main/editline/np/fgetln.c create mode 100644 main/editline/np/strlcat.c create mode 100644 main/editline/np/strlcpy.c create mode 100644 main/editline/np/unvis.c create mode 100644 main/editline/np/vis.c create mode 100644 main/editline/np/vis.h create mode 100644 main/editline/parse.c create mode 100644 main/editline/parse.h create mode 100644 main/editline/prompt.c create mode 100644 main/editline/prompt.h create mode 100644 main/editline/read.c create mode 100644 main/editline/read.h create mode 100644 main/editline/readline.c create mode 100644 main/editline/readline/readline.h create mode 100644 main/editline/refresh.c create mode 100644 main/editline/refresh.h create mode 100644 main/editline/search.c create mode 100644 main/editline/search.h create mode 100644 main/editline/sig.c create mode 100644 main/editline/sig.h create mode 100644 main/editline/sys.h create mode 100644 main/editline/term.c create mode 100644 main/editline/term.h create mode 100644 main/editline/tokenizer.c create mode 100644 main/editline/tokenizer.h create mode 100644 main/editline/tty.c create mode 100644 main/editline/tty.h create mode 100644 main/editline/vi.c create mode 100644 main/enum.c create mode 100644 main/file.c create mode 100644 main/fixedjitterbuf.c create mode 100644 main/fixedjitterbuf.h create mode 100644 main/frame.c create mode 100644 main/fskmodem.c create mode 100644 main/http.c create mode 100644 main/image.c create mode 100644 main/indications.c create mode 100644 main/io.c create mode 100644 main/jitterbuf.c create mode 100644 main/jitterbuf.h create mode 100644 main/loader.c create mode 100644 main/logger.c create mode 100644 main/manager.c create mode 100644 main/md5.c create mode 100644 main/netsock.c create mode 100644 main/pbx.c create mode 100644 main/plc.c create mode 100644 main/poll.c create mode 100644 main/privacy.c create mode 100644 main/rtp.c create mode 100644 main/say.c create mode 100644 main/sched.c create mode 100644 main/sha1.c create mode 100644 main/slinfactory.c create mode 100644 main/srv.c create mode 100644 main/stdtime/Makefile create mode 100644 main/stdtime/localtime.c create mode 100644 main/stdtime/private.h create mode 100644 main/stdtime/test.c create mode 100644 main/stdtime/tzfile.h create mode 100644 main/strcompat.c create mode 100644 main/tdd.c create mode 100644 main/term.c create mode 100644 main/translate.c create mode 100644 main/udptl.c create mode 100644 main/ulaw.c create mode 100644 main/utils.c delete mode 100644 manager.c delete mode 100644 md5.c delete mode 100644 muted.c delete mode 100644 netsock.c delete mode 100644 pbx.c delete mode 100644 plc.c delete mode 100644 poll.c delete mode 100644 privacy.c delete mode 100644 rtp.c delete mode 100644 say.c delete mode 100644 sched.c delete mode 100644 sha1.c delete mode 100644 slinfactory.c delete mode 100644 sounds.txt delete mode 100644 srv.c delete mode 100644 stdtime/Makefile delete mode 100644 stdtime/localtime.c delete mode 100644 stdtime/private.h delete mode 100644 stdtime/test.c delete mode 100644 stdtime/tzfile.h delete mode 100644 strcompat.c delete mode 100644 tdd.c delete mode 100644 term.c delete mode 100644 translate.c delete mode 100644 udptl.c delete mode 100644 ulaw.c delete mode 100644 utils.c create mode 100644 utils/muted.c diff --git a/.cleancount b/.cleancount index aabe6ec39..2bd5a0a98 100644 --- a/.cleancount +++ b/.cleancount @@ -1 +1 @@ -21 +22 diff --git a/Makefile b/Makefile index 1f52edbe3..a42993d35 100644 --- a/Makefile +++ b/Makefile @@ -22,33 +22,16 @@ .EXPORT_ALL_VARIABLES: +include makeopts + #Uncomment this to see all build commands instead of 'quiet' output #NOISY_BUILD=yes # Create OPTIONS variable OPTIONS= -# If cross compiling, define these to suit -#CROSS_COMPILE=/opt/montavista/pro/devkit/arm/xscale_be/bin/xscale_be- -#CROSS_COMPILE_BIN=/opt/montavista/pro/devkit/arm/xscale_be/bin/ -#CROSS_COMPILE_TARGET=/opt/montavista/pro/devkit/arm/xscale_be/target -#CROSS_ARCH=Linux -#CROSS_PROC=arm -#SUB_PROC=xscale # or maverick - -ifeq ($(CROSS_COMPILE),) - OSARCH:=$(shell uname -s) - PROC?:=$(shell uname -m) -else - OSARCH=$(CROSS_ARCH) - PROC=$(CROSS_PROC) -endif - ASTTOPDIR:=$(shell pwd) -# Remember the MAKELEVEL at the top -MAKETOPLEVEL?=$(MAKELEVEL) - # Overwite config files on "make samples" OVERWRITE=y @@ -60,21 +43,8 @@ DEBUG=-g3 # For example, make DESTDIR=/tmp/asterisk woud put things in # /tmp/asterisk/etc/asterisk # !!! Watch out, put no spaces or comments after the value !!! -DESTDIR?= #DESTDIR?=/tmp/asterisk -# Original busydetect routine -#BUSYDETECT = -DBUSYDETECT - -# Improved busydetect routine, comment the previous one if you use this one -#BUSYDETECT+= -DBUSYDETECT_MARTIN -# Detect the busy signal looking only at tone lengths -# For example if you have 3 beeps 100ms tone, 100ms silence separated by 500 ms of silence -#BUSYDETECT+= -DBUSYDETECT_TONEONLY -# Enforce the detection of busy signal (get rid of false hangups) -# Don't use together with -DBUSYDETECT_TONEONLY -#BUSYDETECT+= -DBUSYDETECT_COMPARE_TONE_AND_SILENCE - # Define standard directories for various platforms # These apply if they are not redefined in asterisk.conf ifeq ($(OSARCH),SunOS) @@ -131,59 +101,10 @@ ASTCFLAGS= GLOBAL_MAKEOPTS=$(wildcard /etc/asterisk.makeopts) USER_MAKEOPTS=$(wildcard ~/.asterisk.makeopts) -ifeq ($(strip $(foreach var,clean distclean dist-clean update,$(findstring $(var),$(MAKECMDGOALS)))),) - ifneq ($(wildcard menuselect.makeopts),) - include menuselect.makeopts - include menuselect.makedeps - endif -endif - -ifeq ($(strip $(foreach var,clean distclean dist-clean update,$(findstring $(var),$(MAKECMDGOALS)))),) - ifneq ($(wildcard makeopts),) - include makeopts - endif -endif - -TOPDIR_CFLAGS=-Iinclude -MOD_SUBDIR_CFLAGS=-I../include -I.. -OTHER_SUBDIR_CFLAGS=-I../include -I.. - -ifeq ($(origin MENUSELECT_CFLAGS),undefined) - MENUSELECT_CFLAGS:=$(shell grep MENUSELECT_CFLAGS $(USER_MAKEOPTS) .) - ifeq ($(MENUSELECT_CFLAGS),) - MENUSELECT_CFLAGS:=$(shell grep MENUSELECT_CFLAGS $(GLOBAL_MAKEOPTS) .) - endif - ifneq ($(MENUSELECT_CFLAGS),) - MENUSELECT_CFLAGS:=$(shell echo $(MENUSELECT_CFLAGS) | cut -f2 -d'=') - endif -endif - -ifeq ($(findstring dont-optimize,$(MAKECMDGOALS)),$(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS))) -# More GSM codec optimization -# Uncomment to enable MMXTM optimizations for x86 architecture CPU's -# which support MMX instructions. This should be newer pentiums, -# ppro's, etc, as well as the AMD K6 and K7. -#K6OPT = -DK6OPT - -# Tell gcc to optimize the code -OPTIMIZE+=-O6 -else - # Stack backtraces, while useful for debugging, are incompatible with optimizations - ifeq ($(OSARCH),Linux) - CFLAGS+=-DSTACK_BACKTRACES - endif -endif - -# *CLI> show memory allocations [filename] -# *CLI> show memory summary [filename] -ifneq ($(findstring MALLOC_DEBUG,$(MENUSELECT_CFLAGS)),) - TOPDIR_CFLAGS+=-include include/asterisk/astmm.h - MOD_SUBDIR_CFLAGS+=-include ../include/asterisk/astmm.h -endif +MOD_SUBDIR_CFLAGS=-I../include -I../main +OTHER_SUBDIR_CFLAGS=-I../include -MOD_SUBDIR_CFLAGS+=-fPIC - -ifeq ($(OSARCH),Linux) +ifeq ($(OSARCH),linux-gnu) ifeq ($(PROC),x86_64) # You must have GCC 3.4 to use k8, otherwise use athlon PROC=k8 @@ -216,28 +137,21 @@ ifeq ($(OSARCH),Linux) endif endif -GREP=grep ID=id ifeq ($(OSARCH),SunOS) - GREP=/usr/xpg4/bin/grep M4=/usr/local/bin/m4 ID=/usr/xpg4/bin/id endif ASTCFLAGS+=-pipe -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG) -ifneq ($(OPTIMIZE),) -ASTCFLAGS+=$(OPTIMIZE) -endif ifeq ($(AST_DEVMODE),yes) ASTCFLAGS+=-Werror -Wunused endif -ASTOBJ=-o asterisk - -ifeq ($(findstring BSD,$(OSARCH)),BSD) - ASTCFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib +ifneq ($(findstring BSD,$(OSARCH)),) + ASTCFLAGS+=-I/usr/local/include -L/usr/local/lib endif ifneq ($(PROC),ultrasparc) @@ -249,13 +163,13 @@ ifeq ($(PROC),ppc) endif ifeq ($(OSARCH),FreeBSD) - BSDVERSION=$(shell make -V OSVERSION -f $(CROSS_COMPILE_TARGET)/usr/share/mk/bsd.port.subdir.mk) + BSDVERSION=$(shell make -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk) ASTCFLAGS+=$(shell if test $(BSDVERSION) -lt 500016 ; then echo "-D_THREAD_SAFE"; fi) AST_LIBS+=$(shell if test $(BSDVERSION) -lt 502102 ; then echo "-lc_r"; else echo "-pthread"; fi) -endif # FreeBSD +endif ifeq ($(OSARCH),NetBSD) - AST_CFLAGS+=-pthread -I$(CROSS_COMPILE_TARGET)/usr/pkg/include + ASTCFLAGS+=-pthread -I/usr/pkg/include endif ifeq ($(OSARCH),OpenBSD) @@ -263,11 +177,9 @@ ifeq ($(OSARCH),OpenBSD) endif ifeq ($(OSARCH),SunOS) - ASTCFLAGS+=-Wcast-align -DSOLARIS -Iinclude/solaris-compat -I$(CROSS_COMPILE_TARGET)/opt/ssl/include -I$(CROSS_COMPILE_TARGET)/usr/local/ssl/include + ASTCFLAGS+=-Wcast-align -DSOLARIS -Iinclude/solaris-compat -I/opt/ssl/include -I/usr/local/ssl/include endif -LIBEDIT=editline/libedit.a - ASTERISKVERSION:=$(shell build_tools/make_version .) ifneq ($(wildcard .version),) @@ -283,93 +195,35 @@ endif ASTCFLAGS+=$(MALLOC_DEBUG)$(BUSYDETECT)$(OPTIONS) -MOD_SUBDIRS:=res channels pbx apps codecs formats cdr funcs +MOD_SUBDIRS:=res channels pbx apps codecs formats cdr funcs main OTHER_SUBDIRS:=utils agi +# Note: OTHER_SUBDIRS must be after MOD_SUBDIRS, because 'utils' uses files from 'main' SUBDIRS:=$(MOD_SUBDIRS) $(OTHER_SUBDIRS) SUBDIRS_INSTALL:=$(SUBDIRS:%=%-install) SUBDIRS_CLEAN:=$(SUBDIRS:%=%-clean) SUBDIRS_CLEAN_DEPEND:=$(SUBDIRS:%=%-clean-depend) MOD_SUBDIRS_DEPEND:=$(MOD_SUBDIRS:%=%-depend) OTHER_SUBDIRS_DEPEND:=$(OTHER_SUBDIRS:%=%-depend) -SUBDIRS_DEPEND:=$(MOD_SUBDIRS_DEPEND) $(OTHER_SUBDIRS_DEPEND) +SUBDIRS_DEPEND:=$(OTHER_SUBDIRS_DEPEND) $(MOD_SUBDIRS_DEPEND) SUBDIRS_UNINSTALL:=$(SUBDIRS:%=%-uninstall) +MOD_SUBDIRS_EMBED_LDSCRIPT:=$(MOD_SUBDIRS:%=%-embed-ldscript) +MOD_SUBDIRS_EMBED_LDFLAGS:=$(MOD_SUBDIRS:%=%-embed-ldflags) +MOD_SUBDIRS_EMBED_LIBS:=$(MOD_SUBDIRS:%=%-embed-libs) -OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \ - translate.o file.o pbx.o cli.o md5.o term.o \ - ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \ - cdr.o tdd.o acl.o rtp.o udptl.o manager.o asterisk.o \ - dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \ - astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \ - utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \ - netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \ - cryptostub.o sha1.o http.o fixedjitterbuf.o abstract_jb.o - -# we need to link in the objects statically, not as a library, because -# otherwise modules will not have them available if none of the static -# objects use it. -OBJS+=stdtime/localtime.o - -# At the moment say.o is an optional component which can be overridden -# by a module. -OBJS+=say.o - -ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/sys/poll.h),) - OBJS+= poll.o - ASTCFLAGS+=-DPOLLCOMPAT -endif - -ifeq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/dlfcn.h),) - OBJS+= dlfcn.o - ASTCFLAGS+=-DDLFCNCOMPAT -endif - -ifeq ($(OSARCH),Linux) - AST_LIBS+=-ldl -lpthread $(EDITLINE_LIB) -lm -lresolv #-lnjamd -else - AST_LIBS+=$(EDITLINE_LIB) -lm -endif - -ifeq ($(OSARCH),Darwin) - AST_LIBS+=-lresolv +ifneq ($(findstring darwin,$(OSARCH)),) ASTCFLAGS+=-D__Darwin__ AUDIO_LIBS=-framework CoreAudio - ASTLINK=-Wl,-dynamic SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace - # Mac on Intel CoreDuo does not need poll compatibility layer - ifneq ($(PROC),i386) - OBJS+=poll.o - ASTCFLAGS+=-DPOLLCOMPAT - endif else # These are used for all but Darwin - ASTLINK=-Wl,-E SOLINK=-shared -Xlinker -x - ifeq ($(findstring BSD,$(OSARCH)),BSD) - LDFLAGS+=-L$(CROSS_COMPILE_TARGET)/usr/local/lib + ifneq ($(findstring BSD,$(OSARCH)),) + LDFLAGS+=-L/usr/local/lib endif endif -ifeq ($(OSARCH),FreeBSD) - AST_LIBS+=-lcrypto -endif - -ifeq ($(OSARCH),NetBSD) - AST_LIBS+=-lpthread -lcrypto -lm -L$(CROSS_COMPILE_TARGET)/usr/pkg/lib $(EDITLINE_LIB) -endif - -ifeq ($(OSARCH),OpenBSD) - AST_LIBS+=-lcrypto -lpthread -lm $(EDITLINE_LIB) -endif - ifeq ($(OSARCH),SunOS) - AST_LIBS+=-lpthread -ldl -lnsl -lsocket -lresolv -L$(CROSS_COMPILE_TARGET)/opt/ssl/lib -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib - OBJS+=strcompat.o - ASTLINK= - SOLINK=-shared -fpic -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib -endif - -ifeq ($(MAKETOPLEVEL),$(MAKELEVEL)) - CFLAGS+=$(TOPDIR_CFLAGS)$(ASTCFLAGS) + SOLINK=-shared -fpic -L/usr/local/ssl/lib endif # This is used when generating the doxygen documentation @@ -379,9 +233,7 @@ else HAVEDOT=no endif -include Makefile.rules - -_all: all +all: cleantest $(SUBDIRS) @echo " +--------- Asterisk Build Complete ---------+" @echo " + Asterisk has successfully been built, but +" @echo " + cannot be run before being installed by +" @@ -390,94 +242,44 @@ _all: all @echo " + make install +" @echo " +-------------------------------------------+" -all: cleantest config.status menuselect.makeopts depend $(SUBDIRS) asterisk - -$(MOD_SUBDIRS): - @CFLAGS="$(MOD_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) -C $@ - -$(OTHER_SUBDIRS): - @CFLAGS="$(OTHER_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) -C $@ - -config.status: configure - @CFLAGS="" ./configure - @echo "****" - @echo "**** The configure script was just executed, so 'make' needs to be" - @echo "**** restarted." - @echo "****" - @exit 1 - -makeopts: configure - @CFLAGS="" ./configure +makeopts: @echo "****" - @echo "**** The configure script was just executed, so 'make' needs to be" - @echo "**** restarted." + @echo "**** The configure script must be executed before running 'make'." @echo "****" @exit 1 -menuselect.makeopts menuselect.makedeps: menuselect/menuselect menuselect-tree +menuselect.makeopts: menuselect/menuselect menuselect-tree menuselect/menuselect --check-deps $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS) menuselect.makeopts -#ifneq ($(wildcard tags),) -ctags: tags -#endif - -ifneq ($(wildcard TAGS),) -all: TAGS -endif - -editline/config.h: - cd editline && unset CFLAGS AST_LIBS && CFLAGS="$(OPTIMIZE)" ./configure ; \ - -editline/libedit.a: - cd editline && unset CFLAGS AST_LIBS && test -f config.h || CFLAGS="$(OPTIMIZE)" ./configure - $(MAKE) -C editline libedit.a - -db1-ast/libdb1.a: - $(MAKE) -C db1-ast libdb1.a - -ifeq ($(strip $(foreach var,clean distclean dist-clean update,$(findstring $(var),$(MAKECMDGOALS)))),) - ifneq ($(wildcard .depend),) - include .depend - endif -endif - -ifeq ($(strip $(foreach var,clean distclean dist-clean update,$(findstring $(var),$(MAKECMDGOALS)))),) - ifneq ($(wildcard .tags-depend),) - include .tags-depend - endif -endif +$(MOD_SUBDIRS_EMBED_LDSCRIPT): + @echo "EMBED_LDSCRIPTS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-ldscript=) SUBDIR=$(@:-embed-ldscript=) __embed_ldscript` >> makeopts.embed_rules -ast_expr2.c ast_expr2.h: - bison -o $@ -d --name-prefix=ast_yy ast_expr2.y +$(MOD_SUBDIRS_EMBED_LDFLAGS): + @echo "EMBED_LDFLAGS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-ldflags=) SUBDIR=$(@:-embed-ldflags=) __embed_ldflags` >> makeopts.embed_rules -ast_expr2f.c: - flex -o $@ --full ast_expr2.fl +$(MOD_SUBDIRS_EMBED_LIBS): + @echo "EMBED_LIBS+="`$(MAKE) --quiet --no-print-directory -C $(@:-embed-libs=) SUBDIR=$(@:-embed-libs=) __embed_libs` >> makeopts.embed_rules -testexpr2: config.status include/asterisk/buildopts.h ast_expr2f.c ast_expr2.c ast_expr2.h - $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2f.c - $(CC) -g -c -Iinclude -DSTANDALONE ast_expr2.c - $(CC) -g -o testexpr2 ast_expr2f.o ast_expr2.o - rm ast_expr2.o ast_expr2f.o - -manpage: asterisk.8 - -asterisk.8: asterisk.sgml - rm -f asterisk.8 - docbook2man asterisk.sgml - mv ./*.8 asterisk.8 +makeopts.embed_rules: menuselect.makeopts + @echo "Generating embedded module rules ..." + @rm -f $@ + @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDSCRIPT) + @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LDFLAGS) + @$(MAKE) --no-print-directory $(MOD_SUBDIRS_EMBED_LIBS) -asterisk.pdf: asterisk.sgml - docbook2pdf asterisk.sgml +$(SUBDIRS): depend makeopts.embed_rules -asterisk.ps: asterisk.sgml - docbook2ps asterisk.sgml +# ensure that all module subdirectories are processed before 'main' during +# a parallel build, since if there are modules selected to be embedded the +# directories containing them must be completed before the main Asterisk +# binary can be built +main: $(filter-out main,$(MOD_SUBDIRS)) -asterisk.html: asterisk.sgml - docbook2html asterisk.sgml - mv r1.html asterisk.html +$(MOD_SUBDIRS): + @CFLAGS="$(MOD_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) --no-print-directory -C $@ SUBDIR=$@ all -asterisk.txt: asterisk.sgml - docbook2txt asterisk.sgml +$(OTHER_SUBDIRS): + @CFLAGS="$(OTHER_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) --no-print-directory -C $@ SUBDIR=$@ all defaults.h: makeopts @build_tools/make_defaults_h > $@.tmp @@ -500,39 +302,19 @@ include/asterisk/buildopts.h: menuselect.makeopts fi @rm -f $@.tmp -channel.o: CFLAGS+=$(ZAPTEL_INCLUDE) - -asterisk: include/asterisk/buildopts.h editline/libedit.a db1-ast/libdb1.a $(OBJS) - @build_tools/make_build_h > include/asterisk/build.h.tmp - @if cmp -s include/asterisk/build.h.tmp include/asterisk/build.h ; then echo ; else \ - mv include/asterisk/build.h.tmp include/asterisk/build.h ; \ - fi - @rm -f include/asterisk/build.h.tmp - @$(CC) -c -o buildinfo.o $(CFLAGS) buildinfo.c - @echo " [LD] $(OBJS) buildinfo.o $(LIBEDIT) db1-ast/libdb1.1 $(AST_LIBS) -> $@" - @$(CC) $(DEBUG) $(ASTOBJ) $(ASTLINK) $(OBJS) buildinfo.o $(LIBEDIT) db1-ast/libdb1.a $(AST_LIBS) - -muted: muted.o -muted: LIBS+=$(AUDIO_LIBS) - $(SUBDIRS_CLEAN_DEPEND): - @$(MAKE) -C $(@:-clean-depend=) clean-depend + @$(MAKE) --no-print-directory -C $(@:-clean-depend=) clean-depend $(SUBDIRS_CLEAN): - @$(MAKE) -C $(@:-clean=) clean + @$(MAKE) --no-print-directory -C $(@:-clean=) clean clean-depend: $(SUBDIRS_CLEAN_DEPEND) clean: $(SUBDIRS_CLEAN) clean-depend - rm -f *.o *.so asterisk rm -f defaults.h rm -f include/asterisk/build.h rm -f include/asterisk/version.h - rm -f .tags-sources tags TAGS - rm -f .depend .tags-depend - @if [ -f editline/Makefile ]; then $(MAKE) -C editline distclean ; fi - @$(MAKE) -C db1-ast clean - @$(MAKE) -C stdtime clean + rm -f .depend @$(MAKE) -C menuselect clean dist-clean: distclean @@ -541,7 +323,8 @@ distclean: clean @$(MAKE) -C mxml clean @$(MAKE) -C menuselect dist-clean @$(MAKE) -C sounds dist-clean - rm -f menuselect.makeopts makeopts menuselect-tree menuselect.makedeps + rm -f menuselect.makeopts makeopts makeopts.xml menuselect.makedeps + rm -f makeopts.embed_rules rm -f config.log config.status rm -rf autom4te.cache rm -f include/asterisk/autoconfig.h @@ -595,8 +378,7 @@ bininstall: all mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/monitor - if [ -f asterisk ]; then $(INSTALL) -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/; fi - if [ -f asterisk.dll ]; then $(INSTALL) -m 755 asterisk.dll $(DESTDIR)$(ASTSBINDIR)/; fi + $(INSTALL) -m 755 main/asterisk $(DESTDIR)$(ASTSBINDIR)/ $(LN) -sf asterisk $(DESTDIR)$(ASTSBINDIR)/rasterisk $(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/ $(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/ @@ -618,7 +400,7 @@ bininstall: all mkdir -p $(DESTDIR)$(ASTMANDIR)/man8 $(INSTALL) -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTDATADIR)/keys $(INSTALL) -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTDATADIR)/keys - $(INSTALL) -m 644 asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8 + $(INSTALL) -m 644 doc/asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8 $(INSTALL) -m 644 contrib/scripts/astgenkey.8 $(DESTDIR)$(ASTMANDIR)/man8 $(INSTALL) -m 644 contrib/scripts/autosupport.8 $(DESTDIR)$(ASTMANDIR)/man8 $(INSTALL) -m 644 contrib/scripts/safe_asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8 @@ -781,7 +563,7 @@ progdocs: echo "PROJECT_NUMBER=$(ASTERISKVERSION)") | doxygen - config: - @if [ "${OSARCH}" = "Linux" ]; then \ + @if [ "${OSARCH}" = "linux-gnu" ]; then \ if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \ $(INSTALL) -m 755 contrib/init.d/rc.redhat.asterisk /etc/rc.d/init.d/asterisk; \ /sbin/chkconfig --add asterisk; \ @@ -806,69 +588,29 @@ config: echo "We could not install init scripts for your operating system."; \ fi -dont-optimize: _all - -valgrind: dont-optimize - $(MOD_SUBDIRS_DEPEND): - @CFLAGS="$(MOD_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) -C $(@:-depend=) depend + @CFLAGS="$(MOD_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) --no-print-directory -C $(@:-depend=) depend $(OTHER_SUBDIRS_DEPEND): - @CFLAGS="$(OTHER_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) -C $(@:-depend=) depend + @CFLAGS="$(OTHER_SUBDIR_CFLAGS)$(ASTCFLAGS)" $(MAKE) --no-print-directory -C $(@:-depend=) depend -depend: include/asterisk/version.h include/asterisk/buildopts.h .depend defaults.h $(SUBDIRS_DEPEND) - -.depend: include/asterisk/version.h include/asterisk/buildopts.h defaults.h - build_tools/mkdep $(CFLAGS) $(wildcard *.c) - -.tags-depend: - @echo -n ".tags-depend: " > $@ - @$(FIND) . -maxdepth 1 -name \*.c -printf "\t%p \\\\\n" >> $@ - @$(FIND) . -maxdepth 1 -name \*.h -printf "\t%p \\\\\n" >> $@ - @$(FIND) $(SUBDIRS) -name \*.c -printf "\t%p \\\\\n" >> $@ - @$(FIND) $(SUBDIRS) -name \*.h -printf "\t%p \\\\\n" >> $@ - @$(FIND) include -name \*.h -printf "\t%p \\\\\n" >> $@ - @echo >> $@ - -.tags-sources: - @rm -f $@ - @$(FIND) . -maxdepth 1 -name \*.c -print >> $@ - @$(FIND) . -maxdepth 1 -name \*.h -print >> $@ - @$(FIND) $(SUBDIRS) -name \*.c -print >> $@ - @$(FIND) $(SUBDIRS) -name \*.h -print >> $@ - @$(FIND) include -name \*.h -print >> $@ - -tags: .tags-depend .tags-sources - ctags -L .tags-sources -o $@ - -ctags: tags - -TAGS: .tags-depend .tags-sources - etags -o $@ `cat .tags-sources` - -etags: TAGS - -%_env: - $(MAKE) -C $(shell echo $@ | sed "s/_env//g") env +depend: include/asterisk/version.h include/asterisk/buildopts.h defaults.h $(SUBDIRS_DEPEND) sounds: $(MAKE) -C sounds all -env: - env - # If the cleancount has been changed, force a make clean. # .cleancount is the global clean count, and .lastclean is the # last clean count we had cleantest: - @if cmp -s .cleancount .lastclean ; then echo ; else \ + @if ! cmp -s .cleancount .lastclean ; then \ $(MAKE) clean; cp -f .cleancount .lastclean;\ $(MAKE) defaults.h;\ fi $(SUBDIRS_UNINSTALL): - @$(MAKE) -C $(@:-uninstall=) uninstall + @$(MAKE) --no-print-directory -C $(@:-uninstall=) uninstall _uninstall: $(SUBDIRS_UNINSTALL) rm -f $(DESTDIR)$(MODULES_DIR)/* @@ -905,15 +647,15 @@ uninstall-all: _uninstall menuselect: menuselect/menuselect menuselect-tree -@menuselect/menuselect $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS) menuselect.makeopts && echo "menuselect changes saved!" || echo "menuselect changes NOT saved!" -menuselect/menuselect: menuselect/menuselect.c menuselect/menuselect_curses.c menuselect/menuselect_stub.c menuselect/menuselect.h menuselect/linkedlists.h config.status mxml/libmxml.a - @CFLAGS="-include $(ASTTOPDIR)/include/asterisk/autoconfig.h -I$(ASTTOPDIR)/include" PARENTSRC="$(ASTTOPDIR)" $(MAKE) -C menuselect menuselect +menuselect/menuselect: makeopts menuselect/menuselect.c menuselect/menuselect_curses.c menuselect/menuselect_stub.c menuselect/menuselect.h menuselect/linkedlists.h makeopts mxml/libmxml.a + @CFLAGS="-include $(ASTTOPDIR)/include/asterisk/autoconfig.h -I$(ASTTOPDIR)/include" PARENTSRC="$(ASTTOPDIR)" $(MAKE) -C menuselect CC="$(HOST_CC)" menuselect mxml/libmxml.a: - @cd mxml && unset CFLAGS AST_LIBS && test -f config.h || ./configure + @cd mxml && unset CFLAGS AST_LIBS && test -f config.h || ./configure --build=$(BUILD_PLATFORM) --host=$(BUILD_PLATFORM) $(MAKE) -C mxml libmxml.a -menuselect-tree: $(foreach dir,$(MOD_SUBDIRS),$(wildcard $(dir)/*.c) $(wildcard $(dir)/*.cc)) build_tools/cflags.xml sounds/sounds.xml - @echo "Generating list of available modules ..." +menuselect-tree: $(foreach dir,$(MOD_SUBDIRS),$(wildcard $(dir)/*.c) $(wildcard $(dir)/*.cc)) build_tools/cflags.xml sounds/sounds.xml build_tools/embed_modules.xml + @echo "Generating input for menuselect ..." @build_tools/prep_moduledeps > $@ -.PHONY: menuselect sounds clean clean-depend dist-clean distclean all _all depend cleantest uninstall _uninstall uninstall-all dont-optimize valgrind $(SUBDIRS_INSTALL) $(SUBDIRS_CLEAN) $(SUBDIRS_CLEAN_DEPEND) $(SUBDIRS_DEPEND) $(SUBDIRS_UNINSTALL) $(SUBDIRS) +.PHONY: menuselect main sounds clean clean-depend dist-clean distclean all prereqs depend cleantest uninstall _uninstall uninstall-all dont-optimize $(SUBDIRS_INSTALL) $(SUBDIRS_CLEAN) $(SUBDIRS_CLEAN_DEPEND) $(SUBDIRS_DEPEND) $(SUBDIRS_UNINSTALL) $(SUBDIRS) $(MOD_SUBDIRS_EMBED_LDSCRIPT) $(MOD_SUBDIRS_EMBED_LDFLAGS) $(MOD_SUBDIRS_EMBED_LIBS) diff --git a/Makefile.moddir_rules b/Makefile.moddir_rules index 0a82471e4..8e9c082fe 100644 --- a/Makefile.moddir_rules +++ b/Makefile.moddir_rules @@ -1,7 +1,7 @@ # # Asterisk -- A telephony toolkit for Linux. # -# Makefile rules +# Makefile rules for subdirectories containing modules # # Copyright (C) 2006, Digium, Inc. # @@ -11,50 +11,83 @@ # the GNU General Public License # +ifneq ($(findstring MALLOC_DEBUG,$(MENUSELECT_CFLAGS)),) + CFLAGS+=-include $(ASTTOPDIR)/include/asterisk/astmm.h +endif + +ifneq ($(findstring STATIC_BUILD,$(MENUSELECT_CFLAGS)),) + STATIC_BUILD=-static +endif + include $(ASTTOPDIR)/Makefile.rules -define module_o_c_template -$(1).o: $(1).c -$(1).o: CFLAGS+=$$(MENUSELECT_OPTS_$(1):%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$(1)),$$(value $(dep)_INCLUDE)) -endef +comma:=, -define module_oo_cc_template -$(1).oo: $(1).cc -$(1).oo: CFLAGS+=$$(MENUSELECT_OPTS_$(1):%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$(1)),$$(value $(dep)_INCLUDE)) +define module_o_template +$(2): $(3) +$(2): CFLAGS+=-DAST_MODULE=\"$(1)\" $$(MENUSELECT_OPTS_$(1):%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$(1)),$$(value $(dep)_INCLUDE)) endef -define module_so_o_template -$(1).so: $(1).o +define module_so_template +$(1)=$(1).so +$(1).so: CFLAGS+=-fPIC $(1).so: LIBS+=$(foreach dep,$(MENUSELECT_DEPENDS_$(1)),$$(value $(dep)_LIB)) $(1).so: LDFLAGS+=$(foreach dep,$(MENUSELECT_DEPENDS_$(1)),$$(value $(dep)_LDFLAGS)) +$(1).so: $(2) endef -define module_so_oo_template -$(1).so: $(1).oo -$(1).so: LIBS+=$(foreach dep,$(MENUSELECT_DEPENDS_$(1)),$$(value $(dep)_LIB)) -$(1).so: LDFLAGS+=$(foreach dep,$(MENUSELECT_DEPENDS_$(1)),$$(value $(dep)_LDFLAGS)) +define module_a_template +$(1)=modules.link +modules.link: $(2) endef -$(foreach mod,$(C_MODS),$(eval $(call module_o_c_template,$(mod)))) +$(foreach mod,$(C_MODS),$(eval $(call module_o_template,$(mod),$(mod).o,$(mod).c))) -$(foreach mod,$(C_MODS),$(eval $(call module_so_o_template,$(mod)))) +$(foreach mod,$(CC_MODS),$(eval $(call module_o_template,$(mod),$(mod).oo,$(mod).cc))) -$(foreach mod,$(CC_MODS),$(eval $(call module_oo_cc_template,$(mod)))) +$(foreach mod,$(filter-out $(EMBEDDED_MODS),$(C_MODS)),$(eval $(call module_so_template,$(mod),$(mod).o))) -$(foreach mod,$(CC_MODS),$(eval $(call module_so_oo_template,$(mod)))) +$(foreach mod,$(filter-out $(EMBEDDED_MODS),$(CC_MODS)),$(eval $(call module_so_template,$(mod),$(mod).oo))) + +$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(eval $(call module_a_template,$(mod),$(mod).o))) + +$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(eval $(call module_a_template,$(mod),$(mod).oo))) .PHONY: clean clean-depend depend uninstall _all -_all: $(SELECTED_MODS:%=%.so) +ifneq ($(LOADABLE_MODS),) +_all: $(LOADABLE_MODS:%=%.so) +endif + +ifneq ($(EMBEDDED_MODS),) +_all: modules.link +__embed_ldscript: + @echo "../$(SUBDIR)/modules.link" +__embed_ldflags: + @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))" + @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LDFLAGS))" +__embed_libs: + @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(C_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))" + @echo "$(foreach mod,$(filter $(EMBEDDED_MODS),$(CC_MODS)),$(foreach dep,$(MENUSELECT_DEPENDS_$(mod)),$(dep)_LIB))" +else +__embed_ldscript: +__embed_ldflags: +__embed_libs: +endif + +modules.link: + @rm -f $@ + @for file in $(patsubst $(ASTTOPDIR)/%,%,$(realpath $^)); do echo "INPUT (../$${file})" >> $@; done clean-depend:: rm -f .depend clean:: clean-depend rm -f *.so *.o *.oo + rm -f modules.link install:: all - for x in $(SELECTED_MODS:%=%.so); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done + for x in $(LOADABLE_MODS:%=%.so); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done uninstall:: @@ -65,4 +98,4 @@ endif depend: .depend .depend: - ../build_tools/mkdep $(CFLAGS) `ls *.c` + ../build_tools/mkdep $(CFLAGS) `ls *.c *.cc 2> /dev/null` diff --git a/Makefile.rules b/Makefile.rules index 47a92a5a9..0c2b97d62 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -15,6 +15,8 @@ # Prefixing one or the other with @\# or @ or nothing makes the desired # behaviour. ECHO_PREFIX prefixes the comment, CMD_PREFIX prefixes the command. +include $(ASTTOPDIR)/makeopts + ifeq ($(NOISY_BUILD),) ECHO_PREFIX=@ CMD_PREFIX=@ @@ -23,6 +25,17 @@ else CMD_PREFIX= endif +ifeq ($(findstring DONT_OPTIMIZE,$(MENUSELECT_CFLAGS)),) +# More GSM codec optimization +# Uncomment to enable MMXTM optimizations for x86 architecture CPU's +# which support MMX instructions. This should be newer pentiums, +# ppro's, etc, as well as the AMD K6 and K7. +#K6OPT=-DK6OPT + +OPTIMIZE?=-O6 +CFLAGS+=$(OPTIMIZE) +endif + define ast_make_o_c $(1): $(2) $(ECHO_PREFIX) echo " [CC] $$< -> $$@" @@ -50,13 +63,13 @@ endef define ast_make_so_o $(1): $(2) $(ECHO_PREFIX) echo " [LD] $$^ -> $$@" - $(CMD_PREFIX) $$(CC) -o $$@ $$(LDFLAGS) $$(SOLINK) $$^ $$(LIBS) + $(CMD_PREFIX) $$(CC) $$(STATIC_BUILD) -o $$@ $$(LDFLAGS) $$(SOLINK) $$^ $$(LIBS) endef define ast_make_so_oo $(1): $(2) $(ECHO_PREFIX) echo " [LDXX] $$^ -> $$@" - $(CMD_PREFIX) $$(CXX) -o $$@ $$(LDFLAGS) $$(SOLINK) $$^ $$(LIBS) + $(CMD_PREFIX) $$(CXX) $$(STATIC_BUILD) -o $$@ $$(LDFLAGS) $$(SOLINK) $$^ $$(LIBS) endef define ast_make_a_o @@ -69,13 +82,13 @@ endef define ast_make_final $(1): $(2) $(ECHO_PREFIX) echo " [LD] $$^ -> $$@" - $(CMD_PREFIX) $$(CC) -o $$@ $$(LDFLAGS) $$^ $$(LIBS) + $(CMD_PREFIX) $$(CXX) $$(STATIC_BUILD) -o $$@ $$(LDFLAGS) $$^ $$(LIBS) endef define ast_make_final_host $(1): $(2) $(ECHO_PREFIX) echo " [LD] $$^ -> $$@" - $(CMD_PREFIX) $$(HOST_CC) -o $$@ $$(CFLAGS) $$(LDFLAGS) $$^ $$(LIBS) + $(CMD_PREFIX) $$(HOST_CC) $$(STATIC_BUILD) -o $$@ $$(CFLAGS) $$(LDFLAGS) $$^ $$(LIBS) endef $(eval $(call ast_make_o_c,%.o,%.c)) @@ -84,8 +97,6 @@ $(eval $(call ast_make_oo_cc,%.oo,%.cc)) $(eval $(call ast_make_so_o,%.so,%.o)) -$(eval $(call ast_make_so_oo,%.so,%.oo)) - $(eval $(call ast_make_final,%,%.o)) $(eval $(call ast_make_c_y,%.c,%.y)) diff --git a/abstract_jb.c b/abstract_jb.c deleted file mode 100644 index 1525d81b0..000000000 --- a/abstract_jb.c +++ /dev/null @@ -1,784 +0,0 @@ -/* - * abstract_jb: common implementation-independent jitterbuffer stuff - * - * Copyright (C) 2005, Attractel OOD - * - * Contributors: - * Slav Klenov - * - * 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. - * - * A license has been granted to Digium (via disclaimer) for the use of - * this code. - */ - -/*! \file - * - * \brief Common implementation-independent jitterbuffer stuff. - * - * \author Slav Klenov - */ - -#include "asterisk.h" - -ASTERISK_FILE_VERSION(__FILE__, "$Revision$") - -#include -#include - -#include "asterisk/frame.h" -#include "asterisk/channel.h" -#include "asterisk/logger.h" -#include "asterisk/term.h" -#include "asterisk/options.h" -#include "asterisk/utils.h" - -#include "asterisk/abstract_jb.h" -#include "fixedjitterbuf.h" -#include "jitterbuf.h" - -/*! Internal jb flags */ -enum { - JB_USE = (1 << 0), - JB_TIMEBASE_INITIALIZED = (1 << 1), - JB_CREATED = (1 << 2) -}; - -/* Hooks for the abstract jb implementation */ - -/*! \brief Create */ -typedef void * (*jb_create_impl)(struct ast_jb_conf *general_config, long resynch_threshold); -/*! \brief Destroy */ -typedef void (*jb_destroy_impl)(void *jb); -/*! \brief Put first frame */ -typedef int (*jb_put_first_impl)(void *jb, struct ast_frame *fin, long now); -/*! \brief Put frame */ -typedef int (*jb_put_impl)(void *jb, struct ast_frame *fin, long now); -/*! \brief Get frame for now */ -typedef int (*jb_get_impl)(void *jb, struct ast_frame **fout, long now, long interpl); -/*! \brief Get next */ -typedef long (*jb_next_impl)(void *jb); -/*! \brief Remove first frame */ -typedef int (*jb_remove_impl)(void *jb, struct ast_frame **fout); -/*! \brief Force resynch */ -typedef void (*jb_force_resynch_impl)(void *jb); - - -/*! - * \brief Jitterbuffer implementation private struct. - */ -struct ast_jb_impl -{ - char name[AST_JB_IMPL_NAME_SIZE]; - jb_create_impl create; - jb_destroy_impl destroy; - jb_put_first_impl put_first; - jb_put_impl put; - jb_get_impl get; - jb_next_impl next; - jb_remove_impl remove; - jb_force_resynch_impl force_resync; -}; - -/* Implementation functions */ -/* fixed */ -static void * jb_create_fixed(struct ast_jb_conf *general_config, long resynch_threshold); -static void jb_destroy_fixed(void *jb); -static int jb_put_first_fixed(void *jb, struct ast_frame *fin, long now); -static int jb_put_fixed(void *jb, struct ast_frame *fin, long now); -static int jb_get_fixed(void *jb, struct ast_frame **fout, long now, long interpl); -static long jb_next_fixed(void *jb); -static int jb_remove_fixed(void *jb, struct ast_frame **fout); -static void jb_force_resynch_fixed(void *jb); -/* adaptive */ -static void * jb_create_adaptive(struct ast_jb_conf *general_config, long resynch_threshold); -static void jb_destroy_adaptive(void *jb); -static int jb_put_first_adaptive(void *jb, struct ast_frame *fin, long now); -static int jb_put_adaptive(void *jb, struct ast_frame *fin, long now); -static int jb_get_adaptive(void *jb, struct ast_frame **fout, long now, long interpl); -static long jb_next_adaptive(void *jb); -static int jb_remove_adaptive(void *jb, struct ast_frame **fout); -static void jb_force_resynch_adaptive(void *jb); - -/* Available jb implementations */ -static struct ast_jb_impl avail_impl[] = -{ - { - .name = "fixed", - .create = jb_create_fixed, - .destroy = jb_destroy_fixed, - .put_first = jb_put_first_fixed, - .put = jb_put_fixed, - .get = jb_get_fixed, - .next = jb_next_fixed, - .remove = jb_remove_fixed, - .force_resync = jb_force_resynch_fixed - }, - { - .name = "adaptive", - .create = jb_create_adaptive, - .destroy = jb_destroy_adaptive, - .put_first = jb_put_first_adaptive, - .put = jb_put_adaptive, - .get = jb_get_adaptive, - .next = jb_next_adaptive, - .remove = jb_remove_adaptive, - .force_resync = jb_force_resynch_adaptive - } -}; - -static int default_impl = 0; - - -/*! Abstract return codes */ -enum { - JB_IMPL_OK, - JB_IMPL_DROP, - JB_IMPL_INTERP, - JB_IMPL_NOFRAME -}; - -/* Translations between impl and abstract return codes */ -static int fixed_to_abstract_code[] = - {JB_IMPL_OK, JB_IMPL_DROP, JB_IMPL_INTERP, JB_IMPL_NOFRAME}; -static int adaptive_to_abstract_code[] = - {JB_IMPL_OK, JB_IMPL_NOFRAME, JB_IMPL_NOFRAME, JB_IMPL_INTERP, JB_IMPL_DROP, JB_IMPL_OK}; - -/* JB_GET actions (used only for the frames log) */ -static char *jb_get_actions[] = {"Delivered", "Dropped", "Interpolated", "No"}; - -/*! \brief Macros for the frame log files */ -#define jb_framelog(...) do { \ - if (jb->logfile) { \ - fprintf(jb->logfile, __VA_ARGS__); \ - fflush(jb->logfile); \ - } \ -} while (0) - - -/* Internal utility functions */ -static void jb_choose_impl(struct ast_channel *chan); -static void jb_get_and_deliver(struct ast_channel *chan); -static int create_jb(struct ast_channel *chan, struct ast_frame *first_frame); -static long get_now(struct ast_jb *jb, struct timeval *tv); - - -/* Interface ast jb functions impl */ - - -static void jb_choose_impl(struct ast_channel *chan) -{ - struct ast_jb *jb = &chan->jb; - struct ast_jb_conf *jbconf = &jb->conf; - struct ast_jb_impl *test_impl; - int i, avail_impl_count = sizeof(avail_impl) / sizeof(avail_impl[0]); - - jb->impl = &avail_impl[default_impl]; - - if (ast_strlen_zero(jbconf->impl)) - return; - - for (i = 0; i < avail_impl_count; i++) { - test_impl = &avail_impl[i]; - if (!strcasecmp(jbconf->impl, test_impl->name)) { - jb->impl = test_impl; - return; - } - } -} - -int ast_jb_do_usecheck(struct ast_channel *c0, struct ast_channel *c1) -{ - struct ast_jb *jb0 = &c0->jb; - struct ast_jb *jb1 = &c1->jb; - struct ast_jb_conf *conf0 = &jb0->conf; - struct ast_jb_conf *conf1 = &jb1->conf; - int c0_wants_jitter = c0->tech->properties & AST_CHAN_TP_WANTSJITTER; - int c0_creates_jitter = c0->tech->properties & AST_CHAN_TP_CREATESJITTER; - int c0_jb_enabled = ast_test_flag(conf0, AST_JB_ENABLED); - int c0_force_jb = ast_test_flag(conf0, AST_JB_FORCED); - int c0_jb_timebase_initialized = ast_test_flag(jb0, JB_TIMEBASE_INITIALIZED); - int c0_jb_created = ast_test_flag(jb0, JB_CREATED); - int c1_wants_jitter = c1->tech->properties & AST_CHAN_TP_WANTSJITTER; - int c1_creates_jitter = c1->tech->properties & AST_CHAN_TP_CREATESJITTER; - int c1_jb_enabled = ast_test_flag(conf1, AST_JB_ENABLED); - int c1_force_jb = ast_test_flag(conf1, AST_JB_FORCED); - int c1_jb_timebase_initialized = ast_test_flag(jb1, JB_TIMEBASE_INITIALIZED); - int c1_jb_created = ast_test_flag(jb1, JB_CREATED); - int inuse = 0; - - /* Determine whether audio going to c0 needs a jitter buffer */ - if (((!c0_wants_jitter && c1_creates_jitter) || (c0_force_jb && c1_creates_jitter)) && c0_jb_enabled) { - ast_set_flag(jb0, JB_USE); - if (!c0_jb_timebase_initialized) { - if (c1_jb_timebase_initialized) { - memcpy(&jb0->timebase, &jb1->timebase, sizeof(struct timeval)); - } else { - gettimeofday(&jb0->timebase, NULL); - } - ast_set_flag(jb0, JB_TIMEBASE_INITIALIZED); - } - - if (!c0_jb_created) { - jb_choose_impl(c0); - } - - inuse = 1; - } - - /* Determine whether audio going to c1 needs a jitter buffer */ - if (((!c1_wants_jitter && c0_creates_jitter) || (c1_force_jb && c0_creates_jitter)) && c1_jb_enabled) { - ast_set_flag(jb1, JB_USE); - if (!c1_jb_timebase_initialized) { - if (c0_jb_timebase_initialized) { - memcpy(&jb1->timebase, &jb0->timebase, sizeof(struct timeval)); - } else { - gettimeofday(&jb1->timebase, NULL); - } - ast_set_flag(jb1, JB_TIMEBASE_INITIALIZED); - } - - if (!c1_jb_created) { - jb_choose_impl(c1); - } - - inuse = 1; - } - - return inuse; -} - -int ast_jb_get_when_to_wakeup(struct ast_channel *c0, struct ast_channel *c1, int time_left) -{ - struct ast_jb *jb0 = &c0->jb; - struct ast_jb *jb1 = &c1->jb; - int c0_use_jb = ast_test_flag(jb0, JB_USE); - int c0_jb_is_created = ast_test_flag(jb0, JB_CREATED); - int c1_use_jb = ast_test_flag(jb1, JB_USE); - int c1_jb_is_created = ast_test_flag(jb1, JB_CREATED); - int wait, wait0, wait1; - struct timeval tv_now; - - if (time_left == 0) { - /* No time left - the bridge will be retried */ - /* TODO: Test disable this */ - /*return 0;*/ - } - - if (time_left < 0) { - time_left = INT_MAX; - } - - gettimeofday(&tv_now, NULL); - - wait0 = (c0_use_jb && c0_jb_is_created) ? jb0->next - get_now(jb0, &tv_now) : time_left; - wait1 = (c1_use_jb && c1_jb_is_created) ? jb1->next - get_now(jb1, &tv_now) : time_left; - - wait = wait0 < wait1 ? wait0 : wait1; - wait = wait < time_left ? wait : time_left; - - if (wait == INT_MAX) { - wait = -1; - } else if (wait < 1) { - /* don't let wait=0, because this can cause the pbx thread to loop without any sleeping at all */ - wait = 1; - } - - return wait; -} - - -int ast_jb_put(struct ast_channel *chan, struct ast_frame *f) -{ - struct ast_jb *jb = &chan->jb; - struct ast_jb_impl *jbimpl = jb->impl; - void *jbobj = jb->jbobj; - struct ast_frame *frr; - long now = 0; - - if (!ast_test_flag(jb, JB_USE)) - return -1; - - if (f->frametype != AST_FRAME_VOICE) { - if (f->frametype == AST_FRAME_DTMF && ast_test_flag(jb, JB_CREATED)) { - jb_framelog("JB_PUT {now=%ld}: Received DTMF frame. Force resynching jb...\n", now); - jbimpl->force_resync(jbobj); - } - - return -1; - } - - /* We consider an enabled jitterbuffer should receive frames with valid timing info. */ - if (!f->has_timing_info || f->len < 2 || f->ts < 0) { - ast_log(LOG_WARNING, "%s recieved frame with invalid timing info: " - "has_timing_info=%d, len=%ld, ts=%ld, src=%s\n", - chan->name, f->has_timing_info, f->len, f->ts, f->src); - return -1; - } - - if (f->mallocd & AST_MALLOCD_HDR) - frr = ast_frdup(f); - else - frr = ast_frisolate(f); - - if (!frr) { - ast_log(LOG_ERROR, "Failed to isolate frame for the jitterbuffer on channel '%s'\n", chan->name); - return -1; - } - - if (!ast_test_flag(jb, JB_CREATED)) { - if (create_jb(chan, frr)) { - ast_frfree(frr); - /* Disable the jitterbuffer */ - ast_clear_flag(jb, JB_USE); - return -1; - } - - ast_set_flag(jb, JB_CREATED); - return 0; - } else { - now = get_now(jb, NULL); - if (jbimpl->put(jbobj, frr, now) != JB_IMPL_OK) { - jb_framelog("JB_PUT {now=%ld}: Dropped frame with ts=%ld and len=%ld\n", now, frr->ts, frr->len); - ast_frfree(frr); - /*return -1;*/ - /* TODO: Check this fix - should return 0 here, because the dropped frame shouldn't - be delivered at all */ - return 0; - } - - jb->next = jbimpl->next(jbobj); - - jb_framelog("JB_PUT {now=%ld}: Queued frame with ts=%ld and len=%ld\n", now, frr->ts, frr->len); - - return 0; - } -} - - -void ast_jb_get_and_deliver(struct ast_channel *c0, struct ast_channel *c1) -{ - struct ast_jb *jb0 = &c0->jb; - struct ast_jb *jb1 = &c1->jb; - int c0_use_jb = ast_test_flag(jb0, JB_USE); - int c0_jb_is_created = ast_test_flag(jb0, JB_CREATED); - int c1_use_jb = ast_test_flag(jb1, JB_USE); - int c1_jb_is_created = ast_test_flag(jb1, JB_CREATED); - - if (c0_use_jb && c0_jb_is_created) - jb_get_and_deliver(c0); - - if (c1_use_jb && c1_jb_is_created) - jb_get_and_deliver(c1); -} - - -static void jb_get_and_deliver(struct ast_channel *chan) -{ - struct ast_jb *jb = &chan->jb; - struct ast_jb_impl *jbimpl = jb->impl; - void *jbobj = jb->jbobj; - struct ast_frame *f, finterp; - long now; - int interpolation_len, res; - - now = get_now(jb, NULL); - jb->next = jbimpl->next(jbobj); - if (now < jb->next) { - jb_framelog("\tJB_GET {now=%ld}: now < next=%ld\n", now, jb->next); - return; - } - - while (now >= jb->next) { - interpolation_len = ast_codec_interp_len(jb->last_format); - - res = jbimpl->get(jbobj, &f, now, interpolation_len); - - switch(res) { - case JB_IMPL_OK: - /* deliver the frame */ - ast_write(chan, f); - case JB_IMPL_DROP: - jb_framelog("\tJB_GET {now=%ld}: %s frame with ts=%ld and len=%ld\n", - now, jb_get_actions[res], f->ts, f->len); - jb->last_format = f->subclass; - ast_frfree(f); - break; - case JB_IMPL_INTERP: - /* interpolate a frame */ - f = &finterp; - f->frametype = AST_FRAME_VOICE; - f->subclass = jb->last_format; - f->datalen = 0; - f->samples = interpolation_len * 8; - f->mallocd = 0; - f->src = "JB interpolation"; - f->data = NULL; - f->delivery = ast_tvadd(jb->timebase, ast_samp2tv(jb->next, 1000)); - f->offset = AST_FRIENDLY_OFFSET; - /* deliver the interpolated frame */ - ast_write(chan, f); - jb_framelog("\tJB_GET {now=%ld}: Interpolated frame with len=%d\n", now, interpolation_len); - break; - case JB_IMPL_NOFRAME: - ast_log(LOG_WARNING, - "JB_IMPL_NOFRAME is retuned from the %s jb when now=%ld >= next=%ld, jbnext=%ld!\n", - jbimpl->name, now, jb->next, jbimpl->next(jbobj)); - jb_framelog("\tJB_GET {now=%ld}: No frame for now!?\n", now); - return; - default: - ast_log(LOG_ERROR, "This should never happen!\n"); - CRASH; - break; - } - - jb->next = jbimpl->next(jbobj); - } -} - - -static int create_jb(struct ast_channel *chan, struct ast_frame *frr) -{ - struct ast_jb *jb = &chan->jb; - struct ast_jb_conf *jbconf = &jb->conf; - struct ast_jb_impl *jbimpl = jb->impl; - void *jbobj; - struct ast_channel *bridged; - long now; - char logfile_pathname[20 + AST_JB_IMPL_NAME_SIZE + 2*AST_CHANNEL_NAME + 1]; - char name1[AST_CHANNEL_NAME], name2[AST_CHANNEL_NAME], *tmp; - int res; - - jbobj = jb->jbobj = jbimpl->create(jbconf, jbconf->resync_threshold); - if (!jbobj) { - ast_log(LOG_WARNING, "Failed to create jitterbuffer on channel '%s'\n", chan->name); - return -1; - } - - now = get_now(jb, NULL); - res = jbimpl->put_first(jbobj, frr, now); - - /* The result of putting the first frame should not differ from OK. However, its possible - some implementations (i.e. adaptive's when resynch_threshold is specified) to drop it. */ - if (res != JB_IMPL_OK) { - ast_log(LOG_WARNING, "Failed to put first frame in the jitterbuffer on channel '%s'\n", chan->name); - /* - jbimpl->destroy(jbobj); - return -1; - */ - } - - /* Init next */ - jb->next = jbimpl->next(jbobj); - - /* Init last format for a first time. */ - jb->last_format = frr->subclass; - - /* Create a frame log file */ - if (ast_test_flag(jbconf, AST_JB_LOG)) { - snprintf(name2, sizeof(name2), "%s", chan->name); - tmp = strchr(name2, '/'); - if (tmp) - *tmp = '#'; - - bridged = ast_bridged_channel(chan); - if (!bridged) { - /* We should always have bridged chan if a jitterbuffer is in use */ - CRASH; - } - snprintf(name1, sizeof(name1), "%s", bridged->name); - tmp = strchr(name1, '/'); - if (tmp) - *tmp = '#'; - - snprintf(logfile_pathname, sizeof(logfile_pathname), - "/tmp/ast_%s_jb_%s--%s.log", jbimpl->name, name1, name2); - jb->logfile = fopen(logfile_pathname, "w+b"); - - if (!jb->logfile) - ast_log(LOG_WARNING, "Failed to create frame log file with pathname '%s'\n", logfile_pathname); - - if (res == JB_IMPL_OK) - jb_framelog("JB_PUT_FIRST {now=%ld}: Queued frame with ts=%ld and len=%ld\n", - now, frr->ts, frr->len); - else - jb_framelog("JB_PUT_FIRST {now=%ld}: Dropped frame with ts=%ld and len=%ld\n", - now, frr->ts, frr->len); - } - - if (option_verbose > 2) - ast_verbose(VERBOSE_PREFIX_3 "%s jitterbuffer created on channel %s\n", jbimpl->name, chan->name); - - /* Free the frame if it has not been queued in the jb */ - if (res != JB_IMPL_OK) - ast_frfree(frr); - - return 0; -} - - -void ast_jb_destroy(struct ast_channel *chan) -{ - struct ast_jb *jb = &chan->jb; - struct ast_jb_impl *jbimpl = jb->impl; - void *jbobj = jb->jbobj; - struct ast_frame *f; - - if (jb->logfile) { - fclose(jb->logfile); - jb->logfile = NULL; - } - - if (ast_test_flag(jb, JB_CREATED)) { - /* Remove and free all frames still queued in jb */ - while (jbimpl->remove(jbobj, &f) == JB_IMPL_OK) { - ast_frfree(f); - } - - jbimpl->destroy(jbobj); - jb->jbobj = NULL; - - ast_clear_flag(jb, JB_CREATED); - - if (option_verbose > 2) - ast_verbose(VERBOSE_PREFIX_3 "%s jitterbuffer destroyed on channel %s\n", jbimpl->name, chan->name); - } -} - - -static long get_now(struct ast_jb *jb, struct timeval *tv) -{ - struct timeval now; - - if (!tv) { - tv = &now; - gettimeofday(tv, NULL); - } - - return ast_tvdiff_ms(*tv, jb->timebase); -} - - -int ast_jb_read_conf(struct ast_jb_conf *conf, char *varname, char *value) -{ - int prefixlen = sizeof(AST_JB_CONF_PREFIX) - 1; - char *name; - int tmp; - - if (strncasecmp(AST_JB_CONF_PREFIX, varname, prefixlen)) - return -1; - - name = varname + prefixlen; - - if (!strcasecmp(name, AST_JB_CONF_ENABLE)) { - ast_set2_flag(conf, ast_true(value), AST_JB_ENABLED); - } else if (!strcasecmp(name, AST_JB_CONF_FORCE)) { - ast_set2_flag(conf, ast_true(value), AST_JB_FORCED); - } else if (!strcasecmp(name, AST_JB_CONF_MAX_SIZE)) { - if ((tmp = atoi(value)) > 0) - conf->max_size = tmp; - } else if (!strcasecmp(name, AST_JB_CONF_RESYNCH_THRESHOLD)) { - if ((tmp = atoi(value)) > 0) - conf->resync_threshold = tmp; - } else if (!strcasecmp(name, AST_JB_CONF_IMPL)) { - if (!ast_strlen_zero(value)) - snprintf(conf->impl, sizeof(conf->impl), "%s", value); - } else if (!strcasecmp(name, AST_JB_CONF_LOG)) { - ast_set2_flag(conf, ast_true(value), AST_JB_LOG); - } else { - return -1; - } - - return 0; -} - - -void ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf) -{ - memcpy(&chan->jb.conf, conf, sizeof(*conf)); -} - - -void ast_jb_get_config(const struct ast_channel *chan, struct ast_jb_conf *conf) -{ - memcpy(conf, &chan->jb.conf, sizeof(*conf)); -} - - -/* Implementation functions */ - -/* fixed */ - -static void * jb_create_fixed(struct ast_jb_conf *general_config, long resynch_threshold) -{ - struct fixed_jb_conf conf; - - conf.jbsize = general_config->max_size; - conf.resync_threshold = resynch_threshold; - - return fixed_jb_new(&conf); -} - - -static void jb_destroy_fixed(void *jb) -{ - struct fixed_jb *fixedjb = (struct fixed_jb *) jb; - - /* destroy the jb */ - fixed_jb_destroy(fixedjb); -} - - -static int jb_put_first_fixed(void *jb, struct ast_frame *fin, long now) -{ - struct fixed_jb *fixedjb = (struct fixed_jb *) jb; - int res; - - res = fixed_jb_put_first(fixedjb, fin, fin->len, fin->ts, now); - - return fixed_to_abstract_code[res]; -} - - -static int jb_put_fixed(void *jb, struct ast_frame *fin, long now) -{ - struct fixed_jb *fixedjb = (struct fixed_jb *) jb; - int res; - - res = fixed_jb_put(fixedjb, fin, fin->len, fin->ts, now); - - return fixed_to_abstract_code[res]; -} - - -static int jb_get_fixed(void *jb, struct ast_frame **fout, long now, long interpl) -{ - struct fixed_jb *fixedjb = (struct fixed_jb *) jb; - struct fixed_jb_frame frame; - int res; - - res = fixed_jb_get(fixedjb, &frame, now, interpl); - *fout = frame.data; - - return fixed_to_abstract_code[res]; -} - - -static long jb_next_fixed(void *jb) -{ - struct fixed_jb *fixedjb = (struct fixed_jb *) jb; - - return fixed_jb_next(fixedjb); -} - - -static int jb_remove_fixed(void *jb, struct ast_frame **fout) -{ - struct fixed_jb *fixedjb = (struct fixed_jb *) jb; - struct fixed_jb_frame frame; - int res; - - res = fixed_jb_remove(fixedjb, &frame); - *fout = frame.data; - - return fixed_to_abstract_code[res]; -} - - -static void jb_force_resynch_fixed(void *jb) -{ - struct fixed_jb *fixedjb = (struct fixed_jb *) jb; - - fixed_jb_set_force_resynch(fixedjb); -} - - -/* adaptive */ - -static void *jb_create_adaptive(struct ast_jb_conf *general_config, long resynch_threshold) -{ - jb_conf jbconf; - jitterbuf *adaptivejb; - - adaptivejb = jb_new(); - if (adaptivejb) { - jbconf.max_jitterbuf = general_config->max_size; - jbconf.resync_threshold = general_config->resync_threshold; - jbconf.max_contig_interp = 10; - jb_setconf(adaptivejb, &jbconf); - } - - return adaptivejb; -} - - -static void jb_destroy_adaptive(void *jb) -{ - jitterbuf *adaptivejb = (jitterbuf *) jb; - - jb_destroy(adaptivejb); -} - - -static int jb_put_first_adaptive(void *jb, struct ast_frame *fin, long now) -{ - return jb_put_adaptive(jb, fin, now); -} - - -static int jb_put_adaptive(void *jb, struct ast_frame *fin, long now) -{ - jitterbuf *adaptivejb = (jitterbuf *) jb; - int res; - - res = jb_put(adaptivejb, fin, JB_TYPE_VOICE, fin->len, fin->ts, now); - - return adaptive_to_abstract_code[res]; -} - - -static int jb_get_adaptive(void *jb, struct ast_frame **fout, long now, long interpl) -{ - jitterbuf *adaptivejb = (jitterbuf *) jb; - jb_frame frame; - int res; - - res = jb_get(adaptivejb, &frame, now, interpl); - *fout = frame.data; - - return adaptive_to_abstract_code[res]; -} - - -static long jb_next_adaptive(void *jb) -{ - jitterbuf *adaptivejb = (jitterbuf *) jb; - - return jb_next(adaptivejb); -} - - -static int jb_remove_adaptive(void *jb, struct ast_frame **fout) -{ - jitterbuf *adaptivejb = (jitterbuf *) jb; - jb_frame frame; - int res; - - res = jb_getall(adaptivejb, &frame); - *fout = frame.data; - - return adaptive_to_abstract_code[res]; -} - - -static void jb_force_resynch_adaptive(void *jb) -{ -} diff --git a/acinclude.m4 b/acinclude.m4 index 34eefe82b..1bd093703 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1,3 +1,16 @@ +# AST_GCC_ATTRIBUTE([attribute name]) + +AC_DEFUN([AST_GCC_ATTRIBUTE], +[ +AC_MSG_CHECKING(checking for compiler 'attribute $1' support) +AC_COMPILE_IFELSE( + AC_LANG_PROGRAM([static int __attribute__(($1)) test(void) {}], + []), + AC_MSG_RESULT(yes) + AC_DEFINE_UNQUOTED([HAVE_ATTRIBUTE_$1], 1, [Define to 1 if your GCC C compiler supports the '$1' attribute.]), + AC_MSG_RESULT(no)) +]) + # AST_EXT_LIB_SETUP([package symbol name], [package friendly name], [package option name], [additional help text]) AC_DEFUN([AST_EXT_LIB_SETUP], diff --git a/acl.c b/acl.c deleted file mode 100644 index f3fd5097a..000000000 --- a/acl.c +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Asterisk -- An open source telephony toolkit. - * - * Copyright (C) 1999 - 2006, Digium, Inc. - * - * Mark Spencer - * - * 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 Various sorts of access control - * - * \author Mark Spencer - */ - -#include "asterisk.h" - -ASTERISK_FILE_VERSION(__FILE__, "$Revision$") - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) -#include -#include -#endif - -#if defined(SOLARIS) -#include -#endif - -/* netinet/ip.h may not define the following (See RFCs 791 and 1349) */ -#if !defined(IPTOS_LOWCOST) -#define IPTOS_LOWCOST 0x02 -#endif - -#if !defined(IPTOS_MINCOST) -#define IPTOS_MINCOST IPTOS_LOWCOST -#endif - -#include "asterisk/acl.h" -#include "asterisk/logger.h" -#include "asterisk/channel.h" -#include "asterisk/options.h" -#include "asterisk/utils.h" -#include "asterisk/lock.h" -#include "asterisk/srv.h" - -struct ast_ha { - /* Host access rule */ - struct in_addr netaddr; - struct in_addr netmask; - int sense; - struct ast_ha *next; -}; - -/* Default IP - if not otherwise set, don't breathe garbage */ -static struct in_addr __ourip = { 0x00000000 }; - -struct my_ifreq { - char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "eth0", "ppp0", etc. */ - struct sockaddr_in ifru_addr; -}; - -/* Free HA structure */ -void ast_free_ha(struct ast_ha *ha) -{ - struct ast_ha *hal; - while (ha) { - hal = ha; - ha = ha->next; - free(hal); - } -} - -/* Copy HA structure */ -static void ast_copy_ha(struct ast_ha *from, struct ast_ha *to) -{ - memcpy(&to->netaddr, &from->netaddr, sizeof(from->netaddr)); - memcpy(&to->netmask, &from->netmask, sizeof(from->netmask)); - to->sense = from->sense; -} - -/* Create duplicate of ha structure */ -static struct ast_ha *ast_duplicate_ha(struct ast_ha *original) -{ - struct ast_ha *new_ha; - - if ((new_ha = ast_malloc(sizeof(*new_ha)))) { - /* Copy from original to new object */ - ast_copy_ha(original, new_ha); - } - - return new_ha; -} - -/* Create duplicate HA link list */ -/* Used in chan_sip2 templates */ -struct ast_ha *ast_duplicate_ha_list(struct ast_ha *original) -{ - struct ast_ha *start = original; - struct ast_ha *ret = NULL; - struct ast_ha *link, *prev = NULL; - - while (start) { - link = ast_duplicate_ha(start); /* Create copy of this object */ - if (prev) - prev->next = link; /* Link previous to this object */ - - if (!ret) - ret = link; /* Save starting point */ - - start = start->next; /* Go to next object */ - prev = link; /* Save pointer to this object */ - } - return ret; /* Return start of list */ -} - -struct ast_ha *ast_append_ha(char *sense, char *stuff, struct ast_ha *path) -{ - struct ast_ha *ha; - char *nm = "255.255.255.255"; - char tmp[256]; - struct ast_ha *prev = NULL; - struct ast_ha *ret; - int x, z; - unsigned int y; - - ret = path; - while (path) { - prev = path; - path = path->next; - } - if ((ha = ast_malloc(sizeof(*ha)))) { - ast_copy_string(tmp, stuff, sizeof(tmp)); - nm = strchr(tmp, '/'); - if (!nm) { - nm = "255.255.255.255"; - } else { - *nm = '\0'; - nm++; - } - if (!strchr(nm, '.')) { - if ((sscanf(nm, "%d", &x) == 1) && (x >= 0) && (x <= 32)) { - y = 0; - for (z = 0; z < x; z++) { - y >>= 1; - y |= 0x80000000; - } - ha->netmask.s_addr = htonl(y); - } - } else if (!inet_aton(nm, &ha->netmask)) { - ast_log(LOG_WARNING, "%s is not a valid netmask\n", nm); - free(ha); - return path; - } - if (!inet_aton(tmp, &ha->netaddr)) { - ast_log(LOG_WARNING, "%s is not a valid IP\n", tmp); - free(ha); - return path; - } - ha->netaddr.s_addr &= ha->netmask.s_addr; - if (!strncasecmp(sense, "p", 1)) { - ha->sense = AST_SENSE_ALLOW; - } else { - ha->sense = AST_SENSE_DENY; - } - ha->next = NULL; - if (prev) { - prev->next = ha; - } else { - ret = ha; - } - } - ast_log(LOG_DEBUG, "%s/%s appended to acl for peer\n", stuff, nm); - return ret; -} - -int ast_apply_ha(struct ast_ha *ha, struct sockaddr_in *sin) -{ - /* Start optimistic */ - int res = AST_SENSE_ALLOW; - while (ha) { - char iabuf[INET_ADDRSTRLEN]; - char iabuf2[INET_ADDRSTRLEN]; - /* DEBUG */ - ast_copy_string(iabuf, ast_inet_ntoa(sin->sin_addr), sizeof(iabuf)); - ast_copy_string(iabuf2, ast_inet_ntoa(ha->netaddr), sizeof(iabuf2)); - ast_log(LOG_DEBUG, "##### Testing %s with %s\n", iabuf, iabuf2); - /* For each rule, if this address and the netmask = the net address - apply the current rule */ - if ((sin->sin_addr.s_addr & ha->netmask.s_addr) == ha->netaddr.s_addr) - res = ha->sense; - ha = ha->next; - } - return res; -} - -int ast_get_ip_or_srv(struct sockaddr_in *sin, const char *value, const char *service) -{ - struct hostent *hp; - struct ast_hostent ahp; - char srv[256]; - char host[256]; - int tportno = ntohs(sin->sin_port); - if (inet_aton(value, &sin->sin_addr)) - return 0; - if (service) { - snprintf(srv, sizeof(srv), "%s.%s", service, value); - if (ast_get_srv(NULL, host, sizeof(host), &tportno, srv) > 0) { - sin->sin_port = htons(tportno); - value = host; - } - } - hp = ast_gethostbyname(value, &ahp); - if (hp) { - memcpy(&sin->sin_addr, hp->h_addr, sizeof(sin->sin_addr)); - } else { - ast_log(LOG_WARNING, "Unable to lookup '%s'\n", value); - return -1; - } - return 0; -} - -struct dscp_codepoint { - char *name; - unsigned int space; -}; - -/* IANA registered DSCP codepoints */ - -static const struct dscp_codepoint dscp_pool1[] = { - { "CS0", 0x00 }, - { "CS1", 0x08 }, - { "CS2", 0x10 }, - { "CS3", 0x18 }, - { "CS4", 0x20 }, - { "CS5", 0x28 }, - { "CS6", 0x30 }, - { "CS7", 0x38 }, - { "AF11", 0x0A }, - { "AF12", 0x0C }, - { "AF13", 0x0E }, - { "AF21", 0x12 }, - { "AF22", 0x14 }, - { "AF23", 0x16 }, - { "AF31", 0x1A }, - { "AF32", 0x1C }, - { "AF33", 0x1E }, - { "AF41", 0x22 }, - { "AF42", 0x24 }, - { "AF43", 0x26 }, - { "EF", 0x2E }, -}; - -int ast_str2tos(const char *value, unsigned int *tos) -{ - int fval; - unsigned int x; - - if (sscanf(value, "%i", &fval) == 1) { - *tos = fval & 0xFF; - return 0; - } - - for (x = 0; x < sizeof(dscp_pool1) / sizeof(dscp_pool1[0]); x++) { - if (!strcasecmp(value, dscp_pool1[x].name)) { - *tos = dscp_pool1[x].space << 2; - return 0; - } - } - - if (!strcasecmp(value, "lowdelay")) - *tos = IPTOS_LOWDELAY; - else if (!strcasecmp(value, "throughput")) - *tos = IPTOS_THROUGHPUT; - else if (!strcasecmp(value, "reliability")) - *tos = IPTOS_RELIABILITY; - else if (!strcasecmp(value, "mincost")) - *tos = IPTOS_MINCOST; - else if (!strcasecmp(value, "none")) - *tos = 0; - else - return -1; - - ast_log(LOG_WARNING, "TOS value %s is deprecated. Please see doc/ip-tos.txt for more information.\n", value); - - return 0; -} - -const char *ast_tos2str(unsigned int tos) -{ - unsigned int x; - - switch (tos) { - case 0: - return "none"; - case IPTOS_LOWDELAY: - return "lowdelay"; - case IPTOS_THROUGHPUT: - return "throughput"; - case IPTOS_RELIABILITY: - return "reliability"; - case IPTOS_MINCOST: - return "mincost"; - default: - for (x = 0; x < sizeof(dscp_pool1) / sizeof(dscp_pool1[0]); x++) { - if (dscp_pool1[x].space == (tos >> 2)) - return dscp_pool1[x].name; - } - } - - return "unknown"; -} - -int ast_get_ip(struct sockaddr_in *sin, const char *value) -{ - return ast_get_ip_or_srv(sin, value, NULL); -} - -/* iface is the interface (e.g. eth0); address is the return value */ -int ast_lookup_iface(char *iface, struct in_addr *address) -{ - int mysock, res = 0; - struct my_ifreq ifreq; - - memset(&ifreq, 0, sizeof(ifreq)); - ast_copy_string(ifreq.ifrn_name, iface, sizeof(ifreq.ifrn_name)); - - mysock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); - res = ioctl(mysock, SIOCGIFADDR, &ifreq); - - close(mysock); - if (res < 0) { - ast_log(LOG_WARNING, "Unable to get IP of %s: %s\n", iface, strerror(errno)); - memcpy((char *)address, (char *)&__ourip, sizeof(__ourip)); - return -1; - } else { - memcpy((char *)address, (char *)&ifreq.ifru_addr.sin_addr, sizeof(ifreq.ifru_addr.sin_addr)); - return 0; - } -} - -int ast_ouraddrfor(struct in_addr *them, struct in_addr *us) -{ - int s; - struct sockaddr_in sin; - socklen_t slen; - - s = socket(PF_INET, SOCK_DGRAM, 0); - if (s < 0) { - ast_log(LOG_WARNING, "Cannot create socket\n"); - return -1; - } - sin.sin_family = AF_INET; - sin.sin_port = 5060; - sin.sin_addr = *them; - if (connect(s, (struct sockaddr *)&sin, sizeof(sin))) { - ast_log(LOG_WARNING, "Cannot connect\n"); - close(s); - return -1; - } - slen = sizeof(sin); - if (getsockname(s, (struct sockaddr *)&sin, &slen)) { - ast_log(LOG_WARNING, "Cannot get socket name\n"); - close(s); - return -1; - } - close(s); - *us = sin.sin_addr; - return 0; -} - -int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr) -{ - char ourhost[MAXHOSTNAMELEN] = ""; - struct ast_hostent ahp; - struct hostent *hp; - struct in_addr saddr; - - /* just use the bind address if it is nonzero */ - if (ntohl(bindaddr.sin_addr.s_addr)) { - memcpy(ourip, &bindaddr.sin_addr, sizeof(*ourip)); - return 0; - } - /* try to use our hostname */ - if (gethostname(ourhost, sizeof(ourhost) - 1)) { - ast_log(LOG_WARNING, "Unable to get hostname\n"); - } else { - hp = ast_gethostbyname(ourhost, &ahp); - if (hp) { - memcpy(ourip, hp->h_addr, sizeof(*ourip)); - return 0; - } - } - /* A.ROOT-SERVERS.NET. */ - if (inet_aton("198.41.0.4", &saddr) && !ast_ouraddrfor(&saddr, ourip)) - return 0; - return -1; -} - diff --git a/aescrypt.c b/aescrypt.c deleted file mode 100644 index 1ccddf3f5..000000000 --- a/aescrypt.c +++ /dev/null @@ -1,317 +0,0 @@ -/* - --------------------------------------------------------------------------- - Copyright (c) 2003, Dr Brian Gladman , Worcester, UK. - All rights reserved. - - LICENSE TERMS - - The free distribution and use of this software in both source and binary - form is allowed (with or without changes) provided that: - - 1. distributions of this source code include the above copyright - notice, this list of conditions and the following disclaimer; - - 2. distributions in binary form include the above copyright - notice, this list of conditions and the following disclaimer - in the documentation and/or other associated materials; - - 3. the copyright holder's name is not used to endorse products - built using this software without specific written permission. - - ALTERNATIVELY, provided that this notice is retained in full, this product - may be distributed under the terms of the GNU General Public License (GPL), - in which case the provisions of the GPL apply INSTEAD OF those given above. - - DISCLAIMER - - This software is provided 'as is' with no explicit or implied warranties - in respect of its properties, including, but not limited to, correctness - and/or fitness for purpose. - --------------------------------------------------------------------------- - Issue Date: 26/08/2003 - -*/ - -/*! \file - * - * \brief This file contains the code for implementing encryption and decryption - * for AES (Rijndael) for block and key sizes of 16, 24 and 32 bytes. It - * can optionally be replaced by code written in assembler using NASM. For - * further details see the file aesopt.h - * - * \author Dr Brian Gladman - */ - -#include "aesopt.h" - -#if defined(__cplusplus) -extern "C" -{ -#endif - -#define si(y,x,k,c) (s(y,c) = word_in(x, c) ^ (k)[c]) -#define so(y,x,c) word_out(y, c, s(x,c)) - -#if defined(ARRAYS) -#define locals(y,x) x[4],y[4] -#else -#define locals(y,x) x##0,x##1,x##2,x##3,y##0,y##1,y##2,y##3 -#endif - -#define l_copy(y, x) s(y,0) = s(x,0); s(y,1) = s(x,1); \ - s(y,2) = s(x,2); s(y,3) = s(x,3); -#define state_in(y,x,k) si(y,x,k,0); si(y,x,k,1); si(y,x,k,2); si(y,x,k,3) -#define state_out(y,x) so(y,x,0); so(y,x,1); so(y,x,2); so(y,x,3) -#define round(rm,y,x,k) rm(y,x,k,0); rm(y,x,k,1); rm(y,x,k,2); rm(y,x,k,3) - -#if defined(ENCRYPTION) && !defined(AES_ASM) - -/* Visual C++ .Net v7.1 provides the fastest encryption code when using - Pentium optimiation with small code but this is poor for decryption - so we need to control this with the following VC++ pragmas -*/ - -#if defined(_MSC_VER) -#pragma optimize( "s", on ) -#endif - -/* Given the column (c) of the output state variable, the following - macros give the input state variables which are needed in its - computation for each row (r) of the state. All the alternative - macros give the same end values but expand into different ways - of calculating these values. In particular the complex macro - used for dynamically variable block sizes is designed to expand - to a compile time constant whenever possible but will expand to - conditional clauses on some branches (I am grateful to Frank - Yellin for this construction) -*/ - -#define fwd_var(x,r,c)\ - ( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\ - : r == 1 ? ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))\ - : r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\ - : ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2))) - -#if defined(FT4_SET) -#undef dec_fmvars -#define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(f,n),fwd_var,rf1,c)) -#elif defined(FT1_SET) -#undef dec_fmvars -#define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,upr,t_use(f,n),fwd_var,rf1,c)) -#else -#define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ fwd_mcol(no_table(x,t_use(s,box),fwd_var,rf1,c))) -#endif - -#if defined(FL4_SET) -#define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(f,l),fwd_var,rf1,c)) -#elif defined(FL1_SET) -#define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,ups,t_use(f,l),fwd_var,rf1,c)) -#else -#define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ no_table(x,t_use(s,box),fwd_var,rf1,c)) -#endif - -aes_rval aes_encrypt(const void *in_blk, void *out_blk, const aes_encrypt_ctx cx[1]) -{ aes_32t locals(b0, b1); - const aes_32t *kp = cx->ks; -#ifdef dec_fmvars - dec_fmvars; /* declare variables for fwd_mcol() if needed */ -#endif - - aes_32t nr = (kp[45] ^ kp[52] ^ kp[53] ? kp[52] : 14); - -#ifdef AES_ERR_CHK - if( (nr != 10 || !(kp[0] | kp[3] | kp[4])) - && (nr != 12 || !(kp[0] | kp[5] | kp[6])) - && (nr != 14 || !(kp[0] | kp[7] | kp[8])) ) - return aes_error; -#endif - - state_in(b0, in_blk, kp); - -#if (ENC_UNROLL == FULL) - - switch(nr) - { - case 14: - round(fwd_rnd, b1, b0, kp + 1 * N_COLS); - round(fwd_rnd, b0, b1, kp + 2 * N_COLS); - kp += 2 * N_COLS; - case 12: - round(fwd_rnd, b1, b0, kp + 1 * N_COLS); - round(fwd_rnd, b0, b1, kp + 2 * N_COLS); - kp += 2 * N_COLS; - case 10: - round(fwd_rnd, b1, b0, kp + 1 * N_COLS); - round(fwd_rnd, b0, b1, kp + 2 * N_COLS); - round(fwd_rnd, b1, b0, kp + 3 * N_COLS); - round(fwd_rnd, b0, b1, kp + 4 * N_COLS); - round(fwd_rnd, b1, b0, kp + 5 * N_COLS); - round(fwd_rnd, b0, b1, kp + 6 * N_COLS); - round(fwd_rnd, b1, b0, kp + 7 * N_COLS); - round(fwd_rnd, b0, b1, kp + 8 * N_COLS); - round(fwd_rnd, b1, b0, kp + 9 * N_COLS); - round(fwd_lrnd, b0, b1, kp +10 * N_COLS); - } - -#else - -#if (ENC_UNROLL == PARTIAL) - { aes_32t rnd; - for(rnd = 0; rnd < (nr >> 1) - 1; ++rnd) - { - kp += N_COLS; - round(fwd_rnd, b1, b0, kp); - kp += N_COLS; - round(fwd_rnd, b0, b1, kp); - } - kp += N_COLS; - round(fwd_rnd, b1, b0, kp); -#else - { aes_32t rnd; - for(rnd = 0; rnd < nr - 1; ++rnd) - { - kp += N_COLS; - round(fwd_rnd, b1, b0, kp); - l_copy(b0, b1); - } -#endif - kp += N_COLS; - round(fwd_lrnd, b0, b1, kp); - } -#endif - - state_out(out_blk, b0); -#ifdef AES_ERR_CHK - return aes_good; -#endif -} - -#endif - -#if defined(DECRYPTION) && !defined(AES_ASM) - -/* Visual C++ .Net v7.1 provides the fastest encryption code when using - Pentium optimiation with small code but this is poor for decryption - so we need to control this with the following VC++ pragmas -*/ - -#if defined(_MSC_VER) -#pragma optimize( "t", on ) -#endif - -/* Given the column (c) of the output state variable, the following - macros give the input state variables which are needed in its - computation for each row (r) of the state. All the alternative - macros give the same end values but expand into different ways - of calculating these values. In particular the complex macro - used for dynamically variable block sizes is designed to expand - to a compile time constant whenever possible but will expand to - conditional clauses on some branches (I am grateful to Frank - Yellin for this construction) -*/ - -#define inv_var(x,r,c)\ - ( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\ - : r == 1 ? ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2))\ - : r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\ - : ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))) - -#if defined(IT4_SET) -#undef dec_imvars -#define inv_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(i,n),inv_var,rf1,c)) -#elif defined(IT1_SET) -#undef dec_imvars -#define inv_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,upr,t_use(i,n),inv_var,rf1,c)) -#else -#define inv_rnd(y,x,k,c) (s(y,c) = inv_mcol((k)[c] ^ no_table(x,t_use(i,box),inv_var,rf1,c))) -#endif - -#if defined(IL4_SET) -#define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(i,l),inv_var,rf1,c)) -#elif defined(IL1_SET) -#define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,ups,t_use(i,l),inv_var,rf1,c)) -#else -#define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ no_table(x,t_use(i,box),inv_var,rf1,c)) -#endif - -aes_rval aes_decrypt(const void *in_blk, void *out_blk, const aes_decrypt_ctx cx[1]) -{ aes_32t locals(b0, b1); -#ifdef dec_imvars - dec_imvars; /* declare variables for inv_mcol() if needed */ -#endif - - aes_32t nr = (cx->ks[45] ^ cx->ks[52] ^ cx->ks[53] ? cx->ks[52] : 14); - const aes_32t *kp = cx->ks + nr * N_COLS; - -#ifdef AES_ERR_CHK - if( (nr != 10 || !(cx->ks[0] | cx->ks[3] | cx->ks[4])) - && (nr != 12 || !(cx->ks[0] | cx->ks[5] | cx->ks[6])) - && (nr != 14 || !(cx->ks[0] | cx->ks[7] | cx->ks[8])) ) - return aes_error; -#endif - - state_in(b0, in_blk, kp); - -#if (DEC_UNROLL == FULL) - - switch(nr) - { - case 14: - round(inv_rnd, b1, b0, kp - 1 * N_COLS); - round(inv_rnd, b0, b1, kp - 2 * N_COLS); - kp -= 2 * N_COLS; - case 12: - round(inv_rnd, b1, b0, kp - 1 * N_COLS); - round(inv_rnd, b0, b1, kp - 2 * N_COLS); - kp -= 2 * N_COLS; - case 10: - round(inv_rnd, b1, b0, kp - 1 * N_COLS); - round(inv_rnd, b0, b1, kp - 2 * N_COLS); - round(inv_rnd, b1, b0, kp - 3 * N_COLS); - round(inv_rnd, b0, b1, kp - 4 * N_COLS); - round(inv_rnd, b1, b0, kp - 5 * N_COLS); - round(inv_rnd, b0, b1, kp - 6 * N_COLS); - round(inv_rnd, b1, b0, kp - 7 * N_COLS); - round(inv_rnd, b0, b1, kp - 8 * N_COLS); - round(inv_rnd, b1, b0, kp - 9 * N_COLS); - round(inv_lrnd, b0, b1, kp - 10 * N_COLS); - } - -#else - -#if (DEC_UNROLL == PARTIAL) - { aes_32t rnd; - for(rnd = 0; rnd < (nr >> 1) - 1; ++rnd) - { - kp -= N_COLS; - round(inv_rnd, b1, b0, kp); - kp -= N_COLS; - round(inv_rnd, b0, b1, kp); - } - kp -= N_COLS; - round(inv_rnd, b1, b0, kp); -#else - { aes_32t rnd; - for(rnd = 0; rnd < nr - 1; ++rnd) - { - kp -= N_COLS; - round(inv_rnd, b1, b0, kp); - l_copy(b0, b1); - } -#endif - kp -= N_COLS; - round(inv_lrnd, b0, b1, kp); - } -#endif - - state_out(out_blk, b0); -#ifdef AES_ERR_CHK - return aes_good; -#endif -} - -#endif - -#if defined(__cplusplus) -} -#endif diff --git a/aeskey.c b/aeskey.c deleted file mode 100644 index d34badc6b..000000000 --- a/aeskey.c +++ /dev/null @@ -1,469 +0,0 @@ -/* - --------------------------------------------------------------------------- - Copyright (c) 2003, Dr Brian Gladman , Worcester, UK. - All rights reserved. - - LICENSE TERMS - - The free distribution and use of this software in both source and binary - form is allowed (with or without changes) provided that: - - 1. distributions of this source code include the above copyright - notice, this list of conditions and the following disclaimer; - - 2. distributions in binary form include the above copyright - notice, this list of conditions and the following disclaimer - in the documentation and/or other associated materials; - - 3. the copyright holder's name is not used to endorse products - built using this software without specific written permission. - - ALTERNATIVELY, provided that this notice is retained in full, this product - may be distributed under the terms of the GNU General Public License (GPL), - in which case the provisions of the GPL apply INSTEAD OF those given above. - - DISCLAIMER - - This software is provided 'as is' with no explicit or implied warranties - in respect of its properties, including, but not limited to, correctness - and/or fitness for purpose. - --------------------------------------------------------------------------- - Issue Date: 26/08/2003 - -*/ - -/*! \file - * - * \brief This file contains the code for implementing the key schedule for AES - * (Rijndael) for block and key sizes of 16, 24, and 32 bytes. See aesopt.h - * for further details including optimisation. - * - * \author Dr Brian Gladman - */ - -#include "aesopt.h" - -#if defined(__cplusplus) -extern "C" -{ -#endif - -/* Initialise the key schedule from the user supplied key. The key - length can be specified in bytes, with legal values of 16, 24 - and 32, or in bits, with legal values of 128, 192 and 256. These - values correspond with Nk values of 4, 6 and 8 respectively. - - The following macros implement a single cycle in the key - schedule generation process. The number of cycles needed - for each cx->n_col and nk value is: - - nk = 4 5 6 7 8 - ------------------------------ - cx->n_col = 4 10 9 8 7 7 - cx->n_col = 5 14 11 10 9 9 - cx->n_col = 6 19 15 12 11 11 - cx->n_col = 7 21 19 16 13 14 - cx->n_col = 8 29 23 19 17 14 -*/ - -#define ke4(k,i) \ -{ k[4*(i)+4] = ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+5] = ss[1] ^= ss[0]; \ - k[4*(i)+6] = ss[2] ^= ss[1]; k[4*(i)+7] = ss[3] ^= ss[2]; \ -} -#define kel4(k,i) \ -{ k[4*(i)+4] = ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+5] = ss[1] ^= ss[0]; \ - k[4*(i)+6] = ss[2] ^= ss[1]; k[4*(i)+7] = ss[3] ^= ss[2]; \ -} - -#define ke6(k,i) \ -{ k[6*(i)+ 6] = ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 7] = ss[1] ^= ss[0]; \ - k[6*(i)+ 8] = ss[2] ^= ss[1]; k[6*(i)+ 9] = ss[3] ^= ss[2]; \ - k[6*(i)+10] = ss[4] ^= ss[3]; k[6*(i)+11] = ss[5] ^= ss[4]; \ -} -#define kel6(k,i) \ -{ k[6*(i)+ 6] = ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 7] = ss[1] ^= ss[0]; \ - k[6*(i)+ 8] = ss[2] ^= ss[1]; k[6*(i)+ 9] = ss[3] ^= ss[2]; \ -} - -#define ke8(k,i) \ -{ k[8*(i)+ 8] = ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 9] = ss[1] ^= ss[0]; \ - k[8*(i)+10] = ss[2] ^= ss[1]; k[8*(i)+11] = ss[3] ^= ss[2]; \ - k[8*(i)+12] = ss[4] ^= ls_box(ss[3],0); k[8*(i)+13] = ss[5] ^= ss[4]; \ - k[8*(i)+14] = ss[6] ^= ss[5]; k[8*(i)+15] = ss[7] ^= ss[6]; \ -} -#define kel8(k,i) \ -{ k[8*(i)+ 8] = ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 9] = ss[1] ^= ss[0]; \ - k[8*(i)+10] = ss[2] ^= ss[1]; k[8*(i)+11] = ss[3] ^= ss[2]; \ -} - -#if defined(ENCRYPTION_KEY_SCHEDULE) - -#if defined(AES_128) || defined(AES_VAR) - -aes_rval aes_encrypt_key128(const void *in_key, aes_encrypt_ctx cx[1]) -{ aes_32t ss[4]; - - cx->ks[0] = ss[0] = word_in(in_key, 0); - cx->ks[1] = ss[1] = word_in(in_key, 1); - cx->ks[2] = ss[2] = word_in(in_key, 2); - cx->ks[3] = ss[3] = word_in(in_key, 3); - -#if ENC_UNROLL == NONE - { aes_32t i; - - for(i = 0; i < ((11 * N_COLS - 1) / 4); ++i) - ke4(cx->ks, i); - } -#else - ke4(cx->ks, 0); ke4(cx->ks, 1); - ke4(cx->ks, 2); ke4(cx->ks, 3); - ke4(cx->ks, 4); ke4(cx->ks, 5); - ke4(cx->ks, 6); ke4(cx->ks, 7); - ke4(cx->ks, 8); kel4(cx->ks, 9); -#endif - - /* cx->ks[45] ^ cx->ks[52] ^ cx->ks[53] is zero for a 256 bit */ - /* key and must be non-zero for 128 and 192 bits keys */ - cx->ks[53] = cx->ks[45] = 0; - cx->ks[52] = 10; -#ifdef AES_ERR_CHK - return aes_good; -#endif -} - -#endif - -#if defined(AES_192) || defined(AES_VAR) - -aes_rval aes_encrypt_key192(const void *in_key, aes_encrypt_ctx cx[1]) -{ aes_32t ss[6]; - - cx->ks[0] = ss[0] = word_in(in_key, 0); - cx->ks[1] = ss[1] = word_in(in_key, 1); - cx->ks[2] = ss[2] = word_in(in_key, 2); - cx->ks[3] = ss[3] = word_in(in_key, 3); - cx->ks[4] = ss[4] = word_in(in_key, 4); - cx->ks[5] = ss[5] = word_in(in_key, 5); - -#if ENC_UNROLL == NONE - { aes_32t i; - - for(i = 0; i < (13 * N_COLS - 1) / 6; ++i) - ke6(cx->ks, i); - } -#else - ke6(cx->ks, 0); ke6(cx->ks, 1); - ke6(cx->ks, 2); ke6(cx->ks, 3); - ke6(cx->ks, 4); ke6(cx->ks, 5); - ke6(cx->ks, 6); kel6(cx->ks, 7); -#endif - - /* cx->ks[45] ^ cx->ks[52] ^ cx->ks[53] is zero for a 256 bit */ - /* key and must be non-zero for 128 and 192 bits keys */ - cx->ks[53] = cx->ks[45]; - cx->ks[52] = 12; -#ifdef AES_ERR_CHK - return aes_good; -#endif -} - -#endif - -#if defined(AES_256) || defined(AES_VAR) - -aes_rval aes_encrypt_key256(const void *in_key, aes_encrypt_ctx cx[1]) -{ aes_32t ss[8]; - - cx->ks[0] = ss[0] = word_in(in_key, 0); - cx->ks[1] = ss[1] = word_in(in_key, 1); - cx->ks[2] = ss[2] = word_in(in_key, 2); - cx->ks[3] = ss[3] = word_in(in_key, 3); - cx->ks[4] = ss[4] = word_in(in_key, 4); - cx->ks[5] = ss[5] = word_in(in_key, 5); - cx->ks[6] = ss[6] = word_in(in_key, 6); - cx->ks[7] = ss[7] = word_in(in_key, 7); - -#if ENC_UNROLL == NONE - { aes_32t i; - - for(i = 0; i < (15 * N_COLS - 1) / 8; ++i) - ke8(cx->ks, i); - } -#else - ke8(cx->ks, 0); ke8(cx->ks, 1); - ke8(cx->ks, 2); ke8(cx->ks, 3); - ke8(cx->ks, 4); ke8(cx->ks, 5); - kel8(cx->ks, 6); -#endif -#ifdef AES_ERR_CHK - return aes_good; -#endif -} - -#endif - -#if defined(AES_VAR) - -aes_rval aes_encrypt_key(const void *in_key, int key_len, aes_encrypt_ctx cx[1]) -{ - switch(key_len) - { -#ifdef AES_ERR_CHK - case 16: case 128: return aes_encrypt_key128(in_key, cx); - case 24: case 192: return aes_encrypt_key192(in_key, cx); - case 32: case 256: return aes_encrypt_key256(in_key, cx); - default: return aes_error; -#else - case 16: case 128: aes_encrypt_key128(in_key, cx); return; - case 24: case 192: aes_encrypt_key192(in_key, cx); return; - case 32: case 256: aes_encrypt_key256(in_key, cx); return; -#endif - } -} - -#endif - -#endif - -#if defined(DECRYPTION_KEY_SCHEDULE) - -#if DEC_ROUND == NO_TABLES -#define ff(x) (x) -#else -#define ff(x) inv_mcol(x) -#ifdef dec_imvars -#define d_vars dec_imvars -#endif -#endif - -#if 1 -#define kdf4(k,i) \ -{ ss[0] = ss[0] ^ ss[2] ^ ss[1] ^ ss[3]; ss[1] = ss[1] ^ ss[3]; ss[2] = ss[2] ^ ss[3]; ss[3] = ss[3]; \ - ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; \ - ss[4] ^= k[4*(i)]; k[4*(i)+4] = ff(ss[4]); ss[4] ^= k[4*(i)+1]; k[4*(i)+5] = ff(ss[4]); \ - ss[4] ^= k[4*(i)+2]; k[4*(i)+6] = ff(ss[4]); ss[4] ^= k[4*(i)+3]; k[4*(i)+7] = ff(ss[4]); \ -} -#define kd4(k,i) \ -{ ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; ss[4] = ff(ss[4]); \ - k[4*(i)+4] = ss[4] ^= k[4*(i)]; k[4*(i)+5] = ss[4] ^= k[4*(i)+1]; \ - k[4*(i)+6] = ss[4] ^= k[4*(i)+2]; k[4*(i)+7] = ss[4] ^= k[4*(i)+3]; \ -} -#define kdl4(k,i) \ -{ ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; \ - k[4*(i)+4] = (ss[0] ^= ss[1]) ^ ss[2] ^ ss[3]; k[4*(i)+5] = ss[1] ^ ss[3]; \ - k[4*(i)+6] = ss[0]; k[4*(i)+7] = ss[1]; \ -} -#else -#define kdf4(k,i) \ -{ ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+ 4] = ff(ss[0]); ss[1] ^= ss[0]; k[4*(i)+ 5] = ff(ss[1]); \ - ss[2] ^= ss[1]; k[4*(i)+ 6] = ff(ss[2]); ss[3] ^= ss[2]; k[4*(i)+ 7] = ff(ss[3]); \ -} -#define kd4(k,i) \ -{ ss[4] = ls_box(ss[3],3) ^ t_use(r,c)[i]; \ - ss[0] ^= ss[4]; ss[4] = ff(ss[4]); k[4*(i)+ 4] = ss[4] ^= k[4*(i)]; \ - ss[1] ^= ss[0]; k[4*(i)+ 5] = ss[4] ^= k[4*(i)+ 1]; \ - ss[2] ^= ss[1]; k[4*(i)+ 6] = ss[4] ^= k[4*(i)+ 2]; \ - ss[3] ^= ss[2]; k[4*(i)+ 7] = ss[4] ^= k[4*(i)+ 3]; \ -} -#define kdl4(k,i) \ -{ ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+ 4] = ss[0]; ss[1] ^= ss[0]; k[4*(i)+ 5] = ss[1]; \ - ss[2] ^= ss[1]; k[4*(i)+ 6] = ss[2]; ss[3] ^= ss[2]; k[4*(i)+ 7] = ss[3]; \ -} -#endif - -#define kdf6(k,i) \ -{ ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 6] = ff(ss[0]); ss[1] ^= ss[0]; k[6*(i)+ 7] = ff(ss[1]); \ - ss[2] ^= ss[1]; k[6*(i)+ 8] = ff(ss[2]); ss[3] ^= ss[2]; k[6*(i)+ 9] = ff(ss[3]); \ - ss[4] ^= ss[3]; k[6*(i)+10] = ff(ss[4]); ss[5] ^= ss[4]; k[6*(i)+11] = ff(ss[5]); \ -} -#define kd6(k,i) \ -{ ss[6] = ls_box(ss[5],3) ^ t_use(r,c)[i]; \ - ss[0] ^= ss[6]; ss[6] = ff(ss[6]); k[6*(i)+ 6] = ss[6] ^= k[6*(i)]; \ - ss[1] ^= ss[0]; k[6*(i)+ 7] = ss[6] ^= k[6*(i)+ 1]; \ - ss[2] ^= ss[1]; k[6*(i)+ 8] = ss[6] ^= k[6*(i)+ 2]; \ - ss[3] ^= ss[2]; k[6*(i)+ 9] = ss[6] ^= k[6*(i)+ 3]; \ - ss[4] ^= ss[3]; k[6*(i)+10] = ss[6] ^= k[6*(i)+ 4]; \ - ss[5] ^= ss[4]; k[6*(i)+11] = ss[6] ^= k[6*(i)+ 5]; \ -} -#define kdl6(k,i) \ -{ ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 6] = ss[0]; ss[1] ^= ss[0]; k[6*(i)+ 7] = ss[1]; \ - ss[2] ^= ss[1]; k[6*(i)+ 8] = ss[2]; ss[3] ^= ss[2]; k[6*(i)+ 9] = ss[3]; \ -} - -#define kdf8(k,i) \ -{ ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 8] = ff(ss[0]); ss[1] ^= ss[0]; k[8*(i)+ 9] = ff(ss[1]); \ - ss[2] ^= ss[1]; k[8*(i)+10] = ff(ss[2]); ss[3] ^= ss[2]; k[8*(i)+11] = ff(ss[3]); \ - ss[4] ^= ls_box(ss[3],0); k[8*(i)+12] = ff(ss[4]); ss[5] ^= ss[4]; k[8*(i)+13] = ff(ss[5]); \ - ss[6] ^= ss[5]; k[8*(i)+14] = ff(ss[6]); ss[7] ^= ss[6]; k[8*(i)+15] = ff(ss[7]); \ -} -#define kd8(k,i) \ -{ aes_32t g = ls_box(ss[7],3) ^ t_use(r,c)[i]; \ - ss[0] ^= g; g = ff(g); k[8*(i)+ 8] = g ^= k[8*(i)]; \ - ss[1] ^= ss[0]; k[8*(i)+ 9] = g ^= k[8*(i)+ 1]; \ - ss[2] ^= ss[1]; k[8*(i)+10] = g ^= k[8*(i)+ 2]; \ - ss[3] ^= ss[2]; k[8*(i)+11] = g ^= k[8*(i)+ 3]; \ - g = ls_box(ss[3],0); \ - ss[4] ^= g; g = ff(g); k[8*(i)+12] = g ^= k[8*(i)+ 4]; \ - ss[5] ^= ss[4]; k[8*(i)+13] = g ^= k[8*(i)+ 5]; \ - ss[6] ^= ss[5]; k[8*(i)+14] = g ^= k[8*(i)+ 6]; \ - ss[7] ^= ss[6]; k[8*(i)+15] = g ^= k[8*(i)+ 7]; \ -} -#define kdl8(k,i) \ -{ ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 8] = ss[0]; ss[1] ^= ss[0]; k[8*(i)+ 9] = ss[1]; \ - ss[2] ^= ss[1]; k[8*(i)+10] = ss[2]; ss[3] ^= ss[2]; k[8*(i)+11] = ss[3]; \ -} - -#if defined(AES_128) || defined(AES_VAR) - -aes_rval aes_decrypt_key128(const void *in_key, aes_decrypt_ctx cx[1]) -{ aes_32t ss[5]; -#ifdef d_vars - d_vars; -#endif - cx->ks[0] = ss[0] = word_in(in_key, 0); - cx->ks[1] = ss[1] = word_in(in_key, 1); - cx->ks[2] = ss[2] = word_in(in_key, 2); - cx->ks[3] = ss[3] = word_in(in_key, 3); - -#if DEC_UNROLL == NONE - { aes_32t i; - - for(i = 0; i < (11 * N_COLS - 1) / 4; ++i) - ke4(cx->ks, i); -#if !(DEC_ROUND == NO_TABLES) - for(i = N_COLS; i < 10 * N_COLS; ++i) - cx->ks[i] = inv_mcol(cx->ks[i]); -#endif - } -#else - kdf4(cx->ks, 0); kd4(cx->ks, 1); - kd4(cx->ks, 2); kd4(cx->ks, 3); - kd4(cx->ks, 4); kd4(cx->ks, 5); - kd4(cx->ks, 6); kd4(cx->ks, 7); - kd4(cx->ks, 8); kdl4(cx->ks, 9); -#endif - - /* cx->ks[45] ^ cx->ks[52] ^ cx->ks[53] is zero for a 256 bit */ - /* key and must be non-zero for 128 and 192 bits keys */ - cx->ks[53] = cx->ks[45] = 0; - cx->ks[52] = 10; -#ifdef AES_ERR_CHK - return aes_good; -#endif -} - -#endif - -#if defined(AES_192) || defined(AES_VAR) - -aes_rval aes_decrypt_key192(const void *in_key, aes_decrypt_ctx cx[1]) -{ aes_32t ss[7]; -#ifdef d_vars - d_vars; -#endif - cx->ks[0] = ss[0] = word_in(in_key, 0); - cx->ks[1] = ss[1] = word_in(in_key, 1); - cx->ks[2] = ss[2] = word_in(in_key, 2); - cx->ks[3] = ss[3] = word_in(in_key, 3); - -#if DEC_UNROLL == NONE - cx->ks[4] = ss[4] = word_in(in_key, 4); - cx->ks[5] = ss[5] = word_in(in_key, 5); - { aes_32t i; - - for(i = 0; i < (13 * N_COLS - 1) / 6; ++i) - ke6(cx->ks, i); -#if !(DEC_ROUND == NO_TABLES) - for(i = N_COLS; i < 12 * N_COLS; ++i) - cx->ks[i] = inv_mcol(cx->ks[i]); -#endif - } -#else - cx->ks[4] = ff(ss[4] = word_in(in_key, 4)); - cx->ks[5] = ff(ss[5] = word_in(in_key, 5)); - kdf6(cx->ks, 0); kd6(cx->ks, 1); - kd6(cx->ks, 2); kd6(cx->ks, 3); - kd6(cx->ks, 4); kd6(cx->ks, 5); - kd6(cx->ks, 6); kdl6(cx->ks, 7); -#endif - - /* cx->ks[45] ^ cx->ks[52] ^ cx->ks[53] is zero for a 256 bit */ - /* key and must be non-zero for 128 and 192 bits keys */ - cx->ks[53] = cx->ks[45]; - cx->ks[52] = 12; -#ifdef AES_ERR_CHK - return aes_good; -#endif -} - -#endif - -#if defined(AES_256) || defined(AES_VAR) - -aes_rval aes_decrypt_key256(const void *in_key, aes_decrypt_ctx cx[1]) -{ aes_32t ss[8]; -#ifdef d_vars - d_vars; -#endif - cx->ks[0] = ss[0] = word_in(in_key, 0); - cx->ks[1] = ss[1] = word_in(in_key, 1); - cx->ks[2] = ss[2] = word_in(in_key, 2); - cx->ks[3] = ss[3] = word_in(in_key, 3); - -#if DEC_UNROLL == NONE - cx->ks[4] = ss[4] = word_in(in_key, 4); - cx->ks[5] = ss[5] = word_in(in_key, 5); - cx->ks[6] = ss[6] = word_in(in_key, 6); - cx->ks[7] = ss[7] = word_in(in_key, 7); - { aes_32t i; - - for(i = 0; i < (15 * N_COLS - 1) / 8; ++i) - ke8(cx->ks, i); -#if !(DEC_ROUND == NO_TABLES) - for(i = N_COLS; i < 14 * N_COLS; ++i) - cx->ks[i] = inv_mcol(cx->ks[i]); -#endif - } -#else - cx->ks[4] = ff(ss[4] = word_in(in_key, 4)); - cx->ks[5] = ff(ss[5] = word_in(in_key, 5)); - cx->ks[6] = ff(ss[6] = word_in(in_key, 6)); - cx->ks[7] = ff(ss[7] = word_in(in_key, 7)); - kdf8(cx->ks, 0); kd8(cx->ks, 1); - kd8(cx->ks, 2); kd8(cx->ks, 3); - kd8(cx->ks, 4); kd8(cx->ks, 5); - kdl8(cx->ks, 6); -#endif -#ifdef AES_ERR_CHK - return aes_good; -#endif -} - -#endif - -#if defined(AES_VAR) - -aes_rval aes_decrypt_key(const void *in_key, int key_len, aes_decrypt_ctx cx[1]) -{ - switch(key_len) - { -#ifdef AES_ERR_CHK - case 16: case 128: return aes_decrypt_key128(in_key, cx); - case 24: case 192: return aes_decrypt_key192(in_key, cx); - case 32: case 256: return aes_decrypt_key256(in_key, cx); - default: return aes_error; -#else - case 16: case 128: aes_decrypt_key128(in_key, cx); return; - case 24: case 192: aes_decrypt_key192(in_key, cx); return; - case 32: case 256: aes_decrypt_key256(in_key, cx); return; -#endif - } -} - -#endif - -#endif - -#if defined(__cplusplus) -} -#endif diff --git a/aesopt.h b/aesopt.h deleted file mode 100644 index bb4f05a0b..000000000 --- a/aesopt.h +++ /dev/null @@ -1,1029 +0,0 @@ -/* - --------------------------------------------------------------------------- - Copyright (c) 2003, Dr Brian Gladman , Worcester, UK. - All rights reserved. - - LICENSE TERMS - - The free distribution and use of this software in both source and binary - form is allowed (with or without changes) provided that: - - 1. distributions of this source code include the above copyright - notice, this list of conditions and the following disclaimer; - - 2. distributions in binary form include the above copyright - notice, this list of conditions and the following disclaimer - in the documentation and/or other associated materials; - - 3. the copyright holder's name is not used to endorse products - built using this software without specific written permission. - - ALTERNATIVELY, provided that this notice is retained in full, this product - may be distributed under the terms of the GNU General Public License (GPL), - in which case the provisions of the GPL apply INSTEAD OF those given above. - - DISCLAIMER - - This software is provided 'as is' with no explicit or implied warranties - in respect of its properties, including, but not limited to, correctness - and/or fitness for purpose. - --------------------------------------------------------------------------- - Issue Date: 26/08/2003 - - My thanks go to Dag Arne Osvik for devising the schemes used here for key - length derivation from the form of the key schedule - - This file contains the compilation options for AES (Rijndael) and code - that is common across encryption, key scheduling and table generation. - - OPERATION - - These source code files implement the AES algorithm Rijndael designed by - Joan Daemen and Vincent Rijmen. This version is designed for the standard - block size of 16 bytes and for key sizes of 128, 192 and 256 bits (16, 24 - and 32 bytes). - - This version is designed for flexibility and speed using operations on - 32-bit words rather than operations on bytes. It can be compiled with - either big or little endian internal byte order but is faster when the - native byte order for the processor is used. - - THE CIPHER INTERFACE - - The cipher interface is implemented as an array of bytes in which lower - AES bit sequence indexes map to higher numeric significance within bytes. - - aes_08t (an unsigned 8-bit type) - aes_32t (an unsigned 32-bit type) - struct aes_encrypt_ctx (structure for the cipher encryption context) - struct aes_decrypt_ctx (structure for the cipher decryption context) - aes_rval the function return type - - C subroutine calls: - - aes_rval aes_encrypt_key128(const void *in_key, aes_encrypt_ctx cx[1]); - aes_rval aes_encrypt_key192(const void *in_key, aes_encrypt_ctx cx[1]); - aes_rval aes_encrypt_key256(const void *in_key, aes_encrypt_ctx cx[1]); - aes_rval aes_encrypt(const void *in_blk, - void *out_blk, const aes_encrypt_ctx cx[1]); - - aes_rval aes_decrypt_key128(const void *in_key, aes_decrypt_ctx cx[1]); - aes_rval aes_decrypt_key192(const void *in_key, aes_decrypt_ctx cx[1]); - aes_rval aes_decrypt_key256(const void *in_key, aes_decrypt_ctx cx[1]); - aes_rval aes_decrypt(const void *in_blk, - void *out_blk, const aes_decrypt_ctx cx[1]); - - IMPORTANT NOTE: If you are using this C interface with dynamic tables make sure that - you call genTabs() before AES is used so that the tables are initialised. - - C++ aes class subroutines: - - Class AESencrypt for encryption - - Construtors: - AESencrypt(void) - AESencrypt(const void *in_key) - 128 bit key - Members: - void key128(const void *in_key) - void key192(const void *in_key) - void key256(const void *in_key) - void encrypt(const void *in_blk, void *out_blk) const - - Class AESdecrypt for encryption - Construtors: - AESdecrypt(void) - AESdecrypt(const void *in_key) - 128 bit key - Members: - void key128(const void *in_key) - void key192(const void *in_key) - void key256(const void *in_key) - void decrypt(const void *in_blk, void *out_blk) const - - COMPILATION - - The files used to provide AES (Rijndael) are - - a. aes.h for the definitions needed for use in C. - b. aescpp.h for the definitions needed for use in C++. - c. aesopt.h for setting compilation options (also includes common code). - d. aescrypt.c for encryption and decrytpion, or - e. aeskey.c for key scheduling. - f. aestab.c for table loading or generation. - g. aescrypt.asm for encryption and decryption using assembler code. - h. aescrypt.mmx.asm for encryption and decryption using MMX assembler. - - To compile AES (Rijndael) for use in C code use aes.h and set the - defines here for the facilities you need (key lengths, encryption - and/or decryption). Do not define AES_DLL or AES_CPP. Set the options - for optimisations and table sizes here. - - To compile AES (Rijndael) for use in in C++ code use aescpp.h but do - not define AES_DLL - - To compile AES (Rijndael) in C as a Dynamic Link Library DLL) use - aes.h and include the AES_DLL define. - - CONFIGURATION OPTIONS (here and in aes.h) - - a. set AES_DLL in aes.h if AES (Rijndael) is to be compiled as a DLL - b. You may need to set PLATFORM_BYTE_ORDER to define the byte order. - c. If you want the code to run in a specific internal byte order, then - ALGORITHM_BYTE_ORDER must be set accordingly. - d. set other configuration options decribed below. -*/ - -#ifndef _AESOPT_H -#define _AESOPT_H - -#include "asterisk/aes.h" -#include "asterisk/endian.h" - -/* CONFIGURATION - USE OF DEFINES - - Later in this section there are a number of defines that control the - operation of the code. In each section, the purpose of each define is - explained so that the relevant form can be included or excluded by - setting either 1's or 0's respectively on the branches of the related - #if clauses. -*/ - -/* BYTE ORDER IN 32-BIT WORDS - - To obtain the highest speed on processors with 32-bit words, this code - needs to determine the byte order of the target machine. The following - block of code is an attempt to capture the most obvious ways in which - various environemnts define byte order. It may well fail, in which case - the definitions will need to be set by editing at the points marked - **** EDIT HERE IF NECESSARY **** below. My thanks to Peter Gutmann for - some of these defines (from cryptlib). -*/ - -#define BRG_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ -#define BRG_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ - -#if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \ - defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \ - defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \ - defined( vax ) || defined( vms ) || defined( VMS ) || \ - defined( __VMS ) - -#define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN - -#endif - -#if defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \ - defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \ - defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \ - defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \ - defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \ - defined( __TANDEM ) || defined( THINK_C ) || defined( __VMCMS__ ) - -#define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN - -#endif - -/* if the platform is still not known, try to find its byte order */ -/* from commonly used definitions in the headers included earlier */ - -#if !defined(PLATFORM_BYTE_ORDER) - -#if defined(LITTLE_ENDIAN) || defined(BIG_ENDIAN) -# if defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) -# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN -# elif !defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) -# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN -# elif defined(BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN) -# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN -# elif defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN) -# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN -# endif - -#elif defined(_LITTLE_ENDIAN) || defined(_BIG_ENDIAN) -# if defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) -# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN -# elif !defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN) -# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN -# elif defined(_BYTE_ORDER) && (_BYTE_ORDER == _LITTLE_ENDIAN) -# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN -# elif defined(_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN) -# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN -# endif - -#elif defined(__LITTLE_ENDIAN__) || defined(__BIG_ENDIAN__) -# if defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) -# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN -# elif !defined(__LITTLE_ENDIAN__) && defined(__BIG_ENDIAN__) -# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN -# elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __LITTLE_ENDIAN__) -# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN -# elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __BIG_ENDIAN__) -# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN -# endif - -#elif 0 /* **** EDIT HERE IF NECESSARY **** */ -#define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN - -#elif 0 /* **** EDIT HERE IF NECESSARY **** */ -#define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN - -#else -#error Please edit aesopt.h (line 235 or 238) to set the platform byte order -#endif - -#endif - -/* SOME LOCAL DEFINITIONS */ - -#define NO_TABLES 0 -#define ONE_TABLE 1 -#define FOUR_TABLES 4 -#define NONE 0 -#define PARTIAL 1 -#define FULL 2 - -#if defined(bswap32) -#define aes_sw32 bswap32 -#elif defined(bswap_32) -#define aes_sw32 bswap_32 -#else -#define brot(x,n) (((aes_32t)(x) << n) | ((aes_32t)(x) >> (32 - n))) -#define aes_sw32(x) ((brot((x),8) & 0x00ff00ff) | (brot((x),24) & 0xff00ff00)) -#endif - -/* 1. FUNCTIONS REQUIRED - - This implementation provides subroutines for encryption, decryption - and for setting the three key lengths (separately) for encryption - and decryption. When the assembler code is not being used the following - definition blocks allow the selection of the routines that are to be - included in the compilation. -*/ -#ifdef AES_ENCRYPT -#define ENCRYPTION -#define ENCRYPTION_KEY_SCHEDULE -#endif - -#ifdef AES_DECRYPT -#define DECRYPTION -#define DECRYPTION_KEY_SCHEDULE -#endif - -/* 2. ASSEMBLER SUPPORT - - This define (which can be on the command line) enables the use of the - assembler code routines for encryption and decryption with the C code - only providing key scheduling -*/ -#if 0 -#define AES_ASM -#endif - -/* 3. BYTE ORDER WITHIN 32 BIT WORDS - - The fundamental data processing units in Rijndael are 8-bit bytes. The - input, output and key input are all enumerated arrays of bytes in which - bytes are numbered starting at zero and increasing to one less than the - number of bytes in the array in question. This enumeration is only used - for naming bytes and does not imply any adjacency or order relationship - from one byte to another. When these inputs and outputs are considered - as bit sequences, bits 8*n to 8*n+7 of the bit sequence are mapped to - byte[n] with bit 8n+i in the sequence mapped to bit 7-i within the byte. - In this implementation bits are numbered from 0 to 7 starting at the - numerically least significant end of each byte (bit n represents 2^n). - - However, Rijndael can be implemented more efficiently using 32-bit - words by packing bytes into words so that bytes 4*n to 4*n+3 are placed - into word[n]. While in principle these bytes can be assembled into words - in any positions, this implementation only supports the two formats in - which bytes in adjacent positions within words also have adjacent byte - numbers. This order is called big-endian if the lowest numbered bytes - in words have the highest numeric significance and little-endian if the - opposite applies. - - This code can work in either order irrespective of the order used by the - machine on which it runs. Normally the internal byte order will be set - to the order of the processor on which the code is to be run but this - define can be used to reverse this in special situations - - NOTE: Assembler code versions rely on PLATFORM_BYTE_ORDER being set -*/ -#if 1 || defined(AES_ASM) -#define ALGORITHM_BYTE_ORDER PLATFORM_BYTE_ORDER -#elif 0 -#define ALGORITHM_BYTE_ORDER BRG_LITTLE_ENDIAN -#elif 0 -#define ALGORITHM_BYTE_ORDER BRG_BIG_ENDIAN -#else -#error The algorithm byte order is not defined -#endif - -/* 4. FAST INPUT/OUTPUT OPERATIONS. - - On some machines it is possible to improve speed by transferring the - bytes in the input and output arrays to and from the internal 32-bit - variables by addressing these arrays as if they are arrays of 32-bit - words. On some machines this will always be possible but there may - be a large performance penalty if the byte arrays are not aligned on - the normal word boundaries. On other machines this technique will - lead to memory access errors when such 32-bit word accesses are not - properly aligned. The option SAFE_IO avoids such problems but will - often be slower on those machines that support misaligned access - (especially so if care is taken to align the input and output byte - arrays on 32-bit word boundaries). If SAFE_IO is not defined it is - assumed that access to byte arrays as if they are arrays of 32-bit - words will not cause problems when such accesses are misaligned. -*/ -#if 1 && !defined(_MSC_VER) -#define SAFE_IO -#endif - -/* 5. LOOP UNROLLING - - The code for encryption and decrytpion cycles through a number of rounds - that can be implemented either in a loop or by expanding the code into a - long sequence of instructions, the latter producing a larger program but - one that will often be much faster. The latter is called loop unrolling. - There are also potential speed advantages in expanding two iterations in - a loop with half the number of iterations, which is called partial loop - unrolling. The following options allow partial or full loop unrolling - to be set independently for encryption and decryption -*/ -#if 1 -#define ENC_UNROLL FULL -#elif 0 -#define ENC_UNROLL PARTIAL -#else -#define ENC_UNROLL NONE -#endif - -#if 1 -#define DEC_UNROLL FULL -#elif 0 -#define DEC_UNROLL PARTIAL -#else -#define DEC_UNROLL NONE -#endif - -/* 6. FAST FINITE FIELD OPERATIONS - - If this section is included, tables are used to provide faster finite - field arithmetic (this has no effect if FIXED_TABLES is defined). -*/ -#if 1 -#define FF_TABLES -#endif - -/* 7. INTERNAL STATE VARIABLE FORMAT - - The internal state of Rijndael is stored in a number of local 32-bit - word varaibles which can be defined either as an array or as individual - names variables. Include this section if you want to store these local - varaibles in arrays. Otherwise individual local variables will be used. -*/ -#if 1 -#define ARRAYS -#endif - -/* In this implementation the columns of the state array are each held in - 32-bit words. The state array can be held in various ways: in an array - of words, in a number of individual word variables or in a number of - processor registers. The following define maps a variable name x and - a column number c to the way the state array variable is to be held. - The first define below maps the state into an array x[c] whereas the - second form maps the state into a number of individual variables x0, - x1, etc. Another form could map individual state colums to machine - register names. -*/ - -#if defined(ARRAYS) -#define s(x,c) x[c] -#else -#define s(x,c) x##c -#endif - -/* 8. FIXED OR DYNAMIC TABLES - - When this section is included the tables used by the code are compiled - statically into the binary file. Otherwise the subroutine gen_tabs() - must be called to compute them before the code is first used. -*/ -#if 1 -#define FIXED_TABLES -#endif - -/* 9. TABLE ALIGNMENT - - On some sytsems speed will be improved by aligning the AES large lookup - tables on particular boundaries. This define should be set to a power of - two giving the desired alignment. It can be left undefined if alignment - is not needed. This option is specific to the Microsft VC++ compiler - - it seems to sometimes cause trouble for the VC++ version 6 compiler. -*/ - -#if 0 && defined(_MSC_VER) && (_MSC_VER >= 1300) -#define TABLE_ALIGN 64 -#endif - -/* 10. INTERNAL TABLE CONFIGURATION - - This cipher proceeds by repeating in a number of cycles known as 'rounds' - which are implemented by a round function which can optionally be speeded - up using tables. The basic tables are each 256 32-bit words, with either - one or four tables being required for each round function depending on - how much speed is required. The encryption and decryption round functions - are different and the last encryption and decrytpion round functions are - different again making four different round functions in all. - - This means that: - 1. Normal encryption and decryption rounds can each use either 0, 1 - or 4 tables and table spaces of 0, 1024 or 4096 bytes each. - 2. The last encryption and decryption rounds can also use either 0, 1 - or 4 tables and table spaces of 0, 1024 or 4096 bytes each. - - Include or exclude the appropriate definitions below to set the number - of tables used by this implementation. -*/ - -#if 1 /* set tables for the normal encryption round */ -#define ENC_ROUND FOUR_TABLES -#elif 0 -#define ENC_ROUND ONE_TABLE -#else -#define ENC_ROUND NO_TABLES -#endif - -#if 1 /* set tables for the last encryption round */ -#define LAST_ENC_ROUND FOUR_TABLES -#elif 0 -#define LAST_ENC_ROUND ONE_TABLE -#else -#define LAST_ENC_ROUND NO_TABLES -#endif - -#if 1 /* set tables for the normal decryption round */ -#define DEC_ROUND FOUR_TABLES -#elif 0 -#define DEC_ROUND ONE_TABLE -#else -#define DEC_ROUND NO_TABLES -#endif - -#if 1 /* set tables for the last decryption round */ -#define LAST_DEC_ROUND FOUR_TABLES -#elif 0 -#define LAST_DEC_ROUND ONE_TABLE -#else -#define LAST_DEC_ROUND NO_TABLES -#endif - -/* The decryption key schedule can be speeded up with tables in the same - way that the round functions can. Include or exclude the following - defines to set this requirement. -*/ -#if 1 -#define KEY_SCHED FOUR_TABLES -#elif 0 -#define KEY_SCHED ONE_TABLE -#else -#define KEY_SCHED NO_TABLES -#endif - -/* END OF CONFIGURATION OPTIONS */ - -#define RC_LENGTH (5 * (AES_BLOCK_SIZE / 4 - 2)) - -/* Disable or report errors on some combinations of options */ - -#if ENC_ROUND == NO_TABLES && LAST_ENC_ROUND != NO_TABLES -#undef LAST_ENC_ROUND -#define LAST_ENC_ROUND NO_TABLES -#elif ENC_ROUND == ONE_TABLE && LAST_ENC_ROUND == FOUR_TABLES -#undef LAST_ENC_ROUND -#define LAST_ENC_ROUND ONE_TABLE -#endif - -#if ENC_ROUND == NO_TABLES && ENC_UNROLL != NONE -#undef ENC_UNROLL -#define ENC_UNROLL NONE -#endif - -#if DEC_ROUND == NO_TABLES && LAST_DEC_ROUND != NO_TABLES -#undef LAST_DEC_ROUND -#define LAST_DEC_ROUND NO_TABLES -#elif DEC_ROUND == ONE_TABLE && LAST_DEC_ROUND == FOUR_TABLES -#undef LAST_DEC_ROUND -#define LAST_DEC_ROUND ONE_TABLE -#endif - -#if DEC_ROUND == NO_TABLES && DEC_UNROLL != NONE -#undef DEC_UNROLL -#define DEC_UNROLL NONE -#endif - -/* upr(x,n): rotates bytes within words by n positions, moving bytes to - higher index positions with wrap around into low positions - ups(x,n): moves bytes by n positions to higher index positions in - words but without wrap around - bval(x,n): extracts a byte from a word - - NOTE: The definitions given here are intended only for use with - unsigned variables and with shift counts that are compile - time constants -*/ - -#if (ALGORITHM_BYTE_ORDER == BRG_LITTLE_ENDIAN) -#define upr(x,n) (((aes_32t)(x) << (8 * (n))) | ((aes_32t)(x) >> (32 - 8 * (n)))) -#define ups(x,n) ((aes_32t) (x) << (8 * (n))) -#define bval(x,n) ((aes_08t)((x) >> (8 * (n)))) -#define bytes2word(b0, b1, b2, b3) \ - (((aes_32t)(b3) << 24) | ((aes_32t)(b2) << 16) | ((aes_32t)(b1) << 8) | (b0)) -#endif - -#if (ALGORITHM_BYTE_ORDER == BRG_BIG_ENDIAN) -#define upr(x,n) (((aes_32t)(x) >> (8 * (n))) | ((aes_32t)(x) << (32 - 8 * (n)))) -#define ups(x,n) ((aes_32t) (x) >> (8 * (n)))) -#define bval(x,n) ((aes_08t)((x) >> (24 - 8 * (n)))) -#define bytes2word(b0, b1, b2, b3) \ - (((aes_32t)(b0) << 24) | ((aes_32t)(b1) << 16) | ((aes_32t)(b2) << 8) | (b3)) -#endif - -#if defined(SAFE_IO) - -#define word_in(x,c) bytes2word(((aes_08t*)(x)+4*c)[0], ((aes_08t*)(x)+4*c)[1], \ - ((aes_08t*)(x)+4*c)[2], ((aes_08t*)(x)+4*c)[3]) -#define word_out(x,c,v) { ((aes_08t*)(x)+4*c)[0] = bval(v,0); ((aes_08t*)(x)+4*c)[1] = bval(v,1); \ - ((aes_08t*)(x)+4*c)[2] = bval(v,2); ((aes_08t*)(x)+4*c)[3] = bval(v,3); } - -#elif (ALGORITHM_BYTE_ORDER == PLATFORM_BYTE_ORDER) - -#define word_in(x,c) (*((aes_32t*)(x)+(c))) -#define word_out(x,c,v) (*((aes_32t*)(x)+(c)) = (v)) - -#else - -#define word_in(x,c) aes_sw32(*((aes_32t*)(x)+(c))) -#define word_out(x,c,v) (*((aes_32t*)(x)+(c)) = aes_sw32(v)) - -#endif - -/* the finite field modular polynomial and elements */ - -#define WPOLY 0x011b -#define BPOLY 0x1b - -/* multiply four bytes in GF(2^8) by 'x' {02} in parallel */ - -#define m1 0x80808080 -#define m2 0x7f7f7f7f -#define gf_mulx(x) ((((x) & m2) << 1) ^ ((((x) & m1) >> 7) * BPOLY)) - -/* The following defines provide alternative definitions of gf_mulx that might - give improved performance if a fast 32-bit multiply is not available. Note - that a temporary variable u needs to be defined where gf_mulx is used. - -#define gf_mulx(x) (u = (x) & m1, u |= (u >> 1), ((x) & m2) << 1) ^ ((u >> 3) | (u >> 6)) -#define m4 (0x01010101 * BPOLY) -#define gf_mulx(x) (u = (x) & m1, ((x) & m2) << 1) ^ ((u - (u >> 7)) & m4) -*/ - -/* Work out which tables are needed for the different options */ - -#ifdef AES_ASM -#ifdef ENC_ROUND -#undef ENC_ROUND -#endif -#define ENC_ROUND FOUR_TABLES -#ifdef LAST_ENC_ROUND -#undef LAST_ENC_ROUND -#endif -#define LAST_ENC_ROUND FOUR_TABLES -#ifdef DEC_ROUND -#undef DEC_ROUND -#endif -#define DEC_ROUND FOUR_TABLES -#ifdef LAST_DEC_ROUND -#undef LAST_DEC_ROUND -#endif -#define LAST_DEC_ROUND FOUR_TABLES -#ifdef KEY_SCHED -#undef KEY_SCHED -#define KEY_SCHED FOUR_TABLES -#endif -#endif - -#if defined(ENCRYPTION) || defined(AES_ASM) -#if ENC_ROUND == ONE_TABLE -#define FT1_SET -#elif ENC_ROUND == FOUR_TABLES -#define FT4_SET -#else -#define SBX_SET -#endif -#if LAST_ENC_ROUND == ONE_TABLE -#define FL1_SET -#elif LAST_ENC_ROUND == FOUR_TABLES -#define FL4_SET -#elif !defined(SBX_SET) -#define SBX_SET -#endif -#endif - -#if defined(DECRYPTION) || defined(AES_ASM) -#if DEC_ROUND == ONE_TABLE -#define IT1_SET -#elif DEC_ROUND == FOUR_TABLES -#define IT4_SET -#else -#define ISB_SET -#endif -#if LAST_DEC_ROUND == ONE_TABLE -#define IL1_SET -#elif LAST_DEC_ROUND == FOUR_TABLES -#define IL4_SET -#elif !defined(ISB_SET) -#define ISB_SET -#endif -#endif - -#if defined(ENCRYPTION_KEY_SCHEDULE) || defined(DECRYPTION_KEY_SCHEDULE) -#if KEY_SCHED == ONE_TABLE -#define LS1_SET -#define IM1_SET -#elif KEY_SCHED == FOUR_TABLES -#define LS4_SET -#define IM4_SET -#elif !defined(SBX_SET) -#define SBX_SET -#endif -#endif - -/* generic definitions of Rijndael macros that use tables */ - -#define no_table(x,box,vf,rf,c) bytes2word( \ - box[bval(vf(x,0,c),rf(0,c))], \ - box[bval(vf(x,1,c),rf(1,c))], \ - box[bval(vf(x,2,c),rf(2,c))], \ - box[bval(vf(x,3,c),rf(3,c))]) - -#define one_table(x,op,tab,vf,rf,c) \ - ( tab[bval(vf(x,0,c),rf(0,c))] \ - ^ op(tab[bval(vf(x,1,c),rf(1,c))],1) \ - ^ op(tab[bval(vf(x,2,c),rf(2,c))],2) \ - ^ op(tab[bval(vf(x,3,c),rf(3,c))],3)) - -#define four_tables(x,tab,vf,rf,c) \ - ( tab[0][bval(vf(x,0,c),rf(0,c))] \ - ^ tab[1][bval(vf(x,1,c),rf(1,c))] \ - ^ tab[2][bval(vf(x,2,c),rf(2,c))] \ - ^ tab[3][bval(vf(x,3,c),rf(3,c))]) - -#define vf1(x,r,c) (x) -#define rf1(r,c) (r) -#define rf2(r,c) ((8+r-c)&3) - -/* perform forward and inverse column mix operation on four bytes in long word x in */ -/* parallel. NOTE: x must be a simple variable, NOT an expression in these macros. */ - -#if defined(FM4_SET) /* not currently used */ -#define fwd_mcol(x) four_tables(x,t_use(f,m),vf1,rf1,0) -#elif defined(FM1_SET) /* not currently used */ -#define fwd_mcol(x) one_table(x,upr,t_use(f,m),vf1,rf1,0) -#else -#define dec_fmvars aes_32t g2 -#define fwd_mcol(x) (g2 = gf_mulx(x), g2 ^ upr((x) ^ g2, 3) ^ upr((x), 2) ^ upr((x), 1)) -#endif - -#if defined(IM4_SET) -#define inv_mcol(x) four_tables(x,t_use(i,m),vf1,rf1,0) -#elif defined(IM1_SET) -#define inv_mcol(x) one_table(x,upr,t_use(i,m),vf1,rf1,0) -#else -#define dec_imvars aes_32t g2, g4, g9 -#define inv_mcol(x) (g2 = gf_mulx(x), g4 = gf_mulx(g2), g9 = (x) ^ gf_mulx(g4), g4 ^= g9, \ - (x) ^ g2 ^ g4 ^ upr(g2 ^ g9, 3) ^ upr(g4, 2) ^ upr(g9, 1)) -#endif - -#if defined(FL4_SET) -#define ls_box(x,c) four_tables(x,t_use(f,l),vf1,rf2,c) -#elif defined(LS4_SET) -#define ls_box(x,c) four_tables(x,t_use(l,s),vf1,rf2,c) -#elif defined(FL1_SET) -#define ls_box(x,c) one_table(x,upr,t_use(f,l),vf1,rf2,c) -#elif defined(LS1_SET) -#define ls_box(x,c) one_table(x,upr,t_use(l,s),vf1,rf2,c) -#else -#define ls_box(x,c) no_table(x,t_use(s,box),vf1,rf2,c) -#endif - -#if defined(__cplusplus) -extern "C" -{ -#endif - -/* If there are no global variables, the definitions here can be - used to put the AES tables in a structure so that a pointer - can then be added to the AES context to pass them to the AES - routines that need them. If this facility is used, the calling - program has to ensure that this pointer is managed appropriately. - In particular, the value of the t_dec(in,it) item in the table - structure must be set to zero in order to ensure that the tables - are initialised. In practice the three code sequences in aeskey.c - that control the calls to gen_tabs() and the gen_tabs() routine - itself will have to be changed for a specific implementation. If - global variables are available it will generally be preferable to - use them with the precomputed FIXED_TABLES option that uses static - global tables. - - The following defines can be used to control the way the tables - are defined, initialised and used in embedded environments that - require special features for these purposes - - the 't_dec' construction is used to declare fixed table arrays - the 't_set' construction is used to set fixed table values - the 't_use' construction is used to access fixed table values - - 256 byte tables: - - t_xxx(s,box) => forward S box - t_xxx(i,box) => inverse S box - - 256 32-bit word OR 4 x 256 32-bit word tables: - - t_xxx(f,n) => forward normal round - t_xxx(f,l) => forward last round - t_xxx(i,n) => inverse normal round - t_xxx(i,l) => inverse last round - t_xxx(l,s) => key schedule table - t_xxx(i,m) => key schedule table - - Other variables and tables: - - t_xxx(r,c) => the rcon table -*/ - -#define t_dec(m,n) t_##m##n -#define t_set(m,n) t_##m##n -#define t_use(m,n) t_##m##n - -#if defined(DO_TABLES) /* declare and instantiate tables */ - -/* finite field arithmetic operations for table generation */ - -#if defined(FIXED_TABLES) || !defined(FF_TABLES) - -#define f2(x) ((x<<1) ^ (((x>>7) & 1) * WPOLY)) -#define f4(x) ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY)) -#define f8(x) ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) \ - ^ (((x>>5) & 4) * WPOLY)) -#define f3(x) (f2(x) ^ x) -#define f9(x) (f8(x) ^ x) -#define fb(x) (f8(x) ^ f2(x) ^ x) -#define fd(x) (f8(x) ^ f4(x) ^ x) -#define fe(x) (f8(x) ^ f4(x) ^ f2(x)) - -#else - -#define f2(x) ((x) ? pow[log[x] + 0x19] : 0) -#define f3(x) ((x) ? pow[log[x] + 0x01] : 0) -#define f9(x) ((x) ? pow[log[x] + 0xc7] : 0) -#define fb(x) ((x) ? pow[log[x] + 0x68] : 0) -#define fd(x) ((x) ? pow[log[x] + 0xee] : 0) -#define fe(x) ((x) ? pow[log[x] + 0xdf] : 0) -#define fi(x) ((x) ? pow[ 255 - log[x]] : 0) - -#endif - -#if defined(FIXED_TABLES) /* declare and set values for static tables */ - -#define sb_data(w) \ - w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\ - w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\ - w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\ - w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\ - w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\ - w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\ - w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\ - w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\ - w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\ - w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\ - w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\ - w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\ - w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\ - w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\ - w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\ - w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\ - w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\ - w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\ - w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\ - w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\ - w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\ - w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\ - w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\ - w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\ - w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\ - w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\ - w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\ - w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\ - w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\ - w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\ - w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\ - w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) - -#define isb_data(w) \ - w(0x52), w(0x09), w(0x6a), w(0xd5), w(0x30), w(0x36), w(0xa5), w(0x38),\ - w(0xbf), w(0x40), w(0xa3), w(0x9e), w(0x81), w(0xf3), w(0xd7), w(0xfb),\ - w(0x7c), w(0xe3), w(0x39), w(0x82), w(0x9b), w(0x2f), w(0xff), w(0x87),\ - w(0x34), w(0x8e), w(0x43), w(0x44), w(0xc4), w(0xde), w(0xe9), w(0xcb),\ - w(0x54), w(0x7b), w(0x94), w(0x32), w(0xa6), w(0xc2), w(0x23), w(0x3d),\ - w(0xee), w(0x4c), w(0x95), w(0x0b), w(0x42), w(0xfa), w(0xc3), w(0x4e),\ - w(0x08), w(0x2e), w(0xa1), w(0x66), w(0x28), w(0xd9), w(0x24), w(0xb2),\ - w(0x76), w(0x5b), w(0xa2), w(0x49), w(0x6d), w(0x8b), w(0xd1), w(0x25),\ - w(0x72), w(0xf8), w(0xf6), w(0x64), w(0x86), w(0x68), w(0x98), w(0x16),\ - w(0xd4), w(0xa4), w(0x5c), w(0xcc), w(0x5d), w(0x65), w(0xb6), w(0x92),\ - w(0x6c), w(0x70), w(0x48), w(0x50), w(0xfd), w(0xed), w(0xb9), w(0xda),\ - w(0x5e), w(0x15), w(0x46), w(0x57), w(0xa7), w(0x8d), w(0x9d), w(0x84),\ - w(0x90), w(0xd8), w(0xab), w(0x00), w(0x8c), w(0xbc), w(0xd3), w(0x0a),\ - w(0xf7), w(0xe4), w(0x58), w(0x05), w(0xb8), w(0xb3), w(0x45), w(0x06),\ - w(0xd0), w(0x2c), w(0x1e), w(0x8f), w(0xca), w(0x3f), w(0x0f), w(0x02),\ - w(0xc1), w(0xaf), w(0xbd), w(0x03), w(0x01), w(0x13), w(0x8a), w(0x6b),\ - w(0x3a), w(0x91), w(0x11), w(0x41), w(0x4f), w(0x67), w(0xdc), w(0xea),\ - w(0x97), w(0xf2), w(0xcf), w(0xce), w(0xf0), w(0xb4), w(0xe6), w(0x73),\ - w(0x96), w(0xac), w(0x74), w(0x22), w(0xe7), w(0xad), w(0x35), w(0x85),\ - w(0xe2), w(0xf9), w(0x37), w(0xe8), w(0x1c), w(0x75), w(0xdf), w(0x6e),\ - w(0x47), w(0xf1), w(0x1a), w(0x71), w(0x1d), w(0x29), w(0xc5), w(0x89),\ - w(0x6f), w(0xb7), w(0x62), w(0x0e), w(0xaa), w(0x18), w(0xbe), w(0x1b),\ - w(0xfc), w(0x56), w(0x3e), w(0x4b), w(0xc6), w(0xd2), w(0x79), w(0x20),\ - w(0x9a), w(0xdb), w(0xc0), w(0xfe), w(0x78), w(0xcd), w(0x5a), w(0xf4),\ - w(0x1f), w(0xdd), w(0xa8), w(0x33), w(0x88), w(0x07), w(0xc7), w(0x31),\ - w(0xb1), w(0x12), w(0x10), w(0x59), w(0x27), w(0x80), w(0xec), w(0x5f),\ - w(0x60), w(0x51), w(0x7f), w(0xa9), w(0x19), w(0xb5), w(0x4a), w(0x0d),\ - w(0x2d), w(0xe5), w(0x7a), w(0x9f), w(0x93), w(0xc9), w(0x9c), w(0xef),\ - w(0xa0), w(0xe0), w(0x3b), w(0x4d), w(0xae), w(0x2a), w(0xf5), w(0xb0),\ - w(0xc8), w(0xeb), w(0xbb), w(0x3c), w(0x83), w(0x53), w(0x99), w(0x61),\ - w(0x17), w(0x2b), w(0x04), w(0x7e), w(0xba), w(0x77), w(0xd6), w(0x26),\ - w(0xe1), w(0x69), w(0x14), w(0x63), w(0x55), w(0x21), w(0x0c), w(0x7d), - -#define mm_data(w) \ - w(0x00), w(0x01), w(0x02), w(0x03), w(0x04), w(0x05), w(0x06), w(0x07),\ - w(0x08), w(0x09), w(0x0a), w(0x0b), w(0x0c), w(0x0d), w(0x0e), w(0x0f),\ - w(0x10), w(0x11), w(0x12), w(0x13), w(0x14), w(0x15), w(0x16), w(0x17),\ - w(0x18), w(0x19), w(0x1a), w(0x1b), w(0x1c), w(0x1d), w(0x1e), w(0x1f),\ - w(0x20), w(0x21), w(0x22), w(0x23), w(0x24), w(0x25), w(0x26), w(0x27),\ - w(0x28), w(0x29), w(0x2a), w(0x2b), w(0x2c), w(0x2d), w(0x2e), w(0x2f),\ - w(0x30), w(0x31), w(0x32), w(0x33), w(0x34), w(0x35), w(0x36), w(0x37),\ - w(0x38), w(0x39), w(0x3a), w(0x3b), w(0x3c), w(0x3d), w(0x3e), w(0x3f),\ - w(0x40), w(0x41), w(0x42), w(0x43), w(0x44), w(0x45), w(0x46), w(0x47),\ - w(0x48), w(0x49), w(0x4a), w(0x4b), w(0x4c), w(0x4d), w(0x4e), w(0x4f),\ - w(0x50), w(0x51), w(0x52), w(0x53), w(0x54), w(0x55), w(0x56), w(0x57),\ - w(0x58), w(0x59), w(0x5a), w(0x5b), w(0x5c), w(0x5d), w(0x5e), w(0x5f),\ - w(0x60), w(0x61), w(0x62), w(0x63), w(0x64), w(0x65), w(0x66), w(0x67),\ - w(0x68), w(0x69), w(0x6a), w(0x6b), w(0x6c), w(0x6d), w(0x6e), w(0x6f),\ - w(0x70), w(0x71), w(0x72), w(0x73), w(0x74), w(0x75), w(0x76), w(0x77),\ - w(0x78), w(0x79), w(0x7a), w(0x7b), w(0x7c), w(0x7d), w(0x7e), w(0x7f),\ - w(0x80), w(0x81), w(0x82), w(0x83), w(0x84), w(0x85), w(0x86), w(0x87),\ - w(0x88), w(0x89), w(0x8a), w(0x8b), w(0x8c), w(0x8d), w(0x8e), w(0x8f),\ - w(0x90), w(0x91), w(0x92), w(0x93), w(0x94), w(0x95), w(0x96), w(0x97),\ - w(0x98), w(0x99), w(0x9a), w(0x9b), w(0x9c), w(0x9d), w(0x9e), w(0x9f),\ - w(0xa0), w(0xa1), w(0xa2), w(0xa3), w(0xa4), w(0xa5), w(0xa6), w(0xa7),\ - w(0xa8), w(0xa9), w(0xaa), w(0xab), w(0xac), w(0xad), w(0xae), w(0xaf),\ - w(0xb0), w(0xb1), w(0xb2), w(0xb3), w(0xb4), w(0xb5), w(0xb6), w(0xb7),\ - w(0xb8), w(0xb9), w(0xba), w(0xbb), w(0xbc), w(0xbd), w(0xbe), w(0xbf),\ - w(0xc0), w(0xc1), w(0xc2), w(0xc3), w(0xc4), w(0xc5), w(0xc6), w(0xc7),\ - w(0xc8), w(0xc9), w(0xca), w(0xcb), w(0xcc), w(0xcd), w(0xce), w(0xcf),\ - w(0xd0), w(0xd1), w(0xd2), w(0xd3), w(0xd4), w(0xd5), w(0xd6), w(0xd7),\ - w(0xd8), w(0xd9), w(0xda), w(0xdb), w(0xdc), w(0xdd), w(0xde), w(0xdf),\ - w(0xe0), w(0xe1), w(0xe2), w(0xe3), w(0xe4), w(0xe5), w(0xe6), w(0xe7),\ - w(0xe8), w(0xe9), w(0xea), w(0xeb), w(0xec), w(0xed), w(0xee), w(0xef),\ - w(0xf0), w(0xf1), w(0xf2), w(0xf3), w(0xf4), w(0xf5), w(0xf6), w(0xf7),\ - w(0xf8), w(0xf9), w(0xfa), w(0xfb), w(0xfc), w(0xfd), w(0xfe), w(0xff) - -#define h0(x) (x) - -/* These defines are used to ensure tables are generated in the - right format depending on the internal byte order required -*/ - -#define w0(p) bytes2word(p, 0, 0, 0) -#define w1(p) bytes2word(0, p, 0, 0) -#define w2(p) bytes2word(0, 0, p, 0) -#define w3(p) bytes2word(0, 0, 0, p) - -#define u0(p) bytes2word(f2(p), p, p, f3(p)) -#define u1(p) bytes2word(f3(p), f2(p), p, p) -#define u2(p) bytes2word(p, f3(p), f2(p), p) -#define u3(p) bytes2word(p, p, f3(p), f2(p)) - -#define v0(p) bytes2word(fe(p), f9(p), fd(p), fb(p)) -#define v1(p) bytes2word(fb(p), fe(p), f9(p), fd(p)) -#define v2(p) bytes2word(fd(p), fb(p), fe(p), f9(p)) -#define v3(p) bytes2word(f9(p), fd(p), fb(p), fe(p)) - -const aes_32t t_dec(r,c)[RC_LENGTH] = -{ - w0(0x01), w0(0x02), w0(0x04), w0(0x08), w0(0x10), - w0(0x20), w0(0x40), w0(0x80), w0(0x1b), w0(0x36) -}; - -#define d_1(t,n,b,v) const t n[256] = { b(v##0) } -#define d_4(t,n,b,v) const t n[4][256] = { { b(v##0) }, { b(v##1) }, { b(v##2) }, { b(v##3) } } - -#else /* declare and instantiate tables for dynamic value generation in in tab.c */ - -aes_32t t_dec(r,c)[RC_LENGTH]; - -#define d_1(t,n,b,v) t n[256] -#define d_4(t,n,b,v) t n[4][256] - -#endif - -#else /* declare tables without instantiation */ - -#if defined(FIXED_TABLES) - -extern const aes_32t t_dec(r,c)[RC_LENGTH]; - -#if defined(_MSC_VER) && defined(TABLE_ALIGN) -#define d_1(t,n,b,v) extern __declspec(align(TABLE_ALIGN)) const t n[256] -#define d_4(t,n,b,v) extern __declspec(align(TABLE_ALIGN)) const t n[4][256] -#else -#define d_1(t,n,b,v) extern const t n[256] -#define d_4(t,n,b,v) extern const t n[4][256] -#endif -#else - -extern aes_32t t_dec(r,c)[RC_LENGTH]; - -#if defined(_MSC_VER) && defined(TABLE_ALIGN) -#define d_1(t,n,b,v) extern __declspec(align(TABLE_ALIGN)) t n[256] -#define d_4(t,n,b,v) extern __declspec(align(TABLE_ALIGN)) t n[4][256] -#else -#define d_1(t,n,b,v) extern t n[256] -#define d_4(t,n,b,v) extern t n[4][256] -#endif -#endif - -#endif - -#ifdef SBX_SET - d_1(aes_08t, t_dec(s,box), sb_data, h); -#endif -#ifdef ISB_SET - d_1(aes_08t, t_dec(i,box), isb_data, h); -#endif - -#ifdef FT1_SET - d_1(aes_32t, t_dec(f,n), sb_data, u); -#endif -#ifdef FT4_SET - d_4(aes_32t, t_dec(f,n), sb_data, u); -#endif - -#ifdef FL1_SET - d_1(aes_32t, t_dec(f,l), sb_data, w); -#endif -#ifdef FL4_SET - d_4(aes_32t, t_dec(f,l), sb_data, w); -#endif - -#ifdef IT1_SET - d_1(aes_32t, t_dec(i,n), isb_data, v); -#endif -#ifdef IT4_SET - d_4(aes_32t, t_dec(i,n), isb_data, v); -#endif - -#ifdef IL1_SET - d_1(aes_32t, t_dec(i,l), isb_data, w); -#endif -#ifdef IL4_SET - d_4(aes_32t, t_dec(i,l), isb_data, w); -#endif - -#ifdef LS1_SET -#ifdef FL1_SET -#undef LS1_SET -#else - d_1(aes_32t, t_dec(l,s), sb_data, w); -#endif -#endif - -#ifdef LS4_SET -#ifdef FL4_SET -#undef LS4_SET -#else - d_4(aes_32t, t_dec(l,s), sb_data, w); -#endif -#endif - -#ifdef IM1_SET - d_1(aes_32t, t_dec(i,m), mm_data, v); -#endif -#ifdef IM4_SET - d_4(aes_32t, t_dec(i,m), mm_data, v); -#endif - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/aestab.c b/aestab.c deleted file mode 100644 index c84a480af..000000000 --- a/aestab.c +++ /dev/null @@ -1,232 +0,0 @@ -/* - --------------------------------------------------------------------------- - Copyright (c) 2003, Dr Brian Gladman , Worcester, UK. - All rights reserved. - - LICENSE TERMS - - The free distribution and use of this software in both source and binary - form is allowed (with or without changes) provided that: - - 1. distributions of this source code include the above copyright - notice, this list of conditions and the following disclaimer; - - 2. distributions in binary form include the above copyright - notice, this list of conditions and the following disclaimer - in the documentation and/or other associated materials; - - 3. the copyright holder's name is not used to endorse products - built using this software without specific written permission. - - ALTERNATIVELY, provided that this notice is retained in full, this product - may be distributed under the terms of the GNU General Public License (GPL), - in which case the provisions of the GPL apply INSTEAD OF those given above. - - DISCLAIMER - - This software is provided 'as is' with no explicit or implied warranties - in respect of its properties, including, but not limited to, correctness - and/or fitness for purpose. - --------------------------------------------------------------------------- - Issue Date: 26/08/2003 - -*/ - -#if defined(__cplusplus) -extern "C" -{ -#endif - -#define DO_TABLES - -#include "aesopt.h" - -#if defined(FIXED_TABLES) - -/* implemented in case of wrong call for fixed tables */ - -void gen_tabs(void) -{ -} - -#else /* dynamic table generation */ - -#if !defined(FF_TABLES) - -/* Generate the tables for the dynamic table option - - It will generally be sensible to use tables to compute finite - field multiplies and inverses but where memory is scarse this - code might sometimes be better. But it only has effect during - initialisation so its pretty unimportant in overall terms. -*/ - -/* return 2 ^ (n - 1) where n is the bit number of the highest bit - set in x with x in the range 1 < x < 0x00000200. This form is - used so that locals within fi can be bytes rather than words -*/ - -static aes_08t hibit(const aes_32t x) -{ aes_08t r = (aes_08t)((x >> 1) | (x >> 2)); - - r |= (r >> 2); - r |= (r >> 4); - return (r + 1) >> 1; -} - -/* return the inverse of the finite field element x */ - -static aes_08t fi(const aes_08t x) -{ aes_08t p1 = x, p2 = BPOLY, n1 = hibit(x), n2 = 0x80, v1 = 1, v2 = 0; - - if(x < 2) return x; - - for(;;) - { - if(!n1) return v1; - - while(n2 >= n1) - { - n2 /= n1; p2 ^= p1 * n2; v2 ^= v1 * n2; n2 = hibit(p2); - } - - if(!n2) return v2; - - while(n1 >= n2) - { - n1 /= n2; p1 ^= p2 * n1; v1 ^= v2 * n1; n1 = hibit(p1); - } - } -} - -#endif - -/* The forward and inverse affine transformations used in the S-box */ - -#define fwd_affine(x) \ - (w = (aes_32t)x, w ^= (w<<1)^(w<<2)^(w<<3)^(w<<4), 0x63^(aes_08t)(w^(w>>8))) - -#define inv_affine(x) \ - (w = (aes_32t)x, w = (w<<1)^(w<<3)^(w<<6), 0x05^(aes_08t)(w^(w>>8))) - -static int init = 0; - -void gen_tabs(void) -{ aes_32t i, w; - -#if defined(FF_TABLES) - - aes_08t pow[512], log[256]; - - if(init) return; - /* log and power tables for GF(2^8) finite field with - WPOLY as modular polynomial - the simplest primitive - root is 0x03, used here to generate the tables - */ - - i = 0; w = 1; - do - { - pow[i] = (aes_08t)w; - pow[i + 255] = (aes_08t)w; - log[w] = (aes_08t)i++; - w ^= (w << 1) ^ (w & 0x80 ? WPOLY : 0); - } - while (w != 1); - -#else - if(init) return; -#endif - - for(i = 0, w = 1; i < RC_LENGTH; ++i) - { - t_set(r,c)[i] = bytes2word(w, 0, 0, 0); - w = f2(w); - } - - for(i = 0; i < 256; ++i) - { aes_08t b; - - b = fwd_affine(fi((aes_08t)i)); - w = bytes2word(f2(b), b, b, f3(b)); - -#ifdef SBX_SET - t_set(s,box)[i] = b; -#endif - -#ifdef FT1_SET /* tables for a normal encryption round */ - t_set(f,n)[i] = w; -#endif -#ifdef FT4_SET - t_set(f,n)[0][i] = w; - t_set(f,n)[1][i] = upr(w,1); - t_set(f,n)[2][i] = upr(w,2); - t_set(f,n)[3][i] = upr(w,3); -#endif - w = bytes2word(b, 0, 0, 0); - -#ifdef FL1_SET /* tables for last encryption round (may also */ - t_set(f,l)[i] = w; /* be used in the key schedule) */ -#endif -#ifdef FL4_SET - t_set(f,l)[0][i] = w; - t_set(f,l)[1][i] = upr(w,1); - t_set(f,l)[2][i] = upr(w,2); - t_set(f,l)[3][i] = upr(w,3); -#endif - -#ifdef LS1_SET /* table for key schedule if t_set(f,l) above is */ - t_set(l,s)[i] = w; /* not of the required form */ -#endif -#ifdef LS4_SET - t_set(l,s)[0][i] = w; - t_set(l,s)[1][i] = upr(w,1); - t_set(l,s)[2][i] = upr(w,2); - t_set(l,s)[3][i] = upr(w,3); -#endif - - b = fi(inv_affine((aes_08t)i)); - w = bytes2word(fe(b), f9(b), fd(b), fb(b)); - -#ifdef IM1_SET /* tables for the inverse mix column operation */ - t_set(i,m)[b] = w; -#endif -#ifdef IM4_SET - t_set(i,m)[0][b] = w; - t_set(i,m)[1][b] = upr(w,1); - t_set(i,m)[2][b] = upr(w,2); - t_set(i,m)[3][b] = upr(w,3); -#endif - -#ifdef ISB_SET - t_set(i,box)[i] = b; -#endif -#ifdef IT1_SET /* tables for a normal decryption round */ - t_set(i,n)[i] = w; -#endif -#ifdef IT4_SET - t_set(i,n)[0][i] = w; - t_set(i,n)[1][i] = upr(w,1); - t_set(i,n)[2][i] = upr(w,2); - t_set(i,n)[3][i] = upr(w,3); -#endif - w = bytes2word(b, 0, 0, 0); -#ifdef IL1_SET /* tables for last decryption round */ - t_set(i,l)[i] = w; -#endif -#ifdef IL4_SET - t_set(i,l)[0][i] = w; - t_set(i,l)[1][i] = upr(w,1); - t_set(i,l)[2][i] = upr(w,2); - t_set(i,l)[3][i] = upr(w,3); -#endif - } - init = 1; -} - -#endif - -#if defined(__cplusplus) -} -#endif - diff --git a/alaw.c b/alaw.c deleted file mode 100644 index 782419d9e..000000000 --- a/alaw.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Asterisk -- An open source telephony toolkit. - * - * Copyright (C) 1999 - 2005, Digium, Inc. - * - * Mark Spencer - * - * 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 u-Law to Signed linear conversion - * - * \author Mark Spencer - */ - -#include "asterisk.h" - -ASTERISK_FILE_VERSION(__FILE__, "$Revision$") - -#include "asterisk/alaw.h" - -#define AMI_MASK 0x55 - -static inline unsigned char linear2alaw (short int linear) -{ - int mask; - int seg; - int pcm_val; - static int seg_end[8] = - { - 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF - }; - - pcm_val = linear; - if (pcm_val >= 0) - { - /* Sign (7th) bit = 1 */ - mask = AMI_MASK | 0x80; - } - else - { - /* Sign bit = 0 */ - mask = AMI_MASK; - pcm_val = -pcm_val; - } - - /* Convert the scaled magnitude to segment number. */ - for (seg = 0; seg < 8; seg++) - { - if (pcm_val <= seg_end[seg]) - break; - } - /* Combine the sign, segment, and quantization bits. */ - return ((seg << 4) | ((pcm_val >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask; -} -/*- End of function --------------------------------------------------------*/ - -static inline short int alaw2linear (unsigned char alaw) -{ - int i; - int seg; - - alaw ^= AMI_MASK; - i = ((alaw & 0x0F) << 4); - seg = (((int) alaw & 0x70) >> 4); - if (seg) - i = (i + 0x100) << (seg - 1); - return (short int) ((alaw & 0x80) ? i : -i); -} - -unsigned char __ast_lin2a[8192]; -short __ast_alaw[256]; - -void ast_alaw_init(void) -{ - int i; - /* - * Set up mu-law conversion table - */ - for(i = 0;i < 256;i++) - { - __ast_alaw[i] = alaw2linear(i); - } - /* set up the reverse (mu-law) conversion table */ - for(i = -32768; i < 32768; i++) - { - __ast_lin2a[((unsigned short)i) >> 3] = linear2alaw(i); - } - -} - diff --git a/app.c b/app.c deleted file mode 100644 index 1099feaea..000000000 --- a/app.c +++ /dev/null @@ -1,1328 +0,0 @@ -/* - * Asterisk -- An open source telephony toolkit. - * - * Copyright (C) 1999 - 2005, Digium, Inc. - * - * Mark Spencer - * - * 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 Convenient Application Routines - * - * \author Mark Spencer - */ - -#include "asterisk.h" - -ASTERISK_FILE_VERSION(__FILE__, "$Revision$") - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "asterisk/channel.h" -#include "asterisk/pbx.h" -#include "asterisk/file.h" -#include "asterisk/app.h" -#include "asterisk/dsp.h" -#include "asterisk/logger.h" -#include "asterisk/options.h" -#include "asterisk/utils.h" -#include "asterisk/lock.h" -#include "asterisk/indications.h" - -#define MAX_OTHER_FORMATS 10 - - -/* ! -This function presents a dialtone and reads an extension into 'collect' -which must be a pointer to a **pre-initialized** array of char having a -size of 'size' suitable for writing to. It will collect no more than the smaller -of 'maxlen' or 'size' minus the original strlen() of collect digits. -\return 0 if extension does not exist, 1 if extension exists -*/ -int ast_app_dtget(struct ast_channel *chan, const char *context, char *collect, size_t size, int maxlen, int timeout) -{ - struct tone_zone_sound *ts; - int res=0, x=0; - - if (maxlen > size) - maxlen = size; - - if (!timeout && chan->pbx) - timeout = chan->pbx->dtimeout; - else if (!timeout) - timeout = 5; - - ts = ast_get_indication_tone(chan->zone,"dial"); - if (ts && ts->data[0]) - res = ast_playtones_start(chan, 0, ts->data, 0); - else - ast_log(LOG_NOTICE,"Huh....? no dial for indications?\n"); - - for (x = strlen(collect); x < maxlen; ) { - res = ast_waitfordigit(chan, timeout); - if (!ast_ignore_pattern(context, collect)) - ast_playtones_stop(chan); - if (res < 1) - break; - collect[x++] = res; - if (!ast_matchmore_extension(chan, context, collect, 1, chan->cid.cid_num)) { - if (collect[x-1] == '#') { - /* Not a valid extension, ending in #, assume the # was to finish dialing */ - collect[x-1] = '\0'; - } - break; - } - } - if (res >= 0) - res = ast_exists_extension(chan, context, collect, 1, chan->cid.cid_num) ? 1 : 0; - return res; -} - -/*! \param timeout set timeout to 0 for "standard" timeouts. Set timeout to -1 for - "ludicrous time" (essentially never times out) */ -int ast_app_getdata(struct ast_channel *c, char *prompt, char *s, int maxlen, int timeout) -{ - int res,to,fto; - /* XXX Merge with full version? XXX */ - if (maxlen) - s[0] = '\0'; - if (prompt) { - res = ast_streamfile(c, prompt, c->language); - if (res < 0) - return res; - } - fto = c->pbx ? c->pbx->rtimeout * 1000 : 6000; - to = c->pbx ? c->pbx->dtimeout * 1000 : 2000; - - if (timeout > 0) - fto = to = timeout; - if (timeout < 0) - fto = to = 1000000000; - res = ast_readstring(c, s, maxlen, to, fto, "#"); - return res; -} - - -int ast_app_getdata_full(struct ast_channel *c, char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd) -{ - int res, to, fto; - if (prompt) { - res = ast_streamfile(c, prompt, c->language); - if (res < 0) - return res; - } - fto = 6000; - to = 2000; - if (timeout > 0) - fto = to = timeout; - if (timeout < 0) - fto = to = 1000000000; - res = ast_readstring_full(c, s, maxlen, to, fto, "#", audiofd, ctrlfd); - return res; -} - -static int (*ast_has_voicemail_func)(const char *mailbox, const char *folder) = NULL; -static int (*ast_inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs) = NULL; -static int (*ast_messagecount_func)(const char *context, const char *mailbox, const char *folder) = NULL; - -void ast_install_vm_functions(int (*has_voicemail_func)(const char *mailbox, const char *folder), - int (*inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs), - int (*messagecount_func)(const char *context, const char *mailbox, const char *folder)) -{ - ast_has_voicemail_func = has_voicemail_func; - ast_inboxcount_func = inboxcount_func; - ast_messagecount_func = messagecount_func; -} - -void ast_uninstall_vm_functions(void) -{ - ast_has_voicemail_func = NULL; - ast_inboxcount_func = NULL; - ast_messagecount_func = NULL; -} - -int ast_app_has_voicemail(const char *mailbox, const char *folder) -{ - static int warned = 0; - if (ast_has_voicemail_func) - return ast_has_voicemail_func(mailbox, folder); - - if ((option_verbose > 2) && !warned) { - ast_verbose(VERBOSE_PREFIX_3 "Message check requested for mailbox %s/folder %s but voicemail not loaded.\n", mailbox, folder ? folder : "INBOX"); - warned++; - } - return 0; -} - - -int ast_app_inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs) -{ - static int warned = 0; - if (newmsgs) - *newmsgs = 0; - if (oldmsgs) - *oldmsgs = 0; - if (ast_inboxcount_func) - return ast_inboxcount_func(mailbox, newmsgs, oldmsgs); - - if (!warned && (option_verbose > 2)) { - warned++; - ast_verbose(VERBOSE_PREFIX_3 "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox); - } - - return 0; -} - -int ast_app_messagecount(const char *context, const char *mailbox, const char *folder) -{ - static int warned = 0; - if (ast_messagecount_func) - return ast_messagecount_func(context, mailbox, folder); - - if (!warned && (option_verbose > 2)) { - warned++; - ast_verbose(VERBOSE_PREFIX_3 "Message count requested for mailbox %s@%s/%s but voicemail not loaded.\n", mailbox, context, folder); - } - - return 0; -} - -int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between) -{ - const char *ptr; - int res = 0; - struct ast_frame f = { - .frametype = AST_FRAME_DTMF, - .src = "ast_dtmf_stream" - }; - - if (!between) - between = 100; - - if (peer) - res = ast_autoservice_start(peer); - - if (!res) - res = ast_waitfor(chan, 100); - - /* ast_waitfor will return the number of remaining ms on success */ - if (res < 0) - return res; - - for (ptr = digits; *ptr; ptr++) { - if (*ptr == 'w') { - /* 'w' -- wait half a second */ - if ((res = ast_safe_sleep(chan, 500))) - break; - } else if (strchr("0123456789*#abcdfABCDF", *ptr)) { - /* Character represents valid DTMF */ - if (*ptr == 'f' || *ptr == 'F') { - /* ignore return values if not supported by channel */ - ast_indicate(chan, AST_CONTROL_FLASH); - } else { - f.subclass = *ptr; - if ((res = ast_write(chan, &f))) - break; - } - /* pause between digits */ - if ((res = ast_safe_sleep(chan, between))) - break; - } else - ast_log(LOG_WARNING, "Illegal DTMF character '%c' in string. (0-9*#aAbBcCdD allowed)\n",*ptr); - } - - if (peer) { - /* Stop autoservice on the peer channel, but don't overwrite any error condition - that has occurred previously while acting on the primary channel */ - if (ast_autoservice_stop(peer) && !res) - res = -1; - } - - return res; -} - -struct linear_state { - int fd; - int autoclose; - int allowoverride; - int origwfmt; -}; - -static void linear_release(struct ast_channel *chan, void *params) -{ - struct linear_state *ls = params; - if (ls->origwfmt && ast_set_write_format(chan, ls->origwfmt)) { - ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%d'\n", chan->name, ls->origwfmt); - } - if (ls->autoclose) - close(ls->fd); - free(params); -} - -static int linear_generator(struct ast_channel *chan, void *data, int len, int samples) -{ - struct ast_frame f; - short buf[2048 + AST_FRIENDLY_OFFSET / 2]; - struct linear_state *ls = data; - int res; - len = samples * 2; - if (len > sizeof(buf) - AST_FRIENDLY_OFFSET) { - ast_log(LOG_WARNING, "Can't generate %d bytes of data!\n" ,len); - len = sizeof(buf) - AST_FRIENDLY_OFFSET; - } - memset(&f, 0, sizeof(f)); - res = read(ls->fd, buf + AST_FRIENDLY_OFFSET/2, len); - if (res > 0) { - f.frametype = AST_FRAME_VOICE; - f.subclass = AST_FORMAT_SLINEAR; - f.data = buf + AST_FRIENDLY_OFFSET/2; - f.datalen = res; - f.samples = res / 2; - f.offset = AST_FRIENDLY_OFFSET; - ast_write(chan, &f); - if (res == len) - return 0; - } - return -1; -} - -static void *linear_alloc(struct ast_channel *chan, void *params) -{ - struct linear_state *ls; - /* In this case, params is already malloc'd */ - if (params) { - ls = params; - if (ls->allowoverride) - ast_set_flag(chan, AST_FLAG_WRITE_INT); - else - ast_clear_flag(chan, AST_FLAG_WRITE_INT); - ls->origwfmt = chan->writeformat; - if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) { - ast_log(LOG_WARNING, "Unable to set '%s' to linear format (write)\n", chan->name); - free(ls); - ls = params = NULL; - } - } - return params; -} - -static struct ast_generator linearstream = -{ - alloc: linear_alloc, - release: linear_release, - generate: linear_generator, -}; - -int ast_linear_stream(struct ast_channel *chan, const char *filename, int fd, int allowoverride) -{ - struct linear_state *lin; - char tmpf[256]; - int res = -1; - int autoclose = 0; - if (fd < 0) { - if (ast_strlen_zero(filename)) - return -1; - autoclose = 1; - if (filename[0] == '/') - ast_copy_string(tmpf, filename, sizeof(tmpf)); - else - snprintf(tmpf, sizeof(tmpf), "%s/%s/%s", (char *)ast_config_AST_DATA_DIR, "sounds", filename); - fd = open(tmpf, O_RDONLY); - if (fd < 0){ - ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", tmpf, strerror(errno)); - return -1; - } - } - if ((lin = ast_calloc(1, sizeof(*lin)))) { - lin->fd = fd; - lin->allowoverride = allowoverride; - lin->autoclose = autoclose; - res = ast_activate_generator(chan, &linearstream, lin); - } - return res; -} - -int ast_control_streamfile(struct ast_channel *chan, const char *file, - const char *fwd, const char *rev, - const char *stop, const char *pause, - const char *restart, int skipms) -{ - char *breaks = NULL; - char *end = NULL; - int blen = 2; - int res; - long pause_restart_point = 0; - - if (stop) - blen += strlen(stop); - if (pause) - blen += strlen(pause); - if (restart) - blen += strlen(restart); - - if (blen > 2) { - breaks = alloca(blen + 1); - breaks[0] = '\0'; - if (stop) - strcat(breaks, stop); - if (pause) - strcat(breaks, pause); - if (restart) - strcat(breaks, restart); - } - if (chan->_state != AST_STATE_UP) - res = ast_answer(chan); - - if (file) { - if ((end = strchr(file,':'))) { - if (!strcasecmp(end, ":end")) { - *end = '\0'; - end++; - } - } - } - - for (;;) { - ast_stopstream(chan); - res = ast_streamfile(chan, file, chan->language); - if (!res) { - if (pause_restart_point) { - ast_seekstream(chan->stream, pause_restart_point, SEEK_SET); - pause_restart_point = 0; - } - else if (end) { - ast_seekstream(chan->stream, 0, SEEK_END); - end = NULL; - }; - res = ast_waitstream_fr(chan, breaks, fwd, rev, skipms); - } - - if (res < 1) - break; - - /* We go at next loop if we got the restart char */ - if (restart && strchr(restart, res)) { - ast_log(LOG_DEBUG, "we'll restart the stream here at next loop\n"); - pause_restart_point = 0; - continue; - } - - if (pause && strchr(pause, res)) { - pause_restart_point = ast_tellstream(chan->stream); - for (;;) { - ast_stopstream(chan); - res = ast_waitfordigit(chan, 1000); - if (!res) - continue; - else if (res == -1 || strchr(pause, res) || (stop && strchr(stop, res))) - break; - } - if (res == *pause) { - res = 0; - continue; - } - } - - if (res == -1) - break; - - /* if we get one of our stop chars, return it to the calling function */ - if (stop && strchr(stop, res)) - break; - } - - ast_stopstream(chan); - - return res; -} - -int ast_play_and_wait(struct ast_channel *chan, const char *fn) -{ - int d; - d = ast_streamfile(chan, fn, chan->language); - if (d) - return d; - d = ast_waitstream(chan, AST_DIGIT_ANY); - ast_stopstream(chan); - return d; -} - -static int global_silence_threshold = 128; -static int global_maxsilence = 0; - -/*! Optionally play a sound file or a beep, then record audio and video from the channel. - * @param chan Channel to playback to/record from. - * @param playfile Filename of sound to play before recording begins. - * @param recordfile Filename to record to. - * @param maxtime Maximum length of recording (in milliseconds). - * @param fmt Format(s) to record message in. Multiple formats may be specified by separating them with a '|'. - * @param duration Where to store actual length of the recorded message (in milliseconds). - * @param beep Whether to play a beep before starting to record. - * @param silencethreshold - * @param maxsilence Length of silence that will end a recording (in milliseconds). - * @param path Optional filesystem path to unlock. - * @param prepend If true, prepend the recorded audio to an existing file. - * @param acceptdtmf DTMF digits that will end the recording. - * @param canceldtmf DTMF digits that will cancel the recording. - */ - -static int __ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int beep, int silencethreshold, int maxsilence, const char *path, int prepend, const char *acceptdtmf, const char *canceldtmf) -{ - int d = 0; - char *fmts; - char comment[256]; - int x, fmtcnt = 1, res = -1, outmsg = 0; - struct ast_filestream *others[MAX_OTHER_FORMATS]; - char *sfmt[MAX_OTHER_FORMATS]; - char *stringp = NULL; - time_t start, end; - struct ast_dsp *sildet = NULL; /* silence detector dsp */ - int totalsilence = 0; - int rfmt = 0; - struct ast_silence_generator *silgen = NULL; - char prependfile[80]; - - if (silencethreshold < 0) - silencethreshold = global_silence_threshold; - - if (maxsilence < 0) - maxsilence = global_maxsilence; - - /* barf if no pointer passed to store duration in */ - if (duration == NULL) { - ast_log(LOG_WARNING, "Error play_and_record called without duration pointer\n"); - return -1; - } - - ast_log(LOG_DEBUG,"play_and_record: %s, %s, '%s'\n", playfile ? playfile : "", recordfile, fmt); - snprintf(comment, sizeof(comment), "Playing %s, Recording to: %s on %s\n", playfile ? playfile : "", recordfile, chan->name); - - if (playfile || beep) { - if (!beep) - d = ast_play_and_wait(chan, playfile); - if (d > -1) - d = ast_stream_and_wait(chan, "beep", chan->language, ""); - if (d < 0) - return -1; - } - - if (prepend) { - ast_copy_string(prependfile, recordfile, sizeof(prependfile)); - strncat(prependfile, "-prepend", sizeof(prependfile) - strlen(prependfile) - 1); - } - - fmts = ast_strdupa(fmt); - - stringp = fmts; - strsep(&stringp, "|"); - ast_log(LOG_DEBUG, "Recording Formats: sfmts=%s\n", fmts); - sfmt[0] = ast_strdupa(fmts); - - while ((fmt = strsep(&stringp, "|"))) { - if (fmtcnt > MAX_OTHER_FORMATS - 1) { - ast_log(LOG_WARNING, "Please increase MAX_OTHER_FORMATS in app.c\n"); - break; - } - sfmt[fmtcnt++] = ast_strdupa(fmt); - } - - end = start = time(NULL); /* pre-initialize end to be same as start in case we never get into loop */ - for (x = 0; x < fmtcnt; x++) { - others[x] = ast_writefile(prepend ? prependfile : recordfile, sfmt[x], comment, O_TRUNC, 0, 0700); - if (option_verbose > 2) - ast_verbose(VERBOSE_PREFIX_3 "x=%d, open writing: %s format: %s, %p\n", x, prepend ? prependfile : recordfile, sfmt[x], others[x]); - - if (!others[x]) - break; - } - - if (path) - ast_unlock_path(path); - - if (maxsilence > 0) { - sildet = ast_dsp_new(); /* Create the silence detector */ - if (!sildet) { - ast_log(LOG_WARNING, "Unable to create silence detector :(\n"); - return -1; - } - ast_dsp_set_threshold(sildet, silencethreshold); - rfmt = chan->readformat; - res = ast_set_read_format(chan, AST_FORMAT_SLINEAR); - if (res < 0) { - ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n"); - ast_dsp_free(sildet); - return -1; - } - } - - if (!prepend) { - /* Request a video update */ - ast_indicate(chan, AST_CONTROL_VIDUPDATE); - - if (ast_opt_transmit_silence) - silgen = ast_channel_start_silence_generator(chan); - } - - if (x == fmtcnt) { - /* Loop forever, writing the packets we read to the writer(s), until - we read a digit or get a hangup */ - struct ast_frame *f; - for (;;) { - res = ast_waitfor(chan, 2000); - if (!res) { - ast_log(LOG_DEBUG, "One waitfor failed, trying another\n"); - /* Try one more time in case of masq */ - res = ast_waitfor(chan, 2000); - if (!res) { - ast_log(LOG_WARNING, "No audio available on %s??\n", chan->name); - res = -1; - } - } - - if (res < 0) { - f = NULL; - break; - } - f = ast_read(chan); - if (!f) - break; - if (f->frametype == AST_FRAME_VOICE) { - /* write each format */ - for (x = 0; x < fmtcnt; x++) { - if (prepend && !others[x]) - break; - res = ast_writestream(others[x], f); - } - - /* Silence Detection */ - if (maxsilence > 0) { - int dspsilence = 0; - ast_dsp_silence(sildet, f, &dspsilence); - if (dspsilence) - totalsilence = dspsilence; - else - totalsilence = 0; - - if (totalsilence > maxsilence) { - /* Ended happily with silence */ - if (option_verbose > 2) - ast_verbose( VERBOSE_PREFIX_3 "Recording automatically stopped after a silence of %d seconds\n", totalsilence/1000); - res = 'S'; - outmsg = 2; - break; - } - } - /* Exit on any error */ - if (res) { - ast_log(LOG_WARNING, "Error writing frame\n"); - break; - } - } else if (f->frametype == AST_FRAME_VIDEO) { - /* Write only once */ - ast_writestream(others[0], f); - } else if (f->frametype == AST_FRAME_DTMF) { - if (prepend) { - /* stop recording with any digit */ - if (option_verbose > 2) - ast_verbose(VERBOSE_PREFIX_3 "User ended message by pressing %c\n", f->subclass); - res = 't'; - outmsg = 2; - break; - } - if (strchr(acceptdtmf, f->subclass)) { - if (option_verbose > 2) - ast_verbose(VERBOSE_PREFIX_3 "User ended message by pressing %c\n", f->subclass); - res = f->subclass; - outmsg = 2; - break; - } - if (strchr(canceldtmf, f->subclass)) { - if (option_verbose > 2) - ast_verbose(VERBOSE_PREFIX_3 "User cancelled message by pressing %c\n", f->subclass); - res = f->subclass; - outmsg = 0; - break; - } - } - if (maxtime) { - end = time(NULL); - if (maxtime < (end - start)) { - if (option_verbose > 2) - ast_verbose(VERBOSE_PREFIX_3 "Took too long, cutting it short...\n"); - res = 't'; - outmsg = 2; - break; - } - } - ast_frfree(f); - } - if (!f) { - if (option_verbose > 2) - ast_verbose(VERBOSE_PREFIX_3 "User hung up\n"); - res = -1; - outmsg = 1; - } else { - ast_frfree(f); - } - if (end == start) - end = time(NULL); - } else { - ast_log(LOG_WARNING, "Error creating writestream '%s', format '%s'\n", recordfile, sfmt[x]); - } - - if (!prepend) { - if (silgen) - ast_channel_stop_silence_generator(chan, silgen); - } - *duration = end - start; - - if (!prepend) { - for (x = 0; x < fmtcnt; x++) { - if (!others[x]) - break; - if (res > 0) - ast_stream_rewind(others[x], totalsilence ? totalsilence - 200 : 200); - ast_truncstream(others[x]); - ast_closestream(others[x]); - } - } - - if (prepend && outmsg) { - struct ast_filestream *realfiles[MAX_OTHER_FORMATS]; - struct ast_frame *fr; - - for (x = 0; x < fmtcnt; x++) { - snprintf(comment, sizeof(comment), "Opening the real file %s.%s\n", recordfile, sfmt[x]); - realfiles[x] = ast_readfile(recordfile, sfmt[x], comment, O_RDONLY, 0, 0); - if (!others[x] || !realfiles[x]) - break; - ast_stream_rewind(others[x], totalsilence ? totalsilence - 200 : 200); - ast_truncstream(others[x]); - /* add the original file too */ - while ((fr = ast_readframe(realfiles[x]))) { - ast_writestream(others[x], fr); - ast_frfree(fr); - } - ast_closestream(others[x]); - ast_closestream(realfiles[x]); - ast_filerename(prependfile, recordfile, sfmt[x]); - if (option_verbose > 3) - ast_verbose(VERBOSE_PREFIX_4 "Recording Format: sfmts=%s, prependfile %s, recordfile %s\n", sfmt[x], prependfile, recordfile); - ast_filedelete(prependfile, sfmt[x]); - } - } - if (rfmt && ast_set_read_format(chan, rfmt)) { - ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(rfmt), chan->name); - } - if (outmsg == 2) { - ast_stream_and_wait(chan, "auth-thankyou", chan->language, ""); - } - if (sildet) - ast_dsp_free(sildet); - return res; -} - -static char default_acceptdtmf[] = "#"; -static char default_canceldtmf[] = ""; - -int ast_play_and_record_full(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int silencethreshold, int maxsilence, const char *path, const char *acceptdtmf, const char *canceldtmf) -{ - return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, 0, silencethreshold, maxsilence, path, 0, S_OR(acceptdtmf, default_acceptdtmf), S_OR(canceldtmf, default_canceldtmf)); -} - -int ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int silencethreshold, int maxsilence, const char *path) -{ - return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, 0, silencethreshold, maxsilence, path, 0, default_acceptdtmf, default_canceldtmf); -} - -int ast_play_and_prepend(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt, int *duration, int beep, int silencethreshold, int maxsilence) -{ - return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, beep, silencethreshold, maxsilence, NULL, 1, default_acceptdtmf, default_canceldtmf); -} - -/* Channel group core functions */ - -int ast_app_group_split_group(const char *data, char *group, int group_max, char *category, int category_max) -{ - int res=0; - char tmp[256]; - char *grp=NULL, *cat=NULL; - - if (!ast_strlen_zero(data)) { - ast_copy_string(tmp, data, sizeof(tmp)); - grp = tmp; - cat = strchr(tmp, '@'); - if (cat) { - *cat = '\0'; - cat++; - } - } - - if (!ast_strlen_zero(grp)) - ast_copy_string(group, grp, group_max); - else - res = -1; - - if (cat) - snprintf(category, category_max, "%s_%s", GROUP_CATEGORY_PREFIX, cat); - else - ast_copy_string(category, GROUP_CATEGORY_PREFIX, category_max); - - return res; -} - -int ast_app_group_set_channel(struct ast_channel *chan, const char *data) -{ - int res=0; - char group[80] = ""; - char category[80] = ""; - - if (!ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category))) { - pbx_builtin_setvar_helper(chan, category, group); - } else - res = -1; - - return res; -} - -int ast_app_group_get_count(const char *group, const char *category) -{ - struct ast_channel *chan; - int count = 0; - const char *test; - char cat[80]; - const char *s; - - if (ast_strlen_zero(group)) - return 0; - - s = S_OR(category, GROUP_CATEGORY_PREFIX); - ast_copy_string(cat, s, sizeof(cat)); - - chan = NULL; - while ((chan = ast_channel_walk_locked(chan)) != NULL) { - test = pbx_builtin_getvar_helper(chan, cat); - if (test && !strcasecmp(test, group)) - count++; - ast_channel_unlock(chan); - } - - return count; -} - -int ast_app_group_match_get_count(const char *groupmatch, const char *category) -{ - regex_t regexbuf; - struct ast_channel *chan; - int count = 0; - const char *test; - char cat[80]; - const char *s; - - if (ast_strlen_zero(groupmatch)) - return 0; - - /* if regex compilation fails, return zero matches */ - if (regcomp(®exbuf, groupmatch, REG_EXTENDED | REG_NOSUB)) - return 0; - - s = S_OR(category, GROUP_CATEGORY_PREFIX); - ast_copy_string(cat, s, sizeof(cat)); - - chan = NULL; - while ((chan = ast_channel_walk_locked(chan)) != NULL) { - test = pbx_builtin_getvar_helper(chan, cat); - if (test && !regexec(®exbuf, test, 0, NULL, 0)) - count++; - ast_channel_unlock(chan); - } - - regfree(®exbuf); - - return count; -} - -unsigned int ast_app_separate_args(char *buf, char delim, char **array, int arraylen) -{ - int argc; - char *scan; - int paren = 0, quote = 0; - - if (!buf || !array || !arraylen) - return 0; - - memset(array, 0, arraylen * sizeof(*array)); - - scan = buf; - - for (argc = 0; *scan && (argc < arraylen - 1); argc++) { - array[argc] = scan; - for (; *scan; scan++) { - if (*scan == '(') - paren++; - else if (*scan == ')') { - if (paren) - paren--; - } else if (*scan == '"' && delim != '"') { - quote = quote ? 0 : 1; - /* Remove quote character from argument */ - memmove(scan, scan + 1, strlen(scan)); - scan--; - } else if (*scan == '\\') { - /* Literal character, don't parse */ - memmove(scan, scan + 1, strlen(scan)); - } else if ((*scan == delim) && !paren && !quote) { - *scan++ = '\0'; - break; - } - } - } - - if (*scan) - array[argc++] = scan; - - return argc; -} - -enum AST_LOCK_RESULT ast_lock_path(const char *path) -{ - char *s; - char *fs; - int res; - int fd; - int lp = strlen(path); - time_t start; - - if (!(s = alloca(lp + 10)) || !(fs = alloca(lp + 20))) { - ast_log(LOG_WARNING, "Out of memory!\n"); - return AST_LOCK_FAILURE; - } - - snprintf(fs, strlen(path) + 19, "%s/.lock-%08lx", path, ast_random()); - fd = open(fs, O_WRONLY | O_CREAT | O_EXCL, 0600); - if (fd < 0) { - ast_log(LOG_ERROR, "Unable to create lock file '%s': %s\n", path, strerror(errno)); - return AST_LOCK_PATH_NOT_FOUND; - } - close(fd); - - snprintf(s, strlen(path) + 9, "%s/.lock", path); - start = time(NULL); - while (((res = link(fs, s)) < 0) && (errno == EEXIST) && (time(NULL) - start < 5)) - usleep(1); - - unlink(fs); - - if (res) { - ast_log(LOG_WARNING, "Failed to lock path '%s': %s\n", path, strerror(errno)); - return AST_LOCK_TIMEOUT; - } else { - ast_log(LOG_DEBUG, "Locked path '%s'\n", path); - return AST_LOCK_SUCCESS; - } -} - -int ast_unlock_path(const char *path) -{ - char *s; - int res; - - if (!(s = alloca(strlen(path) + 10))) { - ast_log(LOG_WARNING, "Out of memory!\n"); - return -1; - } - - snprintf(s, strlen(path) + 9, "%s/%s", path, ".lock"); - - if ((res = unlink(s))) - ast_log(LOG_ERROR, "Could not unlock path '%s': %s\n", path, strerror(errno)); - else - ast_log(LOG_DEBUG, "Unlocked path '%s'\n", path); - - return res; -} - -int ast_record_review(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, const char *path) -{ - int silencethreshold = 128; - int maxsilence=0; - int res = 0; - int cmd = 0; - int max_attempts = 3; - int attempts = 0; - int recorded = 0; - int message_exists = 0; - /* Note that urgent and private are for flagging messages as such in the future */ - - /* barf if no pointer passed to store duration in */ - if (duration == NULL) { - ast_log(LOG_WARNING, "Error ast_record_review called without duration pointer\n"); - return -1; - } - - cmd = '3'; /* Want to start by recording */ - - while ((cmd >= 0) && (cmd != 't')) { - switch (cmd) { - case '1': - if (!message_exists) { - /* In this case, 1 is to record a message */ - cmd = '3'; - break; - } else { - ast_stream_and_wait(chan, "vm-msgsaved", chan->language, ""); - cmd = 't'; - return res; - } - case '2': - /* Review */ - ast_verbose(VERBOSE_PREFIX_3 "Reviewing the recording\n"); - cmd = ast_stream_and_wait(chan, recordfile, chan->language, AST_DIGIT_ANY); - break; - case '3': - message_exists = 0; - /* Record */ - if (recorded == 1) - ast_verbose(VERBOSE_PREFIX_3 "Re-recording\n"); - else - ast_verbose(VERBOSE_PREFIX_3 "Recording\n"); - recorded = 1; - cmd = ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, silencethreshold, maxsilence, path); - if (cmd == -1) { - /* User has hung up, no options to give */ - return cmd; - } - if (cmd == '0') { - break; - } else if (cmd == '*') { - break; - } - else { - /* If all is well, a message exists */ - message_exists = 1; - cmd = 0; - } - break; - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '*': - case '#': - cmd = ast_play_and_wait(chan, "vm-sorry"); - break; - default: - if (message_exists) { - cmd = ast_play_and_wait(chan, "vm-review"); - } - else { - cmd = ast_play_and_wait(chan, "vm-torerecord"); - if (!cmd) - cmd = ast_waitfordigit(chan, 600); - } - - if (!cmd) - cmd = ast_waitfordigit(chan, 6000); - if (!cmd) { - attempts++; - } - if (attempts > max_attempts) { - cmd = 't'; - } - } - } - if (cmd == 't') - cmd = 0; - return cmd; -} - -#define RES_UPONE (1 << 16) -#define RES_EXIT (1 << 17) -#define RES_REPEAT (1 << 18) -#define RES_RESTART ((1 << 19) | RES_REPEAT) - -static int ast_ivr_menu_run_internal(struct ast_channel *chan, struct ast_ivr_menu *menu, void *cbdata); - -static int ivr_dispatch(struct ast_channel *chan, struct ast_ivr_option *option, char *exten, void *cbdata) -{ - int res; - int (*ivr_func)(struct ast_channel *, void *); - char *c; - char *n; - - switch(option->action) { - case AST_ACTION_UPONE: - return RES_UPONE; - case AST_ACTION_EXIT: - return RES_EXIT | (((unsigned long)(option->adata)) & 0xffff); - case AST_ACTION_REPEAT: - return RES_REPEAT | (((unsigned long)(option->adata)) & 0xffff); - case AST_ACTION_RESTART: - return RES_RESTART ; - case AST_ACTION_NOOP: - return 0; - case AST_ACTION_BACKGROUND: - res = ast_stream_and_wait(chan, (char *)option->adata, chan->language, AST_DIGIT_ANY); - if (res < 0) { - ast_log(LOG_NOTICE, "Unable to find file '%s'!\n", (char *)option->adata); - res = 0; - } - return res; - case AST_ACTION_PLAYBACK: - res = ast_stream_and_wait(chan, (char *)option->adata, chan->language, ""); - if (res < 0) { - ast_log(LOG_NOTICE, "Unable to find file '%s'!\n", (char *)option->adata); - res = 0; - } - return res; - case AST_ACTION_MENU: - res = ast_ivr_menu_run_internal(chan, (struct ast_ivr_menu *)option->adata, cbdata); - /* Do not pass entry errors back up, treaat ast though ti was an "UPONE" */ - if (res == -2) - res = 0; - return res; - case AST_ACTION_WAITOPTION: - res = ast_waitfordigit(chan, 1000 * (chan->pbx ? chan->pbx->rtimeout : 10)); - if (!res) - return 't'; - return res; - case AST_ACTION_CALLBACK: - ivr_func = option->adata; - res = ivr_func(chan, cbdata); - return res; - case AST_ACTION_TRANSFER: - res = ast_parseable_goto(chan, option->adata); - return 0; - case AST_ACTION_PLAYLIST: - case AST_ACTION_BACKLIST: - res = 0; - c = ast_strdupa(option->adata); - while ((n = strsep(&c, ";"))) { - if ((res = ast_stream_and_wait(chan, n, chan->language, - (option->action == AST_ACTION_BACKLIST) ? AST_DIGIT_ANY : ""))) - break; - } - ast_stopstream(chan); - return res; - default: - ast_log(LOG_NOTICE, "Unknown dispatch function %d, ignoring!\n", option->action); - return 0; - }; - return -1; -} - -static int option_exists(struct ast_ivr_menu *menu, char *option) -{ - int x; - for (x = 0; menu->options[x].option; x++) - if (!strcasecmp(menu->options[x].option, option)) - return x; - return -1; -} - -static int option_matchmore(struct ast_ivr_menu *menu, char *option) -{ - int x; - for (x = 0; menu->options[x].option; x++) - if ((!strncasecmp(menu->options[x].option, option, strlen(option))) && - (menu->options[x].option[strlen(option)])) - return x; - return -1; -} - -static int read_newoption(struct ast_channel *chan, struct ast_ivr_menu *menu, char *exten, int maxexten) -{ - int res=0; - int ms; - while (option_matchmore(menu, exten)) { - ms = chan->pbx ? chan->pbx->dtimeout : 5000; - if (strlen(exten) >= maxexten - 1) - break; - res = ast_waitfordigit(chan, ms); - if (res < 1) - break; - exten[strlen(exten) + 1] = '\0'; - exten[strlen(exten)] = res; - } - return res > 0 ? 0 : res; -} - -static int ast_ivr_menu_run_internal(struct ast_channel *chan, struct ast_ivr_menu *menu, void *cbdata) -{ - /* Execute an IVR menu structure */ - int res=0; - int pos = 0; - int retries = 0; - char exten[AST_MAX_EXTENSION] = "s"; - if (option_exists(menu, "s") < 0) { - strcpy(exten, "g"); - if (option_exists(menu, "g") < 0) { - ast_log(LOG_WARNING, "No 's' nor 'g' extension in menu '%s'!\n", menu->title); - return -1; - } - } - while(!res) { - while(menu->options[pos].option) { - if (!strcasecmp(menu->options[pos].option, exten)) { - res = ivr_dispatch(chan, menu->options + pos, exten, cbdata); - ast_log(LOG_DEBUG, "IVR Dispatch of '%s' (pos %d) yields %d\n", exten, pos, res); - if (res < 0) - break; - else if (res & RES_UPONE) - return 0; - else if (res & RES_EXIT) - return res; - else if (res & RES_REPEAT) { - int maxretries = res & 0xffff; - if ((res & RES_RESTART) == RES_RESTART) { - retries = 0; - } else - retries++; - if (!maxretries) - maxretries = 3; - if ((maxretries > 0) && (retries >= maxretries)) { - ast_log(LOG_DEBUG, "Max retries %d exceeded\n", maxretries); - return -2; - } else { - if (option_exists(menu, "g") > -1) - strcpy(exten, "g"); - else if (option_exists(menu, "s") > -1) - strcpy(exten, "s"); - } - pos = 0; - continue; - } else if (res && strchr(AST_DIGIT_ANY, res)) { - ast_log(LOG_DEBUG, "Got start of extension, %c\n", res); - exten[1] = '\0'; - exten[0] = res; - if ((res = read_newoption(chan, menu, exten, sizeof(exten)))) - break; - if (option_exists(menu, exten) < 0) { - if (option_exists(menu, "i")) { - ast_log(LOG_DEBUG, "Invalid extension entered, going to 'i'!\n"); - strcpy(exten, "i"); - pos = 0; - continue; - } else { - ast_log(LOG_DEBUG, "Aborting on invalid entry, with no 'i' option!\n"); - res = -2; - break; - } - } else { - ast_log(LOG_DEBUG, "New existing extension: %s\n", exten); - pos = 0; - continue; - } - } - } - pos++; - } - ast_log(LOG_DEBUG, "Stopping option '%s', res is %d\n", exten, res); - pos = 0; - if (!strcasecmp(exten, "s")) - strcpy(exten, "g"); - else - break; - } - return res; -} - -int ast_ivr_menu_run(struct ast_channel *chan, struct ast_ivr_menu *menu, void *cbdata) -{ - int res = ast_ivr_menu_run_internal(chan, menu, cbdata); - /* Hide internal coding */ - return res > 0 ? 0 : res; -} - -char *ast_read_textfile(const char *filename) -{ - int fd; - char *output = NULL; - struct stat filesize; - int count = 0; - int res; - if (stat(filename, &filesize) == -1) { - ast_log(LOG_WARNING, "Error can't stat %s\n", filename); - return NULL; - } - count = filesize.st_size + 1; - fd = open(filename, O_RDONLY); - if (fd < 0) { - ast_log(LOG_WARNING, "Cannot open file '%s' for reading: %s\n", filename, strerror(errno)); - return NULL; - } - if ((output = ast_malloc(count))) { - res = read(fd, output, count - 1); - if (res == count - 1) { - output[res] = '\0'; - } else { - ast_log(LOG_WARNING, "Short read of %s (%d of %d): %s\n", filename, res, count - 1, strerror(errno)); - free(output); - output = NULL; - } - } - close(fd); - return output; -} - -int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr) -{ - char *s; - int curarg; - unsigned int argloc; - char *arg; - int res = 0; - - ast_clear_flag(flags, AST_FLAGS_ALL); - - if (!optstr) - return 0; - - s = optstr; - while (*s) { - curarg = *s++ & 0x7f; /* the array (in app.h) has 128 entries */ - ast_set_flag(flags, options[curarg].flag); - argloc = options[curarg].arg_index; - if (*s == '(') { - /* Has argument */ - arg = ++s; - s = strchr(s, ')'); - if (*s) { - if (argloc) - args[argloc - 1] = arg; - *s++ = '\0'; - } else { - ast_log(LOG_WARNING, "Missing closing parenthesis for argument '%c' in string '%s'\n", curarg, arg); - res = -1; - } - } else if (argloc) { - args[argloc - 1] = NULL; - } - } - - return res; -} - diff --git a/apps/Makefile b/apps/Makefile index df5f60a44..0373a3b63 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -9,7 +9,7 @@ # the GNU General Public License # -ifneq ($(wildcard ../menuselect.makeopts),) +ifneq ($(wildcard $(ASTTOPDIR)/menuselect.makeopts),) include ../menuselect.makeopts include ../menuselect.makedeps endif @@ -17,22 +17,25 @@ endif C_MODS:=$(filter-out $(MENUSELECT_APPS),$(patsubst %.c,%,$(wildcard app_*.c))) CC_MODS:=$(filter-out $(MENUSELECT_APPS),$(patsubst %.cc,%,$(wildcard app_*.cc))) -SELECTED_MODS:=$(C_MODS) $(CC_MODS) +LOADABLE_MODS:=$(C_MODS) $(CC_MODS) + +ifneq ($(findstring apps,$(MENUSELECT_EMBED)),) + EMBEDDED_MODS:=$(LOADABLE_MODS) + LOADABLE_MODS:= +endif ifneq ($(findstring ODBC_STORAGE,$(MENUSELECT_OPTS_app_voicemail)),) MENUSELECT_DEPENDS_app_voicemail+=$(MENUSELECT_DEPENDS_ODBC_STORAGE) endif -ifneq ($(findstring EXTENDED_ODBC_STORAGE,$(MENUSELECT_OPTS_app_voicemail)),) -MENUSELECT_DEPENDS_app_voicemail+=$(MENUSELECT_DEPENDS_EXTENDED_ODBC_STORAGE) -endif ifneq ($(findstring IMAP_STORAGE,$(MENUSELECT_OPTS_app_voicemail)),) MENUSELECT_DEPENDS_app_voicemail+=$(MENUSELECT_DEPENDS_IMAP_STORAGE) endif +ifeq (SunOS,$(shell uname)) +MENUSELECT_DEPENDS_app_chanspy+=RT +RT_LIB=-lrt +endif + all: _all include $(ASTTOPDIR)/Makefile.moddir_rules - -ifeq (SunOS,$(shell uname)) -app_chanspy.so: LIBS+=-lrt -endif diff --git a/apps/app_adsiprog.c b/apps/app_adsiprog.c index e8ab87802..04b9000fd 100644 --- a/apps/app_adsiprog.c +++ b/apps/app_adsiprog.c @@ -1545,9 +1545,9 @@ static int adsi_prog(struct ast_channel *chan, char *script) static int adsi_exec(struct ast_channel *chan, void *data) { int res=0; - struct localuser *u; + struct ast_module_user *u; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (ast_strlen_zero(data)) data = "asterisk.adsi"; @@ -1561,16 +1561,16 @@ static int adsi_exec(struct ast_channel *chan, void *data) res = adsi_prog(chan, data); } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); res = ast_unregister_application(app); @@ -1578,20 +1578,9 @@ static int unload_module(void *mod) return res; } -static int load_module(void *mod) +static int load_module(void) { - __mod_desc = mod; return ast_register_application(app, adsi_exec, synopsis, descrip); } -static const char *description(void) -{ - return "Asterisk ADSI Programming Application"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD(MOD_1, NULL, NULL, NULL); +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Asterisk ADSI Programming Application"); diff --git a/apps/app_alarmreceiver.c b/apps/app_alarmreceiver.c index faa2c6a00..5b745d0ab 100644 --- a/apps/app_alarmreceiver.c +++ b/apps/app_alarmreceiver.c @@ -626,13 +626,13 @@ static int receive_ademco_contact_id( struct ast_channel *chan, void *data, int static int alarmreceiver_exec(struct ast_channel *chan, void *data) { int res = 0; - struct localuser *u; + struct ast_module_user *u; event_node_t *elp, *efree; char signalling_type[64] = ""; event_node_t *event_head = NULL; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); /* Set write and read formats to ULAW */ @@ -641,13 +641,13 @@ static int alarmreceiver_exec(struct ast_channel *chan, void *data) if (ast_set_write_format(chan,AST_FORMAT_ULAW)){ ast_log(LOG_WARNING, "AlarmReceiver: Unable to set write format to Mu-law on %s\n",chan->name); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } if (ast_set_read_format(chan,AST_FORMAT_ULAW)){ ast_log(LOG_WARNING, "AlarmReceiver: Unable to set read format to Mu-law on %s\n",chan->name); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -666,7 +666,7 @@ static int alarmreceiver_exec(struct ast_channel *chan, void *data) res = ast_answer(chan); if (res) { - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } } @@ -721,7 +721,7 @@ static int alarmreceiver_exec(struct ast_channel *chan, void *data) } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } @@ -818,32 +818,21 @@ static int load_config(void) */ -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { - __mod_desc = mod; load_config(); return ast_register_application(app, alarmreceiver_exec, synopsis, descrip); } -static const char *description(void) -{ - return "Alarm Receiver for Asterisk"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Alarm Receiver for Asterisk"); diff --git a/apps/app_amd.c b/apps/app_amd.c index 1ffc463b2..2f7148b9c 100644 --- a/apps/app_amd.c +++ b/apps/app_amd.c @@ -321,11 +321,11 @@ static void isAnsweringMachine(struct ast_channel *chan, void *data) static int amd_exec(struct ast_channel *chan, void *data) { - struct localuser *u; + struct ast_module_user *u; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); isAnsweringMachine(chan, data); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } @@ -385,33 +385,26 @@ static void load_config(void) return; } -static int unload_module(void *mod) +static int unload_module(void) { - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return ast_unregister_application(app); } -static int load_module(void *mod) +static int load_module(void) { - __mod_desc = mod; load_config(); return ast_register_application(app, amd_exec, synopsis, descrip); } -static int reload(void *mod) +static int reload(void) { load_config(); return 0; } -static const char *description(void) -{ - return "Answering Machine Detection Application"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD(MOD_1, reload, NULL, NULL); +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Answering Machine Detection Application", + .load = load_module, + .unload = unload_module, + .reload = reload, + ); diff --git a/apps/app_authenticate.c b/apps/app_authenticate.c index 0e6b8eb2c..03bc5ed81 100644 --- a/apps/app_authenticate.c +++ b/apps/app_authenticate.c @@ -95,7 +95,7 @@ static int auth_exec(struct ast_channel *chan, void *data) { int res=0; int retries; - struct localuser *u; + struct ast_module_user *u; char passwd[256]; char *prompt; int maxdigits; @@ -113,12 +113,12 @@ static int auth_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (chan->_state != AST_STATE_UP) { res = ast_answer(chan); if (res) { - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } } @@ -226,15 +226,15 @@ static int auth_exec(struct ast_channel *chan, void *data) res = -1; } } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); res = ast_unregister_application(app); @@ -242,19 +242,9 @@ static int unload_module(void *mod) return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, auth_exec, synopsis, descrip); } -static const char *description(void) -{ - return "Authentication Application"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD(MOD_1, NULL, NULL, NULL); +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Authentication Application"); diff --git a/apps/app_cdr.c b/apps/app_cdr.c index 8d20fb012..e8f76a602 100644 --- a/apps/app_cdr.c +++ b/apps/app_cdr.c @@ -43,48 +43,37 @@ static char *nocdr_descrip = static char *nocdr_app = "NoCDR"; static char *nocdr_synopsis = "Tell Asterisk to not maintain a CDR for the current call"; -LOCAL_USER_DECL; static int nocdr_exec(struct ast_channel *chan, void *data) { - struct localuser *u; + struct ast_module_user *u; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (chan->cdr) { ast_cdr_free(chan->cdr); chan->cdr = NULL; } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(nocdr_app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(nocdr_app, nocdr_exec, nocdr_synopsis, nocdr_descrip); } -static const char *description(void) -{ - return "Tell Asterisk to not maintain a CDR for the current call"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD(MOD_1, NULL, NULL, NULL); +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Tell Asterisk to not maintain a CDR for the current call"); diff --git a/apps/app_chanisavail.c b/apps/app_chanisavail.c index c23aa6edc..c6931d8db 100644 --- a/apps/app_chanisavail.c +++ b/apps/app_chanisavail.c @@ -63,13 +63,12 @@ static char *descrip = " s - Consider the channel unavailable if the channel is in use at all\n" " j - Support jumping to priority n+101 if no channel is available\n"; -LOCAL_USER_DECL; static int chanavail_exec(struct ast_channel *chan, void *data) { int res=-1, inuse=-1, option_state=0, priority_jump=0; int status; - struct localuser *u; + struct ast_module_user *u; char *info, tmp[512], trychan[512], *peers, *tech, *number, *rest, *cur; struct ast_channel *tempchan; AST_DECLARE_APP_ARGS(args, @@ -82,7 +81,7 @@ static int chanavail_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); info = ast_strdupa(data); @@ -108,7 +107,7 @@ static int chanavail_exec(struct ast_channel *chan, void *data) number = strchr(tech, '/'); if (!number) { ast_log(LOG_WARNING, "ChanIsAvail argument takes format ([technology]/[device])\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } *number = '\0'; @@ -145,41 +144,30 @@ static int chanavail_exec(struct ast_channel *chan, void *data) pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", ""); if (priority_jump || ast_opt_priority_jumping) { if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) { - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } } } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } -static int unload_module(void *mod) +static int unload_module(void) { int res = 0; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { - __mod_desc = mod; return ast_register_application(app, chanavail_exec, synopsis, descrip); } -static const char *description(void) -{ - return "Check channel availability"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Check channel availability"); diff --git a/apps/app_channelredirect.c b/apps/app_channelredirect.c index ada623018..a8eedf9b4 100644 --- a/apps/app_channelredirect.c +++ b/apps/app_channelredirect.c @@ -48,12 +48,11 @@ static char *descrip = "ChannelRedirect(channel|[[context|]extension|]priority):\n" " Sends the specified channel to the specified extension priority\n"; -LOCAL_USER_DECL; static int asyncgoto_exec(struct ast_channel *chan, void *data) { int res = -1; - struct localuser *u; + struct ast_module_user *u; char *info, *context, *exten, *priority; int prio = 1; struct ast_channel *chan2 = NULL; @@ -68,7 +67,7 @@ static int asyncgoto_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); info = ast_strdupa(data); AST_STANDARD_APP_ARGS(args, info); @@ -117,36 +116,25 @@ static int asyncgoto_exec(struct ast_channel *chan, void *data) chanquit: ast_mutex_unlock(&chan2->lock); quit: - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { - __mod_desc = mod; return ast_register_application(app, asyncgoto_exec, synopsis, descrip); } -static const char *description(void) -{ - return "Channel Redirect"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Channel Redirect"); diff --git a/apps/app_chanspy.c b/apps/app_chanspy.c index a4fcb0b4a..1f8a9f01c 100644 --- a/apps/app_chanspy.c +++ b/apps/app_chanspy.c @@ -140,7 +140,6 @@ AST_APP_OPTIONS(spy_opts, { AST_APP_OPTION_ARG('r', OPTION_RECORD, OPT_ARG_RECORD), }); -LOCAL_USER_DECL; struct chanspy_translation_helper { /* spy data */ @@ -540,7 +539,7 @@ static int common_exec(struct ast_channel *chan, const struct ast_flags *flags, static int chanspy_exec(struct ast_channel *chan, void *data) { - struct localuser *u; + struct ast_module_user *u; char *options = NULL; char *spec = NULL; char *argv[2]; @@ -555,7 +554,7 @@ static int chanspy_exec(struct ast_channel *chan, void *data) data = ast_strdupa(data); - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if ((argc = ast_app_separate_args(data, '|', argv, sizeof(argv) / sizeof(argv[0])))) { spec = argv[0]; @@ -593,7 +592,7 @@ static int chanspy_exec(struct ast_channel *chan, void *data) oldwf = chan->writeformat; if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) { ast_log(LOG_ERROR, "Could Not Set Write Format.\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -615,14 +614,14 @@ static int chanspy_exec(struct ast_channel *chan, void *data) if (oldwf && ast_set_write_format(chan, oldwf) < 0) ast_log(LOG_ERROR, "Could Not Set Write Format.\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } static int extenspy_exec(struct ast_channel *chan, void *data) { - struct localuser *u; + struct ast_module_user *u; char *options = NULL; char *exten = NULL; char *context = NULL; @@ -638,7 +637,7 @@ static int extenspy_exec(struct ast_channel *chan, void *data) data = ast_strdupa(data); - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if ((argc = ast_app_separate_args(data, '|', argv, sizeof(argv) / sizeof(argv[0])))) { context = argv[0]; @@ -676,7 +675,7 @@ static int extenspy_exec(struct ast_channel *chan, void *data) oldwf = chan->writeformat; if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) { ast_log(LOG_ERROR, "Could Not Set Write Format.\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -698,43 +697,31 @@ static int extenspy_exec(struct ast_channel *chan, void *data) if (oldwf && ast_set_write_format(chan, oldwf) < 0) ast_log(LOG_ERROR, "Could Not Set Write Format.\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res = 0; res |= ast_unregister_application(app_chan); res |= ast_unregister_application(app_ext); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { int res = 0; - __mod_desc = mod; - res |= ast_register_application(app_chan, chanspy_exec, tdesc, desc_chan); res |= ast_register_application(app_ext, extenspy_exec, tdesc, desc_ext); return res; } -static const char *description(void) -{ - return (char *) tdesc; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD(MOD_1, NULL, NULL, NULL); +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Listen to the audio of an active channel"); diff --git a/apps/app_controlplayback.c b/apps/app_controlplayback.c index a2e3929da..8a5a845cd 100644 --- a/apps/app_controlplayback.c +++ b/apps/app_controlplayback.c @@ -66,7 +66,6 @@ static const char *descrip = " CPLAYBACKSTATUS - This variable contains the status of the attempt as a text\n" " string, one of: SUCCESS | USERSTOPPED | ERROR\n"; -LOCAL_USER_DECL; static int is_on_phonepad(char key) { @@ -77,7 +76,7 @@ static int controlplayback_exec(struct ast_channel *chan, void *data) { int res = 0, priority_jump = 0; int skipms = 0; - struct localuser *u; + struct ast_module_user *u; char *tmp; int argc; char *argv[8]; @@ -97,7 +96,7 @@ static int controlplayback_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); tmp = ast_strdupa(data); memset(argv, 0, sizeof(argv)); @@ -106,7 +105,7 @@ static int controlplayback_exec(struct ast_channel *chan, void *data) if (argc < 1) { ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -149,31 +148,21 @@ static int controlplayback_exec(struct ast_channel *chan, void *data) pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "SUCCESS"); } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, controlplayback_exec, synopsis, descrip); } -static const char *description(void) -{ - return "Control Playback Application"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD(MOD_1, NULL, NULL, NULL); +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Control Playback Application"); diff --git a/apps/app_db.c b/apps/app_db.c index fc8c52b1a..73d092ab6 100644 --- a/apps/app_db.c +++ b/apps/app_db.c @@ -64,14 +64,13 @@ static char *dt_app = "DBdeltree"; static char *d_synopsis = "Delete a key from the database"; static char *dt_synopsis = "Delete a family or keytree from the database"; -LOCAL_USER_DECL; static int deltree_exec(struct ast_channel *chan, void *data) { char *argv, *family, *keytree; - struct localuser *u; + struct ast_module_user *u; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); argv = ast_strdupa(data); @@ -80,7 +79,7 @@ static int deltree_exec(struct ast_channel *chan, void *data) keytree = strsep(&argv, "\0"); if (!family || !keytree) { ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } if (ast_strlen_zero(keytree)) @@ -102,7 +101,7 @@ static int deltree_exec(struct ast_channel *chan, void *data) ast_verbose(VERBOSE_PREFIX_3 "DBdeltree: Error deleting key from database.\n"); } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } @@ -110,10 +109,10 @@ static int deltree_exec(struct ast_channel *chan, void *data) static int del_exec(struct ast_channel *chan, void *data) { char *argv, *family, *key; - struct localuser *u; + struct ast_module_user *u; static int deprecation_warning = 0; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (!deprecation_warning) { deprecation_warning = 1; @@ -127,7 +126,7 @@ static int del_exec(struct ast_channel *chan, void *data) key = strsep(&argv, "\0"); if (!family || !key) { ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } if (option_verbose > 2) @@ -140,12 +139,12 @@ static int del_exec(struct ast_channel *chan, void *data) ast_log(LOG_DEBUG, "Ignoring, no parameters\n"); } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } -static int unload_module(void *mod) +static int unload_module(void) { int retval; @@ -155,25 +154,14 @@ static int unload_module(void *mod) return retval; } -static int load_module(void *mod) +static int load_module(void) { int retval; - __mod_desc = mod; retval = ast_register_application(d_app, del_exec, d_synopsis, d_descrip); retval |= ast_register_application(dt_app, deltree_exec, dt_synopsis, dt_descrip); return retval; } -static const char *description(void) -{ - return "Database Access Functions"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD(MOD_1, NULL, NULL, NULL); +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Database Access Functions"); diff --git a/apps/app_dial.c b/apps/app_dial.c index 99392abbc..13b5b3371 100644 --- a/apps/app_dial.c +++ b/apps/app_dial.c @@ -298,7 +298,6 @@ struct dial_localuser { struct dial_localuser *next; }; -LOCAL_USER_DECL; static void hanguptree(struct dial_localuser *outgoing, struct ast_channel *exception) { @@ -769,7 +768,7 @@ static int valid_priv_reply(struct ast_flags *opts, int res) static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags *peerflags) { int res = -1; - struct localuser *u; + struct ast_module_user *u; char *rest, *cur; struct dial_localuser *outgoing = NULL; struct ast_channel *peer; @@ -813,7 +812,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); parse = ast_strdupa(data); @@ -1634,7 +1633,7 @@ out: res = 0; done: - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } @@ -1650,7 +1649,7 @@ static int retrydial_exec(struct ast_channel *chan, void *data) char *announce = NULL, *dialdata = NULL; const char *context = NULL; int sleep = 0, loops = 0, res = -1; - struct localuser *u; + struct ast_module_user *u; struct ast_flags peerflags; if (ast_strlen_zero(data)) { @@ -1658,7 +1657,7 @@ static int retrydial_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); announce = ast_strdupa(data); @@ -1739,23 +1738,23 @@ static int retrydial_exec(struct ast_channel *chan, void *data) if (ast_test_flag(chan, AST_FLAG_MOH)) ast_moh_stop(chan); done: - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); res |= ast_unregister_application(rapp); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { int res; @@ -1765,14 +1764,4 @@ static int load_module(void *mod) return res; } -static const char *description(void) -{ - return "Dialing Application"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD(MOD_1, NULL, NULL, NULL); +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dialing Application"); diff --git a/apps/app_dictate.c b/apps/app_dictate.c index b77a389ae..0c46118e4 100644 --- a/apps/app_dictate.c +++ b/apps/app_dictate.c @@ -51,7 +51,6 @@ static char *synopsis = "Virtual Dictation Machine"; static char *desc = " Dictate([[|]])\n" "Start dictation machine using optional base dir for files.\n"; -LOCAL_USER_DECL; typedef enum { DFLAG_RECORD = (1 << 0), @@ -90,7 +89,7 @@ static int dictate_exec(struct ast_channel *chan, void *data) struct ast_flags flags = {0}; struct ast_filestream *fs; struct ast_frame *f = NULL; - struct localuser *u; + struct ast_module_user *u; int ffactor = 320 * 80, res = 0, done = 0, @@ -103,7 +102,7 @@ static int dictate_exec(struct ast_channel *chan, void *data) maxlen = 0, mode = 0; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); snprintf(dftbase, sizeof(dftbase), "%s/dictate", ast_config_AST_SPOOL_DIR); if (!ast_strlen_zero(data)) { @@ -123,7 +122,7 @@ static int dictate_exec(struct ast_channel *chan, void *data) oldr = chan->readformat; if ((res = ast_set_read_format(chan, AST_FORMAT_SLINEAR)) < 0) { ast_log(LOG_WARNING, "Unable to set to linear mode.\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -330,31 +329,20 @@ static int dictate_exec(struct ast_channel *chan, void *data) if (oldr) { ast_set_read_format(chan, oldr); } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); return res; } -static int load_module(void *mod) +static int load_module(void) { - __mod_desc = mod; return ast_register_application(app, dictate_exec, synopsis, desc); } -static const char *description(void) -{ - return "Virtual Dictation Machine"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD(MOD_1, NULL, NULL, NULL); +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Virtual Dictation Machine"); diff --git a/apps/app_directed_pickup.c b/apps/app_directed_pickup.c index c79bad26f..e45c87603 100644 --- a/apps/app_directed_pickup.c +++ b/apps/app_directed_pickup.c @@ -53,12 +53,11 @@ static const char *descrip = "10@PICKUPMARK, this application tries to find a channel which has defined a channel variable with the same context\n" "as \"extension\"."; -LOCAL_USER_DECL; static int pickup_exec(struct ast_channel *chan, void *data) { int res = 0; - struct localuser *u = NULL; + struct ast_module_user *u = NULL; struct ast_channel *origin = NULL, *target = NULL; char *tmp = NULL, *exten = NULL, *context = NULL, *rest=data; char workspace[256] = ""; @@ -69,7 +68,7 @@ static int pickup_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); while (!target && (exten = rest) ) { res = 0; @@ -146,12 +145,12 @@ static int pickup_exec(struct ast_channel *chan, void *data) if (target) ast_mutex_unlock(&target->lock); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; @@ -160,20 +159,9 @@ static int unload_module(void *mod) return res; } -static int load_module(void *mod) +static int load_module(void) { - __mod_desc = mod; return ast_register_application(app, pickup_exec, synopsis, descrip); } -static const char *description(void) -{ - return "Directed Call Pickup Application"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD(MOD_1, NULL, NULL, NULL); +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Directed Call Pickup Application"); diff --git a/apps/app_directory.c b/apps/app_directory.c index 55e91ce49..6f660e326 100644 --- a/apps/app_directory.c +++ b/apps/app_directory.c @@ -87,7 +87,6 @@ static char *descrip = /* How many digits to read in */ #define NUMDIGITS 3 -LOCAL_USER_DECL; #ifdef USE_ODBC_STORAGE static void retrieve_file(char *dir) @@ -514,7 +513,7 @@ static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char * static int directory_exec(struct ast_channel *chan, void *data) { int res = 0; - struct localuser *u; + struct ast_module_user *u; struct ast_config *cfg; int last = 1; int readext = 0; @@ -531,7 +530,7 @@ static int directory_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); parse = ast_strdupa(data); @@ -552,7 +551,7 @@ static int directory_exec(struct ast_channel *chan, void *data) cfg = realtime_directory(args.vmcontext); if (!cfg) { ast_log(LOG_ERROR, "Unable to read the configuration data!\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -583,20 +582,19 @@ static int directory_exec(struct ast_channel *chan, void *data) break; } ast_config_destroy(cfg); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); return res; } -static int load_module(void *mod) +static int load_module(void) { - __mod_desc = mod; #ifdef USE_ODBC_STORAGE struct ast_config *cfg = ast_config_load(VOICEMAIL_CONFIG); char *tmp; @@ -619,14 +617,4 @@ static int load_module(void *mod) return ast_register_application(app, directory_exec, synopsis, descrip); } -static const char *description(void) -{ - return "Extension Directory"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Extension Directory"); diff --git a/apps/app_disa.c b/apps/app_disa.c index 12019acbd..1ec0531bf 100644 --- a/apps/app_disa.c +++ b/apps/app_disa.c @@ -95,7 +95,6 @@ static char *descrip = "exists in the context, it will be used. Also, if you set the 5th argument\n" "to 'NOANSWER', the DISA application will not answer initially.\n"; -LOCAL_USER_DECL; static void play_dialtone(struct ast_channel *chan, char *mailbox) { @@ -115,7 +114,7 @@ static int disa_exec(struct ast_channel *chan, void *data) int i,j,k,x,did_ignore,special_noanswer; int firstdigittimeout = 20000; int digittimeout = 10000; - struct localuser *u; + struct ast_module_user *u; char *tmp, exten[AST_MAX_EXTENSION],acctcode[20]=""; char pwline[256]; char ourcidname[256],ourcidnum[256]; @@ -137,7 +136,7 @@ static int disa_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (chan->pbx) { firstdigittimeout = chan->pbx->rtimeout*1000; @@ -146,12 +145,12 @@ static int disa_exec(struct ast_channel *chan, void *data) if (ast_set_write_format(chan,AST_FORMAT_ULAW)) { ast_log(LOG_WARNING, "Unable to set write format to Mu-law on %s\n", chan->name); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } if (ast_set_read_format(chan,AST_FORMAT_ULAW)) { ast_log(LOG_WARNING, "Unable to set read format to Mu-law on %s\n", chan->name); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -209,13 +208,13 @@ static int disa_exec(struct ast_channel *chan, void *data) f = ast_read(chan); if (f == NULL) { - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP)) { ast_frfree(f); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } if (f->frametype == AST_FRAME_VOICE) { @@ -245,7 +244,7 @@ static int disa_exec(struct ast_channel *chan, void *data) fp = fopen(args.passcode,"r"); if (!fp) { ast_log(LOG_WARNING,"DISA password file %s not found on chan %s\n",args.passcode,chan->name); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } pwline[0] = 0; @@ -346,7 +345,7 @@ static int disa_exec(struct ast_channel *chan, void *data) if (special_noanswer) flags.flags = 0; ast_cdr_reset(chan->cdr, &flags); ast_explicit_goto(chan, args.context, exten, 1); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } } @@ -367,34 +366,24 @@ reorder: ast_frfree(f); } ast_playtones_stop(chan); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, disa_exec, synopsis, descrip); } -static const char *description(void) -{ - return "DISA (Direct Inward System Access) Application"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "DISA (Direct Inward System Access) Application"); diff --git a/apps/app_dumpchan.c b/apps/app_dumpchan.c index 8a06baef3..426ba4eab 100644 --- a/apps/app_dumpchan.c +++ b/apps/app_dumpchan.c @@ -56,7 +56,6 @@ static char *desc = "displayed when the verbose level is currently set to that number\n" "or greater. \n"; -LOCAL_USER_DECL; static int serialize_showchan(struct ast_channel *c, char *buf, size_t size) { @@ -137,13 +136,13 @@ static int serialize_showchan(struct ast_channel *c, char *buf, size_t size) static int dumpchan_exec(struct ast_channel *chan, void *data) { - struct localuser *u; + struct ast_module_user *u; char vars[BUFSIZ * 4]; char info[1024]; int level = 0; static char *line = "================================================================================"; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (!ast_strlen_zero(data)) level = atoi(data); @@ -153,35 +152,25 @@ static int dumpchan_exec(struct ast_channel *chan, void *data) if (option_verbose >= level) ast_verbose("\nDumping Info For Channel: %s:\n%s\nInfo:\n%s\nVariables:\n%s%s\n", chan->name, line, info, vars, line); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, dumpchan_exec, synopsis, desc); } -static const char *description(void) -{ - return "Dump Info About The Calling Channel"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dump Info About The Calling Channel"); diff --git a/apps/app_echo.c b/apps/app_echo.c index 85df130f1..19a86382e 100644 --- a/apps/app_echo.c +++ b/apps/app_echo.c @@ -41,8 +41,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/pbx.h" #include "asterisk/module.h" -static char *tdesc = "Simple Echo Application"; - static char *app = "Echo"; static char *synopsis = "Echo audio, video, or DTMF back to the calling party"; @@ -52,15 +50,14 @@ static char *descrip = "the calling channel back to itself. If the DTMF digit '#' is received, the\n" "application will exit.\n"; -LOCAL_USER_DECL; static int echo_exec(struct ast_channel *chan, void *data) { int res = -1; int format; - struct localuser *u; + struct ast_module_user *u; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); format = ast_best_codec(chan->nativeformats); ast_set_write_format(chan, format); @@ -95,34 +92,24 @@ static int echo_exec(struct ast_channel *chan, void *data) ast_frfree(f); } end: - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, echo_exec, synopsis, descrip); } -static const char *description(void) -{ - return tdesc; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application"); diff --git a/apps/app_exec.c b/apps/app_exec.c index d0c2591df..0aafac343 100644 --- a/apps/app_exec.c +++ b/apps/app_exec.c @@ -45,8 +45,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") /* Maximum length of any variable */ #define MAXRESULT 1024 -static char *tdesc = "Executes dialplan applications"; - /*! Note * * The key difference between these two apps is exit status. In a @@ -90,16 +88,14 @@ static char *execif_descrip = "If is true, but is not found, then the application\n" "will return a non-zero value.\n"; -LOCAL_USER_DECL; - static int exec_exec(struct ast_channel *chan, void *data) { int res=0; - struct localuser *u; + struct ast_module_user *u; char *s, *appname, *endargs, args[MAXRESULT] = ""; struct ast_app *app; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); /* Check and parse arguments */ if (data) { @@ -122,18 +118,18 @@ static int exec_exec(struct ast_channel *chan, void *data) } } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } static int tryexec_exec(struct ast_channel *chan, void *data) { int res=0; - struct localuser *u; + struct ast_module_user *u; char *s, *appname, *endargs, args[MAXRESULT] = ""; struct ast_app *app; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); /* Check and parse arguments */ if (data) { @@ -157,19 +153,20 @@ static int tryexec_exec(struct ast_channel *chan, void *data) } } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } -static int execif_exec(struct ast_channel *chan, void *data) { - int res=0; - struct localuser *u; +static int execif_exec(struct ast_channel *chan, void *data) +{ + int res = 0; + struct ast_module_user *u; char *myapp = NULL; char *mydata = NULL; char *expr = NULL; struct ast_app *app = NULL; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); expr = ast_strdupa(data); @@ -195,11 +192,12 @@ static int execif_exec(struct ast_channel *chan, void *data) { res = -1; } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); + return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; @@ -207,12 +205,12 @@ static int unload_module(void *mod) res |= ast_unregister_application(app_tryexec); res |= ast_unregister_application(app_execif); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { int res = ast_register_application(app_exec, exec_exec, exec_synopsis, exec_descrip); res |= ast_register_application(app_tryexec, tryexec_exec, tryexec_synopsis, tryexec_descrip); @@ -220,14 +218,4 @@ static int load_module(void *mod) return res; } -static const char *description(void) -{ - return tdesc; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Executes dialplan applications"); diff --git a/apps/app_externalivr.c b/apps/app_externalivr.c index 787cc369c..e81f4f34f 100644 --- a/apps/app_externalivr.c +++ b/apps/app_externalivr.c @@ -83,7 +83,6 @@ struct ivr_localuser { int option_autoclear; }; -LOCAL_USER_DECL; struct gen_state { struct ivr_localuser *u; @@ -242,7 +241,7 @@ static struct playlist_entry *make_entry(const char *filename) static int app_exec(struct ast_channel *chan, void *data) { - struct localuser *lu = NULL; + struct ast_module_user *lu; struct playlist_entry *entry; const char *args = data; int child_stdin[2] = { 0,0 }; @@ -263,14 +262,14 @@ static int app_exec(struct ast_channel *chan, void *data) }; struct ivr_localuser *u = &foo; - LOCAL_USER_ADD(lu); + lu = ast_module_user_add(chan); u->abort_current_sound = 0; u->chan = chan; if (ast_strlen_zero(args)) { ast_log(LOG_WARNING, "ExternalIVR requires a command to execute\n"); - LOCAL_USER_REMOVE(lu); + ast_module_user_remove(lu); return -1; } @@ -545,35 +544,25 @@ static int app_exec(struct ast_channel *chan, void *data) while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list))) free(entry); - LOCAL_USER_REMOVE(lu); + ast_module_user_remove(lu); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, app_exec, synopsis, descrip); } -static const char *description(void) -{ - return "External IVR Interface Application"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "External IVR Interface Application"); diff --git a/apps/app_festival.c b/apps/app_festival.c index caec727c8..f6e1d7503 100644 --- a/apps/app_festival.c +++ b/apps/app_festival.c @@ -68,7 +68,6 @@ static char *descrip = "play it to the user, allowing any given interrupt keys to immediately terminate and return\n" "the value, or 'any' to allow any number back (useful in dialplan)\n"; -LOCAL_USER_DECL; static char *socket_receive_file_to_buff(int fd,int *size) { @@ -275,7 +274,7 @@ static int festival_exec(struct ast_channel *chan, void *vdata) { int usecache; int res=0; - struct localuser *u; + struct ast_module_user *u; struct sockaddr_in serv_addr; struct hostent *serverhost; struct ast_hostent ahp; @@ -314,12 +313,12 @@ static int festival_exec(struct ast_channel *chan, void *vdata) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); cfg = ast_config_load(FESTIVAL_CONFIG); if (!cfg) { ast_log(LOG_WARNING, "No such configuration file %s\n", FESTIVAL_CONFIG); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } if (!(host = ast_variable_retrieve(cfg, "general", "host"))) { @@ -376,7 +375,7 @@ static int festival_exec(struct ast_channel *chan, void *vdata) if (fd < 0) { ast_log(LOG_WARNING,"festival_client: can't get socket\n"); ast_config_destroy(cfg); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } memset(&serv_addr, 0, sizeof(serv_addr)); @@ -386,7 +385,7 @@ static int festival_exec(struct ast_channel *chan, void *vdata) if (serverhost == (struct hostent *)0) { ast_log(LOG_WARNING,"festival_client: gethostbyname failed\n"); ast_config_destroy(cfg); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } memmove(&serv_addr.sin_addr,serverhost->h_addr, serverhost->h_length); @@ -397,7 +396,7 @@ static int festival_exec(struct ast_channel *chan, void *vdata) if (connect(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != 0) { ast_log(LOG_WARNING,"festival_client: connect to server failed\n"); ast_config_destroy(cfg); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -489,7 +488,7 @@ static int festival_exec(struct ast_channel *chan, void *vdata) ast_log(LOG_WARNING,"Unable to read from cache/festival fd"); close(fd); ast_config_destroy(cfg); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } n += read_data; @@ -516,36 +515,25 @@ static int festival_exec(struct ast_channel *chan, void *vdata) } while (strcmp(ack,"OK\n") != 0); close(fd); ast_config_destroy(cfg); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, festival_exec, synopsis, descrip); } -static const char *description(void) -{ - return "Simple Festival Interface"; - -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Festival Interface"); diff --git a/apps/app_flash.c b/apps/app_flash.c index d237fbc06..446b2a1f8 100644 --- a/apps/app_flash.c +++ b/apps/app_flash.c @@ -59,7 +59,6 @@ static char *descrip = "people who want to perform transfers and such via AGI and is generally\n" "quite useless oths application will only work on Zap trunks.\n"; -LOCAL_USER_DECL; static inline int zt_wait_event(int fd) { @@ -75,9 +74,9 @@ static int flash_exec(struct ast_channel *chan, void *data) { int res = -1; int x; - struct localuser *u; + struct ast_module_user *u; struct zt_params ztp; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (!strcasecmp(chan->tech->type, "Zap")) { memset(&ztp, 0, sizeof(ztp)); res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp); @@ -101,35 +100,25 @@ static int flash_exec(struct ast_channel *chan, void *data) ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno)); } else ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, flash_exec, synopsis, descrip); } -static const char *description(void) -{ - return "Flash zap trunk application"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application"); diff --git a/apps/app_followme.c b/apps/app_followme.c index 09fb45169..24f134d85 100644 --- a/apps/app_followme.c +++ b/apps/app_followme.c @@ -72,10 +72,7 @@ static char *descrip = " s - Playback the incoming status message prior to starting the follow-me step(s)\n" " a - Record the caller's name so it can be announced to the callee on each step\n" " n - Playback the unreachable status message if we've run out of steps to reach the\n" -" or the callee has elected not to be reachable.\n" - - -LOCAL_USER_DECL; +" or the callee has elected not to be reachable.\n"; struct number { char number[512]; /*!< Phone Number(s) and/or Extension(s) */ @@ -916,7 +913,7 @@ static int app_exec(struct ast_channel *chan, void *data) struct ast_call_followme *f; struct number *nm, *newnm; int res = 0; - struct localuser *u; + struct ast_module_user *u; char *argstr; char namerecloc[255]; int duration = 0; @@ -938,7 +935,7 @@ static int app_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); AST_STANDARD_APP_ARGS(args, argstr); @@ -1074,47 +1071,47 @@ static int app_exec(struct ast_channel *chan, void *data) } outrun: - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); + return res; } -static int unload_module(void *mod) +static int unload_module(void) { struct ast_call_followme *f; - STANDARD_HANGUP_LOCALUSERS; + + ast_module_user_hangup_all(); + ast_unregister_application(app); + /* Free Memory. Yeah! I'm free! */ AST_LIST_LOCK(&followmes); - AST_LIST_TRAVERSE_SAFE_BEGIN(&followmes, f, entry) { + while ((f = AST_LIST_REMOVE_HEAD(&followmes, entry))) { free_numbers(f); - AST_LIST_REMOVE_CURRENT(&followmes, entry); free(f); } - AST_LIST_TRAVERSE_SAFE_END + AST_LIST_UNLOCK(&followmes); + return 0; } -static int load_module(void *mod) +static int load_module(void) { reload_followme(); - return ast_register_application(app, app_exec, synopsis, descrip); -} -static const char *description(void) -{ - return "Find-Me/Follow-Me Application"; + return ast_register_application(app, app_exec, synopsis, descrip); } -static int reload(void *mod) +static int reload(void) { reload_followme(); - return 0; -} -static const char *key(void) -{ - return ASTERISK_GPL_KEY; + return 0; } -STD_MOD(MOD_1, reload, NULL, NULL); +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Find-Me/Follow-Me Application", + .load = load_module, + .unload = unload_module, + .reload = reload, + ); diff --git a/apps/app_forkcdr.c b/apps/app_forkcdr.c index 620148604..d9c5b293f 100644 --- a/apps/app_forkcdr.c +++ b/apps/app_forkcdr.c @@ -50,7 +50,6 @@ static char *descrip = "cdr record starting from the time of the fork call\n" "If the option 'v' is passed all cdr variables will be passed along also.\n"; -LOCAL_USER_DECL; static void ast_cdr_fork(struct ast_channel *chan) { @@ -78,48 +77,38 @@ static void ast_cdr_fork(struct ast_channel *chan) static int forkcdr_exec(struct ast_channel *chan, void *data) { int res = 0; - struct localuser *u; + struct ast_module_user *u; if (!chan->cdr) { ast_log(LOG_WARNING, "Channel does not have a CDR\n"); return 0; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (!ast_strlen_zero(data)) ast_set2_flag(chan->cdr, strchr(data, 'v'), AST_CDR_FLAG_KEEP_VARS); ast_cdr_fork(chan); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, forkcdr_exec, synopsis, descrip); } -static const char *description(void) -{ - return "Fork The CDR into 2 separate entities."; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Fork The CDR into 2 separate entities"); diff --git a/apps/app_getcpeid.c b/apps/app_getcpeid.c index be0e0657d..7dbd5f6fd 100644 --- a/apps/app_getcpeid.c +++ b/apps/app_getcpeid.c @@ -51,7 +51,6 @@ static char *descrip = " GetCPEID: Obtains and displays ADSI CPE ID and other information in order\n" "to properly setup zapata.conf for on-hook operations.\n"; -LOCAL_USER_DECL; static int cpeid_setstatus(struct ast_channel *chan, char *stuff[], int voice) { @@ -67,7 +66,7 @@ static int cpeid_setstatus(struct ast_channel *chan, char *stuff[], int voice) static int cpeid_exec(struct ast_channel *chan, void *idata) { int res=0; - struct localuser *u; + struct ast_module_user *u; unsigned char cpeid[4]; int gotgeometry = 0; int gotcpeid = 0; @@ -75,7 +74,7 @@ static int cpeid_exec(struct ast_channel *chan, void *idata) char data[4][80]; char *stuff[4]; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); stuff[0] = data[0]; stuff[1] = data[1]; stuff[2] = data[2]; @@ -127,34 +126,24 @@ static int cpeid_exec(struct ast_channel *chan, void *idata) adsi_unload_session(chan); } } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, cpeid_exec, synopsis, descrip); } -static const char *description(void) -{ - return "Get ADSI CPE ID"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get ADSI CPE ID"); diff --git a/apps/app_hasnewvoicemail.c b/apps/app_hasnewvoicemail.c index 22a5d3f30..33204bbe9 100644 --- a/apps/app_hasnewvoicemail.c +++ b/apps/app_hasnewvoicemail.c @@ -77,11 +77,10 @@ static char *hasnewvoicemail_descrip = " HASVMSTATUS The result of the new voicemail check returned as a text string as follows\n" " <# of messages in the folder, 0 for NONE>\n"; -LOCAL_USER_DECL; static int hasvoicemail_exec(struct ast_channel *chan, void *data) { - struct localuser *u; + struct ast_module_user *u; char *input, *varname = NULL, *vmbox, *context = "default"; char *vmfolder; int vmcount = 0; @@ -104,7 +103,7 @@ static int hasvoicemail_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); input = ast_strdupa(data); @@ -146,21 +145,21 @@ static int hasvoicemail_exec(struct ast_channel *chan, void *data) snprintf(tmp, sizeof(tmp), "%d", vmcount); pbx_builtin_setvar_helper(chan, "HASVMSTATUS", tmp); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } static int acf_vmcount_exec(struct ast_channel *chan, char *cmd, char *argsstr, char *buf, size_t len) { - struct localuser *u; + struct ast_module_user *u; char *context; AST_DECLARE_APP_ARGS(args, AST_APP_ARG(vmbox); AST_APP_ARG(folder); ); - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); buf[0] = '\0'; @@ -179,7 +178,7 @@ static int acf_vmcount_exec(struct ast_channel *chan, char *cmd, char *argsstr, snprintf(buf, len, "%d", ast_app_messagecount(context, args.vmbox, args.folder)); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } @@ -194,7 +193,7 @@ struct ast_custom_function acf_vmcount = { .read = acf_vmcount_exec, }; -static int unload_module(void *mod) +static int unload_module(void) { int res; @@ -202,12 +201,12 @@ static int unload_module(void *mod) res |= ast_unregister_application(app_hasvoicemail); res |= ast_unregister_application(app_hasnewvoicemail); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { int res; @@ -218,14 +217,4 @@ static int load_module(void *mod) return res; } -static const char *description(void) -{ - return "Indicator for whether a voice mailbox has messages in a given folder."; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Indicator for whether a voice mailbox has messages in a given folder."); diff --git a/apps/app_ices.c b/apps/app_ices.c index 67b107e41..9d93dabdf 100644 --- a/apps/app_ices.c +++ b/apps/app_ices.c @@ -60,7 +60,6 @@ static char *descrip = "(available separately). A configuration file must be supplied\n" "for ices (see examples/asterisk-ices.conf). \n"; -LOCAL_USER_DECL; static int icesencode(char *filename, int fd) { @@ -91,7 +90,7 @@ static int icesencode(char *filename, int fd) static int ices_exec(struct ast_channel *chan, void *data) { int res=0; - struct localuser *u; + struct ast_module_user *u; int fds[2]; int ms = -1; int pid = -1; @@ -107,13 +106,13 @@ static int ices_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); last = ast_tv(0, 0); if (pipe(fds)) { ast_log(LOG_WARNING, "Unable to create pipe\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } flags = fcntl(fds[1], F_GETFL); @@ -128,7 +127,7 @@ static int ices_exec(struct ast_channel *chan, void *data) close(fds[0]); close(fds[1]); ast_log(LOG_WARNING, "Answer failed!\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -138,7 +137,7 @@ static int ices_exec(struct ast_channel *chan, void *data) close(fds[0]); close(fds[1]); ast_log(LOG_WARNING, "Unable to set write format to signed linear\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } if (((char *)data)[0] == '/') @@ -188,35 +187,25 @@ static int ices_exec(struct ast_channel *chan, void *data) if (!res && oreadformat) ast_set_read_format(chan, oreadformat); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, ices_exec, synopsis, descrip); } -static const char *description(void) -{ - return "Encode and Stream via icecast and ices"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Encode and Stream via icecast and ices"); diff --git a/apps/app_image.c b/apps/app_image.c index b6308f0be..f5f327197 100644 --- a/apps/app_image.c +++ b/apps/app_image.c @@ -44,8 +44,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/app.h" #include "asterisk/options.h" -static char *tdesc = "Image Transmission Application"; - static char *app = "SendImage"; static char *synopsis = "Send an image file"; @@ -61,12 +59,11 @@ static char *descrip = " SENDIMAGESTATUS The status is the result of the attempt as a text string, one of\n" " OK | NOSUPPORT \n"; -LOCAL_USER_DECL; static int sendimage_exec(struct ast_channel *chan, void *data) { int res = 0; - struct localuser *u; + struct ast_module_user *u; char *parse; int priority_jump = 0; AST_DECLARE_APP_ARGS(args, @@ -74,7 +71,7 @@ static int sendimage_exec(struct ast_channel *chan, void *data) AST_APP_ARG(options); ); - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); parse = ast_strdupa(data); @@ -95,7 +92,7 @@ static int sendimage_exec(struct ast_channel *chan, void *data) if (priority_jump || ast_opt_priority_jumping) ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101); pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "NOSUPPORT"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } @@ -104,35 +101,25 @@ static int sendimage_exec(struct ast_channel *chan, void *data) if (!res) pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "OK"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, sendimage_exec, synopsis, descrip); } -static const char *description(void) -{ - return tdesc; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Image Transmission Application"); diff --git a/apps/app_ivrdemo.c b/apps/app_ivrdemo.c index d3dd2e9a0..933ae9040 100644 --- a/apps/app_ivrdemo.c +++ b/apps/app_ivrdemo.c @@ -88,19 +88,18 @@ AST_IVR_DECLARE_MENU(ivr_demo, "IVR Demo Main Menu", 0, { NULL }, }); -LOCAL_USER_DECL; static int skel_exec(struct ast_channel *chan, void *data) { int res=0; - struct localuser *u; + struct ast_module_user *u; if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "skel requires an argument (filename)\n"); return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); /* Do our thing here */ @@ -109,36 +108,25 @@ static int skel_exec(struct ast_channel *chan, void *data) if (!res) res = ast_ivr_menu_run(chan, &ivr_demo, data); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, skel_exec, tdesc, synopsis); } -static const char *description(void) -{ - return tdesc; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; - +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "IVR Demo Application"); diff --git a/apps/app_lookupblacklist.c b/apps/app_lookupblacklist.c index b0f3a419f..2eb1e545a 100644 --- a/apps/app_lookupblacklist.c +++ b/apps/app_lookupblacklist.c @@ -47,8 +47,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/astdb.h" #include "asterisk/options.h" -static char *tdesc = "Look up Caller*ID name/number from blacklist database"; - static char *app = "LookupBlacklist"; static char *synopsis = "Look up Caller*ID name/number from blacklist database"; @@ -63,7 +61,6 @@ static char *descrip = " FOUND | NOTFOUND\n" "Example: exten => 1234,1,LookupBlacklist()\n"; -LOCAL_USER_DECL; static int blacklist_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { @@ -95,12 +92,12 @@ static int lookupblacklist_exec (struct ast_channel *chan, void *data) { char blacklist[1]; - struct localuser *u; + struct ast_module_user *u; int bl = 0; int priority_jump = 0; static int dep_warning = 0; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (!dep_warning) { dep_warning = 1; @@ -134,38 +131,28 @@ lookupblacklist_exec (struct ast_channel *chan, void *data) } else pbx_builtin_setvar_helper(chan, "LOOKUPBLSTATUS", "NOTFOUND"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); res |= ast_custom_function_unregister(&blacklist_function); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { int res = ast_custom_function_register(&blacklist_function); res |= ast_register_application (app, lookupblacklist_exec, synopsis,descrip); return res; } -static const char *description(void) -{ - return tdesc; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up Caller*ID name/number from blacklist database"); diff --git a/apps/app_lookupcidname.c b/apps/app_lookupcidname.c index 711ca5b76..5a0042a29 100644 --- a/apps/app_lookupcidname.c +++ b/apps/app_lookupcidname.c @@ -45,8 +45,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/callerid.h" #include "asterisk/astdb.h" -static char *tdesc = "Look up CallerID Name from local database"; - static char *app = "LookupCIDName"; static char *synopsis = "Look up CallerID Name from local database"; @@ -59,56 +57,45 @@ static char *descrip = "name delivery, or if you want to change the names on some incoming\n" "calls.\n"; -LOCAL_USER_DECL; -static int -lookupcidname_exec (struct ast_channel *chan, void *data) +static int lookupcidname_exec (struct ast_channel *chan, void *data) { - char dbname[64]; - struct localuser *u; + char dbname[64]; + struct ast_module_user *u; static int dep_warning = 0; - LOCAL_USER_ADD (u); + u = ast_module_user_add(chan); if (!dep_warning) { dep_warning = 1; ast_log(LOG_WARNING, "LookupCIDName is deprecated. Please use ${DB(cidname/${CALLERID(num)})} instead.\n"); } - if (chan->cid.cid_num) { - if (!ast_db_get ("cidname", chan->cid.cid_num, dbname, sizeof (dbname))) { - ast_set_callerid (chan, NULL, dbname, NULL); - if (option_verbose > 2) - ast_verbose (VERBOSE_PREFIX_3 "Changed Caller*ID name to %s\n", - dbname); + if (chan->cid.cid_num) { + if (!ast_db_get ("cidname", chan->cid.cid_num, dbname, sizeof (dbname))) { + ast_set_callerid (chan, NULL, dbname, NULL); + if (option_verbose > 2) + ast_verbose (VERBOSE_PREFIX_3 "Changed Caller*ID name to %s\n", + dbname); + } } - } - LOCAL_USER_REMOVE (u); - return 0; + ast_module_user_remove(u); + + return 0; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application (app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application (app, lookupcidname_exec, synopsis, descrip); } -static const char *description(void) -{ - return tdesc; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Look up CallerID Name from local database"); diff --git a/apps/app_macro.c b/apps/app_macro.c index 13db5ce8a..5adc0a07f 100644 --- a/apps/app_macro.c +++ b/apps/app_macro.c @@ -50,8 +50,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") /* special result value used to force macro exit */ #define MACRO_EXIT_RESULT 1024 -static char *tdesc = "Extension Macros"; - static char *descrip = " Macro(macroname|arg1|arg2...): Executes a macro using the context\n" "'macro-', jumping to the 's' extension of that context and\n" @@ -94,7 +92,6 @@ static char *if_synopsis = "Conditional Macro Implementation"; static char *exclusive_synopsis = "Exclusive Macro Implementation"; static char *exit_synopsis = "Exit From Macro"; -LOCAL_USER_DECL; static int _macro_exec(struct ast_channel *chan, void *data, int exclusive) { @@ -120,14 +117,14 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive) char *save_macro_context; char *save_macro_priority; char *save_macro_offset; - struct localuser *u; + struct ast_module_user *u; if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "Macro() requires arguments. See \"show application macro\" for help.\n"); return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); /* does the user want a deeper rabbit hole? */ s = pbx_builtin_getvar_helper(chan, "MACRO_RECURSION"); @@ -140,7 +137,7 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive) sscanf(s, "%d", &depth); if (depth >= maxdepth) { ast_log(LOG_ERROR, "Macro(): possible infinite loop detected. Returning early.\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } snprintf(depthc, sizeof(depthc), "%d", depth + 1); @@ -151,7 +148,7 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive) macro = strsep(&rest, "|"); if (ast_strlen_zero(macro)) { ast_log(LOG_WARNING, "Invalid macro name specified\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } @@ -161,7 +158,7 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive) ast_log(LOG_WARNING, "No such context '%s' for macro '%s'\n", fullmacro, macro); else ast_log(LOG_WARNING, "Context '%s' for macro '%s' lacks 's' extension, priority 1\n", fullmacro, macro); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } @@ -172,7 +169,8 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive) if (ast_context_lockmacro(fullmacro)) { ast_log(LOG_WARNING, "Failed to lock macro '%s' as in-use\n", fullmacro); ast_autoservice_stop(chan); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); + return 0; } ast_autoservice_stop(chan); @@ -339,7 +337,8 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive) } } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); + return res; } @@ -357,12 +356,12 @@ static int macroif_exec(struct ast_channel *chan, void *data) { char *expr = NULL, *label_a = NULL, *label_b = NULL; int res = 0; - struct localuser *u; + struct ast_module_user *u; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (!(expr = ast_strdupa(data))) { - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -380,7 +379,7 @@ static int macroif_exec(struct ast_channel *chan, void *data) } else ast_log(LOG_WARNING, "Invalid Syntax.\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } @@ -390,7 +389,7 @@ static int macro_exit_exec(struct ast_channel *chan, void *data) return MACRO_EXIT_RESULT; } -static int unload_module(void *mod) +static int unload_module(void) { int res; @@ -399,12 +398,12 @@ static int unload_module(void *mod) res |= ast_unregister_application(app); res |= ast_unregister_application(exclusive_app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { int res; @@ -416,14 +415,4 @@ static int load_module(void *mod) return res; } -static const char *description(void) -{ - return tdesc; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Extension Macros"); diff --git a/apps/app_meetme.c b/apps/app_meetme.c index 4abfdb3c3..1f2ffc5c7 100644 --- a/apps/app_meetme.c +++ b/apps/app_meetme.c @@ -64,8 +64,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "enter.h" #include "leave.h" -LOCAL_USER_DECL; - #define CONFIG_FILE_NAME "meetme.conf" /*! each buffer is 20ms, so this is 640ms total */ @@ -292,8 +290,6 @@ static const char *descripslat = #define CONFIG_FILE_NAME "meetme.conf" #define CONFIG_FILE_NAME_SLA "sla.conf" -LOCAL_USER_DECL; - /*! \brief The MeetMe Conference object */ struct ast_conference { ast_mutex_t playlock; /*!< Conference specific lock (players) */ @@ -2099,7 +2095,7 @@ static struct ast_conference *find_conf(struct ast_channel *chan, char *confno, /*! \brief The MeetmeCount application */ static int count_exec(struct ast_channel *chan, void *data) { - struct localuser *u; + struct ast_module_user *u; int res = 0; struct ast_conference *conf; int count; @@ -2115,10 +2111,10 @@ static int count_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (!(localdata = ast_strdupa(data))) { - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -2140,7 +2136,7 @@ static int count_exec(struct ast_channel *chan, void *data) ast_answer(chan); res = ast_say_number(chan, count, "", chan->language, (char *) NULL); /* Needs gender */ } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } @@ -2149,7 +2145,7 @@ static int count_exec(struct ast_channel *chan, void *data) static int conf_exec(struct ast_channel *chan, void *data) { int res=-1; - struct localuser *u; + struct ast_module_user *u; char confno[AST_MAX_EXTENSION] = ""; int allowretry = 0; int retrycnt = 0; @@ -2165,7 +2161,7 @@ static int conf_exec(struct ast_channel *chan, void *data) AST_APP_ARG(pin); ); - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (ast_strlen_zero(data)) { allowretry = 1; @@ -2403,7 +2399,7 @@ static int conf_exec(struct ast_channel *chan, void *data) } } while (allowretry); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } @@ -2500,7 +2496,7 @@ static int sla_checkforhold(struct ast_conference *conf, int hangup) static int sla_exec(struct ast_channel *chan, void *data, int trunk) { int res=-1; - struct localuser *u; + struct ast_module_user *u; char confno[AST_MAX_EXTENSION] = ""; struct ast_sla *sla; struct ast_conference *cnf; @@ -2526,8 +2522,7 @@ static int sla_exec(struct ast_channel *chan, void *data, int trunk) return -1; } - LOCAL_USER_ADD(u); - + u = ast_module_user_add(chan); if (args.options) ast_app_parse_options(sla_opts, &confflags, NULL, args.options); @@ -2562,7 +2557,7 @@ static int sla_exec(struct ast_channel *chan, void *data, int trunk) ast_log(LOG_WARNING, "SLA%c: SLA '%s' not found!\n", trunk ? 'T' : 'S', args.confno); } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } @@ -2600,7 +2595,7 @@ static int admin_exec(struct ast_channel *chan, void *data) { char *params; struct ast_conference *cnf; struct ast_conf_user *user = NULL; - struct localuser *u; + struct ast_module_user *u; AST_DECLARE_APP_ARGS(args, AST_APP_ARG(confno); AST_APP_ARG(command); @@ -2612,7 +2607,7 @@ static int admin_exec(struct ast_channel *chan, void *data) { return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); AST_LIST_LOCK(&confs); @@ -2622,7 +2617,7 @@ static int admin_exec(struct ast_channel *chan, void *data) { if (!args.command) { ast_log(LOG_WARNING, "MeetmeAdmin requires a command!\n"); AST_LIST_UNLOCK(&confs); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } AST_LIST_TRAVERSE(&confs, cnf, list) { @@ -2632,8 +2627,8 @@ static int admin_exec(struct ast_channel *chan, void *data) { if (!cnf) { ast_log(LOG_WARNING, "Conference number '%s' not found!\n", args.confno); - LOCAL_USER_REMOVE(u); AST_LIST_UNLOCK(&confs); + ast_module_user_remove(u); return 0; } @@ -2740,7 +2735,7 @@ static int admin_exec(struct ast_channel *chan, void *data) { AST_LIST_UNLOCK(&confs); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } @@ -3051,11 +3046,11 @@ static void load_config(void) load_config_sla(); } -static int unload_module(void *mod) +static int unload_module(void) { - int res; + int res = 0; - res = ast_cli_unregister(&cli_show_confs); + res |= ast_cli_unregister(&cli_show_confs); res |= ast_cli_unregister(&cli_sla_show); res |= ast_cli_unregister(&cli_conf); res |= ast_manager_unregister("MeetmeMute"); @@ -3066,14 +3061,14 @@ static int unload_module(void *mod) res |= ast_unregister_application(appslas); res |= ast_unregister_application(appslat); + ast_module_user_hangup_all(); ast_devstate_prov_del("Meetme"); ast_devstate_prov_del("SLA"); - STANDARD_HANGUP_LOCALUSERS; return res; } -static int load_module(void *mod) +static int load_module(void) { int res; @@ -3095,22 +3090,16 @@ static int load_module(void *mod) return res; } -static int reload(void *mod) +static int reload(void) { load_config(); return 0; } -static const char *description(void) -{ - return "MeetMe conference bridge"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD(MOD_1, reload, NULL, NULL); +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "MeetMe conference bridge", + .load = load_module, + .unload = unload_module, + .reload = reload, + ); diff --git a/apps/app_milliwatt.c b/apps/app_milliwatt.c index 8c7fbe4c0..08a96f96b 100644 --- a/apps/app_milliwatt.c +++ b/apps/app_milliwatt.c @@ -50,7 +50,6 @@ static char *synopsis = "Generate a Constant 1000Hz tone at 0dbm (mu-law)"; static char *descrip = "Milliwatt(): Generate a Constant 1000Hz tone at 0dbm (mu-law)\n"; -LOCAL_USER_DECL; static char digital_milliwatt[] = {0x1e,0x0b,0x0b,0x1e,0x9e,0x8b,0x8b,0x9e} ; @@ -118,8 +117,8 @@ static struct ast_generator milliwattgen = static int milliwatt_exec(struct ast_channel *chan, void *data) { - struct localuser *u; - LOCAL_USER_ADD(u); + struct ast_module_user *u; + u = ast_module_user_add(chan); ast_set_write_format(chan, AST_FORMAT_ULAW); ast_set_read_format(chan, AST_FORMAT_ULAW); if (chan->_state != AST_STATE_UP) @@ -129,39 +128,29 @@ static int milliwatt_exec(struct ast_channel *chan, void *data) if (ast_activate_generator(chan,&milliwattgen,"milliwatt") < 0) { ast_log(LOG_WARNING,"Failed to activate generator on '%s'\n",chan->name); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } while(!ast_safe_sleep(chan, 10000)); ast_deactivate_generator(chan); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, milliwatt_exec, synopsis, descrip); } -static const char *description(void) -{ - return "Digital Milliwatt (mu-law) Test Application"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Digital Milliwatt (mu-law) Test Application"); diff --git a/apps/app_mixmonitor.c b/apps/app_mixmonitor.c index 35511c4b2..2aaf7d6a8 100644 --- a/apps/app_mixmonitor.c +++ b/apps/app_mixmonitor.c @@ -164,7 +164,6 @@ static void *mixmonitor_thread(void *obj) struct mixmonitor *mixmonitor = obj; struct ast_frame *f = NULL; - ast_atomic_fetchadd_int(&__mod_desc->usecnt, +1); if (option_verbose > 1) ast_verbose(VERBOSE_PREFIX_2 "Begin MixMonitor Recording %s\n", mixmonitor->name); @@ -219,7 +218,6 @@ static void *mixmonitor_thread(void *obj) free(mixmonitor); - ast_atomic_fetchadd_int(&__mod_desc->usecnt, -1); return NULL; } @@ -322,7 +320,7 @@ static void launch_monitor_thread(struct ast_channel *chan, const char *filename static int mixmonitor_exec(struct ast_channel *chan, void *data) { int x, readvol = 0, writevol = 0; - struct localuser *u; + struct ast_module_user *u; struct ast_flags flags = {0}; char *parse; AST_DECLARE_APP_ARGS(args, @@ -336,7 +334,7 @@ static int mixmonitor_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); parse = ast_strdupa(data); @@ -344,7 +342,7 @@ static int mixmonitor_exec(struct ast_channel *chan, void *data) if (ast_strlen_zero(args.filename)) { ast_log(LOG_WARNING, "MixMonitor requires an argument (filename)\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -396,22 +394,22 @@ static int mixmonitor_exec(struct ast_channel *chan, void *data) pbx_builtin_setvar_helper(chan, "MIXMONITOR_FILENAME", args.filename); launch_monitor_thread(chan, args.filename, flags.flags, readvol, writevol, args.post_process); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } static int stop_mixmonitor_exec(struct ast_channel *chan, void *data) { - struct localuser *u; + struct ast_module_user *u; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); ast_channel_lock(chan); ast_channel_spy_stop_by_type(chan, mixmonitor_spy_type); ast_channel_unlock(chan); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } @@ -453,7 +451,7 @@ static struct ast_cli_entry cli_mixmonitor = { complete_mixmonitor_cli }; -static int unload_module(void *mod) +static int unload_module(void) { int res; @@ -461,12 +459,12 @@ static int unload_module(void *mod) res |= ast_unregister_application(stop_app); res |= ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { int res; @@ -477,14 +475,4 @@ static int load_module(void *mod) return res; } -static const char *description(void) -{ - return "Mixed Audio Monitoring Application"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Mixed Audio Monitoring Application"); diff --git a/apps/app_morsecode.c b/apps/app_morsecode.c index 9bb02479e..cd4211231 100644 --- a/apps/app_morsecode.c +++ b/apps/app_morsecode.c @@ -41,8 +41,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/module.h" #include "asterisk/indications.h" -static char *tdesc = "Morse code"; - static char *app_morsecode = "Morsecode"; static char *morsecode_synopsis = "Plays morse code"; @@ -54,7 +52,6 @@ static char *morsecode_descrip = "(defaults to 80). Additionally, if MORSETONE is set, it will use that tone\n" "(in Hz). The tone default is 800.\n"; -LOCAL_USER_DECL; static char *morsecode[] = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", /* 0-15 */ @@ -114,13 +111,13 @@ static int morsecode_exec(struct ast_channel *chan, void *data) int res=0, ditlen, tone; char *digit; const char *ditlenc, *tonec; - struct localuser *u; + struct ast_module_user *u; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "Syntax: Morsecode() - no argument found\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } @@ -158,34 +155,24 @@ static int morsecode_exec(struct ast_channel *chan, void *data) playtone(chan, 0, 2 * ditlen); } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app_morsecode); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app_morsecode, morsecode_exec, morsecode_synopsis, morsecode_descrip); } -static const char *description(void) -{ - return tdesc; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Morse code"); diff --git a/apps/app_mp3.c b/apps/app_mp3.c index 3a48e7ef8..667de67ad 100644 --- a/apps/app_mp3.c +++ b/apps/app_mp3.c @@ -50,8 +50,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #define LOCAL_MPG_123 "/usr/local/bin/mpg123" #define MPG_123 "/usr/bin/mpg123" -static char *tdesc = "Silly MP3 Application"; - static char *app = "MP3Player"; static char *synopsis = "Play an MP3 file or stream"; @@ -61,7 +59,6 @@ static char *descrip = "which typically would be a filename or a URL. User can exit by pressing\n" "any key on the dialpad, or by hanging up."; -LOCAL_USER_DECL; static int mp3play(char *filename, int fd) { @@ -118,7 +115,7 @@ static int timed_read(int fd, void *data, int datalen, int timeout) static int mp3_exec(struct ast_channel *chan, void *data) { int res=0; - struct localuser *u; + struct ast_module_user *u; int fds[2]; int ms = -1; int pid = -1; @@ -137,11 +134,11 @@ static int mp3_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (pipe(fds)) { ast_log(LOG_WARNING, "Unable to create pipe\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -151,7 +148,7 @@ static int mp3_exec(struct ast_channel *chan, void *data) res = ast_set_write_format(chan, AST_FORMAT_SLINEAR); if (res < 0) { ast_log(LOG_WARNING, "Unable to set write format to signed linear\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -224,35 +221,25 @@ static int mp3_exec(struct ast_channel *chan, void *data) if (!res && owriteformat) ast_set_write_format(chan, owriteformat); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, mp3_exec, synopsis, descrip); } -static const char *description(void) -{ - return tdesc; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Silly MP3 Application"); diff --git a/apps/app_nbscat.c b/apps/app_nbscat.c index 188aa3c97..346584346 100644 --- a/apps/app_nbscat.c +++ b/apps/app_nbscat.c @@ -55,8 +55,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #define AF_LOCAL AF_UNIX #endif -static char *tdesc = "Silly NBS Stream Application"; - static char *app = "NBScat"; static char *synopsis = "Play an NBS local stream"; @@ -65,7 +63,6 @@ static char *descrip = " NBScat: Executes nbscat to listen to the local NBS stream.\n" "User can exit by pressing any key\n."; -LOCAL_USER_DECL; static int NBScatplay(int fd) { @@ -109,7 +106,7 @@ static int timed_read(int fd, void *data, int datalen) static int NBScat_exec(struct ast_channel *chan, void *data) { int res=0; - struct localuser *u; + struct ast_module_user *u; int fds[2]; int ms = -1; int pid = -1; @@ -122,11 +119,11 @@ static int NBScat_exec(struct ast_channel *chan, void *data) short frdata[160]; } myf; - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds)) { ast_log(LOG_WARNING, "Unable to create socketpair\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -136,7 +133,7 @@ static int NBScat_exec(struct ast_channel *chan, void *data) res = ast_set_write_format(chan, AST_FORMAT_SLINEAR); if (res < 0) { ast_log(LOG_WARNING, "Unable to set write format to signed linear\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -206,35 +203,25 @@ static int NBScat_exec(struct ast_channel *chan, void *data) if (!res && owriteformat) ast_set_write_format(chan, owriteformat); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app, NBScat_exec, synopsis, descrip); } -static const char *description(void) -{ - return tdesc; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Silly NBS Stream Application"); diff --git a/apps/app_osplookup.c b/apps/app_osplookup.c index 88d90a984..c700e81ce 100644 --- a/apps/app_osplookup.c +++ b/apps/app_osplookup.c @@ -878,29 +878,29 @@ static int osp_finish(int handle, int recorded, int cause, time_t start, time_t static int ospauth_exec(struct ast_channel* chan, void* data) { int res; - struct localuser* u; + struct ast_module_user *u; const char* provider = OSP_DEF_PROVIDER; int priority_jump = 0; - struct varshead* headp; - struct ast_var_t* current; - const char* source = ""; - const char* token = ""; + struct varshead *headp; + struct ast_var_t *current; + const char *source = ""; + const char *token = ""; int handle; unsigned int timelimit; char buffer[OSP_INTSTR_SIZE]; - const char* status; - char* tmp; + const char *status; + char *tmp; AST_DECLARE_APP_ARGS(args, AST_APP_ARG(provider); AST_APP_ARG(options); ); - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (!(tmp = ast_strdupa(data))) { ast_log(LOG_ERROR, "Out of memory\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -959,7 +959,7 @@ static int ospauth_exec(struct ast_channel* chan, void* data) res = 0; } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } @@ -973,16 +973,16 @@ static int ospauth_exec(struct ast_channel* chan, void* data) static int osplookup_exec(struct ast_channel* chan, void* data) { int res, cres; - struct localuser* u; - const char* provider = OSP_DEF_PROVIDER; + struct ast_module_user *u; + const char *provider = OSP_DEF_PROVIDER; int priority_jump = 0; - struct varshead* headp; + struct varshead *headp; struct ast_var_t* current; - const char* srcdev = ""; + const char *srcdev = ""; char buffer[OSP_TOKSTR_SIZE]; struct osp_result result; - const char* status; - char* tmp; + const char *status; + char *tmp; AST_DECLARE_APP_ARGS(args, AST_APP_ARG(exten); @@ -995,11 +995,11 @@ static int osplookup_exec(struct ast_channel* chan, void* data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (!(tmp = ast_strdupa(data))) { ast_log(LOG_ERROR, "Out of memory\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -1039,7 +1039,7 @@ static int osplookup_exec(struct ast_channel* chan, void* data) ast_log(LOG_DEBUG, "OSPLookup: source device '%s'\n", srcdev); if ((cres = ast_autoservice_start(chan)) < 0) { - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -1090,7 +1090,7 @@ static int osplookup_exec(struct ast_channel* chan, void* data) } if ((cres = ast_autoservice_stop(chan)) < 0) { - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -1105,7 +1105,7 @@ static int osplookup_exec(struct ast_channel* chan, void* data) res = 0; } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } @@ -1119,7 +1119,7 @@ static int osplookup_exec(struct ast_channel* chan, void* data) static int ospnext_exec(struct ast_channel* chan, void* data) { int res; - struct localuser* u; + struct ast_module_user *u; int priority_jump = 0; int cause = 0; struct varshead* headp; @@ -1139,11 +1139,11 @@ static int ospnext_exec(struct ast_channel* chan, void* data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (!(tmp = ast_strdupa(data))) { ast_log(LOG_ERROR, "Out of memory\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -1243,7 +1243,7 @@ static int ospnext_exec(struct ast_channel* chan, void* data) res = 0; } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } @@ -1257,30 +1257,30 @@ static int ospnext_exec(struct ast_channel* chan, void* data) static int ospfinished_exec(struct ast_channel* chan, void* data) { int res = 1; - struct localuser* u; + struct ast_module_user *u; int priority_jump = 0; int cause = 0; - struct varshead* headp; - struct ast_var_t* current; + struct varshead *headp; + struct ast_var_t *current; int inhandle = OSP_INVALID_HANDLE; int outhandle = OSP_INVALID_HANDLE; int recorded = 0; time_t start, connect, end; unsigned int release; char buffer[OSP_INTSTR_SIZE]; - const char* status; - char* tmp; + const char *status; + char *tmp; AST_DECLARE_APP_ARGS(args, AST_APP_ARG(cause); AST_APP_ARG(options); ); - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (!(tmp = ast_strdupa(data))) { ast_log(LOG_ERROR, "Out of memory\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -1376,7 +1376,7 @@ static int ospfinished_exec(struct ast_channel* chan, void* data) res = 0; } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } @@ -1602,9 +1602,7 @@ static struct ast_cli_entry osp_cli = { osp_usage }; -LOCAL_USER_DECL; - -static int load_module(void* mod) +static int load_module(void) { int res; @@ -1618,7 +1616,7 @@ static int load_module(void* mod) return res; } -static int unload_module(void* mod) +static int unload_module(void) { int res; @@ -1629,26 +1627,21 @@ static int unload_module(void* mod) res |= ast_cli_unregister(&osp_cli); osp_unload(); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int reload(void* mod) +static int reload(void) { osp_unload(); osp_load(); - return 0; -} -static const char* description(void) -{ - return "Open Settlement Protocol Applications"; -} - -static const char* key(void) -{ - return ASTERISK_GPL_KEY; + return 0; } -STD_MOD(MOD_1, reload, NULL, NULL); +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Open Settlement Protocol Applications", + .load = load_module, + .unload = unload_module, + .reload = reload, + ); diff --git a/apps/app_page.c b/apps/app_page.c index 0d8965976..93146c9cd 100644 --- a/apps/app_page.c +++ b/apps/app_page.c @@ -63,7 +63,6 @@ static const char *page_descrip = " q - quiet, do not play beep to caller\n" " r - record the page into a file (see 'r' for app_meetme)\n"; -LOCAL_USER_DECL; enum { PAGE_DUPLEX = (1 << 0), @@ -143,7 +142,7 @@ static void launch_page(struct ast_channel *chan, const char *meetmeopts, const static int page_exec(struct ast_channel *chan, void *data) { - struct localuser *u; + struct ast_module_user *u; char *options; char *tech, *resource; char meetmeopts[80]; @@ -159,11 +158,11 @@ static int page_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); if (!(app = pbx_findapp("MeetMe"))) { ast_log(LOG_WARNING, "There is no MeetMe application available!\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; }; @@ -204,36 +203,26 @@ static int page_exec(struct ast_channel *chan, void *data) pbx_exec(chan, app, meetmeopts); } - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app_page); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application(app_page, page_exec, page_synopsis, page_descrip); } -static const char *description(void) -{ - return "Page Multiple Phones"; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Page Multiple Phones"); diff --git a/apps/app_parkandannounce.c b/apps/app_parkandannounce.c index 1b30a4902..66203b1b0 100644 --- a/apps/app_parkandannounce.c +++ b/apps/app_parkandannounce.c @@ -51,8 +51,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/lock.h" #include "asterisk/utils.h" -static char *tdesc = "Call Parking and Announce Application"; - static char *app = "ParkAndAnnounce"; static char *synopsis = "Park and Announce"; @@ -75,7 +73,6 @@ static char *descrip = "call was placed. Use with the Local channel to allow the dialplan to make\n" "use of this information.\n"; -LOCAL_USER_DECL; static int parkandannounce_exec(struct ast_channel *chan, void *data) { @@ -93,18 +90,18 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data) struct outgoing_helper oh; int outstate; - struct localuser *u; + struct ast_module_user *u; if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "ParkAndAnnounce requires arguments: (announce:template|timeout|dial|[return_context])\n"); return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); l=strlen(data)+2; if (!(orig_s = ast_malloc(l))) { - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } s=orig_s; @@ -114,7 +111,7 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data) if(! template) { ast_log(LOG_WARNING, "PARK: An announce template must be defined\n"); free(orig_s); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -126,7 +123,7 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data) if(!dial) { ast_log(LOG_WARNING, "PARK: A dial resource must be specified i.e: Console/dsp or Zap/g1/5551212\n"); free(orig_s); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } else { dialtech=strsep(&dial, "/"); @@ -159,7 +156,7 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data) if(atoi(priority) < 0) { ast_log(LOG_WARNING, "Priority '%s' must be a number > 0\n", priority); free(orig_s); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } /* At this point we have a priority and maybe an extension and a context */ @@ -206,13 +203,13 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data) ast_log(LOG_WARNING, "PARK: Channel %s was never answered for the announce.\n", dchan->name); ast_hangup(dchan); free(orig_s); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } } else { ast_log(LOG_WARNING, "PARK: Unable to allocate announce channel.\n"); free(orig_s); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } @@ -250,36 +247,26 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data) ast_hangup(dchan); free(orig_s); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { /* return ast_register_application(app, park_exec); */ return ast_register_application(app, parkandannounce_exec, synopsis, descrip); } -static const char *description(void) -{ - return tdesc; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Call Parking and Announce Application"); diff --git a/apps/app_playback.c b/apps/app_playback.c index 32114cad7..f3788c351 100644 --- a/apps/app_playback.c +++ b/apps/app_playback.c @@ -47,8 +47,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/localtime.h" #include "asterisk/say.h" -static char *tdesc = "Sound File Playback Application"; - static char *app = "Playback"; static char *synopsis = "Play a file"; @@ -69,7 +67,6 @@ static char *descrip = " SUCCESS | FAILED\n" ; -LOCAL_USER_DECL; static struct ast_config *say_cfg; /* save the say' api calls. @@ -381,7 +378,7 @@ static struct ast_cli_entry myclis[] = { static int playback_exec(struct ast_channel *chan, void *data) { int res = 0; - struct localuser *u; + struct ast_module_user *u; char *tmp; int option_skip=0; int option_say=0; @@ -400,7 +397,7 @@ static int playback_exec(struct ast_channel *chan, void *data) tmp = ast_strdupa(data); - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); AST_STANDARD_APP_ARGS(args, tmp); if (args.options) { @@ -446,11 +443,11 @@ static int playback_exec(struct ast_channel *chan, void *data) pbx_builtin_setvar_helper(chan, "PLAYBACKSTATUS", mres ? "FAILED" : "SUCCESS"); } done: - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return res; } -static int reload(void *mod) +static int reload(void) { if (say_cfg) { ast_config_destroy(say_cfg); @@ -464,13 +461,13 @@ static int reload(void *mod) return 0; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application(app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); if (say_cfg) ast_config_destroy(say_cfg); @@ -478,21 +475,15 @@ static int unload_module(void *mod) return res; } -static int load_module(void *mod) +static int load_module(void) { - reload(mod); + reload(); ast_cli_register_multiple(myclis, sizeof(myclis)/sizeof(struct ast_cli_entry)); return ast_register_application(app, playback_exec, synopsis, descrip); } -static const char *description(void) -{ - return tdesc; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD(MOD_1,reload,NULL,NULL); +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Sound File Playback Application", + .load = load_module, + .unload = unload_module, + .reload = reload, + ); diff --git a/apps/app_privacy.c b/apps/app_privacy.c index 45c80ac16..277ffba4c 100644 --- a/apps/app_privacy.c +++ b/apps/app_privacy.c @@ -49,8 +49,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #define PRIV_CONFIG "privacy.conf" -static char *tdesc = "Require phone number to be entered, if no CallerID sent"; - static char *app = "PrivacyManager"; static char *synopsis = "Require phone number to be entered, if no CallerID sent"; @@ -76,7 +74,6 @@ static char *descrip = " SUCCESS | FAILED \n" ; -LOCAL_USER_DECL; static int privacy_exec (struct ast_channel *chan, void *data) { @@ -87,7 +84,7 @@ static int privacy_exec (struct ast_channel *chan, void *data) int x = 0; char *s; char phone[30]; - struct localuser *u; + struct ast_module_user *u; struct ast_config *cfg = NULL; char *parse = NULL; int priority_jump = 0; @@ -97,7 +94,8 @@ static int privacy_exec (struct ast_channel *chan, void *data) AST_APP_ARG(options); ); - LOCAL_USER_ADD (u); + u = ast_module_user_add(chan); + if (!ast_strlen_zero(chan->cid.cid_num)) { if (option_verbose > 2) ast_verbose (VERBOSE_PREFIX_3 "CallerID Present: Skipping\n"); @@ -106,13 +104,12 @@ static int privacy_exec (struct ast_channel *chan, void *data) if (chan->_state != AST_STATE_UP) { res = ast_answer(chan); if (res) { - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } } - if (!ast_strlen_zero((char *)data)) - { + if (!ast_strlen_zero(data)) { parse = ast_strdupa(data); AST_STANDARD_APP_ARGS(args, parse); @@ -211,34 +208,25 @@ static int privacy_exec (struct ast_channel *chan, void *data) ast_config_destroy(cfg); } - LOCAL_USER_REMOVE (u); - return 0; + ast_module_user_remove(u); + + return 0; } -static int unload_module(void *mod) +static int unload_module(void) { int res; res = ast_unregister_application (app); - STANDARD_HANGUP_LOCALUSERS; + ast_module_user_hangup_all(); return res; } -static int load_module(void *mod) +static int load_module(void) { return ast_register_application (app, privacy_exec, synopsis, descrip); } -static const char *description(void) -{ - return tdesc; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD1; +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Require phone number to be entered, if no CallerID sent"); diff --git a/apps/app_queue.c b/apps/app_queue.c index 3e2f15340..448e8ca74 100644 --- a/apps/app_queue.c +++ b/apps/app_queue.c @@ -124,8 +124,6 @@ static struct strategy { #define RES_OUTOFMEMORY (-2) /* Out of memory */ #define RES_NOSUCHQUEUE (-3) /* No such queue */ -static char *tdesc = "True Call Queueing"; - static char *app = "Queue"; static char *synopsis = "Queue a call for a call queue"; @@ -289,7 +287,6 @@ struct callattempt { struct member *member; }; -LOCAL_USER_DECL; struct queue_ent { struct call_queue *parent; /*!< What queue is our parent */ @@ -2936,7 +2933,7 @@ static void reload_queue_members(void) static int pqm_exec(struct ast_channel *chan, void *data) { - struct localuser *lu; + struct ast_module_user *lu; char *parse; int priority_jump = 0; AST_DECLARE_APP_ARGS(args, @@ -2954,7 +2951,7 @@ static int pqm_exec(struct ast_channel *chan, void *data) AST_STANDARD_APP_ARGS(args, parse); - LOCAL_USER_ADD(lu); + lu = ast_module_user_add(chan); if (args.options) { if (strchr(args.options, 'j')) @@ -2963,7 +2960,7 @@ static int pqm_exec(struct ast_channel *chan, void *data) if (ast_strlen_zero(args.interface)) { ast_log(LOG_WARNING, "Missing interface argument to PauseQueueMember ([queuename]|interface[|options])\n"); - LOCAL_USER_REMOVE(lu); + ast_module_user_remove(lu); return -1; } @@ -2972,16 +2969,16 @@ static int pqm_exec(struct ast_channel *chan, void *data) if (priority_jump || ast_opt_priority_jumping) { if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) { pbx_builtin_setvar_helper(chan, "PQMSTATUS", "NOTFOUND"); - LOCAL_USER_REMOVE(lu); + ast_module_user_remove(lu); return 0; } } - LOCAL_USER_REMOVE(lu); + ast_module_user_remove(lu); pbx_builtin_setvar_helper(chan, "PQMSTATUS", "NOTFOUND"); return -1; } - LOCAL_USER_REMOVE(lu); + ast_module_user_remove(lu); pbx_builtin_setvar_helper(chan, "PQMSTATUS", "PAUSED"); return 0; @@ -2989,7 +2986,7 @@ static int pqm_exec(struct ast_channel *chan, void *data) static int upqm_exec(struct ast_channel *chan, void *data) { - struct localuser *lu; + struct ast_module_user *lu; char *parse; int priority_jump = 0; AST_DECLARE_APP_ARGS(args, @@ -3007,7 +3004,7 @@ static int upqm_exec(struct ast_channel *chan, void *data) AST_STANDARD_APP_ARGS(args, parse); - LOCAL_USER_ADD(lu); + lu = ast_module_user_add(chan); if (args.options) { if (strchr(args.options, 'j')) @@ -3016,7 +3013,7 @@ static int upqm_exec(struct ast_channel *chan, void *data) if (ast_strlen_zero(args.interface)) { ast_log(LOG_WARNING, "Missing interface argument to PauseQueueMember ([queuename]|interface[|options])\n"); - LOCAL_USER_REMOVE(lu); + ast_module_user_remove(lu); return -1; } @@ -3025,16 +3022,16 @@ static int upqm_exec(struct ast_channel *chan, void *data) if (priority_jump || ast_opt_priority_jumping) { if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) { pbx_builtin_setvar_helper(chan, "UPQMSTATUS", "NOTFOUND"); - LOCAL_USER_REMOVE(lu); + ast_module_user_remove(lu); return 0; } } - LOCAL_USER_REMOVE(lu); + ast_module_user_remove(lu); pbx_builtin_setvar_helper(chan, "UPQMSTATUS", "NOTFOUND"); return -1; } - LOCAL_USER_REMOVE(lu); + ast_module_user_remove(lu); pbx_builtin_setvar_helper(chan, "UPQMSTATUS", "UNPAUSED"); return 0; @@ -3043,7 +3040,7 @@ static int upqm_exec(struct ast_channel *chan, void *data) static int rqm_exec(struct ast_channel *chan, void *data) { int res=-1; - struct localuser *lu; + struct ast_module_user *lu; char *parse, *temppos = NULL; int priority_jump = 0; AST_DECLARE_APP_ARGS(args, @@ -3062,7 +3059,7 @@ static int rqm_exec(struct ast_channel *chan, void *data) AST_STANDARD_APP_ARGS(args, parse); - LOCAL_USER_ADD(lu); + lu = ast_module_user_add(chan); if (ast_strlen_zero(args.interface)) { args.interface = ast_strdupa(chan->name); @@ -3096,7 +3093,7 @@ static int rqm_exec(struct ast_channel *chan, void *data) break; } - LOCAL_USER_REMOVE(lu); + ast_module_user_remove(lu); return res; } @@ -3104,7 +3101,7 @@ static int rqm_exec(struct ast_channel *chan, void *data) static int aqm_exec(struct ast_channel *chan, void *data) { int res=-1; - struct localuser *lu; + struct ast_module_user *lu; char *parse, *temppos = NULL; int priority_jump = 0; AST_DECLARE_APP_ARGS(args, @@ -3124,7 +3121,7 @@ static int aqm_exec(struct ast_channel *chan, void *data) AST_STANDARD_APP_ARGS(args, parse); - LOCAL_USER_ADD(lu); + lu = ast_module_user_add(chan); if (ast_strlen_zero(args.interface)) { args.interface = ast_strdupa(chan->name); @@ -3169,14 +3166,14 @@ static int aqm_exec(struct ast_channel *chan, void *data) break; } - LOCAL_USER_REMOVE(lu); + ast_module_user_remove(lu); return res; } static int ql_exec(struct ast_channel *chan, void *data) { - struct localuser *u; + struct ast_module_user *u; char *parse; AST_DECLARE_APP_ARGS(args, @@ -3192,7 +3189,7 @@ static int ql_exec(struct ast_channel *chan, void *data) return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); parse = ast_strdupa(data); @@ -3201,14 +3198,14 @@ static int ql_exec(struct ast_channel *chan, void *data) if (ast_strlen_zero(args.queuename) || ast_strlen_zero(args.uniqueid) || ast_strlen_zero(args.peer) || ast_strlen_zero(args.event)) { ast_log(LOG_WARNING, "QueueLog requires arguments (queuename|uniqueid|peer|event[|additionalinfo])\n"); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return -1; } ast_queue_log(args.queuename, args.uniqueid, args.peer, args.event, "%s", args.params ? args.params : ""); - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } @@ -3217,7 +3214,7 @@ static int queue_exec(struct ast_channel *chan, void *data) { int res=-1; int ringing=0; - struct localuser *lu; + struct ast_module_user *lu; const char *user_priority; const char *max_penalty_str; int prio; @@ -3245,7 +3242,7 @@ static int queue_exec(struct ast_channel *chan, void *data) parse = ast_strdupa(data); AST_STANDARD_APP_ARGS(args, parse); - LOCAL_USER_ADD(lu); + lu = ast_module_user_add(chan); /* Setup our queue entry */ memset(&qe, 0, sizeof(qe)); @@ -3473,7 +3470,7 @@ check_turns: set_queue_result(chan, reason); res = 0; } - LOCAL_USER_REMOVE(lu); + ast_module_user_remove(lu); return res; } @@ -3482,7 +3479,7 @@ static int queue_function_qac(struct ast_channel *chan, char *cmd, char *data, c { int count = 0; struct call_queue *q; - struct localuser *lu; + struct ast_module_user *lu; struct member *m; buf[0] = '\0'; @@ -3492,7 +3489,7 @@ static int queue_function_qac(struct ast_channel *chan, char *cmd, char *data, c return -1; } - LOCAL_USER_ADD(lu); + lu = ast_module_user_add(chan); AST_LIST_LOCK(&queues); AST_LIST_TRAVERSE(&queues, q, list) { @@ -3515,7 +3512,7 @@ static int queue_function_qac(struct ast_channel *chan, char *cmd, char *data, c ast_log(LOG_WARNING, "queue %s was not found\n", data); snprintf(buf, len, "%d", count); - LOCAL_USER_REMOVE(lu); + ast_module_user_remove(lu); return 0; } @@ -3524,7 +3521,7 @@ static int queue_function_queuewaitingcount(struct ast_channel *chan, char *cmd, { int count = 0; struct call_queue *q; - struct localuser *lu; + struct ast_module_user *lu; buf[0] = '\0'; @@ -3533,7 +3530,7 @@ static int queue_function_queuewaitingcount(struct ast_channel *chan, char *cmd, return -1; } - LOCAL_USER_ADD(lu); + lu = ast_module_user_add(chan); AST_LIST_LOCK(&queues); AST_LIST_TRAVERSE(&queues, q, list) { @@ -3551,13 +3548,13 @@ static int queue_function_queuewaitingcount(struct ast_channel *chan, char *cmd, ast_log(LOG_WARNING, "queue %s was not found\n", data); snprintf(buf, len, "%d", count); - LOCAL_USER_REMOVE(lu); + ast_module_user_remove(lu); return 0; } static int queue_function_queuememberlist(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { - struct localuser *u; + struct ast_module_user *u; struct call_queue *q; struct member *m; @@ -3569,7 +3566,7 @@ static int queue_function_queuememberlist(struct ast_channel *chan, char *cmd, c return -1; } - LOCAL_USER_ADD(u); + u = ast_module_user_add(chan); AST_LIST_LOCK(&queues); AST_LIST_TRAVERSE(&queues, q, list) { @@ -3603,7 +3600,7 @@ static int queue_function_queuememberlist(struct ast_channel *chan, char *cmd, c /* We should already be terminated, but let's make sure. */ buf[len - 1] = '\0'; - LOCAL_USER_REMOVE(u); + ast_module_user_remove(u); return 0; } @@ -4328,7 +4325,7 @@ static struct ast_cli_entry cli_remove_queue_member = { { "remove", "queue", "member", NULL }, handle_remove_queue_member, "Removes a channel from a specified queue", rqm_cmd_usage, complete_remove_queue_member }; -static int unload_module(void *mod) +static int unload_module(void) { int res; @@ -4352,14 +4349,14 @@ static int unload_module(void *mod) res |= ast_custom_function_unregister(&queuewaitingcount_function); res |= ast_unregister_application(app); - clear_and_free_interfaces(); + ast_module_user_hangup_all(); - STANDARD_HANGUP_LOCALUSERS; + clear_and_free_interfaces(); return res; } -static int load_module(void *mod) +static int load_module(void) { int res; @@ -4393,21 +4390,15 @@ static int load_module(void *mod) return res; } -static int reload(void *mod) +static int reload(void) { reload_queues(); return 0; } -static const char *description(void) -{ - return tdesc; -} - -static const char *key(void) -{ - return ASTERISK_GPL_KEY; -} - -STD_MOD(MOD_1, reload, NULL, NULL); +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "True Call Queueing", + .load = load_module, + .unload = unload_module, + .reload = reload, + ); diff --git a/apps/app_random.c b/apps/app_random.c index 60ac2c141..8484f656d 100644 --- a/apps/app_random.c +++ b/apps/app_random.c @@ -41,8 +41,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") /*! \todo The Random() app should be removed from trunk following the release of 1.4 */ -static char *tdesc = "Random goto"; - static char *app_random = "Random"; static char *random_synopsis = "Conditionally branches, based upon a probability"; @@ -52,12 +50,11 @@ static char *random_descrip = " probability := INTEGER in the range 1 to 100\n" "DEPRECATED: Use GotoIf($[${RAND(1,100)} > ]?